diff --git a/OMPlot/OMPlotGUI/PlotWindow.cpp b/OMPlot/OMPlotGUI/PlotWindow.cpp index 0c4d1b97a8b..c221c36f4c5 100644 --- a/OMPlot/OMPlotGUI/PlotWindow.cpp +++ b/OMPlot/OMPlotGUI/PlotWindow.cpp @@ -110,9 +110,16 @@ void PlotWindow::initializePlot(QStringList arguments) setCurveStyle(QString(arguments[14]).toInt()); setLegendPosition(QString(arguments[15])); setFooter(QString(arguments[16])); + if (QString(arguments[17]) == "true") { + setAutoScale(true); + } else if (QString(arguments[17]) == "false") { + setAutoScale(false); + } else { + throw PlotException("Invalid input" + arguments[17]); + } /* read variables */ QStringList variablesToRead; - for(int i = 17; i < arguments.length(); i++) + for(int i = 18; i < arguments.length(); i++) variablesToRead.append(QString(arguments[i])); setVariablesList(variablesToRead); @@ -176,6 +183,13 @@ void PlotWindow::setupToolbar() connect(mpPanButton, SIGNAL(toggled(bool)), SLOT(enablePanMode(bool))); toolBar->addWidget(mpPanButton); toolBar->addSeparator(); + // Auto scale + mpAutoScaleButton = new QToolButton(toolBar); + mpAutoScaleButton->setText(tr("Auto Scale")); + mpAutoScaleButton->setCheckable(true); + connect(mpAutoScaleButton, SIGNAL(toggled(bool)), SLOT(setAutoScale(bool))); + toolBar->addWidget(mpAutoScaleButton); + toolBar->addSeparator(); //Fit in View QToolButton *fitInViewButton = new QToolButton(toolBar); fitInViewButton->setText(tr("Fit in View")); @@ -1046,6 +1060,13 @@ void PlotWindow::setLogY(bool on) mpPlot->replot(); } +void PlotWindow::setAutoScale(bool on) +{ + bool state = mpAutoScaleButton->blockSignals(true); + mpAutoScaleButton->setChecked(on); + mpAutoScaleButton->blockSignals(state); +} + void PlotWindow::showSetupDialog() { SetupDialog *pSetupDialog = new SetupDialog(this); diff --git a/OMPlot/OMPlotGUI/PlotWindow.h b/OMPlot/OMPlotGUI/PlotWindow.h index d5c1f673a8f..81971e3f8b3 100644 --- a/OMPlot/OMPlotGUI/PlotWindow.h +++ b/OMPlot/OMPlotGUI/PlotWindow.h @@ -63,6 +63,7 @@ class PlotWindow : public QMainWindow QToolButton *mpNoGridButton; QToolButton *mpZoomButton; QToolButton *mpPanButton; + QToolButton *mpAutoScaleButton; QToolButton *mpSetupButton; QTextStream *mpTextStream; QFile mFile; @@ -94,6 +95,7 @@ class PlotWindow : public QMainWindow QString getGrid(); QCheckBox* getLogXCheckBox(); QCheckBox* getLogYCheckBox(); + QToolButton* getAutoScaleButton() {return mpAutoScaleButton;} void setXLabel(QString label); void setYLabel(QString label); void setUnit(QString unit) {mUnit = unit;} @@ -130,6 +132,7 @@ public slots: void fitInView(); void setLogX(bool on); void setLogY(bool on); + void setAutoScale(bool on); void showSetupDialog(); void showSetupDialog(QString variable); }; diff --git a/OMPlot/OMPlotGUI/main.cpp b/OMPlot/OMPlotGUI/main.cpp index 98ff6dc3088..5f0e22efcb0 100644 --- a/OMPlot/OMPlotGUI/main.cpp +++ b/OMPlot/OMPlotGUI/main.cpp @@ -64,6 +64,7 @@ void printUsage() printf(" --curve-style=STYLE Sets the STYLE of the curve. SolidLine=1, DashLine=2, DotLine=3, DashDotLine=4, DashDotDotLine=5, Sticks=6, Steps=7\n"); printf(" --legend-position=POSITION Sets the POSITION of the legend i.e left, right, top, bottom, none\n"); printf(" --footer=FOOTER Sets the FOOTER of the plot window\n"); + printf(" --auto-scale=[true|false] Use auto scale while plotting.\n"); } int main(int argc, char *argv[]) @@ -86,6 +87,7 @@ int main(int argc, char *argv[]) int curveStyle = 1; QString legendPosition = "top"; QString footer(""); + bool autoScale = true; QStringList vars; QString filename; for(int i = 1; i < argc; i++) @@ -139,6 +141,8 @@ int main(int argc, char *argv[]) legendPosition = argv[i]+18; } else if (strncmp(argv[i], "--footer=", 9) == 0) { footer = argv[i]+9; + } else if (strncmp(argv[i], "--auto-scale=",13) == 0) { + CONSUME_BOOL_ARG(i,13,autoScale); } else if (strncmp(argv[i], "--", 2) == 0) { fprintf(stderr, "Error: Unknown option: %s\n", argv[i]); return 1; @@ -169,6 +173,7 @@ int main(int argc, char *argv[]) arguments.append(QString::number(curveStyle)); arguments.append(legendPosition); arguments.append(footer); + arguments.append(autoScale ? "true" : "false"); arguments.append(vars); // create the plot application object that is used to check that only one instance of application is running PlotApplication app(argc, argv, "OMPlot");