]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
- Rewrite sequence container to use std::map
authorMichal Malý <madcatxster@devoid-pointer.net>
Thu, 12 Mar 2015 23:27:05 +0000 (00:27 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Thu, 12 Mar 2015 23:27:05 +0000 (00:27 +0100)
- Modify the handling of sequences and single runs to avoid unnecessary
updates
- Add option to close loaded sequence

12 files changed:
datamanager.cpp
datamanager.h
gui/mainwindow.cpp
gui/mainwindow.h
gui/mainwindow.ui
main.cpp
sequence.cpp
sequence.h
sequenceselectormodel.cpp
sequenceselectormodel.h
singlerunsselectormodel.cpp
singlerunsselectormodel.h

index 7e08414f505a5fc443be67fe48c0eadb1e11885e..971bb6c886ad0f8a332aaad2591a057785a44a47 100644 (file)
@@ -37,15 +37,16 @@ const char DataManager::UNIT_WATTS_TEXT[] = {0x57, 0x00};
 const QStringList DataManager::DATA_DIR_SUFFIX = QStringList() << "*.D";
 const QString DataManager::S_RES_DATAEXPORT("Error while exporting data to file");
 const QString DataManager::S_RES_IMGEXPORT("Error while exporting graph to image");
+const std::string DataManager::S_SEQ_KEY_SINGLE_RUNS = "Single runs";
 
 DataManager::DataManager(QObject* parent) :
   QObject(parent),
-  m_sequenceRejected(false),
+  m_prevSequenceKey(""),
   m_exportRawDataDialog(DataFileExporter::supportedFormats()),
   m_graphToImageExportDialog(ImageDrawer::supportedImageFormats())
 {
-  m_sequences.push_back(std::make_pair<const QString, std::shared_ptr<Sequence>>("Single runs", std::shared_ptr<Sequence>(new Sequence())));
-  m_seqSelModel.setSequences(&m_sequences);
+  m_sequences[S_SEQ_KEY_SINGLE_RUNS] = std::shared_ptr<Sequence>(new Sequence());
+  m_seqSelModel.setSequences(allSequenceKeys());
   m_sigNameCodec = QTextCodec::codecForName("ISO-8859-1");
 }
 
@@ -54,9 +55,9 @@ void DataManager::saveUserDataOnExit()
   enum class Choice { YESTOALL, NOTOALL, ASK };
   Choice c = Choice::ASK;
 
-  for (NameSequencePair& nsp : m_sequences) {
-    const QString seqName = nsp.first;
-    std::shared_ptr<Sequence> seq = nsp.second;
+  for (auto& s : m_sequences) {
+    const QString seqName = QString::fromStdString(s.first);
+    std::shared_ptr<Sequence> seq = s.second;
     SingleRunsMap::const_iterator it = seq->begin();
 
     while (it != seq->end()) {
@@ -99,6 +100,17 @@ void DataManager::saveUserDataOnExit()
 
 /* Private functions */
 
+std::vector<std::string> DataManager::allSequenceKeys() const
+{
+  std::vector<std::string> keys;
+
+  keys.reserve(m_sequences.size());
+  for (auto& s : m_sequences)
+    keys.push_back(s.first);
+
+  return keys;
+}
+
 void DataManager::generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string> &keys)
 {
   for (const std::string& key : keys) {
@@ -151,26 +163,6 @@ void DataManager::generateRawDataWriteList(DataFileExporter::WriteList& writeLis
   }
 }
 
-std::shared_ptr<Sequence> DataManager::sequenceByKey(const QString& key)
-{
-  for (NameSequencePair p : m_sequences) {
-    if (p.first.compare(key) == 0)
-      return p.second;
-  }
-  return nullptr;
-}
-
-int DataManager::sequenceIdxByKey(const QString& key)
-{
-  int idx = 0;
-  for (NameSequencePair p : m_sequences) {
-    if (p.first.compare(key) == 0)
-      return idx;
-    idx++;
-  }
-  return -1;
-}
-
 Signal::Equipment DataManager::equipmentFromFiletype(HPCS_FileType filetype)
 {
   switch (filetype) {
@@ -566,7 +558,7 @@ void DataManager::onExportRawData()
 void DataManager::onLoadSequence(const QString& dir)
 {
   QDir rootDir(dir);
-  QString uniqueName;
+  std::string uniqueName;
   int nameSuffix = 1;
   bool isUnique = false;
   std::shared_ptr<Sequence> nSeq(new Sequence());
@@ -586,53 +578,57 @@ void DataManager::onLoadSequence(const QString& dir)
   }
 
   /* Generate unique name for the sequence */
-  uniqueName = rootDir.dirName();
+  uniqueName = rootDir.dirName().toStdString();
   while (!isUnique) {
-    for (const NameSequencePair& nsp : m_sequences) {
+
+    for (const auto& nsp : m_sequences) {
       if (nsp.first.compare(uniqueName) == 0) {
         if (nameSuffix == 1)
-          uniqueName += QString("_1");
+          uniqueName += "_1";
         else
-          uniqueName.replace(uniqueName.length()-1, 1, QString::number(nameSuffix));
+          uniqueName.replace(uniqueName.length()-1, 1, std::to_string(nameSuffix));
         nameSuffix++;
       } else
         isUnique = true;
     }
   }
 
-  m_sequences.push_back(NameSequencePair(uniqueName, nSeq));
-  m_seqSelModel.seqenceAdded();
-
-  emit setActiveSequenceIndex(m_sequences.size()-1);
+  m_sequences[uniqueName] = nSeq;
+  m_seqSelModel.addSequence(uniqueName);
+  onSequenceSelected(QString::fromStdString(uniqueName));
 }
 
 void DataManager::onLoadSingleRun(const QString& str)
 {
-  QString uniqueName;
+  std::string uniqueName;
   int nameSuffix = 1;
-  std::shared_ptr<Sequence> srseq = m_sequences.at(0).second;
+  std::shared_ptr<Sequence> srseq = m_sequences[S_SEQ_KEY_SINGLE_RUNS];
   QDir dir(str);
   std::shared_ptr<SingleRunData> srdata = loadSingleRun(dir);
   if (srdata == nullptr)
     return;
 
   /* Generate unique name for the single run data */
-  uniqueName = dir.dirName();
-  while (srseq->at(uniqueName.toStdString()) != nullptr) {
-    Logger::log(Logger::Level::INFO, ME_SENDER_STR, "[" + uniqueName + "]: Already there, adjusting.");
+  uniqueName = dir.dirName().toStdString();
+  while (srseq->at(uniqueName) != nullptr) {
+    Logger::log(Logger::Level::INFO, ME_SENDER_STR, "[" + QString::fromStdString(uniqueName) + "]: Already there, adjusting.");
     if (nameSuffix == 1) {
-      uniqueName += QString("_1");
+      uniqueName += "_1";
     } else {
-      uniqueName.replace(uniqueName.length()-1, 1, QString::number(nameSuffix));
+      uniqueName.replace(uniqueName.length()-1, 1, std::to_string(nameSuffix));
     }
     nameSuffix++;
   }
 
-  //TODO: Rewrite to std::string completely
+  srseq->add(uniqueName, srdata);
+  srseq->setSelectedRun(uniqueName);
 
-  srseq->add(uniqueName.toStdString(), srdata);
-  srseq->setSelectedRun(uniqueName.toStdString());
-  emit setActiveSequenceIndex(0);
+  if (srseq == m_activeSequence) {
+    m_singleSelModel.addSingleRun(uniqueName);
+    onSingleRunSelected(QString::fromStdString(uniqueName));
+    emit setActiveSingleRunKey(uniqueName);
+  } else
+    onSequenceSelected(QString::fromStdString(S_SEQ_KEY_SINGLE_RUNS));
 }
 
 void DataManager::onSaveChanges()
@@ -648,7 +644,7 @@ void DataManager::onSaveChanges()
 
 void DataManager::onSaveAllChanges()
 {
-  for (NameSequencePair& p : m_sequences) {
+  for (auto& p : m_sequences) {
     std::shared_ptr<Sequence> s = p.second;
     SingleRunsMap::iterator it = s->begin();
 
@@ -659,34 +655,82 @@ void DataManager::onSaveAllChanges()
   }
 }
 
-void DataManager::onSequenceSelected(const QString& key)
+void DataManager::onSequenceClose(const QString& key)
 {
-  if (m_sequenceRejected) {
-    m_sequenceRejected = false;
+  std::shared_ptr<Sequence> seq;
+  QString newKey;
+  std::string stdKey = key.toStdString();
+
+  if (stdKey.compare(S_SEQ_KEY_SINGLE_RUNS) == 0) {
+    Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + "\"Single runs\" cannot be removed");
+    return;
+  }
+
+  try {
+    seq = m_sequences.at(stdKey);
+  } catch (std::out_of_range) {
+    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, __QFUNC__ + "[" + key + "]: No such sequence.");
     return;
   }
 
-  m_activeSequence = sequenceByKey(key);
-  if (m_activeSequence == nullptr) {
-    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, "[" + key + "]: No such sequence.");
-    m_activeSequence = sequenceByKey(m_prevSequenceKey);
-    m_sequenceRejected = true;
-    emit setActiveSequenceIndex(sequenceIdxByKey(m_prevSequenceKey));
+  SequenceMap::const_iterator cit = m_sequences.cbegin();
+  while (cit != m_sequences.cend()) {
+    if (cit->first.compare(stdKey) == 0)
+      break;
+    cit++;
+  }
+  if (cit == m_sequences.cend()) {
+    Logger::log(Logger::Level::CRITICAL, ME_SENDER_STR, __QFUNC__ + "Sequence \"" + key + "\" is valid but the key was not found");
+    return;
+  }
+  /* Closed single run was the last in the sequence */
+  if (std::next(cit) == m_sequences.cend())
+    newKey = QString::fromStdString(std::prev(cit)->first);
+  else
+    newKey = QString::fromStdString(std::next(cit)->first);
+
+  m_sequences.erase(stdKey);
+  m_prevSequenceKey = "";
+  m_seqSelModel.setSequences(allSequenceKeys());
+  emit cleanDashboard();
+  onSequenceSelected(newKey);
+}
+
+void DataManager::onSequenceSelected(const QString& key)
+{
+  std::shared_ptr<Sequence> seq;
+  std::string stdKey = key.toStdString();
+
+  try {
+    seq = m_sequences.at(stdKey);
+  } catch (std::out_of_range) {
+    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, __QFUNC__ + "[" + key + "]: No such sequence");
+    if (m_prevSequenceKey.compare("") != 0)
+      onSequenceSelected(QString::fromStdString(m_prevSequenceKey));
+    else
+      m_singleSelModel.setSingleRuns(std::vector<std::string>()); /* Make sure we empty the list of single runs */
     return;
   }
 
-  if (m_activeSequence->count() < 1) {
-    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, "There are no runs in sequence [" + key + "].");
+  if (seq == m_activeSequence)
+    return;
+
+  if (seq->count() < 1) {
+    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, __QFUNC__ + "There are no runs in sequence [" + key + "].");
     QMessageBox::information(nullptr, "Data manager", "Sequence '" + key + "' does not contain any runs.");
     /* Revert to previous sequence */
-    m_activeSequence = sequenceByKey(m_prevSequenceKey);
-    m_sequenceRejected = true;
-    emit setActiveSequenceIndex(sequenceIdxByKey(m_prevSequenceKey));
+    if (m_prevSequenceKey.compare("") != 0)
+      onSequenceSelected(QString::fromStdString(m_prevSequenceKey));
+    else
+      m_singleSelModel.setSingleRuns(std::vector<std::string>()); /* Make sure we empty the list of single runs */
     return;
   }
 
-  m_prevSequenceKey = key;
+  m_activeSequence = seq;
+  m_prevSequenceKey = stdKey;
   m_singleSelModel.setSingleRuns(m_activeSequence->allRunKeys());
+  emit setActiveSequenceKey(stdKey);
+  onSingleRunSelected(QString::fromStdString(m_activeSequence->selectedRunKey()));
   emit setActiveSingleRunKey(m_activeSequence->selectedRunKey());
 }
 
@@ -732,11 +776,13 @@ void DataManager::onSingleRunClose(const QString& key)
 
 void DataManager::onSingleRunSelected(const QString& key)
 {
+  std::string stdKey = key.toStdString();
+
   if (m_activeSequence == nullptr)
     return;
 
-  if (!m_activeSequence->setSelectedRun(key.toStdString())) {
-    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, "[" + key + "]: No such single run.");
+  if (!m_activeSequence->setSelectedRun(stdKey)) {
+    Logger::log(Logger::Level::ERROR, ME_SENDER_STR, __QFUNC__ + "[" + key + "]: No such single run.");
     return;
   }
 
@@ -749,5 +795,5 @@ void DataManager::onSingleRunSelected(const QString& key)
   }
 
   emit setSingleRunInfo(srdata->methodName(), srdata->operatorName(), srdata->sampleInfo(), srdata->date().toString() +" "+ srdata->time().toString());
-  Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, "Single run changed.");
+  Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + "Single run changed.");
 }
index 221c5dd1d81c173652efda4df5c380a7df93f03d..0c0dcaab79455a5695a6b4ed674d28cd93d5d701 100644 (file)
@@ -40,6 +40,7 @@
 #include "metatypes.h"
 
 typedef std::function<void (DataFileExporter::WriteList&, const std::shared_ptr<SingleRunData>, std::vector<std::string>&)> GeneratorFunc;
+typedef std::map<const std::string, std::shared_ptr<Sequence>> SequenceMap;
 
 class DataManager : public QObject
 {
@@ -51,6 +52,7 @@ public:
   SingleRunsSelectorModel* singleRunsSelectorModel() { return &m_singleSelModel; }
 
 private:
+  std::vector<std::string> allSequenceKeys() const;
   Signal::Equipment equipmentFromFiletype(HPCS_FileType filetype);
   void generateIntegDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys);
   void generateRawDataWriteList(DataFileExporter::WriteList& writeList, const std::shared_ptr<SingleRunData> sr, const std::vector<std::string>& keys);
@@ -65,13 +67,11 @@ private:
   Signal::YUnit yunitFromUnitStr(const char* str);
 
   std::shared_ptr<Sequence> m_activeSequence;
-  QString m_prevSequenceKey;
-  QString m_prevSingleRunKey;
+  std::string m_prevSequenceKey;
   SequenceSelectorModel m_seqSelModel;
-  bool m_sequenceRejected;
   SingleRunsSelectorModel m_singleSelModel;
   QTextCodec* m_sigNameCodec;
-  std::vector<NameSequencePair> m_sequences;
+  SequenceMap m_sequences;
   DataFilesLoader m_dfl;
 
   ExportRawDataDialog m_exportRawDataDialog;
@@ -91,11 +91,12 @@ private:
 
   static const QString S_RES_DATAEXPORT;
   static const QString S_RES_IMGEXPORT;
+  static const std::string S_SEQ_KEY_SINGLE_RUNS;
 
 signals:
   void addToDashboard(SignalView* sw);
   void cleanDashboard();
-  void setActiveSequenceIndex(const int idx);
+  void setActiveSequenceKey(const std::string& key);
   void setActiveSingleRunKey(const std::string& key);
   void setSingleRunInfo(const QString& method, const QString& operatorname, const QString& sample, const QString& datetime);
 
@@ -107,6 +108,7 @@ public slots:
   void onLoadSingleRun(const QString& dir);
   void onSaveChanges();
   void onSaveAllChanges();
+  void onSequenceClose(const QString& key);
   void onSequenceSelected(const QString& key);
   void onSingleRunClose(const QString& key);
   void onSingleRunSelected(const QString& key);
index 1a49029ed8cfa86b795cee87890bbe8e5e1fd258..f89b986faf5b4fe2798b5f6f16ec38e1b1dc1c78 100644 (file)
@@ -70,6 +70,7 @@ void MainWindow::connectActions()
   connect(ui->actionLoad_single_run, SIGNAL(triggered()), this, SLOT(onLoadSingleRun()));
   connect(ui->actionLoad_sequence, SIGNAL(triggered()), this, SLOT(onLoadSequence()));
   connect(ui->actionClose_single_run, SIGNAL(triggered()), this, SLOT(onCloseSingleRun()));
+  connect(ui->actionClose_sequence, SIGNAL(triggered()), this, SLOT(onCloseSequence()));
   connect(ui->actionSave_changes, SIGNAL(triggered()), this, SLOT(onSaveChanges()));
   connect(ui->actionSave_all_changes, SIGNAL(triggered()), this, SLOT(onSaveAllChanges()));
   /* EXPORT menu */
@@ -79,8 +80,8 @@ void MainWindow::connectActions()
   /* HELP menu */
   connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(onAboutAnyanka()));
   /* RUN/SEQ cboxes*/
-  connect(ui->qcbox_sequence, SIGNAL(currentIndexChanged(QString)), this, SLOT(onSequenceSelected(QString)));
-  connect(ui->qcbox_singleRun, SIGNAL(currentIndexChanged(QString)), this, SLOT(onSingleRunSelected(QString)));
+  connect(ui->qcbox_sequence, SIGNAL(activated(QString)), this, SLOT(onSequenceSelected(QString)));
+  connect(ui->qcbox_singleRun, SIGNAL(activated(QString)), this, SLOT(onSingleRunSelected(QString)));
 }
 
 /* Public slots */
@@ -124,17 +125,22 @@ void MainWindow::onCloseSingleRun()
   emit singleRunClose(ui->qcbox_singleRun->currentText());
 }
 
-void MainWindow::onSetActiveSequenceIndex(const int idx)
+void MainWindow::onSetActiveSequenceKey(const std::string& key)
 {
-  if (ui->qcbox_sequence->currentIndex() == idx)
-    emit onSequenceSelected(ui->qcbox_sequence->currentText());
-  else
-    ui->qcbox_sequence->setCurrentIndex(idx);
+  const SequenceSelectorModel* model = static_cast<const SequenceSelectorModel*>(ui->qcbox_sequence->model());
+  if (key.compare("") == 0)
+    ui->qcbox_sequence->setCurrentIndex(-1);
+
+  int idx = model->idxFromKey(key);
+  ui->qcbox_sequence->setCurrentIndex(idx);
 }
 
 void MainWindow::onSetActiveSingleRunKey(const std::string& key)
 {
   const SingleRunsSelectorModel* model = static_cast<const SingleRunsSelectorModel*>(ui->qcbox_singleRun->model());
+  if (key.compare("") == 0)
+    ui->qcbox_singleRun->setCurrentIndex(-1);
+
   int idx = model->idxFromKey(key);
   ui->qcbox_singleRun->setCurrentIndex(idx);
 }
@@ -154,6 +160,11 @@ void MainWindow::onAboutAnyanka()
   aa.exec();
 }
 
+void MainWindow::onCloseSequence()
+{
+  emit sequenceClose(ui->qcbox_sequence->currentText());
+}
+
 void MainWindow::onIntegrateBaselineSelected()
 {
   emit integrateBaselineMode();
index 912586d255bd22dd893f3f128ee2ca4ca636e58c..bab4ce61a04abfe15c7e2528d0bb8d8253b0826d 100644 (file)
@@ -63,12 +63,13 @@ private:
 public slots:
   void onAddToDashboard(SignalView* sw);
   void onCleanDashboard();
-  void onSetActiveSequenceIndex(const int idx);
+  void onSetActiveSequenceKey(const std::string& key);
   void onSetActiveSingleRunKey(const std::string& key);
   void onSetSingleRunInfo(const QString& method, const QString& operatorname, const QString& sample, const QString& datetime);
 
 private slots:
   void onAboutAnyanka();
+  void onCloseSequence();
   void onCloseSingleRun();
   void onExportGraphToImage() { emit exportGraphToImage(); }
   void onExportPeaks() { emit exportPeaks(); }
@@ -94,6 +95,7 @@ signals:
   void loadSingleRun(const QString& dir);
   void saveChanges();
   void saveAllChanges();
+  void sequenceClose(const QString& str);
   void sequenceSelected(const QString& str);
   void singleRunClose(const QString& key);
   void singleRunSelected(const QString& str);
index 23cf885625d1849328b5a37d07668bc0a8acce79..f2fea0d72858a7dd8c313710db5a5969284ee79d 100644 (file)
     <addaction name="actionLoad_sequence"/>
     <addaction name="separator"/>
     <addaction name="actionClose_single_run"/>
+    <addaction name="actionClose_sequence"/>
     <addaction name="separator"/>
     <addaction name="actionSave_changes"/>
     <addaction name="actionSave_all_changes"/>
     <string>Close single run</string>
    </property>
   </action>
+  <action name="actionClose_sequence">
+   <property name="text">
+    <string>Close sequence</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections/>
index f141a3303f76c975e68b9a175f47f7214fd6c81f..be923d3e850d25783de7d3d846627881db0aed9e 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -50,11 +50,11 @@ int main(int argc, char *argv[])
   mWin->setSequenceListModel(dMgr->sequenceSelectorModel());
   mWin->setSingleRunsListModel(dMgr->singleRunsSelectorModel());
   /* Default to no sequence on load */
-  mWin->onSetActiveSequenceIndex(-1);
+  mWin->onSetActiveSequenceKey("");
   /* Connect SIGNALS/SLOTS */
   QObject::connect(dMgr.get(), SIGNAL(addToDashboard(SignalView*)), mWin.get(), SLOT(onAddToDashboard(SignalView*)));
   QObject::connect(dMgr.get(), SIGNAL(cleanDashboard()), mWin.get(), SLOT(onCleanDashboard()));
-  QObject::connect(dMgr.get(), SIGNAL(setActiveSequenceIndex(int)), mWin.get(), SLOT(onSetActiveSequenceIndex(int)));
+  QObject::connect(dMgr.get(), SIGNAL(setActiveSequenceKey(std::string)), mWin.get(), SLOT(onSetActiveSequenceKey(std::string)));
   QObject::connect(dMgr.get(), SIGNAL(setActiveSingleRunKey(std::string)), mWin.get(), SLOT(onSetActiveSingleRunKey(std::string)));
   QObject::connect(dMgr.get(), SIGNAL(setSingleRunInfo(QString,QString,QString,QString)), mWin.get(), SLOT(onSetSingleRunInfo(QString,QString,QString,QString)));
   QObject::connect(mWin.get(), SIGNAL(exportGraphToImage()),dMgr.get(), SLOT(onExportGraphToImage()));
@@ -65,6 +65,7 @@ int main(int argc, char *argv[])
   QObject::connect(mWin.get(), SIGNAL(loadSingleRun(QString)), dMgr.get(), SLOT(onLoadSingleRun(QString)));
   QObject::connect(mWin.get(), SIGNAL(loadSequence(QString)), dMgr.get(), SLOT(onLoadSequence(QString)));
   QObject::connect(mWin.get(), SIGNAL(sequenceSelected(QString)), dMgr.get(), SLOT(onSequenceSelected(QString)));
+  QObject::connect(mWin.get(), SIGNAL(sequenceClose(QString)), dMgr.get(), SLOT(onSequenceClose(QString)));
   QObject::connect(mWin.get(), SIGNAL(singleRunClose(QString)), dMgr.get(), SLOT(onSingleRunClose(QString)));
   QObject::connect(mWin.get(), SIGNAL(singleRunSelected(QString)), dMgr.get(), SLOT(onSingleRunSelected(QString)));
 
index 06aee4420e96c4e4e2311c1ec725ec52d32afb6e..aae81016055becbd1a33ae36f65ea9db1d4d5432 100644 (file)
@@ -68,6 +68,11 @@ void Sequence::remove(const std::string& key)
   m_singleRuns.erase(m_singleRuns.find(key));
 }
 
+void Sequence::removeAll()
+{
+  m_singleRuns.clear();
+}
+
 std::shared_ptr<SingleRunData> Sequence::selectedRun()
 {
   if (m_selectedRunKey.compare("") == 0)
index d5862cdee2b24387b04056503bca4a6e5f4bd89d..d79c28333c3b84a577808609716832858a9c6364 100644 (file)
@@ -49,6 +49,7 @@ public:
   size_t count() const { return m_singleRuns.size(); }
   SingleRunsMap::iterator end() { return m_singleRuns.end(); }
   void remove(const std::string& key);
+  void removeAll();
   std::string selectedRunKey() const { return m_selectedRunKey; }
   std::shared_ptr<SingleRunData> selectedRun();
   bool setSelectedRun(const std::string& key);
index d37d6c951f80c4c0ad747740b32f5ba59101d742..d90aae1881d33ce3a0dbf3c782d3cba668463ae3 100644 (file)
 #include "sequenceselectormodel.h"
 
 SequenceSelectorModel::SequenceSelectorModel(QObject* parent) :
-  QAbstractListModel(parent),
-  m_activeSequences(nullptr)
+  QAbstractListModel(parent)
 {
 }
 
-SequenceSelectorModel::SequenceSelectorModel(const std::vector<NameSequencePair>* sequences, QObject* parent) :
-  QAbstractListModel(parent),
-  m_activeSequences(sequences)
+void SequenceSelectorModel::addSequence(const std::string& key)
 {
+  beginInsertRows(QModelIndex(), m_sequenceKeys.size(), m_sequenceKeys.size());
+  m_sequenceKeys.push_back(key);
+  endInsertRows();
 }
 
 QVariant SequenceSelectorModel::data(const QModelIndex& index, int role) const
@@ -39,37 +39,39 @@ QVariant SequenceSelectorModel::data(const QModelIndex& index, int role) const
   int seqIdx = 0;
   if (role != Qt::DisplayRole)
     return QVariant();
-  if (m_activeSequences == nullptr)
+  if (m_sequenceKeys.size() == 0)
     return QVariant();
 
-  std::vector<NameSequencePair>::const_iterator cit = m_activeSequences->cbegin();
-  while (cit != m_activeSequences->cend()) {
+  for (const std::string& s : m_sequenceKeys) {
     if (seqIdx == index.row())
-      return cit->first;
-    seqIdx++; cit++;
+      return QString::fromStdString(s);
+    seqIdx++;
   }
+
   return QVariant();
 }
 
-int SequenceSelectorModel::rowCount(const QModelIndex& parent) const
+int SequenceSelectorModel::idxFromKey(const std::string& key) const
 {
-  Q_UNUSED(parent);
+  int idx = 0;
+  for (const std::string& s : m_sequenceKeys) {
+    if (s.compare(key) == 0) return idx;
+    else idx++;
+  }
 
-  if (m_activeSequences == nullptr)
-    return 0;
-  else
-    return m_activeSequences->size();
+  return -1;
 }
 
-void SequenceSelectorModel::seqenceAdded()
+int SequenceSelectorModel::rowCount(const QModelIndex& parent) const
 {
-  beginInsertRows(QModelIndex(), m_activeSequences->size()-1, m_activeSequences->size()-1);
-  endInsertRows();
+  Q_UNUSED(parent);
+
+  return m_sequenceKeys.size();
 }
 
-void SequenceSelectorModel::setSequences(const std::vector<NameSequencePair>* sequences)
+void SequenceSelectorModel::setSequences(const std::vector<std::string> sequenceKeys)
 {
   beginResetModel();
-  m_activeSequences = sequences;
+  m_sequenceKeys = sequenceKeys;
   endResetModel();
 }
index d917a3c3a1ce5fd26cad0b6c3a40219b64b4b021..5a29473f3d4b310ecad65ec68841e4ef9265611a 100644 (file)
 #define SEQUENCESELECTORMODEL_H
 
 #include "sequence.h"
-#include <mutex>
 #include <QtCore/QAbstractListModel>
 
-typedef std::pair<const QString, std::shared_ptr<Sequence>> NameSequencePair;
-
 class SequenceSelectorModel : public QAbstractListModel
 {
 public:
   SequenceSelectorModel(QObject* parent = nullptr);
-  SequenceSelectorModel(const std::vector<NameSequencePair>* sequences, QObject* parent = nullptr);
+  void addSequence(const std::string& key);
   QVariant data(const QModelIndex& index, int role) const;
-  void seqenceAdded();
   int rowCount(const QModelIndex& parent) const;
-  void setSequences(const std::vector<NameSequencePair>* sequence);
+  int idxFromKey(const std::string& key) const;
+  void setSequences(const std::vector<std::string> sequenceKeys);
 
 private:
-  const std::vector<NameSequencePair>* m_activeSequences;
+  std::vector<std::string> m_sequenceKeys;
 };
 
 #endif // SEQUENCESELECTORMODEL_H
index 057f0e1fb35fb9a9d947863a089c65cc1fe228f4..9d342afbaca0f19082247adb8878cb4ce9f053cb 100644 (file)
@@ -27,6 +27,13 @@ SingleRunsSelectorModel::SingleRunsSelectorModel(QObject *parent) :
 {
 }
 
+void SingleRunsSelectorModel::addSingleRun(const std::string& key)
+{
+  beginInsertRows(QModelIndex(), m_singleRunKeys.size(), m_singleRunKeys.size());
+  m_singleRunKeys.push_back(key);
+  endInsertRows();
+}
+
 QVariant SingleRunsSelectorModel::data(const QModelIndex& index, int role) const
 {
   int runIdx = 0;
@@ -51,8 +58,6 @@ int SingleRunsSelectorModel::idxFromKey(const std::string& key) const
     else idx++;
   }
 
-   /* if (idx == m_singleRunKeys.size())
-    * Unknown key */
   return -1;
 }
 
index 91fccea466d8352045c234bf8c8263e4534b4e52..b3ce156ffa73ebf99184de11b2097486297033f3 100644 (file)
@@ -32,6 +32,7 @@ class SingleRunsSelectorModel : public QAbstractListModel
   Q_OBJECT
 public:
   explicit SingleRunsSelectorModel(QObject* parent = nullptr);
+  void addSingleRun(const std::string& key);
   QVariant data(const QModelIndex& index, int role) const;
   int idxFromKey(const std::string& key) const;
   int rowCount(const QModelIndex& parent) const;