Skip to content

Commit f149e16

Browse files
author
Haris Kapidzic
committed
Works with qwt-5.2.1 version now.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8182 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 1942028 commit f149e16

File tree

4 files changed

+143
-82
lines changed

4 files changed

+143
-82
lines changed

OMPlot/OMPlotGUI/OMPlotGUI.pro

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,17 @@ QT += core gui
99
TARGET = OMPlot
1010
TEMPLATE = app
1111

12-
SOURCES += main.cpp\
12+
SOURCES += main.cpp \
1313
plotwindow.cpp \
1414
../../c_runtime/read_matlab4.c
1515

16-
HEADERS +=\
17-
plotwindow.h \
16+
HEADERS += plotwindow.h \
1817
../../c_runtime/read_matlab4.h
1918

20-
2119
win32 {
22-
LIBS += -L $$(OMDEV)/lib/qwt-6.0.0-mingw/lib \
23-
-lqwtd
20+
LIBS += -L$$(OMDEV)/lib/qwt-5.2.1-mingw/lib -lqwtd5
2421

25-
INCLUDEPATH += $$(OMDEV)/lib/qwt-6.0.0-mingw/include
22+
INCLUDEPATH += $$(OMDEV)/lib/qwt-5.2.1-mingw/include #C:\\qwt-6.0.0-rc5\\include
2623
} else {
2724
include(OMPlotGUI.config)
2825
}

OMPlot/OMPlotGUI/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ int main(int argc, char *argv[])
5656
msgBox->exec();
5757

5858
return -1;
59-
}
59+
}
6060
}

OMPlot/OMPlotGUI/plotwindow.cpp

Lines changed: 91 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,28 @@ PlotWindow::PlotWindow(QStringList arguments, QWidget *parent)
4242

4343
//Set up arguments
4444
setTitle(QString(arguments[2]));
45-
setLegend(QString(arguments[3]));
45+
46+
if(QString(arguments[3]) == "true")
47+
setLegend(true);
48+
else if(QString(arguments[3]) == "false")
49+
setLegend(false);
50+
4651
if(QString(arguments[4]) == "true")
4752
setGrid(true);
4853
else if(QString(arguments[4]) == "false")
4954
setGrid(false);
5055
QString plotType = arguments[5];
51-
setLogX(QString(arguments[6]));
52-
setLogY(QString(arguments[7]));
56+
57+
if(QString(arguments[6]) == "true")
58+
setLogX(true);
59+
else if(QString(arguments[6]) == "false")
60+
setLogX(false);
61+
62+
if(QString(arguments[7]) == "true")
63+
setLogY(true);
64+
else if(QString(arguments[7]) == "false")
65+
setLogY(false);
66+
5367
setXLabel(QString(arguments[8]));
5468
setYLabel(QString(arguments[9]));
5569
setXRange(QString(arguments[10]).toDouble(), QString(arguments[11]).toDouble());
@@ -80,15 +94,6 @@ PlotWindow::~PlotWindow()
8094
delete mpFile;
8195
delete mpTextStream;
8296

83-
// delete mpPlotPicker;
84-
// delete mpPlotPanner;
85-
// delete mpPanButton;
86-
// delete mpGridButton;
87-
// delete mpPlotZoomer;
88-
// delete mpXCheckBox;
89-
// delete mpYCheckBox;
90-
// delete mpZoomButton;
91-
// delete mpGrid;
9297

9398
// delete mpQwtLegend;
9499
delete mpQwtPlot;
@@ -105,24 +110,26 @@ void PlotWindow::openFile(QString file)
105110
}
106111

107112
void PlotWindow::initializePlot()
108-
{
113+
{
109114
//Create the Plot window, size and grid, legend
110-
mpQwtPlot = new QwtPlot(QwtText(""));
115+
//mpQwtPlot = new QwtPlot();
116+
//mpQwtPlot = new QwtPlot(QwtText("Title"));
117+
mpQwtPlot = new QwtPlot(QwtText("Wazzup"));
111118
mpQwtPlot->setGeometry(100, 100, 700, 400);
112119
mpQwtPlot->setCanvasBackground(Qt::GlobalColor(Qt::white));
113120
mpGrid = new QwtPlotGrid();
114121
mpGrid->attach(mpQwtPlot);
115122
mpQwtLegend = new QwtLegend();
116123
mpQwtPlot->insertLegend(mpQwtLegend, QwtPlot::RightLegend);
117124
mpQwtPlot->setTitle(QwtText("Plot Window"));
118-
mpQwtPlot->replot();
125+
mpQwtPlot->replot();
119126

120127
//plotpicker, Plotpanner, plotzoomer
121-
mpPlotPicker = new QwtPlotPicker((int)QwtPlot::xBottom, (int)QwtPlot::yLeft,
122-
(int)QwtPlotPicker::CrossRubberBand, (int) QwtPicker::AlwaysOn,
128+
mpPlotPicker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::PointSelection, QwtPlotPicker::CrossRubberBand,QwtPicker::AlwaysOn,
123129
mpQwtPlot->canvas());
124-
mpPlotPicker->setStateMachine(new QwtPickerDragPointMachine());
125-
mpPlotPicker->setTrackerPen(QColor(Qt::black));
130+
mpPlotPicker->setTrackerPen(QColor(Qt::black));
131+
mpPlotPicker->setRubberBandPen(QColor(Qt::black));
132+
126133
mpPlotPanner = new QwtPlotPanner(mpQwtPlot->canvas());
127134
mpPlotPanner->setEnabled(false);
128135

@@ -190,6 +197,15 @@ void PlotWindow::setupToolbar()
190197
connect(mpYCheckBox, SIGNAL(clicked()), SLOT(setLog()));
191198
toolBar->addWidget(mpYCheckBox);
192199

200+
//OPTIONS
201+
// QToolButton *pOptions = new QToolButton(toolBar);
202+
// pOptions->setText("Options");
203+
// pOptions->setCheckable(true);
204+
// connect(pOptions, SIGNAL(clicked()), ))
205+
// toolBar->addWidget(pOptions);
206+
207+
// toolBar->addSeparator();
208+
193209
addToolBar(toolBar);
194210
}
195211

@@ -242,7 +258,7 @@ void PlotWindow::plot(QStringList variables)
242258
if(variables[i] == currentVariable || plotAll)
243259
{
244260
variableExists.replace(i , 1);
245-
curveData curve;
261+
CurveData curve;
246262
currentLine = mpTextStream->readLine();
247263
intervalSize = intervalString.toInt();
248264
while(intervalSize != 0)
@@ -294,7 +310,7 @@ void PlotWindow::plot(QStringList variables)
294310
variablesToPlotIndex.push_back(i);
295311
}
296312

297-
curveData curve[variablesToPlotIndex.size()];
313+
CurveData curve[variablesToPlotIndex.size()];
298314

299315
//Assign Values
300316
while(!mpTextStream->atEnd())
@@ -351,7 +367,7 @@ void PlotWindow::plot(QStringList variables)
351367
variables.removeFirst();
352368
}
353369

354-
curveData curve[variables.length()];
370+
CurveData curve[variables.length()];
355371

356372
//Read in values
357373
for(int i = 0; i < variables.length(); i++)
@@ -410,7 +426,7 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
410426

411427
QStringList variablesList(xVariable);
412428
variablesList.append(yVariable);
413-
curveData curve;
429+
CurveData curve;
414430

415431
//Collect variables
416432
while(!mpTextStream->atEnd())
@@ -483,7 +499,7 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
483499
}
484500

485501
currentLine = mpTextStream->readLine();
486-
curveData curve;
502+
CurveData curve;
487503

488504
//Collect values
489505
while(!mpTextStream->atEnd())
@@ -520,7 +536,7 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
520536
if(yVariable == "time")
521537
yVariable = "Time";
522538

523-
curveData curve;
539+
CurveData curve;
524540

525541
//Fill variable x with data
526542
var = omc_matlab4_find_var(&reader, xVariable.toStdString().c_str());
@@ -544,7 +560,7 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
544560
plotGraph(mCurveDataList);
545561
}
546562

547-
void PlotWindow::plotGraph(QList<curveData> mCurveDataList)
563+
void PlotWindow::plotGraph(QList<CurveData> mCurveDataList)
548564
{
549565
QwtPlotCurve *mpPlotCurve[mCurveDataList.length()];
550566
for(int i = 0; i < mCurveDataList.length(); i++)
@@ -555,7 +571,8 @@ void PlotWindow::plotGraph(QList<curveData> mCurveDataList)
555571
QPen pen(QColor(Qt::GlobalColor(colorValue + 1)));
556572
pen.setWidth(2);
557573
mpPlotCurve[i] = new QwtPlotCurve(mCurveDataList[i].curveName);
558-
mpPlotCurve[i]->setSamples(mCurveDataList[i].xAxisVector,mCurveDataList[i].yAxisVector);
574+
//mpPlotCurve[i]->setSamples(mCurveDataList[i].xAxisVector,mCurveDataList[i].yAxisVector);
575+
mpPlotCurve[i]->setData(mCurveDataList[i].xAxisVector,mCurveDataList[i].yAxisVector);
559576
mpPlotCurve[i]->setPen(pen);
560577
mpPlotCurve[i]->attach(mpQwtPlot);
561578
}
@@ -602,42 +619,15 @@ void PlotWindow::enablePanMode(bool on)
602619
}
603620

604621
void PlotWindow::exportDocument()
605-
{
606-
const QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();
607-
608-
QStringList filter;
609-
filter += "PDF Documents (*.pdf)";
610-
filter += "SVG Documents (*.svg)";
611-
filter += "Postscript Documents (*.ps)";
612-
613-
if ( imageFormats.size() > 0 )
614-
{
615-
QString imageFilter("Images (");
616-
for ( int i = 0; i < imageFormats.size(); i++ )
617-
{
618-
if ( i > 0 )
619-
imageFilter += " ";
620-
imageFilter += "*.";
621-
imageFilter += imageFormats[i];
622-
}
623-
imageFilter += ")";
624-
625-
filter += imageFilter;
626-
}
627-
628-
QString fileName = "ThisPlot";
629-
fileName = QFileDialog::getSaveFileName( this, "Export File Name", fileName, filter.join(";;"), NULL, QFileDialog::DontConfirmOverwrite);
622+
{
623+
//Include ps ;;Postscript Documents (*.ps)
624+
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File As"), QDir::currentPath(), tr("Image Files (*.png *.bmp *.jpg)"));
630625

631626
if ( !fileName.isEmpty() )
632-
{
633-
QwtPlotRenderer renderer;
634-
635-
// flags to make the document look like the widget
636-
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
637-
renderer.setLayoutFlag(QwtPlotRenderer::KeepMargins, true);
638-
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
639-
640-
renderer.renderDocument(mpQwtPlot, fileName, QSizeF(300, 200), 85);
627+
{
628+
QPixmap pixmap(mpQwtPlot->size());
629+
mpQwtPlot->render(&pixmap);
630+
pixmap.save(fileName);
641631
}
642632
}
643633

@@ -688,29 +678,29 @@ void PlotWindow::setTitle(QString title)
688678
mpQwtPlot->setTitle(QwtText(title));
689679
}
690680

691-
void PlotWindow::setLegend(QString on)
681+
void PlotWindow::setLegend(bool on)
692682
{
693-
//Fixa LEGENDEN
694-
if(on == "true")
683+
//Can be fixed better
684+
if(on)
695685
{
696686
//mpQwtPlot->insertLegend(mpQwtLegend, QwtPlot::RightLegend);
697687
}
698688
else
699689
delete mpQwtLegend;
700690
}
701691

702-
void PlotWindow::setLogX(QString on)
692+
void PlotWindow::setLogX(bool on)
703693
{
704-
if(on == "true")
694+
if(on)
705695
{
706696
mpXCheckBox->setChecked(true);
707697
setLog();
708698
}
709699
}
710700

711-
void PlotWindow::setLogY(QString on)
701+
void PlotWindow::setLogY(bool on)
712702
{
713-
if(on == "true")
703+
if(on)
714704
{
715705
mpYCheckBox->setChecked(true);
716706
setLog();
@@ -750,3 +740,36 @@ void PlotWindow::checkForErrors(QStringList variables, QVector<int> variableExis
750740
if(nonExistingVariables != "")
751741
throw NoVariableException(QString("Variable(s) doesnt exist : ").append(nonExistingVariables).toStdString().c_str());
752742
}
743+
744+
//Options
745+
//Options::Options(PlotWindow *pPlotWindow)
746+
//{
747+
// setWindowTitle(QString("OMPLOT - Options"));
748+
// setAttribute(Qt::WA_DeleteOnClose);
749+
// setMaximumSize(175, 150);
750+
751+
// mpPlotWindow = pPlotWindow;
752+
753+
// setUpForm();
754+
//}
755+
756+
//void Options::setUpForm()
757+
//{
758+
// QGridLayout *label = new QGridLayout;
759+
// mpLabelGroup = new QGroupBox();
760+
// mpTitleLabel = new QLabel(tr("Title:"));
761+
// mpTitle = new QLineEdit("");
762+
// label->addWidget(mpTitleLabel, 0, 0);
763+
// label->addWidget(mpTitle, 0, 1);
764+
765+
// mpLabelGroup->setLayout(label);
766+
767+
// QGridLayout *mainLayout = new QGridLayout;
768+
// mainLayout->addWidget(mpLabelGroup, 1, 0);
769+
// setLayout(mainLayout);
770+
//}
771+
772+
//void Options::edit()
773+
//{
774+
// qDebug() << "Waxxuup";
775+
//}

0 commit comments

Comments
 (0)