From a68e38c5dade5a922f1334aed6a4dca2d9466346 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Fri, 10 Oct 2014 19:12:50 +0200 Subject: [PATCH] - Do not draw graph when no valid constrains have been set - Use system locale to parse values from ExportGraphToImageDialog --- datamanager.cpp | 12 ++++++--- gui/exportgraphtoimagedialog.cpp | 42 +++++++++++++++++--------------- gui/exportgraphtoimagedialog.h | 16 +++++++++++- signaldrawer.cpp | 7 +++++- signaldrawer.h | 1 + 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/datamanager.cpp b/datamanager.cpp index 74fdbea..2a7b6bd 100644 --- a/datamanager.cpp +++ b/datamanager.cpp @@ -496,6 +496,10 @@ void DataManager::onExportGraphToImage() std::shared_ptr ctrl = sr->controllerAt(key); GraphLayers gl = GraphLayers::GRAPH | GraphLayers::SCALE; ImageDrawer::ReturnCode drwRet; + const double absFromX = m_graphToImageExportDialog.fromX(); + const double absFromY = m_graphToImageExportDialog.fromY(); + const double absToX = m_graphToImageExportDialog.toX(); + const double absToY = m_graphToImageExportDialog.toY(); double relFromX, relFromY, relToX, relToY; if (ctrl == nullptr) { @@ -511,10 +515,10 @@ void DataManager::onExportGraphToImage() if (m_graphToImageExportDialog.includePeaks()) gl |= GraphLayers::INTEGRATION; - relFromX = ctrl->timeToRel(m_graphToImageExportDialog.fromX()); - relToX = ctrl->timeToRel(m_graphToImageExportDialog.toX()); - relFromY = ctrl->valueToRel(m_graphToImageExportDialog.fromY()); - relToY = ctrl->valueToRel(m_graphToImageExportDialog.toY()); + relFromX = ctrl->timeToRel(absFromX); + relToX = ctrl->timeToRel(absToX); + relFromY = ctrl->valueToRel(absFromY); + relToY = ctrl->valueToRel(absToY); ImageDrawer imageDrawer(ctrl); drwRet = imageDrawer.render(m_graphToImageExportDialog.path(), m_graphToImageExportDialog.imageFormat().toLatin1(), diff --git a/gui/exportgraphtoimagedialog.cpp b/gui/exportgraphtoimagedialog.cpp index 35f5452..705283c 100644 --- a/gui/exportgraphtoimagedialog.cpp +++ b/gui/exportgraphtoimagedialog.cpp @@ -65,7 +65,7 @@ void ExportGraphToImageDialog::addSignal(const double fromX, const double fromY, double ExportGraphToImageDialog::fromX() const { try { - return std::get<0>(m_bounds.at(m_curKey)); + return m_bounds.at(m_curKey).fromX; } catch (std::out_of_range&) { return 0; } @@ -74,7 +74,7 @@ double ExportGraphToImageDialog::fromX() const double ExportGraphToImageDialog::fromY() const { try { - return std::get<1>(m_bounds.at(m_curKey)); + return m_bounds.at(m_curKey).fromY; } catch (std::out_of_range&) { return 0; } @@ -125,7 +125,7 @@ QString ExportGraphToImageDialog::selectedSignal() const double ExportGraphToImageDialog::toX() const { try { - return std::get<2>(m_bounds.at(m_curKey)); + return m_bounds.at(m_curKey).toX; } catch (std::out_of_range&) { return 0; } @@ -134,7 +134,7 @@ double ExportGraphToImageDialog::toX() const double ExportGraphToImageDialog::toY() const { try { - return std::get<3>(m_bounds.at(m_curKey)); + return m_bounds.at(m_curKey).toY; } catch (std::out_of_range&) { return 0; } @@ -169,13 +169,13 @@ void ExportGraphToImageDialog::changeBounds(const QString& key) oldBounds = m_bounds.at(m_curKey); fX = ui->qle_fromX->text().toDouble(&ok); - if (ok) std::get<0>(oldBounds) = fX; + if (ok) oldBounds.fromX = fX; fY = ui->qle_fromY->text().toDouble(&ok); - if (ok) std::get<1>(oldBounds) = fY; + if (ok) oldBounds.fromY = fY; tX = ui->qle_toX->text().toDouble(&ok); - if (ok) std::get<2>(oldBounds) = tX; + if (ok) oldBounds.toX = tX; tY = ui->qle_toY->text().toDouble(&ok); - if (ok) std::get<3>(oldBounds) = tY; + if (ok) oldBounds.toY = tY; m_bounds[m_curKey] = oldBounds; } catch (std::out_of_range&) { @@ -184,10 +184,10 @@ void ExportGraphToImageDialog::changeBounds(const QString& key) try { newBounds = m_bounds.at(skey); - ui->qle_fromX->setText(l.toString(std::get<0>(newBounds))); - ui->qle_fromY->setText(l.toString(std::get<1>(newBounds))); - ui->qle_toX->setText(l.toString(std::get<2>(newBounds))); - ui->qle_toY->setText(l.toString(std::get<3>(newBounds))); + ui->qle_fromX->setText(l.toString(newBounds.fromX)); + ui->qle_fromY->setText(l.toString(newBounds.fromY)); + ui->qle_toX->setText(l.toString(newBounds.toX)); + ui->qle_toY->setText(l.toString(newBounds.toY)); m_curKey = skey; } catch (std::out_of_range&) { } @@ -198,17 +198,18 @@ void ExportGraphToImageDialog::checkAndAccept() try { double fX, fY, tX, tY; bool ok; + QLocale l = QLocale::system(); const std::string key = ui->qcbox_signal->currentText().toStdString(); Bounds b = m_bounds.at(key); - fX = ui->qle_fromX->text().toDouble(&ok); - if (ok) std::get<0>(b) = fX; - fY = ui->qle_fromY->text().toDouble(&ok); - if (ok) std::get<1>(b) = fY; - tX = ui->qle_toX->text().toDouble(&ok); - if (ok) std::get<2>(b) = tX; - tY = ui->qle_toY->text().toDouble(&ok); - if (ok) std::get<3>(b) = tY; + fX = l.toDouble(ui->qle_fromX->text(), &ok); + if (ok) b.fromX = fX; + fY = l.toDouble(ui->qle_fromY->text(), &ok); + if (ok) b.fromY = fY; + tX = l.toDouble(ui->qle_toX->text(), &ok); + if (ok) b.toX = tX; + tY = l.toDouble(ui->qle_toY->text(), &ok); + if (ok) b.toY = tY; m_bounds[key] = b; } catch (std::out_of_range&) { @@ -223,6 +224,7 @@ void ExportGraphToImageDialog::checkAndAccept() void ExportGraphToImageDialog::onBrowseClicked() { QFileDialog fdlg(this, "Pick destination", QString()); + fdlg.setAcceptMode(QFileDialog::AcceptSave); if (fdlg.exec() == QDialog::Accepted) ui->qle_destPath->setText(fdlg.selectedFiles()[0]); } diff --git a/gui/exportgraphtoimagedialog.h b/gui/exportgraphtoimagedialog.h index c100233..d2c2ddd 100644 --- a/gui/exportgraphtoimagedialog.h +++ b/gui/exportgraphtoimagedialog.h @@ -35,7 +35,21 @@ class ExportGraphToImageDialog : public QDialog { Q_OBJECT - typedef std::tuple Bounds; + struct Bounds { + Bounds() + { + fromX = 0; fromY = 0; toX = 0; toY = 0; + } + Bounds(const double _fromX, const double _fromY, const double _toX, const double _toY) + { + fromX = _fromX; + fromY = _fromY; + toX = _toX; + toY = _toY; + } + + double fromX, fromY, toX, toY; + }; public: struct Parameters { diff --git a/signaldrawer.cpp b/signaldrawer.cpp index 719d9c5..cda8ca9 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -40,6 +40,7 @@ SignalDrawer::SignalDrawer(std::shared_ptr controller, const C m_relYMax(constraints.toY), m_relYMin(constraints.fromY), m_leftGraphOffset(0), + m_validConstraints(false), m_axisLabelFont(QFont("arial", 10)), m_axisLabelFM(QFontMetrics(m_axisLabelFont)), m_xAxisLabelText("[" + controller->signal()->xunitAsString() + "]"), @@ -142,7 +143,9 @@ bool SignalDrawer::setDimensions(const int width, const int height) //qDebug() << __QFUNC__ << width << height << m_width << m_height; - return draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax); + if (m_validConstraints) + return draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax); + return true; } /** Protected methods **/ @@ -674,6 +677,8 @@ void SignalDrawer::setNewRelativeConstraints(const double fromX, const double fr m_relYMin = toY; m_relYMax = fromY; } + + m_validConstraints = true; } double SignalDrawer::subStep(const double step) diff --git a/signaldrawer.h b/signaldrawer.h index a7eba19..e3de035 100644 --- a/signaldrawer.h +++ b/signaldrawer.h @@ -118,6 +118,7 @@ private: int m_gHeight; int m_gWidth; int m_leftGraphOffset; + bool m_validConstraints; double m_oldRelXMax; double m_oldRelXMin; -- 2.43.5