-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQEScalarBarchart-bak.cpp
465 lines (394 loc) · 13.9 KB
/
QEScalarBarchart-bak.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/* QEScalarBarchart.cpp
*
* This file is part of the EPICS QT Framework, initially developed at the
* Australian Synchrotron.
*
* The EPICS QT Framework is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The EPICS QT Framework 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 the EPICS QT Framework. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright (c) 2014 Australian Synchrotron.
*
* Author:
* Andrew Starritt
* Contact details:
*/
#include <QDebug>
#include <QECommon.h>
#include <QCaObject.h>
#include <QEScalarBarchart.h>
#define DEBUG qDebug () << "QEScalarBarchart" << __FUNCTION__ << __LINE__
//------------------------------------------------------------------------------
// Constructor with no initialisation
//
QEScalarBarchart::QEScalarBarchart (QWidget * parent) : QEFrame (parent)
{
// Set default property values
// Super class....
//
this->setFrameShape (QFrame::Panel);
this->setFrameShadow (QFrame::Plain);
this->setVariableAsToolTip (true);
// Create internal widget.
//
this->layout = new QHBoxLayout (this);
this->layout->setMargin (0); // extact fit.
this->barchart = new QEBarchart (this);
this->layout->addWidget (this->barchart);
// Set barchart properties.
//
this->barchart->setFrameShape (QFrame::NoFrame);
this->barchart->setFrameShadow (QFrame::Plain);
this->barchart->setAutoScale (true);
this->barchart->setMouseTracking (true);
this->barchart->installEventFilter (this);
this->mScaleMode = Manual;
for (int j = 0; j < ARRAY_LENGTH (this->isFirstUpdate); j++) {
this->isFirstUpdate [j] = true;
}
// Set up data
//
this->setNumVariables (ARRAY_LENGTH (this->vnpm));
// Set up default properties
//
this->setAllowDrop (false);
// Use default context menu.
//
this->setupContextMenu ();
this->selectedChannel = -1;
// Set up a connection to recieve variable name property changes
// The variable name property manager class only delivers an updated
// variable name after the user has stopped typing.
//
for (int j = 0; j < ARRAY_LENGTH (this->vnpm); j++) {
this->vnpm [j].setVariableIndex (j);
QObject::connect (&this->vnpm [j], SIGNAL (newVariableNameProperty (QString, QString, unsigned int)),
this, SLOT (newVariableNameProperty (QString, QString, unsigned int)));
}
}
//------------------------------------------------------------------------------
// This is the slot used to recieve new PV information.
//
void QEScalarBarchart::newVariableNameProperty (QString pvName, QString subs, unsigned int pvi)
{
this->barchart->clearValue ((int) pvi);
this->setVariableNameAndSubstitutions (pvName, subs, pvi);
}
//------------------------------------------------------------------------------
// Implementation of QEWidget's virtual funtion to create the specific type of
// QCaObject required. For a barchart floating point numbers are required.
//
qcaobject::QCaObject* QEScalarBarchart::createQcaItem (unsigned int pvi)
{
qcaobject::QCaObject* result = NULL;
if (pvi < ARRAY_LENGTH (this->vnpm)) {
QString pvName = this->getSubstitutedVariableName (pvi);
result = new QEFloating (pvName, this, &this->floatingFormatting, pvi);
}
return result;
}
//------------------------------------------------------------------------------
// Start updating.
//
void QEScalarBarchart::establishConnection (unsigned int variableIndex)
{
if (variableIndex >= ARRAY_LENGTH (this->vnpm)) {
DEBUG << "unexpected variableIndex" << variableIndex;
return;
}
// Create a connection.
// If successfull, the QCaObject object that will supply data update signals will be returned
// Note createConnection creates the connection and returns reference to existing QCaObject.
//
qcaobject::QCaObject* qca = this->createConnection (variableIndex);
// If a QCaObject object is now available to supply data update signals,
// connect it to the appropriate slots.
//
if (qca) {
QObject::connect (qca, SIGNAL (floatingChanged (const double &, QCaAlarmInfo &, QCaDateTime &, const unsigned int &)),
this, SLOT (setChannelValue (const double &, QCaAlarmInfo &, QCaDateTime &, const unsigned int &)));
QObject::connect (qca, SIGNAL (connectionChanged (QCaConnectionInfo &, const unsigned int &)),
this, SLOT (connectionChanged (QCaConnectionInfo &, const unsigned int &)));
// Also set/reset value.
// Note: this also creates the underlying entry with the barchart widget.
// Usefull for indexOfPosition calls before first PV update or missing PVs.
//
this->barchart->setValue ((int) variableIndex, 0.0);
}
}
//------------------------------------------------------------------------------
// Act on a connection change.
// This is the slot used to recieve connection updates from a QCaObject based class.
//
void QEScalarBarchart::connectionChanged (QCaConnectionInfo & connectionInfo,
const unsigned int & variableIndex)
{
bool pvConnected;
if (variableIndex >= ARRAY_LENGTH (this->vnpm)) {
DEBUG << "unexpected variableIndex" << variableIndex;
return;
}
// Note the connected state
//
pvConnected = connectionInfo.isChannelConnected ();
// Display the connected state
//
this->updateToolTipConnection (pvConnected, variableIndex);
// This is a multi PV widget.
// Do not use updateConnectionStyle.
//
// If this is a disconnect - set gray.
// If this is a connect, we will soon change from gray to required colour.
//
this->barchart->setColour ((int) variableIndex, QColor (0xe8e8e8));
// More trob. than it's worth to check if this is a connect or disconnect.
//
this->isFirstUpdate [variableIndex] = true;
}
//------------------------------------------------------------------------------
//
void QEScalarBarchart::updatebarchartScale ()
{
qcaobject::QCaObject* qca = NULL;
double lopr;
double hopr;
switch (this->mScaleMode) {
case Manual:
this->barchart->setAutoScale (false);
break;
case Auto:
this->barchart->setAutoScale (true);
break;
case OperationalRange:
lopr = 0.0;
hopr = 0.0;
for (int j = 0; j < QE_BARCHART_NUMBER_VARIABLES; j++) {
qca = this->getQcaItem (j);
if (qca) {
double lowLim = qca->getDisplayLimitLower ();
double upLim = qca->getDisplayLimitUpper ();
// Has the operating range been defined??
//
if ((lowLim != 0.0) || (upLim != 0.0)) {
// Yes - incorporate into overall operating range.
//
lopr = MIN (lopr, lowLim);
hopr = MAX (hopr, upLim);
}
}
}
// Has at least one PV specified a valid range?
//
if ((lopr != 0.0) || (hopr != 0.0)) {
// Yes - use the range.
//
this->barchart->setMinimum (lopr);
this->barchart->setMaximum (hopr);
this->barchart->setAutoScale (false);
}
// else just leave as is.
break;
}
}
//------------------------------------------------------------------------------
// Update the barchart bar value
// This is the slot used to recieve data updates from a QCaObject based class.
//
void QEScalarBarchart::setChannelValue (const double& value,
QCaAlarmInfo& alarmInfo,
QCaDateTime&,
const unsigned int &variableIndex)
{
if (variableIndex >= ARRAY_LENGTH (this->vnpm)) {
DEBUG << "unexpected variableIndex" << variableIndex;
return;
}
QColor colour;
if (this->getDisplayAlarmState ()) {
colour = this->getColor (alarmInfo, 255);
} else {
colour = this->barchart->getBarColour ();
}
this->barchart->setColour ((int) variableIndex, colour);
this->barchart->setValue ((int) variableIndex, value);
// First update (for this connection).
//
if (this->isFirstUpdate [variableIndex]) {
this->updatebarchartScale ();
}
// Don't invoke common alarm handling processing.
// Invoke for tool tip processing directly.
//
this->updateToolTipAlarm (alarmInfo.severityName (), variableIndex);
}
//------------------------------------------------------------------------------
//
void QEScalarBarchart::addPvName (const QString& pvName)
{
for (int slot = 0; slot < ARRAY_LENGTH (this->vnpm); slot++) {
QString currentPvName = this->getSubstitutedVariableName (slot);
if (currentPvName.isEmpty ()) {
// Found an empty slot.
//
this->setVariableName (pvName, slot);
this->establishConnection (slot);
break;
}
}
}
//------------------------------------------------------------------------------
//
void QEScalarBarchart::setPvNameSubstitutions (const QString& pvNameSubstitutions)
{
// Set all (but read 1).
//
for (int j = 0; j < ARRAY_LENGTH (this->vnpm); j++) {
this->vnpm [j].setSubstitutionsProperty (pvNameSubstitutions);
}
}
//------------------------------------------------------------------------------
//
QString QEScalarBarchart::getPvNameSubstitutions () const
{
// All the same - any will do.
//
return this->vnpm [0].getSubstitutionsProperty ();
}
//------------------------------------------------------------------------------
//
void QEScalarBarchart::setScaleMode (const ScaleModes scaleModeIn)
{
this->mScaleMode = scaleModeIn;
this->updatebarchartScale ();
}
//------------------------------------------------------------------------------
//
QEScalarBarchart::ScaleModes QEScalarBarchart::getScaleMode () const
{
return this->mScaleMode;
}
//------------------------------------------------------------------------------
//
void QEScalarBarchart::setReadOut (const QString& text)
{
message_types mt (MESSAGE_TYPE_INFO, MESSAGE_KIND_STATUS);
this->sendMessage (text, mt);
}
//------------------------------------------------------------------------------
// Index is channel number.
//
void QEScalarBarchart::genReadOut (const int index)
{
qcaobject::QCaObject* qca = NULL;
QString text;
if (index >= 0) {
qca = this->getQcaItem ((unsigned int) index);
}
if (qca) {
bool isDefined;
QVariant value;
QCaAlarmInfo alarmInfo;
QCaDateTime timeStamp;
qca->getLastData (isDefined, value, alarmInfo, timeStamp);
text = qca->getRecordName ();
if (isDefined) {
text.append (" ").append (value.toString ());
text.append(" ").append (qca->getEgu ());
} else {
text.append (" undefined.");
}
} else {
text = "";
}
this->setReadOut (text);
}
//==============================================================================
// Events.
//
bool QEScalarBarchart::eventFilter (QObject *obj, QEvent *event)
{
const Qt::MouseButtons leftRight= Qt::LeftButton | Qt::RightButton;
const QEvent::Type type = event->type ();
QMouseEvent* mouseEvent = NULL;
Qt::MouseButton button;
switch (type) {
case QEvent::MouseButtonPress:
mouseEvent = static_cast<QMouseEvent *> (event);
button = mouseEvent->button();
if ((obj == this->barchart) && ((button & leftRight) != 0)) {
// We are about to launch the context menu or drag variable or data.
// Identify current item (if any).
//
QMouseEvent*mouseEvent = static_cast<QMouseEvent *> (event);
this->selectedChannel = this->barchart->indexOfPosition (mouseEvent->pos ());
// event has not fully handled - fall through.
}
break;
case QEvent::MouseMove:
mouseEvent = static_cast<QMouseEvent *> (event);
if (obj == this->barchart) {
int index = this->barchart->indexOfPosition (mouseEvent->pos ());
this->genReadOut (index);
return true; // event has been handled.
}
break;
default:
// Just fall through
break;
}
return false; // we did not handle this event.
}
//==============================================================================
// Copy (no paste)
//
QString QEScalarBarchart::copyVariable ()
{
if (this->selectedChannel >= 0) {
return this->getSubstitutedVariableName ((unsigned int) this->selectedChannel);
} else {
return "";
}
}
//------------------------------------------------------------------------------
//
QVariant QEScalarBarchart::copyData ()
{
QVariant result (QVariant::Invalid);
qcaobject::QCaObject* qca = NULL;
if (this->selectedChannel >= 0) {
qca = this->getQcaItem ((unsigned int) this->selectedChannel);
}
if (qca) {
bool isDefined;
QVariant value;
QCaAlarmInfo alarmInfo;
QCaDateTime timeStamp;
qca->getLastData (isDefined, value, alarmInfo, timeStamp);
if (isDefined) {
result = value;
}
} else {
result = QVariant ();
}
return result;
}
//---------------------------------------------------------------------------------
//
void QEScalarBarchart::paste (QVariant s)
{
QStringList pvNameList = QEUtilities::variantToStringList (s);
for (int j = 0; j < pvNameList.count (); j++) {
this->addPvName (pvNameList.value (j));
}
}
// end