Main.cpp
#include <QtGui/QApplication>
#include "viewer.h"
int main(int argc, char *argv[])
{
Viewer w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "viewer.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Viewer w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Viewer.cpp == MainWindow
#include "viewer.h"
#include "ui_viewer.h"
Viewer* Viewer::instance = 0;
Viewer* Viewer::getInstance(){
if(instance==0){
instance = new Viewer;
}
return instance;
}
#include <QtGui>
#include <QDebug>
ui(new Ui::Viewer)
{
ui->setupUi(this);
//connects(...);
}
Viewer::~Viewer()
{
delete ui;
}
if(plotType=="dark") ui->darkPlot->addWidget(plot);
else ui->lightPlot->addWidget(plot);
}
Various functions without
QwtPlot () {...
}
#include "viewer.h"
#include "ui_viewer.h"
Viewer* Viewer::instance = 0;
Viewer* Viewer::getInstance(){
if(instance==0){
instance = new Viewer;
}
return instance;
}
#include <QtGui>
#include <QDebug>
Viewer::Viewer(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Viewer)
{
ui->setupUi(this);
//connects(...);
}
Viewer::~Viewer()
{
delete ui;
}
void Viewer::setPlot(QwtPlot *plot, QString plotType){
if(plotType=="dark") ui->darkPlot->addWidget(plot);
else ui->lightPlot->addWidget(plot);
}
Various functions without QwtPlot () {...}
To copy to clipboard, switch view to plain text mode
viewer.h
{
Q_OBJECT
public:
explicit Viewer
(QWidget *parent
= 0);
static Viewer* getInstance();
~Viewer();
void VariousFunctionsWithoutQwt(...);
private slots:
void VariousFunctionsWithoutQwt(...);
private:
Ui::Viewer *ui;
static Viewer* instance;
};
class Viewer : public QMainWindow
{
Q_OBJECT
public:
explicit Viewer(QWidget *parent = 0);
static Viewer* getInstance();
~Viewer();
void VariousFunctionsWithoutQwt(...);
private slots:
void VariousFunctionsWithoutQwt(...);
private:
Ui::Viewer *ui;
static Viewer* instance;
};
To copy to clipboard, switch view to plain text mode
and finally my plot.cpp and plot.h where there is Qwt used.
plot.cpp:
#include "plot.h"
#include "viewer.h"
Viewer* viewer = Viewer::getInstance();
{
}
void Plot::initPlot(){
if(viewer->isPlotEmpty("dark")){
...
viewer->setPlot(plotD,"dark");
}
if(viewer->isPlotEmpty("light")){
...
viewer->setPlot(plotL,"light");
}
}
void Plot::plot(){
...
plotD->replot();
plotL->replot();
}
#include "plot.h"
#include "viewer.h"
QwtPlot *plotD;
QwtPlot *plotL;
Viewer* viewer = Viewer::getInstance();
Plot::Plot(QWidget *parent) : QWidget(parent)
{
}
void Plot::initPlot(){
if(viewer->isPlotEmpty("dark")){
plotD = new QwtPlot();
...
viewer->setPlot(plotD,"dark");
}
if(viewer->isPlotEmpty("light")){
plotL = new QwtPlot();
...
viewer->setPlot(plotL,"light");
}
}
void Plot::plot(){
...
plotD->replot();
plotL->replot();
}
To copy to clipboard, switch view to plain text mode
plot.h
#ifndef PLOT_H
#define PLOT_H
#include <QWidget>
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_symbol.h"
#include "qwt_plot_marker.h"
#include "qwt_legend.h"
#include "qwt_scale_engine.h"
{
Q_OBJECT
public:
private:
void initPlot();
private slots:
void plot();
};
#endif // PLOT_H
#ifndef PLOT_H
#define PLOT_H
#include <QWidget>
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_symbol.h"
#include "qwt_plot_marker.h"
#include "qwt_legend.h"
#include "qwt_scale_engine.h"
class Plot : public QWidget
{
Q_OBJECT
public:
explicit Plot(QWidget *parent);
private:
void initPlot();
private slots:
void plot();
};
#endif // PLOT_H
To copy to clipboard, switch view to plain text mode
Thanks
Bookmarks