]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Store last used state in the ExportGraphToImageDialog instead of
authorMichal Malý <madcatxster@devoid-pointer.net>
Thu, 31 Jul 2014 08:34:20 +0000 (10:34 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Thu, 31 Jul 2014 08:34:20 +0000 (10:34 +0200)
DataManager

datamanager.cpp
datamanager.h
gui/exportgraphtoimagedialog.cpp
gui/exportgraphtoimagedialog.h

index 010e23e6f3e083edb80508d7193574ea457ca572..b15796729aaa4ffc8d47534bb21187642dc6a31f 100644 (file)
@@ -39,13 +39,12 @@ const QString DataManager::S_RES_IMGEXPORT("Error while exporting graph to image
 
 DataManager::DataManager(QObject* parent) :
   QObject(parent),
-  m_sequenceRejected(false)
+  m_sequenceRejected(false),
+  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_sigNameCodec = QTextCodec::codecForName("ISO-8859-1");
-
-  m_oldExportToImageParams = ExportGraphToImageDialog::Parameters();
 }
 
 void DataManager::saveUserDataOnExit()
@@ -441,7 +440,7 @@ void DataManager::showOneSignal(std::shared_ptr<SignalController> ctrl)
 
 void DataManager::onExportGraphToImage()
 {
-  ExportGraphToImageDialog dlg(ImageDrawer::supportedImageFormats(), m_oldExportToImageParams);
+  QMetaObject::Connection conn;
   std::shared_ptr<SingleRunData> sr;
   int ret = 1;
 
@@ -451,20 +450,22 @@ void DataManager::onExportGraphToImage()
   if (sr == nullptr)
     return;
 
-  connect(&dlg, &ExportGraphToImageDialog::fileNameChanged, [&dlg, this](const QString& name) {
+  m_graphToImageExportDialog.removeAllSignals();
+
+  conn = connect(&m_graphToImageExportDialog, &ExportGraphToImageDialog::fileNameChanged, [this](const QString& name) {
     int idx = ImageDrawer::guessFormatFromSuffix(name);
     if (idx > 0)
-      dlg.onFormatChanged(idx);
+      m_graphToImageExportDialog.onFormatChanged(idx);
   });
 
   for (const std::pair<std::string, std::shared_ptr<SignalController>>& p : sr->allControllers()) {
     GUIViewport vp = p.second->guiViewport();
-    dlg.addSignal(vp.absFromTime, vp.absFromValue, vp.absToTime, vp.absToValue, p.first);
+    m_graphToImageExportDialog.addSignal(vp.absFromTime, vp.absFromValue, vp.absToTime, vp.absToValue, p.first);
   }
 
   do {
-    if (dlg.exec() == QDialog::Accepted) {
-      const std::string key = dlg.selectedSignal().toStdString();
+    if (m_graphToImageExportDialog.exec() == QDialog::Accepted) {
+      const std::string key = m_graphToImageExportDialog.selectedSignal().toStdString();
       std::shared_ptr<SignalController> ctrl = sr->controllerAt(key);
       GraphLayers gl = GraphLayers::GRAPH | GraphLayers::SCALE;
       ImageDrawer::ReturnCode drwRet;
@@ -475,21 +476,22 @@ void DataManager::onExportGraphToImage()
         continue;
       }
 
-      if (dlg.path().length() == 0) {
+      if (m_graphToImageExportDialog.path().length() == 0) {
         QMessageBox::warning(nullptr, "Error while exporting to image", "Invalid path");
         continue;
       }
 
-      if (dlg.includePeaks())
+      if (m_graphToImageExportDialog.includePeaks())
         gl |= GraphLayers::INTEGRATION;
 
-      relFromX = ctrl->timeToRel(dlg.fromX());
-      relToX = ctrl->timeToRel(dlg.toX());
-      relFromY = ctrl->valueToRel(dlg.fromY());
-      relToY = ctrl->valueToRel(dlg.toY());
+      relFromX = ctrl->timeToRel(m_graphToImageExportDialog.fromX());
+      relToX = ctrl->timeToRel(m_graphToImageExportDialog.toX());
+      relFromY = ctrl->valueToRel(m_graphToImageExportDialog.fromY());
+      relToY = ctrl->valueToRel(m_graphToImageExportDialog.toY());
 
       ImageDrawer imageDrawer(ctrl);
-      drwRet = imageDrawer.render(dlg.path(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(),
+      drwRet = imageDrawer.render(m_graphToImageExportDialog.path(), m_graphToImageExportDialog.imageFormat().toLatin1(),
+                                  m_graphToImageExportDialog.imageWidth(), m_graphToImageExportDialog.imageHeight(),
                                   relFromX, relFromY, relToX, relToY, gl);
       switch (drwRet) {
       case ImageDrawer::ReturnCode::SUCCESS:
@@ -511,7 +513,8 @@ void DataManager::onExportGraphToImage()
       break;
   } while (ret == 1);
 
-  m_oldExportToImageParams = dlg.parameters();
+  disconnect(conn);
+
 }
 
 void DataManager::onExportPeaks()
index 538e966fad5519e10ad2abddab430454e57d2a4d..84713a517f51452b16460653377b28163031d201 100644 (file)
@@ -74,7 +74,7 @@ private:
   std::vector<NameSequencePair> m_sequences;
   DataFilesLoader m_dfl;
 
-  ExportGraphToImageDialog::Parameters m_oldExportToImageParams;
+  ExportGraphToImageDialog m_graphToImageExportDialog;
 
   static const QString ME_SENDER_STR;
   static const QString UNIT_KILOVOLTS_TEXT;
index 22d186bb08e9928bd1b5c3ba45b2e7fd553b5a0f..58e7f25cebb53a19d600d867aa7cde1b8bcf1553 100644 (file)
@@ -34,6 +34,8 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList<QByteArray> formats, Pa
   ui(new Ui::ExportGraphToImageDialog)
 {
   ui->setupUi(this);
+  m_lastUsedPath = "";
+  m_lastUsedParameters = params;
 
   for (const QByteArray ba : formats)
     ui->qcbox_outputFormat->addItem(QString::fromLatin1(ba));
@@ -44,6 +46,7 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList<QByteArray> formats, Pa
   connect(ui->qcbox_signal, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeBounds(QString)));
   connect(ui->qle_destPath, SIGNAL(textChanged(QString)), this, SLOT(onFileNameChanged(QString)));
 
+  ui->qle_destPath->setText(m_lastUsedPath);
   ui->qle_width->setText(QString::number(params.width));
   ui->qle_height->setText(QString::number(params.height));
   ui->qcbox_outputFormat->setCurrentIndex(params.formatIdx);
@@ -104,6 +107,15 @@ QString ExportGraphToImageDialog::path() const
   return ui->qle_destPath->text();
 }
 
+void ExportGraphToImageDialog::removeAllSignals()
+{
+  while (ui->qcbox_signal->count())
+    ui->qcbox_signal->removeItem(0);
+
+  m_signalKeys.clear();
+  m_bounds.clear();
+}
+
 QString ExportGraphToImageDialog::selectedSignal() const
 {
   return ui->qcbox_signal->currentText();
@@ -201,6 +213,9 @@ void ExportGraphToImageDialog::checkAndAccept()
   } catch (std::out_of_range&) {
   }
 
+
+  m_lastUsedParameters = Parameters(imageWidth(), imageHeight(), ui->qcbox_outputFormat->currentIndex(), ui->qck_includeInteg->isChecked());
+  m_lastUsedPath = ui->qle_destPath->text();
   accept();
 }
 
index 3530451b94738ec7fcc81c27509ac9374f5c9fc9..c1002332550d0051d80a32c87f95631084092061 100644 (file)
@@ -59,6 +59,7 @@ public:
   bool includePeaks() const;
   Parameters parameters() const;
   QString path() const;
+  void removeAllSignals();
   QString selectedSignal() const;
   double toX() const;
   double toY() const;
@@ -68,6 +69,8 @@ private:
   std::unordered_map<std::string, Bounds> m_bounds;
   std::string m_curKey;
   std::vector<std::string> m_signalKeys;
+  QString m_lastUsedPath;
+  Parameters m_lastUsedParameters;
 
   Ui::ExportGraphToImageDialog *ui;