-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestPlot2D.cpp
158 lines (136 loc) · 5.04 KB
/
TestPlot2D.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "TestPlot2D.h"
#include <QPlot/GradientSelector.h>
#include "ui_TestPlot2D.h"
#include <iostream>
TestPlot2D::TestPlot2D(QWidget *parent)
: QWidget(parent)
, ui(new Ui::TestPlot2D)
{
ui->setupUi(this);
// ui->plot->setOpenGl(true);
ui->plot->setSizePolicy(QSizePolicy::Preferred,
QSizePolicy::MinimumExpanding);
updateShowOptions(ui->plot->visibleOptions());
QPlot::Gradients g;
g.addStandardGradients();
ui->plot->setGradients(g);
ui->plot->setGradient("Spectrum2");
ui->plot->setScaleType("Linear");
ui->plot->setShowGradientLegend(true);
connect(ui->plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel(QWheelEvent*)));
connect(ui->plot, SIGNAL(zoomedOut()), this, SLOT(zoomedOut()));
connect(ui->plot, SIGNAL(flipYChanged(bool)), this, SLOT(changedFlipY(bool)));
connect(ui->plot, SIGNAL(clickedPlot(double, double, Qt::MouseButton)), this,
SLOT(clickedPlot(double, double, Qt::MouseButton)));
connect(ui->checkStyle, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkScale, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkLabels, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkThemes, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkThickness, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkGrid, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkTitle, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkZoom, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkSave, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkGradients, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkDither, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
connect(ui->checkFlipY, SIGNAL(clicked()), this, SLOT(updateShowOptions()));
}
void TestPlot2D::init(uint32_t nx, uint32_t ny)
{
QPlot::HistList2D hist;
for (uint32_t x=0; x<nx; ++x)
{
double xx = double(x) / double(nx);
for (uint32_t y=0; y<ny; ++y)
{
double yy = double(y) / double(ny);
double r = 3*qSqrt(xx*xx+yy*yy)+1e-2;
// the B field strength of dipole radiation (modulo physical constants)
double z = 2*x*(qCos(r+2)/r-qSin(r+2)/r);
hist.push_back(QPlot::p2d(x, y, z));
}
}
uint32_t res_x = nx - 1;
uint32_t res_y = ny - 1;
ui->plot->clearExtras();
ui->plot->clearData();
ui->plot->setAxes("x", 0, res_x, "y", 0, res_y, "z");
ui->plot->updatePlot(res_x + 1, res_y + 1, hist);
ui->plot->replotExtras();
if (!user_zoomed_)
ui->plot->zoomOut();
}
void TestPlot2D::refresh()
{
ui->plot->replot(QCustomPlot::rpQueuedRefresh);
}
void TestPlot2D::mouseWheel (QWheelEvent *event)
{
user_zoomed_ = true;
}
void TestPlot2D::zoomedOut()
{
user_zoomed_ = false;
}
void TestPlot2D::changedFlipY(bool)
{
qDebug() << "changed flip Y = " << ui->plot->flipY();
}
void TestPlot2D::clickedPlot(double x, double y, Qt::MouseButton button)
{
qDebug() << "Clicked on (" << x << "," << y << ")";
}
void TestPlot2D::updateShowOptions()
{
QPlot::ShowOptions opts;
if (ui->checkStyle->isChecked())
opts |= QPlot::style;
if (ui->checkScale->isChecked())
opts |= QPlot::scale;
if (ui->checkLabels->isChecked())
opts |= QPlot::labels;
if (ui->checkThemes->isChecked())
opts |= QPlot::themes;
if (ui->checkThickness->isChecked())
opts |= QPlot::thickness;
if (ui->checkGrid->isChecked())
opts |= QPlot::grid;
if (ui->checkTitle->isChecked())
opts |= QPlot::title;
if (ui->checkZoom->isChecked())
opts |= QPlot::zoom;
if (ui->checkSave->isChecked())
opts |= QPlot::save;
if (ui->checkGradients->isChecked())
opts |= QPlot::gradients;
if (ui->checkDither->isChecked())
opts |= QPlot::dither;
if (ui->checkFlipY->isChecked())
opts |= QPlot::flip_y;
ui->plot->setVisibleOptions(opts);
}
void TestPlot2D::updateShowOptions(QPlot::ShowOptions opts)
{
ui->checkStyle->setChecked(opts.testFlag(QPlot::style));
ui->checkScale->setChecked(opts.testFlag(QPlot::scale));
ui->checkLabels->setChecked(opts.testFlag(QPlot::labels));
ui->checkThemes->setChecked(opts.testFlag(QPlot::themes));
ui->checkThickness->setChecked(opts.testFlag(QPlot::thickness));
ui->checkGrid->setChecked(opts.testFlag(QPlot::grid));
ui->checkTitle->setChecked(opts.testFlag(QPlot::title));
ui->checkZoom->setChecked(opts.testFlag(QPlot::zoom));
ui->checkSave->setChecked(opts.testFlag(QPlot::save));
ui->checkGradients->setChecked(opts.testFlag(QPlot::gradients));
ui->checkDither->setChecked(opts.testFlag(QPlot::dither));
ui->checkFlipY->setChecked(opts.testFlag(QPlot::flip_y));
}
void TestPlot2D::on_pushGradientSelector_clicked()
{
auto gs = new QPlot::GradientSelector(ui->plot->gradients(),
ui->plot->gradient(),
qobject_cast<QWidget*> (parent()));
gs->setModal(true);
gs->exec();
ui->plot->setGradient(gs->selected_gradient());
ui->plot->replot();
}