#include <QApplication>
#include "MyMainWindow.h"
#include <QGridLayout>
#include "RunSimulation.h"
int main(int argc, char *argv[])
{
MyMainWindow fenetre;
fenetre.show();
return app.exec();
}
#include <QApplication>
#include "MyMainWindow.h"
#include <QGridLayout>
#include "RunSimulation.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyMainWindow fenetre;
fenetre.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
-------------------.h-----------------
#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QMessageBox>
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
class MyMainWindow
: public QWidget{
Q_OBJECT
public:
explicit MyMainWindow
(QWidget* parent
= 0);
void plotValuesFromFunction(std::vector< std::vector<double> >);
public slots:
void myRunSlot();
private:
};
#endif // MYMAINWINDOW_H
--------------.cpp--------------------------
#include "MyMainWindow.h"
#include <QGridLayout>
#include <QHBoxLayout>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h> //for symbol in the curve
#include "RunSimulation.h"
#include <vector>
using namespace std;
{
setLayout(mainLayout);
myPlot1->setMinimumSize(200, 100);
myPlot2->setMinimumSize(200, 100);
buttonLayout->addWidget(BUTTONRun ,0,1);
buttonLayout->addWidget(BUTTONQuit ,1,1);
buttonLayout->addWidget(BUTTONAbout ,2,1);
buttonLayout->addWidget(BUTTONContact,3,1);
buttonWidget->setLayout(buttonLayout);
mainLayout->addWidget(myPlot1 ,0,0,1,1);
mainLayout->addWidget(myPlot2 ,0,1,1,1);
mainLayout->addWidget(buttonWidget ,0,3,1,1);
myCurve1.attach(myPlot1);
myCurve2.attach(myPlot2);
QObject::connect(BUTTONQuit,
SIGNAL(clicked
()),
qApp,
SLOT(quit
()));
QObject::connect(BUTTONAbout,
SIGNAL(clicked
()),
qApp,
SLOT(aboutQt
()));
QObject::connect(BUTTONRun,
SIGNAL(clicked
()),
this,
SLOT(myRunSlot
()));
}
void MyMainWindow::plotValuesFromFunction(vector< vector<double> > Points_OneXtwoY)
{
int sizeOfVector=Points_OneXtwoY[0].size();
QVector<double> x(sizeOfVector);
QVector<double> y(sizeOfVector);
for (int z=0;z<sizeOfVector;z++)
{
x.append( Points_OneXtwoY[0][z] );
y.append( Points_OneXtwoY[1][z] );
}
myPlot1->replot();
myPlot2->replot();
myCurve1.setSamples(x.data(),y.data(),x.size());
myCurve2.setSamples(x.data(),y.data(),x.size());
myPlot1->show();
myPlot2->show();
}
void MyMainWindow::myRunSlot()
{
RunSimulation(this); //this
}
-------------------.h-----------------
#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QMessageBox>
#include <qwt_plot_curve.h>
#include <qwt_plot.h>
class MyMainWindow : public QWidget
{
Q_OBJECT
public:
explicit MyMainWindow(QWidget* parent = 0);
void plotValuesFromFunction(std::vector< std::vector<double> >);
public slots:
void myRunSlot();
private:
QPushButton *BUTTONRun;
QPushButton *BUTTONQuit;
QPushButton *BUTTONAbout;
QPushButton *BUTTONContact;
QwtPlot *myPlot1;
QwtPlot *myPlot2;
QwtPlotCurve myCurve1;
QwtPlotCurve myCurve2;
};
#endif // MYMAINWINDOW_H
--------------.cpp--------------------------
#include "MyMainWindow.h"
#include <QGridLayout>
#include <QHBoxLayout>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h> //for symbol in the curve
#include "RunSimulation.h"
#include <vector>
using namespace std;
MyMainWindow::MyMainWindow(QWidget* parent) : QWidget(parent)
{
QGridLayout* mainLayout = new QGridLayout();
setLayout(mainLayout);
myPlot1 = new QwtPlot();
myPlot2 = new QwtPlot();
myPlot1->setMinimumSize(200, 100);
myPlot2->setMinimumSize(200, 100);
QWidget* buttonWidget = new QWidget();
QGridLayout* buttonLayout = new QGridLayout();
BUTTONRun = new QPushButton("RUN");
BUTTONQuit = new QPushButton("STOP");
BUTTONAbout = new QPushButton("About");
BUTTONContact = new QPushButton("Contact");
buttonLayout->addWidget(BUTTONRun ,0,1);
buttonLayout->addWidget(BUTTONQuit ,1,1);
buttonLayout->addWidget(BUTTONAbout ,2,1);
buttonLayout->addWidget(BUTTONContact,3,1);
buttonWidget->setLayout(buttonLayout);
mainLayout->addWidget(myPlot1 ,0,0,1,1);
mainLayout->addWidget(myPlot2 ,0,1,1,1);
mainLayout->addWidget(buttonWidget ,0,3,1,1);
myCurve1.attach(myPlot1);
myCurve2.attach(myPlot2);
QObject::connect(BUTTONQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
QObject::connect(BUTTONAbout, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
QObject::connect(BUTTONRun, SIGNAL(clicked()), this, SLOT(myRunSlot()));
}
void MyMainWindow::plotValuesFromFunction(vector< vector<double> > Points_OneXtwoY)
{
int sizeOfVector=Points_OneXtwoY[0].size();
QVector<double> x(sizeOfVector);
QVector<double> y(sizeOfVector);
for (int z=0;z<sizeOfVector;z++)
{
x.append( Points_OneXtwoY[0][z] );
y.append( Points_OneXtwoY[1][z] );
}
myPlot1->replot();
myPlot2->replot();
myCurve1.setSamples(x.data(),y.data(),x.size());
myCurve2.setSamples(x.data(),y.data(),x.size());
myPlot1->show();
myPlot2->show();
}
void MyMainWindow::myRunSlot()
{
RunSimulation(this); //this
}
To copy to clipboard, switch view to plain text mode
------------------.h---------------------
#ifndef RUNSIMULATION_H
#define RUNSIMULATION_H
#include "MyMainWindow.h"
void RunSimulation(MyMainWindow *fenetre);
#endif // RUNSIMULATION_H
------------------.cpp-------------------
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <vector>
#include "function.h"
#include "RunSimulation.h"
#include "MyMainWindow.h"
using namespace std;
void RunSimulation(MyMainWindow *fenetre)
{
vector<double> coordX;
vector<double> coordY;
vector< vector<double> >coordX_Y;
coordX_Y.push_back(coordX);
coordX_Y.push_back(coordY);
vector<double> points;
for (int i=1;i<10;i++)
{
points.clear();
points=function();
coordX_Y[0].push_back(points[0]);
coordX_Y[1].push_back(points[1]);
fenetre->plotValuesFromFunction(coordX_Y);
}
}
------------------.h---------------------
#ifndef RUNSIMULATION_H
#define RUNSIMULATION_H
#include "MyMainWindow.h"
void RunSimulation(MyMainWindow *fenetre);
#endif // RUNSIMULATION_H
------------------.cpp-------------------
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <vector>
#include "function.h"
#include "RunSimulation.h"
#include "MyMainWindow.h"
using namespace std;
void RunSimulation(MyMainWindow *fenetre)
{
vector<double> coordX;
vector<double> coordY;
vector< vector<double> >coordX_Y;
coordX_Y.push_back(coordX);
coordX_Y.push_back(coordY);
vector<double> points;
for (int i=1;i<10;i++)
{
points.clear();
points=function();
coordX_Y[0].push_back(points[0]);
coordX_Y[1].push_back(points[1]);
fenetre->plotValuesFromFunction(coordX_Y);
}
}
To copy to clipboard, switch view to plain text mode
----------------.h------------------
#ifndef FUNCTION_HPP
#define FUNCTION_HPP
std::vector<double> function();
#endif // FUNCTION_HPP
-----------------.cpp---------------
#include <vector>
#include <ctime> // to generate random point
#include <cstdlib> // to generate random point
#include "function.h"
#include "windows.h"
using namespace std;
vector<double> function()
{
vector<double> ppoints;
ppoints.clear();
//----------------
srand(time(0));
Sleep(1000);
//----------------
ppoints.push_back(rand() % 1800);
ppoints.push_back(rand() % 500);
return ppoints;
}
----------------.h------------------
#ifndef FUNCTION_HPP
#define FUNCTION_HPP
std::vector<double> function();
#endif // FUNCTION_HPP
-----------------.cpp---------------
#include <vector>
#include <ctime> // to generate random point
#include <cstdlib> // to generate random point
#include "function.h"
#include "windows.h"
using namespace std;
vector<double> function()
{
vector<double> ppoints;
ppoints.clear();
//----------------
srand(time(0));
Sleep(1000);
//----------------
ppoints.push_back(rand() % 1800);
ppoints.push_back(rand() % 500);
return ppoints;
}
To copy to clipboard, switch view to plain text mode
Bookmarks