-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.cpp
130 lines (108 loc) · 3.05 KB
/
plot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <QtGui>
#include <QLabel>
#include <QGridLayout>
#include <QPrintDialog>
#include <QPrinter>
#include <qwt.h>
#include <qwt_scale_engine.h>
#include "pxplot.h"
#include "plot.h"
#include "curve.h"
Plot::Plot(QWidget *parent): QWidget(parent)
{
px = new PxPlot();
zoomer = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, px->canvas());
zoomer->setRubberBand(QwtPicker::RectRubberBand);
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Qt::RightButton);
zoomer->setEnabled(true);
// zoomer->zoom(0);
panner = new QwtPlotPanner(px->canvas());
panner->setMouseButton(Qt::MiddleButton);
QGridLayout *layout = new QGridLayout;
layout->addWidget(px,0,0,1,-1);
label = new QLabel(tr("")); // place for future status/cursor line
layout->addWidget(label,1,1);
setLayout(layout);
}
bool Plot::addDataFile(const QString& name, const QString & format)
{
bool ok;
ok = px->setData(name,format);
if (ok) {
zoomer->setZoomBase();
}
return(ok);
}
bool Plot::removeCurve(Curve *c)
{
bool ok;
ok = px->removeCurve(c);
return(ok);
}
QList<Curve*> Plot::curveList()
{
return(px->curveList());
}
void Plot::fexport()
{
// change from gui theme colours to black axes / labels
QPalette pgui, pfile;
pgui = this->palette();
pfile = pgui;
pfile.setColor(QPalette::Text,QColor(Qt::black));
pfile.setColor(QPalette::WindowText,QColor(Qt::black));
this->setPalette(pfile);
QwtPlotRenderer rx;
rx.setDiscardFlag(QwtPlotRenderer::DiscardBackground);
rx.setDiscardFlag(QwtPlotRenderer::DiscardCanvasFrame);
// FIXME: set default filename more intelligently
QString fn = "";
// fn += px->title().text(); this is set to space; use last filename
if (fn.isEmpty())
{
fn = "pxv";
}
// FIXME: set size, resolution as params of exportTo, from options
// this is roughly half of an A4; RSC double width
rx.exportTo(this->px,fn,QSizeF(170,113),300);
// restore colours
this->setPalette(pgui);
}
void Plot::print()
{
QPrinter printer;
QPrintDialog dia(&printer);
if (dia.exec())
{
QwtPlotRenderer pf;
pf.setDiscardFlag(QwtPlotRenderer::DiscardNone,true);
if (printer.colorMode() == QPrinter::GrayScale)
{
pf.setDiscardFlag(QwtPlotRenderer::DiscardBackground,true);
}
pf.renderTo(px,printer);
}
}
void Plot::zoomToFit()
{
QRectF bounds = px->boundingRect();
if (bounds.isValid())
{
QwtLinearScaleEngine scaler;
double x1, x2, step;
x1 = bounds.left();
x2 = bounds.right();
scaler.autoScale(20,x1,x2,step);
bounds.setLeft(x1);
bounds.setRight(x2);
x1 = bounds.top();
x2 = bounds.bottom();
scaler.autoScale(20,x1,x2,step);
bounds.setTop(x1);
bounds.setBottom(x2);
zoomer->zoom(bounds);
}
}