forked from analogdevicesinc/scopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraticule.cpp
155 lines (134 loc) · 5.23 KB
/
graticule.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
/*
* Copyright (c) 2019 Analog Devices Inc.
*
* This file is part of Scopy
* (see http://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "graticule.h"
using namespace adiscope;
Graticule::Graticule(QwtPlot *plot):
enabled(false),
plot(plot)
{
vertScale = new GraticulePlotScaleItem(QwtScaleDraw::LeftScale,-1);
horizScale = new GraticulePlotScaleItem(QwtScaleDraw::BottomScale,-1);
vertScale2 = new GraticulePlotScaleItem(QwtScaleDraw::RightScale,-1);
horizScale2 = new GraticulePlotScaleItem(QwtScaleDraw::TopScale,-1);
QPalette palette = vertScale->palette();
palette.setBrush(QPalette::Foreground, QColor("#6E6E6F"));
palette.setBrush(QPalette::Text, QColor("#6E6E6F"));
double minTick = vertScale->scaleDraw()->tickLength(QwtScaleDiv::MinorTick);
double medTick = vertScale->scaleDraw()->tickLength(QwtScaleDiv::MediumTick);
double majTick = vertScale->scaleDraw()->tickLength(QwtScaleDiv::MajorTick);
vertScale->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Backbone, false);
vertScale->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels, false);
vertScale->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,minTick*3/4);
vertScale->scaleDraw()->setTickLength(QwtScaleDiv::MediumTick,medTick*3/4);
vertScale->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,majTick*3/4);
vertScale->setPalette(palette);
horizScale->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Backbone, false);
horizScale->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels, false);
horizScale->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,minTick*3/4);
horizScale->scaleDraw()->setTickLength(QwtScaleDiv::MediumTick,medTick*3/4);
horizScale->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,majTick*3/4);
horizScale->setPalette(palette);
vertScale2->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Backbone, false);
vertScale2->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels, false);
vertScale2->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,minTick*3/4);
vertScale2->scaleDraw()->setTickLength(QwtScaleDiv::MediumTick,medTick*3/4);
vertScale2->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,majTick*3/4);
vertScale2->setPalette(palette);
horizScale2->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Backbone, false);
horizScale2->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels, false);
horizScale2->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,minTick*3/4);
horizScale2->scaleDraw()->setTickLength(QwtScaleDiv::MediumTick,medTick*3/4);
horizScale2->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,majTick*3/4);
horizScale2->setPalette(palette);
}
Graticule::~Graticule()
{
delete vertScale;
delete vertScale2;
delete horizScale;
delete horizScale2;
}
void Graticule::toggleGraticule(){
enabled = !enabled;
if(enabled){
vertScale->attach(plot);
vertScale2->attach(plot);
horizScale->attach(plot);
horizScale2->attach(plot);
}
else{
vertScale->detach();
vertScale2->detach();
horizScale->detach();
horizScale2->detach();
}
}
void Graticule::enableGraticule(bool enable){
if(enable != enabled){
enabled = enable;
if(enabled){
vertScale->attach(plot);
vertScale2->attach(plot);
horizScale->attach(plot);
horizScale2->attach(plot);
}
else{
vertScale->detach();
vertScale2->detach();
horizScale->detach();
horizScale2->detach();
}
}
}
void Graticule::onCanvasSizeChanged(){
vertScale->setBorderDistance(plot->canvas()->width()/2);
horizScale->setBorderDistance(plot->canvas()->height()/2);
vertScale2->setBorderDistance(plot->canvas()->width()/2);
horizScale2->setBorderDistance(plot->canvas()->height()/2);
}
GraticulePlotScaleItem::GraticulePlotScaleItem(
QwtScaleDraw::Alignment alignment, const double pos ):
QwtPlotScaleItem(alignment, pos)
{
}
static QwtScaleDiv getGraticuleScaleDiv(const QwtScaleDiv& from_scaleDiv)
{
double lowerBound;
double upperBound;
QList<double> minorTicks;
QList<double> mediumTicks;
QList<double> majorTicks;
lowerBound = from_scaleDiv.lowerBound();
upperBound = from_scaleDiv.upperBound();
minorTicks = from_scaleDiv.ticks(QwtScaleDiv::MinorTick);
mediumTicks = from_scaleDiv.ticks(QwtScaleDiv::MediumTick);
majorTicks = from_scaleDiv.ticks(QwtScaleDiv::MajorTick);
if (majorTicks.size() >= 2) {
majorTicks.erase(majorTicks.begin());
majorTicks.erase(majorTicks.end() - 1);
}
return QwtScaleDiv(lowerBound, upperBound, minorTicks, mediumTicks, majorTicks);
}
void GraticulePlotScaleItem::updateScaleDiv( const QwtScaleDiv& xScaleDiv,
const QwtScaleDiv& yScaleDiv )
{
QwtPlotScaleItem::updateScaleDiv(getGraticuleScaleDiv(xScaleDiv),
getGraticuleScaleDiv(yScaleDiv));
}