From: Michal MalĂ˝ Date: Thu, 31 Jul 2014 08:34:20 +0000 (+0200) Subject: Store last used state in the ExportGraphToImageDialog instead of X-Git-Tag: 0.3a~9 X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=c437ff4dbd52e0affccac26c1c9bbd2707d8b0b4;p=anyanka.git Store last used state in the ExportGraphToImageDialog instead of DataManager --- diff --git a/datamanager.cpp b/datamanager.cpp index 010e23e..b157967 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -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>("Single runs", std::shared_ptr(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 ctrl) void DataManager::onExportGraphToImage() { - ExportGraphToImageDialog dlg(ImageDrawer::supportedImageFormats(), m_oldExportToImageParams); + QMetaObject::Connection conn; std::shared_ptr 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>& 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 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() diff --git a/datamanager.h b/datamanager.h index 538e966..84713a5 100644 --- a/datamanager.h +++ b/datamanager.h @@ -74,7 +74,7 @@ private: std::vector m_sequences; DataFilesLoader m_dfl; - ExportGraphToImageDialog::Parameters m_oldExportToImageParams; + ExportGraphToImageDialog m_graphToImageExportDialog; static const QString ME_SENDER_STR; static const QString UNIT_KILOVOLTS_TEXT; diff --git a/gui/exportgraphtoimagedialog.cpp b/gui/exportgraphtoimagedialog.cpp index 22d186b..58e7f25 100644 --- a/gui/exportgraphtoimagedialog.cpp +++ b/gui/exportgraphtoimagedialog.cpp @@ -34,6 +34,8 @@ ExportGraphToImageDialog::ExportGraphToImageDialog(QList 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 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(); } diff --git a/gui/exportgraphtoimagedialog.h b/gui/exportgraphtoimagedialog.h index 3530451..c100233 100644 --- a/gui/exportgraphtoimagedialog.h +++ b/gui/exportgraphtoimagedialog.h @@ -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 m_bounds; std::string m_curKey; std::vector m_signalKeys; + QString m_lastUsedPath; + Parameters m_lastUsedParameters; Ui::ExportGraphToImageDialog *ui;