]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
- Do not draw graph when no valid constrains have been set
authorMichal Malý <madcatxster@devoid-pointer.net>
Fri, 10 Oct 2014 17:12:50 +0000 (19:12 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Fri, 10 Oct 2014 17:12:50 +0000 (19:12 +0200)
- Use system locale to parse values from ExportGraphToImageDialog

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

index 74fdbea584720cf85ea9f4b5645217bfba08c749..2a7b6bd4dcfdd5ef33bdcf8d1e15566969f5c7e9 100644 (file)
@@ -496,6 +496,10 @@ void DataManager::onExportGraphToImage()
       std::shared_ptr<SignalController> 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(),
index 35f545255c1ce4c35e40df1c350d5f8dd190df9c..705283c69654e43ad2657426feaf438548fb3ade 100644 (file)
@@ -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]);
 }
index c1002332550d0051d80a32c87f95631084092061..d2c2dddafb40e09e1b87a0e46bcd04855fb04c7e 100644 (file)
@@ -35,7 +35,21 @@ class ExportGraphToImageDialog : public QDialog
 {
   Q_OBJECT
 
-  typedef std::tuple<double, double, double, double> 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 {
index 719d9c5fb4756469d56f6db826dec364363be167..cda8ca91a8aad83c27a0bbd72e03c72583129779 100644 (file)
@@ -40,6 +40,7 @@ SignalDrawer::SignalDrawer(std::shared_ptr<SignalController> 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)
index a7eba19ee1a2359636c3d2283b1211782a5c102f..e3de035d9c37e746b52cc44578bce35a92153c70 100644 (file)
@@ -118,6 +118,7 @@ private:
   int m_gHeight;
   int m_gWidth;
   int m_leftGraphOffset;
+  bool m_validConstraints;
 
   double m_oldRelXMax;
   double m_oldRelXMin;