Skip to content

Commit

Permalink
Check if auto scale is enabled before automatically calling fitInView (
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 22, 2024
1 parent 299ac6e commit 8d62ffa
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 115 deletions.
8 changes: 2 additions & 6 deletions OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp
Expand Up @@ -559,7 +559,7 @@ void PlotWindowContainer::clearPlotWindow()
return;
}
removePlotCurves(pPlotWindow);
pPlotWindow->fitInView();
pPlotWindow->updatePlot();
MainWindow::instance()->getVariablesWidget()->updateVariablesTreeHelper(subWindowList(QMdiArea::ActivationHistoryOrder).last());
}

Expand Down Expand Up @@ -657,11 +657,7 @@ void PlotWindowContainer::updatePlotWindows(QString variable)
if (variable.compare(pPlotCurve->getFileName()) == 0) {
pPlotWindow->getPlot()->removeCurve(pPlotCurve);
pPlotCurve->detach();
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
}
} // is plotWidget
Expand Down
54 changes: 9 additions & 45 deletions OMEdit/OMEditLIB/Plotting/VariablesWidget.cpp
Expand Up @@ -1620,11 +1620,7 @@ void VariablesWidget::variablesUpdated()
}
}
}
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
}
updateVariablesTreeHelper(MainWindow::instance()->getPlotWindowContainer()->currentSubWindow());
Expand Down Expand Up @@ -1682,11 +1678,7 @@ void VariablesWidget::updateVariablesTreeHelper(QMdiSubWindow *pSubWindow)
mpVariablesTreeModel->setData(mpVariablesTreeModel->variablesTreeItemIndex(pVariablesTreeItem), Qt::Checked, Qt::CheckStateRole);
}
// if a simulation was left running, make a replot
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
}
mpVariablesTreeModel->blockSignals(state);
Expand Down Expand Up @@ -2024,22 +2016,14 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize());
}
}
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
} else if (!pVariablesTreeItem->isChecked()) { // if user unchecks the variable then remove it from the plot
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
QString curveTitle = pPlotCurve->getNameStructure();
if (curveTitle.compare(pVariablesTreeItem->getVariableName()) == 0) {
pPlotWindow->getPlot()->removeCurve(pPlotCurve);
pPlotCurve->detach();
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
break;
}
}
Expand Down Expand Up @@ -2142,11 +2126,7 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
}
}

if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
}
} else if (!pVariablesTreeItem->isChecked()) { // if user unchecks the variable then remove it from the plot
Expand Down Expand Up @@ -2206,11 +2186,7 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
i++;
}
if (curveRemoved) {
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
}
} else { // if plottype is INTERACTIVE then
Expand Down Expand Up @@ -2262,11 +2238,7 @@ void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickne
if (pVariablesTreeItem->getVariableName().endsWith("." + pPlotCurve->getYVariable())) {
pPlotWindow->getPlot()->removeCurve(pPlotCurve);
pPlotCurve->detach();
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
break;
}
}
Expand Down Expand Up @@ -2332,11 +2304,7 @@ void VariablesWidget::unitChanged(const QModelIndex &index)
}
}
}
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
} catch (PlotException &e) {
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), e.what(), Helper::ok);
Expand Down Expand Up @@ -2679,11 +2647,7 @@ void VariablesWidget::timeUnitChanged(QString unit)
}
pPlotCurve->setData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize());
}
if (pPlotWindow->getAutoScaleButton()->isChecked()) {
pPlotWindow->fitInView();
} else {
pPlotWindow->updatePlot();
}
pPlotWindow->updatePlot();
}
}
} catch (PlotException &e) {
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/DrModelica/QuickTour/HelloWorld.onb
Expand Up @@ -33,7 +33,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">The program contains a declaration of a class called &lt;/span>&lt;span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">HelloWorld&lt;/span>&lt;span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;"> with two fields and one equation. The first field is the variable x which is initialized to a start value 1 at the time when the simulation starts. The second field is the variable a, which is a constant that is initialized to 1 at the beginning of the simulation. Such a constant is prefixed by the keyword parameter in order to indicate that it is constant during simulation but is a model parameter that can be changed between simulations.&lt;br />&lt;br />The Modelica program solves a trivial differential equation:    &lt;/span>&lt;span style=" font-family:'Courier New'; font-size:12pt; color:#000000;">x' = - a * x. &lt;/span>&lt;span style=" font-family:'Times New Roman'; font-size:12pt; color:#000000;">The variable x is a state variable that can change value over time. The x ' is the time derivative of x.&lt;br />&lt;/span>&lt;/p>&lt;/td>&lt;/tr>&lt;/table>&lt;/body>&lt;/html></Text>
</TextCell>
<GraphCell style="Graph" closed="false">
<Input>class HelloWorld
<Input>model HelloWorld
Real x(start = 1,fixed=true);
parameter Real a = 1;
equation
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/graphcell.cpp
Expand Up @@ -1494,7 +1494,7 @@ namespace IAEX {
Fix for bug #2047.
*/
// mpPlotWindow->fitInView();
mpPlotWindow->getPlot()->getPlotZoomer()->setZoomBase(false);
mpPlotWindow->updatePlot();
}
catch (PlotException &e)
{
Expand Down
3 changes: 1 addition & 2 deletions OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp
Expand Up @@ -664,8 +664,7 @@ namespace IAEX
}
}
gCell->mpPlotWindow->show();
gCell->mpPlotWindow->fitInView();
gCell->mpPlotWindow->getPlot()->getPlotZoomer()->setZoomBase(false);
gCell->mpPlotWindow->updatePlot();
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions OMPlot/OMPlot/OMPlotGUI/Legend.cpp
Expand Up @@ -104,8 +104,7 @@ void Legend::toggleSign(bool checked)
{
if (mpPlotCurve) {
mpPlot->getParentPlotWindow()->toggleSign(mpPlotCurve, checked);
mpPlot->replot();
mpPlot->getParentPlotWindow()->fitInView();
mpPlot->getParentPlotWindow()->updatePlot();
mpPlotCurve = 0;
}
}
Expand Down
106 changes: 50 additions & 56 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -1402,15 +1402,19 @@ void PlotWindow::setTitle(QString title)

/*!
* \brief PlotWindow::updatePlot
* This function is called by OMEdit when auto scale is false.
* Updates the plot manually.
* Updates the plot.
* If auto scale is enabled then calls PlotWindow::fitInView()
*/
void PlotWindow::updatePlot()
{
mpPlot->updateLayout();
mpPlot->replot();
if (mpPlot->getPlotZoomer()->zoomStack().size() == 1) {
mpPlot->getPlotZoomer()->setZoomBase(false);
if (mpAutoScaleButton->isChecked()) {
fitInView();
} else {
mpPlot->updateLayout();
mpPlot->replot();
if (mpPlot->getPlotZoomer()->zoomStack().size() == 1) {
mpPlot->getPlotZoomer()->setZoomBase(false);
}
}
}

Expand Down Expand Up @@ -1662,6 +1666,15 @@ void PlotWindow::closeEvent(QCloseEvent *event)
event->accept();
}

void PlotWindow::fitInView()
{
mpPlot->getPlotZoomer()->zoom(0);
mpPlot->setAxisAutoScale(QwtPlot::yLeft);
mpPlot->setAxisAutoScale(QwtPlot::xBottom);
mpPlot->replot();
mpPlot->getPlotZoomer()->setZoomBase(false);
}

void PlotWindow::updateCurves()
{
for (auto & p : mpPlot->getPlotCurvesList()) {
Expand Down Expand Up @@ -1805,15 +1818,6 @@ void PlotWindow::setGrid(int index)
mpPlot->replot();
}

void PlotWindow::fitInView()
{
mpPlot->getPlotZoomer()->zoom(0);
mpPlot->setAxisAutoScale(QwtPlot::yLeft);
mpPlot->setAxisAutoScale(QwtPlot::xBottom);
mpPlot->replot();
mpPlot->getPlotZoomer()->setZoomBase(false);
}

void PlotWindow::setLogX(bool on)
{
if (on) {
Expand Down Expand Up @@ -2215,40 +2219,36 @@ void SetupDialog::selectVariable(QString variable)
}
}

bool SetupDialog::setupPlotCurve(VariablePageWidget *pVariablePageWidget)
void SetupDialog::setupPlotCurve(VariablePageWidget *pVariablePageWidget)
{
if (!pVariablePageWidget) {
return false;
}

PlotCurve *pPlotCurve = pVariablePageWidget->getPlotCurve();

/* set the legend title */
if (pPlotCurve->getCustomTitle().isEmpty() && pPlotCurve->title().text().compare(pVariablePageWidget->getLegendTextBox()->text()) == 0) {
pPlotCurve->setCustomTitle("");
} else {
pPlotCurve->setCustomTitle(pVariablePageWidget->getLegendTextBox()->text());
}
/* set the curve color title */
pPlotCurve->setCustomColor(!pVariablePageWidget->getAutomaticColorCheckBox()->isChecked());
if (pVariablePageWidget->getAutomaticColorCheckBox()->isChecked()) {
pVariablePageWidget->setCurveColor(pPlotCurve->pen().color());
pVariablePageWidget->setCurvePickColorButtonIcon();
} else {
QPen pen = pPlotCurve->pen();
pen.setColor(pVariablePageWidget->getCurveColor());
pPlotCurve->setPen(pen);
if (pVariablePageWidget) {
PlotCurve *pPlotCurve = pVariablePageWidget->getPlotCurve();
/* set the legend title */
if (pPlotCurve->getCustomTitle().isEmpty() && pPlotCurve->title().text().compare(pVariablePageWidget->getLegendTextBox()->text()) == 0) {
pPlotCurve->setCustomTitle("");
} else {
pPlotCurve->setCustomTitle(pVariablePageWidget->getLegendTextBox()->text());
}
/* set the curve color title */
pPlotCurve->setCustomColor(!pVariablePageWidget->getAutomaticColorCheckBox()->isChecked());
if (pVariablePageWidget->getAutomaticColorCheckBox()->isChecked()) {
pVariablePageWidget->setCurveColor(pPlotCurve->pen().color());
pVariablePageWidget->setCurvePickColorButtonIcon();
} else {
QPen pen = pPlotCurve->pen();
pen.setColor(pVariablePageWidget->getCurveColor());
pPlotCurve->setPen(pen);
}
/* set the curve style */
QComboBox *pPatternComboBox = pVariablePageWidget->getPatternComboBox();
pPlotCurve->setCurveStyle(pPatternComboBox->itemData(pPatternComboBox->currentIndex()).toInt());
/* set the curve width */
pPlotCurve->setCurveWidth(pVariablePageWidget->getThicknessSpinBox()->value());
/* set the curve visibility */
pPlotCurve->toggleVisibility(!pVariablePageWidget->getHideCheckBox()->isChecked());
/* set the curve toggle sign */
mpPlotWindow->toggleSign(pPlotCurve, pVariablePageWidget->getToggleSignCheckBox()->isChecked());
}
/* set the curve style */
QComboBox *pPatternComboBox = pVariablePageWidget->getPatternComboBox();
pPlotCurve->setCurveStyle(pPatternComboBox->itemData(pPatternComboBox->currentIndex()).toInt());
/* set the curve width */
pPlotCurve->setCurveWidth(pVariablePageWidget->getThicknessSpinBox()->value());
/* set the curve visibility */
pPlotCurve->toggleVisibility(!pVariablePageWidget->getHideCheckBox()->isChecked());
/* set the curve toggle sign */
bool toggleSign = mpPlotWindow->toggleSign(pPlotCurve, pVariablePageWidget->getToggleSignCheckBox()->isChecked());
return toggleSign;
}

void SetupDialog::variableSelected(QListWidgetItem *current, QListWidgetItem *previous)
Expand Down Expand Up @@ -2281,12 +2281,9 @@ void SetupDialog::saveSetup()
void SetupDialog::applySetup()
{
// set the variables attributes
bool requiresFitInView = false;
for (int i = 0 ; i < mpVariablePagesStackedWidget->count() ; i++) {
// if any of the variable requires call to fitinview because of toggle sign.
if (setupPlotCurve(qobject_cast<VariablePageWidget*>(mpVariablePagesStackedWidget->widget(i)))) {
requiresFitInView = true;
}
setupPlotCurve(qobject_cast<VariablePageWidget*>(mpVariablePagesStackedWidget->widget(i)));
}
// set the font sizes. Don't move this line. We should set the font sizes before calling setLegendPosition
mpPlotWindow->getPlot()->setFontSizes(mpTitleFontSizeSpinBox->value(), mpVerticalAxisTitleFontSizeSpinBox->value(), mpVerticalAxisNumbersFontSizeSpinBox->value(),
Expand All @@ -2311,9 +2308,6 @@ void SetupDialog::applySetup()
mpPlotWindow->setXRange(mpXMinimumTextBox->text().toDouble(), mpXMaximumTextBox->text().toDouble());
mpPlotWindow->setYRange(mpYMinimumTextBox->text().toDouble(), mpYMaximumTextBox->text().toDouble());
}
// replot
mpPlotWindow->getPlot()->replot();
if (requiresFitInView) {
mpPlotWindow->fitInView();
}
// update plot
mpPlotWindow->updatePlot();
}
5 changes: 3 additions & 2 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -213,6 +213,8 @@ class PlotWindow : public QMainWindow
void setInteractiveControls(bool enabled);
signals:
void closingDown();
private slots:
void fitInView();
public slots:
void updateCurves();
void updateYAxis(QPair<double, double> minMaxValues);
Expand All @@ -221,7 +223,6 @@ public slots:
void exportDocument();
void printPlot();
void setGrid(int index);
void fitInView();
void setLogX(bool on);
void setLogY(bool on);
void setAutoScale(bool on);
Expand Down Expand Up @@ -353,7 +354,7 @@ class SetupDialog : public QDialog
public:
SetupDialog(PlotWindow *pPlotWindow);
void selectVariable(QString variable);
bool setupPlotCurve(VariablePageWidget *pVariablePageWidget);
void setupPlotCurve(VariablePageWidget *pVariablePageWidget);
public slots:
void variableSelected(QListWidgetItem *current, QListWidgetItem *previous);
void autoScaleChecked(bool checked);
Expand Down

0 comments on commit 8d62ffa

Please sign in to comment.