Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- OMPlot setup option to set titles.
- Added the footer option to plots.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20530 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed May 9, 2014
1 parent af5679d commit dd28aa9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
39 changes: 38 additions & 1 deletion OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -116,9 +116,10 @@ void PlotWindow::initializePlot(QStringList arguments)
setCurveWidth(QString(arguments[13]).toDouble());
setCurveStyle(QString(arguments[14]).toInt());
setLegendPosition(QString(arguments[15]));
setFooter(QString(arguments[16]));
/* read variables */
QStringList variablesToRead;
for(int i = 16; i < arguments.length(); i++)
for(int i = 17; i < arguments.length(); i++)
variablesToRead.append(QString(arguments[i]));

setVariablesList(variablesToRead);
Expand Down Expand Up @@ -773,6 +774,11 @@ QString PlotWindow::getLegendPosition()
}
}

void PlotWindow::setFooter(QString footer)
{
mpPlot->setFooter(footer);
}

void PlotWindow::checkForErrors(QStringList variables, QStringList variablesPlotted)
{
QStringList nonExistingVariables;
Expand Down Expand Up @@ -1138,12 +1144,36 @@ SetupDialog::SetupDialog(PlotWindow *pPlotWindow)
connect(mpVariablesListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), SLOT(variableSelected(QListWidgetItem*,QListWidgetItem*)));
// Variables Tab Layout
QGridLayout *pVariablesTabGridLayout = new QGridLayout;
pVariablesTabGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pVariablesTabGridLayout->addWidget(mpVariableLabel, 0, 0);
pVariablesTabGridLayout->addWidget(mpVariablesListWidget, 1, 0);
pVariablesTabGridLayout->addWidget(mpVariablePagesStackedWidget, 2, 0);
mpVariablesTab->setLayout(pVariablesTabGridLayout);
// title tab
mpTitlesTab = new QWidget;
mpPlotTitleLabel = new QLabel(tr("Plot Title"));
mpPlotTitleTextBox = new QLineEdit(mpPlotWindow->getPlot()->title().text());
mpVerticalAxisLabel = new QLabel(tr("Vertical Axis Title"));
mpVerticalAxisTextBox = new QLineEdit(mpPlotWindow->getPlot()->axisTitle(QwtPlot::yLeft).text());
mpHorizontalAxisLabel = new QLabel(tr("Horizontal Axis Title"));
mpHorizontalAxisTextBox = new QLineEdit(mpPlotWindow->getPlot()->axisTitle(QwtPlot::xBottom).text());
mpPlotFooterLabel = new QLabel(tr("Plot Footer"));
mpPlotFooterTextBox = new QLineEdit(mpPlotWindow->getPlot()->footer().text());
// title tab layout
QGridLayout *pTitlesTabGridLayout = new QGridLayout;
pTitlesTabGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pTitlesTabGridLayout->addWidget(mpPlotTitleLabel, 0, 0);
pTitlesTabGridLayout->addWidget(mpPlotTitleTextBox, 0, 1);
pTitlesTabGridLayout->addWidget(mpVerticalAxisLabel, 1, 0);
pTitlesTabGridLayout->addWidget(mpVerticalAxisTextBox, 1, 1);
pTitlesTabGridLayout->addWidget(mpHorizontalAxisLabel, 2, 0);
pTitlesTabGridLayout->addWidget(mpHorizontalAxisTextBox, 2, 1);
pTitlesTabGridLayout->addWidget(mpPlotFooterLabel, 3, 0);
pTitlesTabGridLayout->addWidget(mpPlotFooterTextBox, 3, 1);
mpTitlesTab->setLayout(pTitlesTabGridLayout);
// add tabs
mpSetupTabWidget->addTab(mpVariablesTab, tr("Variables"));
mpSetupTabWidget->addTab(mpTitlesTab, tr("Titles"));
// Create the buttons
mpOkButton = new QPushButton(tr("OK"));
mpOkButton->setAutoDefault(true);
Expand Down Expand Up @@ -1241,9 +1271,16 @@ void SetupDialog::saveSetup()

void SetupDialog::applySetup()
{
// set the variables attributes
for (int i = 0 ; i < mpVariablePagesStackedWidget->count() ; i++)
{
setupPlotCurve(qobject_cast<VariablePageWidget*>(mpVariablePagesStackedWidget->widget(i)));
}
// set the titles
mpPlotWindow->getPlot()->setTitle(mpPlotTitleTextBox->text());
mpPlotWindow->getPlot()->setAxisTitle(QwtPlot::yLeft, mpVerticalAxisTextBox->text());
mpPlotWindow->getPlot()->setAxisTitle(QwtPlot::xBottom, mpHorizontalAxisTextBox->text());
mpPlotWindow->getPlot()->setFooter(mpPlotFooterTextBox->text());
// replot
mpPlotWindow->getPlot()->replot();
}
15 changes: 13 additions & 2 deletions OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -104,6 +104,7 @@ class PlotWindow : public QMainWindow
int getCurveStyle();
void setLegendPosition(QString position);
QString getLegendPosition();
void setFooter(QString footer);
void checkForErrors(QStringList variables, QStringList variablesPlotted);
Plot* getPlot();
QToolButton* getPanButton();
Expand Down Expand Up @@ -192,12 +193,22 @@ class SetupDialog : public QDialog
private:
PlotWindow *mpPlotWindow;
QTabWidget *mpSetupTabWidget;

/* variables tab */
QWidget *mpVariablesTab;
QLabel *mpVariableLabel;
QListWidget *mpVariablesListWidget;
QStackedWidget *mpVariablePagesStackedWidget;

/* titles tab */
QWidget *mpTitlesTab;
QLabel *mpPlotTitleLabel;
QLineEdit *mpPlotTitleTextBox;
QLabel *mpVerticalAxisLabel;
QLineEdit *mpVerticalAxisTextBox;
QLabel *mpHorizontalAxisLabel;
QLineEdit *mpHorizontalAxisTextBox;
QLabel *mpPlotFooterLabel;
QLineEdit *mpPlotFooterTextBox;
/* buttons */
QPushButton *mpOkButton;
QPushButton *mpApplyButton;
QPushButton *mpCancelButton;
Expand Down
5 changes: 5 additions & 0 deletions OMPlot/OMPlotGUI/main.cpp
Expand Up @@ -63,6 +63,7 @@ void printUsage()
printf(" --curve-width=WIDTH Sets the WIDTH of the curve\n");
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");
}

int main(int argc, char *argv[])
Expand All @@ -84,6 +85,7 @@ int main(int argc, char *argv[])
double curveWidth = 1.0;
int curveStyle = 1;
QString legendPosition = "top";
QString footer("");
QStringList vars;
QString filename;
for(int i = 1; i < argc; i++)
Expand Down Expand Up @@ -135,6 +137,8 @@ int main(int argc, char *argv[])
}
} else if (strncmp(argv[i], "--legend-position=",18) == 0) {
legendPosition = argv[i]+18;
} else if (strncmp(argv[i], "--footer=", 9) == 0) {
footer = argv[i]+9;
} else if (strncmp(argv[i], "--", 2) == 0) {
fprintf(stderr, "Error: Unknown option: %s\n", argv[i]);
return 1;
Expand Down Expand Up @@ -164,6 +168,7 @@ int main(int argc, char *argv[])
arguments.append(QString::number(curveWidth));
arguments.append(QString::number(curveStyle));
arguments.append(legendPosition);
arguments.append(footer);
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");
Expand Down

0 comments on commit dd28aa9

Please sign in to comment.