Skip to content

Commit

Permalink
Ticket 5447 (#7405)
Browse files Browse the repository at this point in the history
* More fixes for #5447

Add the prefix value in the legend with the actual unit
Added more prefixes from 10^3 to 10^15 and 10^-3 to 10^-15

* Remove the unnecessary methods
  • Loading branch information
adeas31 committed Apr 23, 2021
1 parent b4031d6 commit 0e423e1
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 128 deletions.
18 changes: 9 additions & 9 deletions OMEdit/OMEditLIB/Options/OptionsDialog.cpp
Expand Up @@ -788,9 +788,9 @@ void OptionsDialog::readPlottingSettings()
if (mpSettings->contains("plotting/autoScale")) {
mpPlottingPage->getAutoScaleCheckBox()->setChecked(mpSettings->value("plotting/autoScale").toBool());
}
// read the prefix axes
if (mpSettings->contains("plotting/prefixAxes")) {
mpPlottingPage->getPrefixAxesCheckbox()->setChecked(mpSettings->value("plotting/prefixAxes").toBool());
// read the prefix units
if (mpSettings->contains("plotting/prefixUnits")) {
mpPlottingPage->getPrefixUnitsCheckbox()->setChecked(mpSettings->value("plotting/prefixUnits").toBool());
}
// read the plotting view mode
if (mpSettings->contains("plotting/viewmode")) {
Expand Down Expand Up @@ -1411,8 +1411,8 @@ void OptionsDialog::savePlottingSettings()
{
// save the auto scale
mpSettings->setValue("plotting/autoScale", mpPlottingPage->getAutoScaleCheckBox()->isChecked());
// save the prefix axes
mpSettings->setValue("plotting/prefixAxes", mpPlottingPage->getPrefixAxesCheckbox()->isChecked());
// save the prefix units
mpSettings->setValue("plotting/prefixUnits", mpPlottingPage->getPrefixUnitsCheckbox()->isChecked());
// save plotting view mode
mpSettings->setValue("plotting/viewmode", mpPlottingPage->getPlottingViewMode());
if (mpPlottingPage->getPlottingViewMode().compare(Helper::subWindow) == 0) {
Expand Down Expand Up @@ -4416,13 +4416,13 @@ PlottingPage::PlottingPage(OptionsDialog *pOptionsDialog)
// auto scale
mpAutoScaleCheckBox = new QCheckBox(tr("Auto Scale"));
mpAutoScaleCheckBox->setToolTip(tr("Auto scale the plot to fit in view when variable is plotted."));
// prefix axes
mpPrefixAxesCheckbox = new QCheckBox(tr("Prefix Axes"));
mpPrefixAxesCheckbox->setToolTip(tr("Automatically pick the right prefix for axes values."));
// prefix units
mpPrefixUnitsCheckbox = new QCheckBox(tr("Prefix Units"));
mpPrefixUnitsCheckbox->setToolTip(tr("Automatically pick the right prefix for units."));
// set general groupbox layout
QGridLayout *pGeneralGroupBoxLayout = new QGridLayout;
pGeneralGroupBoxLayout->addWidget(mpAutoScaleCheckBox, 0, 0);
pGeneralGroupBoxLayout->addWidget(mpPrefixAxesCheckbox, 1, 0);
pGeneralGroupBoxLayout->addWidget(mpPrefixUnitsCheckbox, 1, 0);
mpGeneralGroupBox->setLayout(pGeneralGroupBoxLayout);
// Plotting View Mode
mpPlottingViewModeGroupBox = new QGroupBox(tr("Default Plotting View Mode"));
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Options/OptionsDialog.h
Expand Up @@ -800,7 +800,7 @@ class PlottingPage : public QWidget
void setPlottingViewMode(QString value);
QString getPlottingViewMode();
QCheckBox* getAutoScaleCheckBox() {return mpAutoScaleCheckBox;}
QCheckBox* getPrefixAxesCheckbox() {return mpPrefixAxesCheckbox;}
QCheckBox* getPrefixUnitsCheckbox() {return mpPrefixUnitsCheckbox;}
void setCurvePattern(int pattern);
int getCurvePattern();
void setCurveThickness(qreal thickness);
Expand All @@ -817,7 +817,7 @@ class PlottingPage : public QWidget
OptionsDialog *mpOptionsDialog;
QGroupBox *mpGeneralGroupBox;
QCheckBox *mpAutoScaleCheckBox;
QCheckBox *mpPrefixAxesCheckbox;
QCheckBox *mpPrefixUnitsCheckbox;
QGroupBox *mpPlottingViewModeGroupBox;
QRadioButton *mpPlottingTabbedViewRadioButton;
QRadioButton *mpPlottingSubWindowViewRadioButton;
Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp
Expand Up @@ -273,7 +273,7 @@ void PlotWindowContainer::addPlotWindow(bool maximized)
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(OptionsDialog::instance()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setPrefixAxes(OptionsDialog::instance()->getPlottingPage()->getPrefixAxesCheckbox()->isChecked());
pPlotWindow->setPrefixUnits(OptionsDialog::instance()->getPlottingPage()->getPrefixUnitsCheckbox()->isChecked());
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->setXLabel(QString("time"));
pPlotWindow->installEventFilter(this);
Expand Down Expand Up @@ -307,7 +307,7 @@ void PlotWindowContainer::addParametricPlotWindow()
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(OptionsDialog::instance()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setPrefixAxes(OptionsDialog::instance()->getPlottingPage()->getPrefixAxesCheckbox()->isChecked());
pPlotWindow->setPrefixUnits(OptionsDialog::instance()->getPlottingPage()->getPrefixUnitsCheckbox()->isChecked());
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->installEventFilter(this);
QMdiSubWindow *pSubWindow = addSubWindow(pPlotWindow);
Expand Down Expand Up @@ -338,7 +338,7 @@ void PlotWindowContainer::addArrayPlotWindow(bool maximized)
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(OptionsDialog::instance()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setPrefixAxes(OptionsDialog::instance()->getPlottingPage()->getPrefixAxesCheckbox()->isChecked());
pPlotWindow->setPrefixUnits(OptionsDialog::instance()->getPlottingPage()->getPrefixUnitsCheckbox()->isChecked());
QComboBox* unitComboBox = MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox();
if (unitComboBox->currentText() == ""){
int currentIndex = unitComboBox->findText("s", Qt::MatchExactly);
Expand Down Expand Up @@ -381,7 +381,7 @@ PlotWindow* PlotWindowContainer::addInteractivePlotWindow(bool maximized, QStrin
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(OptionsDialog::instance()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setPrefixAxes(OptionsDialog::instance()->getPlottingPage()->getPrefixAxesCheckbox()->isChecked());
pPlotWindow->setPrefixUnits(OptionsDialog::instance()->getPlottingPage()->getPrefixUnitsCheckbox()->isChecked());
pPlotWindow->setTimeUnit(MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox()->currentText());
pPlotWindow->setXLabel(QString("time"));
pPlotWindow->installEventFilter(this);
Expand Down Expand Up @@ -418,7 +418,7 @@ void PlotWindowContainer::addArrayParametricPlotWindow()
pPlotWindow->setTitle("");
pPlotWindow->setLegendPosition("top");
pPlotWindow->setAutoScale(OptionsDialog::instance()->getPlottingPage()->getAutoScaleCheckBox()->isChecked());
pPlotWindow->setPrefixAxes(OptionsDialog::instance()->getPlottingPage()->getPrefixAxesCheckbox()->isChecked());
pPlotWindow->setPrefixUnits(OptionsDialog::instance()->getPlottingPage()->getPrefixUnitsCheckbox()->isChecked());
QComboBox* unitComboBox = MainWindow::instance()->getVariablesWidget()->getSimulationTimeComboBox();
if (unitComboBox->currentText() == ""){
int currentIndex = unitComboBox->findText("s", Qt::MatchExactly);
Expand Down
17 changes: 5 additions & 12 deletions OMPlot/OMPlot/OMPlotGUI/Plot.cpp
Expand Up @@ -232,6 +232,7 @@ void Plot::replot()
pen.setColor(getUniqueColor(i, mPlotCurvesList.length()));
mPlotCurvesList[i]->setPen(pen);
}
mPlotCurvesList[i]->setTitleLocal();
}

if (mpParentPlotWindow->getXCustomLabel().isEmpty()) {
Expand All @@ -240,28 +241,20 @@ void Plot::replot()
|| mpParentPlotWindow->getPlotType() == PlotWindow::PLOTALL
|| mpParentPlotWindow->getPlotType() == PlotWindow::PLOTINTERACTIVE
|| mpParentPlotWindow->getPlotType() == PlotWindow::PLOTARRAY) {
if (mpXScaleDraw->getAxesPrefix().isEmpty()) {
if (mpXScaleDraw->getUnitPrefix().isEmpty()) {
setAxisTitle(QwtPlot::xBottom, QString("%1 (%2)").arg(mpParentPlotWindow->getXLabel(), timeUnit));
} else {
setAxisTitle(QwtPlot::xBottom, QString("%1 (%2%3)").arg(mpParentPlotWindow->getXLabel(), mpXScaleDraw->getAxesPrefix(), timeUnit));
setAxisTitle(QwtPlot::xBottom, QString("%1 (%2%3)").arg(mpParentPlotWindow->getXLabel(), mpXScaleDraw->getUnitPrefix(), timeUnit));
}
} else {
if (mpXScaleDraw->getAxesPrefix().isEmpty()) {
setAxisTitle(QwtPlot::xBottom, "");
} else {
setAxisTitle(QwtPlot::xBottom, QString("(%1)").arg(mpXScaleDraw->getAxesPrefix()));
}
setAxisTitle(QwtPlot::xBottom, "");
}
} else {
setAxisTitle(QwtPlot::xBottom, mpParentPlotWindow->getXCustomLabel());
}

if (mpParentPlotWindow->getYCustomLabel().isEmpty()) {
if (mpYScaleDraw->getAxesPrefix().isEmpty()) {
setAxisTitle(QwtPlot::yLeft, "");
} else {
setAxisTitle(QwtPlot::yLeft, QString("(%1)").arg(mpYScaleDraw->getAxesPrefix()));
}
setAxisTitle(QwtPlot::yLeft, "");
} else {
setAxisTitle(QwtPlot::yLeft, mpParentPlotWindow->getYCustomLabel());
}
Expand Down
29 changes: 17 additions & 12 deletions OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -56,6 +56,7 @@ PlotCurve::PlotCurve(const QString &fileName, const QString &absoluteFilePath, c
setXDisplayUnit(xDisplayUnit);
setYUnit(yUnit);
setYDisplayUnit(yDisplayUnit);
mCustomTitle = "";
setTitleLocal();
/* set curve width and style */
setCurveWidth(mpParentPlot->getParentPlotWindow()->getCurveWidth());
Expand All @@ -74,21 +75,25 @@ PlotCurve::PlotCurve(const QString &fileName, const QString &absoluteFilePath, c

void PlotCurve::setTitleLocal()
{
QString titleStr = getYVariable();
if (!getYDisplayUnit().isEmpty()) {
titleStr += QString(" (%1)").arg(getYDisplayUnit());
}

if (mpParentPlot->getParentPlotWindow()->getPlotType() == PlotWindow::PLOTPARAMETRIC) {
QString xVariable = getXVariable();
if (!getXDisplayUnit().isEmpty()) {
xVariable += QString(" (%1)").arg(getXDisplayUnit());
if (mCustomTitle.isEmpty()) {
QString titleStr = getYVariable();
if (!getYDisplayUnit().isEmpty() || !mpParentPlot->getYScaleDraw()->getUnitPrefix().isEmpty()) {
titleStr += QString(" (%1%2)").arg(mpParentPlot->getYScaleDraw()->getUnitPrefix(), getYDisplayUnit());
}
if (!xVariable.isEmpty()) {
titleStr += QString(" <i>vs</i> %1").arg(xVariable);

if (mpParentPlot->getParentPlotWindow()->getPlotType() == PlotWindow::PLOTPARAMETRIC) {
QString xVariable = getXVariable();
if (!getXDisplayUnit().isEmpty() || !mpParentPlot->getXScaleDraw()->getUnitPrefix().isEmpty()) {
xVariable += QString(" (%1%2)").arg(mpParentPlot->getXScaleDraw()->getUnitPrefix(), getXDisplayUnit());
}
if (!xVariable.isEmpty()) {
titleStr += QString(" <i>vs</i> %1").arg(xVariable);
}
}
QwtPlotItem::setTitle(titleStr);
} else {
QwtPlotItem::setTitle(mCustomTitle);
}
QwtPlotItem::setTitle(titleStr);
}

Qt::PenStyle PlotCurve::getPenStyle(int style)
Expand Down
3 changes: 3 additions & 0 deletions OMPlot/OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -55,6 +55,7 @@ class PlotCurve : public QwtPlotCurve
qreal mWidth;
int mStyle;
bool mToggleSign;
QString mCustomTitle;

Plot *mpParentPlot;
QwtPlotDirectPainter *mpPlotDirectPainter;
Expand Down Expand Up @@ -83,6 +84,8 @@ class PlotCurve : public QwtPlotCurve
int getCurveStyle() {return mStyle;}
bool getToggleSign() const {return mToggleSign;}
void setToggleSign(bool toggleSign) {mToggleSign = toggleSign;}
QString getCustomTitle() const {return mCustomTitle;}
void setCustomTitle(const QString &customTitle) {mCustomTitle = customTitle;}
void setXAxisVector(QVector<double> vector);
void addXAxisValue(double value);
void updateXAxisValue(int index, double value);
Expand Down
29 changes: 17 additions & 12 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -130,7 +130,7 @@ void PlotWindow::initializePlot(QStringList arguments)
throw PlotException("Invalid input" + arguments[17]);
}
setTimeUnit("");
setPrefixAxes(false);
setPrefixUnits(false);
/* read variables */
QStringList variablesToRead;
for(int i = 18; i < arguments.length(); i++)
Expand Down Expand Up @@ -1584,14 +1584,14 @@ QString PlotWindow::getFooter()
#endif
}

bool PlotWindow::getPrefixAxes() const
bool PlotWindow::getPrefixUnits() const
{
return mPrefixAxes;
return mPrefixUnits;
}

void PlotWindow::setPrefixAxes(bool prefixAxes)
void PlotWindow::setPrefixUnits(bool prefixUnits)
{
mPrefixAxes = prefixAxes;
mPrefixUnits = prefixUnits;
}

void PlotWindow::checkForErrors(QStringList variables, QStringList variablesPlotted)
Expand Down Expand Up @@ -1877,7 +1877,7 @@ VariablePageWidget::VariablePageWidget(PlotCurve *pPlotCurve, SetupDialog *pSetu
// general group box
mpGeneralGroupBox = new QGroupBox(tr("General"));
mpLegendLabel = new QLabel(tr("Legend"));
mpLegendTextBox = new QLineEdit(mpPlotCurve->title().text());
mpLegendTextBox = new QLineEdit(mpPlotCurve->getCustomTitle().isEmpty() ? mpPlotCurve->title().text() : mpPlotCurve->getCustomTitle());
mpResetLabelButton = new QPushButton(tr("Reset"));
mpResetLabelButton->setAutoDefault(false);
connect(mpResetLabelButton, SIGNAL(clicked()), SLOT(resetLabel()));
Expand Down Expand Up @@ -1955,6 +1955,7 @@ void VariablePageWidget::setCurvePickColorButtonIcon()

void VariablePageWidget::resetLabel()
{
mpPlotCurve->setCustomTitle("");
mpPlotCurve->setTitleLocal();
mpLegendTextBox->setText(mpPlotCurve->title().text());
}
Expand Down Expand Up @@ -2129,15 +2130,15 @@ SetupDialog::SetupDialog(PlotWindow *pPlotWindow)
mpXMaximumTextBox->setValidator(pDoubleValidator);
mpYMinimumTextBox->setValidator(pDoubleValidator);
mpXMaximumTextBox->setValidator(pDoubleValidator);
mpPrefixAxesCheckbox = new QCheckBox(tr("Prefix Axes"));
mpPrefixAxesCheckbox->setChecked(mpPlotWindow->getPrefixAxes());
mpPrefixUnitsCheckbox = new QCheckBox(tr("Prefix Units"));
mpPrefixUnitsCheckbox->setChecked(mpPlotWindow->getPrefixUnits());
// range tab layout
QVBoxLayout *pRangeTabVerticalLayout = new QVBoxLayout;
pRangeTabVerticalLayout->setAlignment(Qt::AlignTop);
pRangeTabVerticalLayout->addWidget(mpAutoScaleCheckbox);
pRangeTabVerticalLayout->addWidget(mpXAxisGroupBox);
pRangeTabVerticalLayout->addWidget(mpYAxisGroupBox);
pRangeTabVerticalLayout->addWidget(mpPrefixAxesCheckbox);
pRangeTabVerticalLayout->addWidget(mpPrefixUnitsCheckbox);
mpRangeTab->setLayout(pRangeTabVerticalLayout);
// add tabs
mpSetupTabWidget->addTab(mpVariablesTab, tr("Variables"));
Expand Down Expand Up @@ -2190,7 +2191,11 @@ bool SetupDialog::setupPlotCurve(VariablePageWidget *pVariablePageWidget)
PlotCurve *pPlotCurve = pVariablePageWidget->getPlotCurve();

/* set the legend title */
pPlotCurve->setTitle(pVariablePageWidget->getLegendTextBox()->text());
if (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()) {
Expand Down Expand Up @@ -2261,8 +2266,8 @@ void SetupDialog::applySetup()
mpPlotWindow->setFooter(mpPlotFooterTextBox->text());
// set the legend
mpPlotWindow->setLegendPosition(mpLegendPositionComboBox->itemData(mpLegendPositionComboBox->currentIndex()).toString());
// set the prefix axes
mpPlotWindow->setPrefixAxes(mpPrefixAxesCheckbox->isChecked());
// set the prefix units
mpPlotWindow->setPrefixUnits(mpPrefixUnitsCheckbox->isChecked());
// set the auto scale
mpPlotWindow->setAutoScale(mpAutoScaleCheckbox->isChecked());
// set the range
Expand Down
8 changes: 4 additions & 4 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -102,7 +102,7 @@ class PlotWindow : public QMainWindow
int mInteractivePort;
QwtSeriesData<QPointF>* mpInteractiveData;
QString mInteractiveModelName;
bool mPrefixAxes;
bool mPrefixUnits;
QMdiSubWindow *mpSubWindow;
public:
PlotWindow(QStringList arguments = QStringList(), QWidget *parent = 0, bool isInteractiveSimulation = false);
Expand Down Expand Up @@ -173,8 +173,8 @@ class PlotWindow : public QMainWindow
QString getLegendPosition();
void setFooter(QString footer);
QString getFooter();
bool getPrefixAxes() const;
void setPrefixAxes(bool prefixAxes);
bool getPrefixUnits() const;
void setPrefixUnits(bool prefixUnits);
void checkForErrors(QStringList variables, QStringList variablesPlotted);
Plot* getPlot();
void receiveMessage(QStringList arguments);
Expand Down Expand Up @@ -315,7 +315,7 @@ class SetupDialog : public QDialog
QLineEdit *mpYMinimumTextBox;
QLabel *mpYMaximumLabel;
QLineEdit *mpYMaximumTextBox;
QCheckBox *mpPrefixAxesCheckbox;
QCheckBox *mpPrefixUnitsCheckbox;
/* buttons */
QPushButton *mpOkButton;
QPushButton *mpApplyButton;
Expand Down
1 change: 1 addition & 0 deletions OMPlot/OMPlot/OMPlotGUI/PlotZoomer.cpp
Expand Up @@ -55,6 +55,7 @@ PlotZoomer::PlotZoomer(int xAxis, int yAxis, QwtPlotCanvas *pParent)
// Ctrl+RightButton: zoom out to full size
setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
connect(this, SIGNAL(zoomed(QRectF)), plot(), SLOT(replot()));
}

PlotZoomer::~PlotZoomer()
Expand Down

0 comments on commit 0e423e1

Please sign in to comment.