THE SOFTWARE.
*/
+#include "logger.h"
#include "sequenceselectormodel.h"
+#include <algorithm>
SequenceSelectorModel::SequenceSelectorModel(QObject* parent) :
QAbstractListModel(parent)
void SequenceSelectorModel::addSequence(const std::string& key)
{
- beginInsertRows(QModelIndex(), m_sequenceKeys.size(), m_sequenceKeys.size());
- m_sequenceKeys.push_back(key);
+ size_t idx;
+ /* Very naive lookup of the index where to put the new key */
+ for (idx = 1; idx < m_sequenceKeys.size(); idx++) {
+ if (key.compare(m_sequenceKeys[idx]) < 0)
+ break;
+ }
+
+ Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, QString("Inserting new key at %1, total items: %2").arg(idx).arg(m_sequenceKeys.size()+1));
+ beginInsertRows(QModelIndex(), idx, idx);
+ m_sequenceKeys.insert(m_sequenceKeys.begin()+idx, key);
endInsertRows();
}
{
beginResetModel();
m_sequenceKeys = sequenceKeys;
+ sortKeys();
endResetModel();
}
+
+/** Private methods */
+void SequenceSelectorModel::sortKeys()
+{
+ std::sort(m_sequenceKeys.begin(), m_sequenceKeys.end(),
+ [](const std::string& s1, const std::string s2) {
+ static const std::string ALWAYS_FIRST = "Single runs";
+
+ if (s1.compare(ALWAYS_FIRST) == 0)
+ return true;
+ if (s2.compare(ALWAYS_FIRST) == 0)
+ return false;
+
+ if (s1.compare(s2) <= 0)
+ return true;
+ return false;}
+ );
+}