-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraph_Tracker.cc
215 lines (181 loc) · 5.3 KB
/
Graph_Tracker.cc
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* Graph_Tracker
HiROC CVS ID: $Id: Graph_Tracker.cc,v 1.8 2013/09/24 18:43:16 guym Exp $
Copyright (C) 2011 Arizona Board of Regents on behalf of the
Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
the University of Arizona.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, version 2.1,
as published by the Free Software Foundation.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*******************************************************************************/
#include "Graph_Tracker.hh"
#include <QPoint>
#include <QCursor>
#include <QMouseEvent>
#include <qwt_plot.h>
#include <qwt_scale_div.h>
#if defined (DEBUG_SECTION)
/* DEBUG_SECTION controls
DEBUG_SECTION report selection options.
Define any of the following options to obtain the desired debug reports:
*/
#define DEBUG_OFF 0
#define DEBUG_ALL -1
#define DEBUG_CONSTRUCTORS (1 << 0)
#define DEBUG_ACCESSORS (1 << 1)
#define DEBUG_SIGNALS (1 << 2)
#define DEBUG_EVENTS (1 << 3)
#define DEBUG_DEFAULT DEBUG_ALL
#if (DEBUG_SECTION +0) == 0
#undef DEBUG_SECTION
#define DEBUG_SECTION DEBUG_OFF
#endif
#include "HiView_Utilities.hh"
#include <iostream>
#include <iomanip>
using std::clog;
using std::endl;
#endif // DEBUG_SECTION
namespace UA::HiRISE
{
/*==============================================================================
Constants
*/
const char* const
Graph_Tracker::ID =
"UA::HiRISE::Graph_Tracker ($Revision: 1.8 $ $Date: 2013/09/24 18:43:16 $)";
#ifndef DEFAULT_GRAPH_TRACKER_SELECTION_MODE
#define DEFAULT_GRAPH_TRACKER_SELECTION_MODE QwtPicker::PointSelection | \
QwtPicker::ClickSelection
#endif
/*==============================================================================
Constructors
*/
Graph_Tracker::Graph_Tracker
(
QwtPlotCanvas *canvas
)
// Default picker modes:
: QwtPlotPicker
// Axes used for coordinate system
(QwtPlot::xBottom, QwtPlot::yLeft,
// SelectionType and SelectionMode
//DEFAULT_GRAPH_TRACKER_SELECTION_MODE,
// RubberBand
QwtPlotPicker::NoRubberBand,
// DisplayMode
QwtPicker::AlwaysOn,
canvas)
{
#if ((DEBUG_SECTION) & DEBUG_CONSTRUCTORS)
clog << ">-< Graph_Tracker @ " << (void*)this << endl;
#endif
}
/*==============================================================================
Helpers
*/
void
Graph_Tracker::set_cursor
(
const QCursor& cursor
)
{parentWidget ()->setCursor (cursor);}
void
Graph_Tracker::set_cursor_position
(
const QPoint& graph_position
)
{
QCursor::setPos (parentWidget ()->mapToGlobal
(transform (QPointF(graph_position))));
}
/*==============================================================================
QwtPlotPicker override
*/
QwtText
Graph_Tracker::trackerText
(
const QPoint& coordinate
) const
{
#if ((DEBUG_SECTION) & DEBUG_ACCESSORS)
clog << ">>> Graph_Tracker::trackerText: " << coordinate << endl;
#endif
if (coordinate.x () < plot ()->axisScaleDiv (xAxis ()).lowerBound () ||
coordinate.x () > plot ()->axisScaleDiv (xAxis ()).upperBound () ||
coordinate.y () < plot ()->axisScaleDiv (yAxis ()).lowerBound () ||
coordinate.y () > plot ()->axisScaleDiv (yAxis ()).upperBound ())
return QwtText ();
//QPoint point (coordinate);
QString
text;
switch (rubberBand ())
{
case HLineRubberBand:
text = QString::number (coordinate.y ());
break;
case VLineRubberBand:
text = QString::number (coordinate.x ());
break;
default:
text = QString::number (coordinate.x ());
text += ", ";
text += QString::number (coordinate.y ());
}
#if ((DEBUG_SECTION) & DEBUG_ACCESSORS)
clog << "<<< Graph_Tracker::trackerText: " << text << endl;
#endif
return QwtText (text);
}
void
Graph_Tracker::widgetMouseMoveEvent
(
QMouseEvent* event
)
{
#if ((DEBUG_SECTION) & DEBUG_EVENTS)
clog << ">-< Graph_Tracker::widgetMouseMoveEvent: position = "
<< event->pos () << endl;
#endif
QwtPlotPicker::widgetMouseMoveEvent (event);
QPoint
point (invTransform (event->pos ()).toPoint ());
#if ((DEBUG_SECTION) & DEBUG_EVENTS)
clog << " graph data position = " << point << endl;
#endif
if (point.rx () >= int (plot ()->axisScaleDiv (xAxis ()).lowerBound ()) &&
point.rx () <= int (plot ()->axisScaleDiv (xAxis ()).upperBound ()) &&
point.ry () >= int (plot ()->axisScaleDiv (yAxis ()).lowerBound ()) &&
point.ry () <= int (plot ()->axisScaleDiv (yAxis ()).upperBound ()))
{
// >>> SIGNAL <<<
#if ((DEBUG_SECTION) & DEBUG_EVENTS)
clog << "^^^ Graph_Tracker::widgetMouseMoveEvent: "
"emit position " << point << endl;
#endif
emit position (point);
}
}
void
Graph_Tracker::widgetLeaveEvent
(
QEvent* event
)
{
#if ((DEBUG_SECTION) & DEBUG_EVENTS)
clog << ">-< Graph_Tracker::widgetLeaveEvent" << endl;
#endif
QwtPlotPicker::widgetLeaveEvent (event);
// >>> SIGNAL <<<
#if ((DEBUG_SECTION) & DEBUG_EVENTS)
clog << "^^^ Graph_Tracker::widgetLeaveEvent " << endl;
#endif
//emit leave_widget ();
}
} // namespace UA::HiRISE