QXRD  0.11.16
qxrdpowderpointproperty.cpp
Go to the documentation of this file.
2 #include "qcepmutexlocker.h"
3 #include "qcepdebug.h"
4 #include "qcepsettingssaver.h"
5 #include <QScriptEngine>
6 #include <stdio.h>
7 
8 QxrdPowderPointProperty::QxrdPowderPointProperty(QcepSettingsSaverWPtr saver, QcepObject *parent, const char *name, QxrdPowderPoint value, QString toolTip) :
9  QcepProperty(saver, parent, name, toolTip),
10  m_Default(value),
11  m_Value(value)
12 {
13 }
14 
16  QcepObject *parent,
17  const char *name,
18  int n1, int n2, int n3, double x, double y, double r1, double r2, double az,
19  QString toolTip) :
20  QcepProperty(saver, parent, name, toolTip),
21  m_Default(QxrdPowderPoint(n1,n2,n3,x,y,r1,r2,az)),
22  m_Value(QxrdPowderPoint(n1,n2,n3,x,y,r1,r2,az))
23 {
24 }
25 
27 {
28  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
29 
30  return m_Value;
31 }
32 
34 {
35  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
36 
37  return m_Default;
38 }
39 
40 double QxrdPowderPointProperty::subValue(int axis) const
41 {
42  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
43 
44  double res = 0;
45 
46  switch (axis) {
47  case 0:
48  res = m_Value.n1();
49  break;
50  case 1:
51  res = m_Value.n2();
52  break;
53  case 2:
54  res = m_Value.n3();
55  break;
56  case 3:
57  res = m_Value.x();
58  break;
59  case 4:
60  res = m_Value.y();
61  break;
62  case 5:
63  res = m_Value.r1();
64  break;
65  case 6:
66  res = m_Value.r2();
67  break;
68  case 7:
69  res = m_Value.az();
70  break;
71  }
72 
73  return res;
74 }
75 
77 {
78  if (debug()) {
79  printMessage(tr("%1 QxrdPowderPointProperty::setValue(CctwDoubleVector3D %2, int %3) [%4]")
80  .arg(name()).arg(toString(val)).arg(index).arg(this->index()));
81  }
82 
83  if (index == this->index()) {
84  setValue(val);
85  }
86 }
87 
88 void QxrdPowderPointProperty::setSubValue(int axis, double value, int index)
89 {
90  if (index == this->index()) {
91  setSubValue(axis, value);
92  }
93 }
94 
95 void QxrdPowderPointProperty::setSubValue(int axis, int value, int index)
96 {
97  if (index == this->index()) {
98  setSubValue(axis, value);
99  }
100 }
101 
102 void QxrdPowderPointProperty::setSubValue(int axis, int value)
103 {
104  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
105 
106  switch (axis) {
107  case 0:
108  if (value != m_Value.n1()) {
109  int newIndex = incIndex(1);
110 
111  emit subValueChanged(axis, value, newIndex);
112 
113  m_Value.n1() = value;
114 
115  emit valueChanged(m_Value, newIndex);
116  }
117  break;
118 
119  case 1:
120  if (value != m_Value.n2()) {
121  int newIndex = incIndex(1);
122 
123  emit subValueChanged(axis, value, newIndex);
124 
125  m_Value.n2() = value;
126 
127  emit valueChanged(m_Value, newIndex);
128  }
129  break;
130 
131  case 2:
132  if (value != m_Value.n3()) {
133  int newIndex = incIndex(1);
134 
135  emit subValueChanged(axis, value, newIndex);
136 
137  m_Value.n3() = value;
138 
139  emit valueChanged(m_Value, newIndex);
140  }
141  break;
142  }
143 }
144 
145 void QxrdPowderPointProperty::setSubValue(int axis, double value)
146 {
147  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
148 
149  switch (axis) {
150  case 3:
151  if (value != m_Value.x()) {
152  int newIndex = incIndex(1);
153 
154  emit subValueChanged(axis, value, newIndex);
155 
156  m_Value.x() = value;
157 
158  emit valueChanged(m_Value, newIndex);
159  }
160  break;
161 
162  case 4:
163  if (value != m_Value.y()) {
164  int newIndex = incIndex(1);
165 
166  emit subValueChanged(axis, value, newIndex);
167 
168  m_Value.y() = value;
169 
170  emit valueChanged(m_Value, newIndex);
171  }
172  break;
173 
174  case 5:
175  if (value != m_Value.r1()) {
176  int newIndex = incIndex(1);
177 
178  emit subValueChanged(axis, value, newIndex);
179 
180  m_Value.r1() = value;
181 
182  emit valueChanged(m_Value, newIndex);
183  }
184  break;
185 
186  case 6:
187  if (value != m_Value.r2()) {
188  int newIndex = incIndex(1);
189 
190  emit subValueChanged(axis, value, newIndex);
191 
192  m_Value.r2() = value;
193 
194  emit valueChanged(m_Value, newIndex);
195  }
196  break;
197 
198  case 7:
199  if (value != m_Value.az()) {
200  int newIndex = incIndex(1);
201 
202  emit subValueChanged(axis, value, newIndex);
203 
204  m_Value.az() = value;
205 
206  emit valueChanged(m_Value, newIndex);
207  }
208  break;
209  }
210 }
211 
213 {
214  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
215 
216  QString res = tr("[ %1 %2 %3 %4 %5 %6 %7 %8 ]").arg(val.n1()).arg(val.n2()).arg(val.n3()).arg(val.x()).arg(val.y()).arg(val.r1()).arg(val.r2()).arg(val.az());
217 
218  return res;
219 }
220 
222 {
223  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
224 
226  printMessage(tr("%1 QxrdPowderPointProperty::setValue(QxrdPowderPoint %2)")
227  .arg(name()).arg(toString(val)));
228  }
229 
230  if (val != m_Value) {
231  int newIndex = incIndex(1);
232 
233  if (debug()) {
234  printMessage(tr("%1: QxrdPowderPointProperty::setValue(QxrdPowderPoint %2) [%3]")
235  .arg(name()).arg(toString(val)).arg(index()));
236  }
237 
238  if (val.n1() != m_Value.n1()) {
239  emit subValueChanged(0, val.n1(), newIndex);
240  }
241 
242  if (val.n2() != m_Value.n2()) {
243  emit subValueChanged(1, val.n2(), newIndex);
244  }
245 
246  if (val.n3() != m_Value.n3()) {
247  emit subValueChanged(2, val.n3(), newIndex);
248  }
249 
250  if (val.x() != m_Value.x()) {
251  emit subValueChanged(3, val.x(), newIndex);
252  }
253 
254  if (val.y() != m_Value.y()) {
255  emit subValueChanged(4, val.y(), newIndex);
256  }
257 
258  if (val.r1() != m_Value.r1()) {
259  emit subValueChanged(5, val.r1(), newIndex);
260  }
261 
262  if (val.r2() != m_Value.r2()) {
263  emit subValueChanged(6, val.r2(), newIndex);
264  }
265 
266  if (val.az() != m_Value.az()) {
267  emit subValueChanged(7, val.az(), newIndex);
268  }
269 
270  m_Value = val;
271 
273 
274  if (saver) {
275  saver->changed(this);
276  }
277 
278  emit valueChanged(m_Value, newIndex);
279  }
280 }
281 
283 {
284  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
285 
286  m_Default = val;
287 }
288 
290 {
292  printMessage(tr("%1: QxrdPowderPointProperty::resetValue").arg(name()));
293  }
294 
296 }
297 
298 void QxrdPowderPointProperty::linkTo(QSpinBox *n1SpinBox,
299  QSpinBox *n2SpinBox,
300  QSpinBox *n3SpinBox,
301  QDoubleSpinBox *xSpinBox,
302  QDoubleSpinBox *ySpinBox,
303  QDoubleSpinBox *r1SpinBox,
304  QDoubleSpinBox *r2SpinBox,
305  QDoubleSpinBox *azSpinBox)
306 {
307  if (n1SpinBox) {
308  linkTo(0, n1SpinBox);
309  }
310 
311  if (n2SpinBox) {
312  linkTo(1, n2SpinBox);
313  }
314 
315  if (n3SpinBox) {
316  linkTo(2, n3SpinBox);
317  }
318 
319  if (xSpinBox) {
320  linkTo(3, xSpinBox);
321  }
322 
323  if (ySpinBox) {
324  linkTo(4, ySpinBox);
325  }
326 
327  if (r1SpinBox) {
328  linkTo(5, r1SpinBox);
329  }
330 
331  if (r2SpinBox) {
332  linkTo(6, r2SpinBox);
333  }
334 
335  if (azSpinBox) {
336  linkTo(7, azSpinBox);
337  }
338 }
339 
340 void QxrdPowderPointProperty::linkTo(int axis, QSpinBox *spinBox)
341 {
342  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
343 
344  if (axis>=0 && axis<=2) {
346  = new QxrdPowderPointPropertySpinBoxHelper(spinBox, this, axis);
347 
348  helper->moveToThread(spinBox->thread());
349  helper->connect();
350 
351  spinBox -> setValue((int) subValue(axis));
352  spinBox -> setKeyboardTracking(false);
353 
354  setWidgetToolTip(spinBox);
355 
356  connect(this, (void (QxrdPowderPointProperty::*)(int, int, int)) &QxrdPowderPointProperty::subValueChanged,
359  this, (void (QxrdPowderPointProperty::*)(int, int, int)) &QxrdPowderPointProperty::setSubValue);
360  }
361 }
362 
363 void QxrdPowderPointProperty::linkTo(int axis, QDoubleSpinBox *spinBox)
364 {
365  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
366 
367  if (axis>=3 && axis<=7) {
369  = new QxrdPowderPointPropertyDoubleSpinBoxHelper(spinBox, this, axis);
370 
371  helper->moveToThread(spinBox->thread());
372  helper->connect();
373 
374  spinBox -> setValue(subValue(axis));
375  spinBox -> setKeyboardTracking(false);
376 
377  setWidgetToolTip(spinBox);
378 
379  connect(this, (void (QxrdPowderPointProperty::*)(int, double, int)) &QxrdPowderPointProperty::subValueChanged,
382  this, (void (QxrdPowderPointProperty::*)(int, double, int)) &QxrdPowderPointProperty::setSubValue);
383  }
384 }
385 
387  (QSpinBox *spinBox, QxrdPowderPointProperty *property, int axis)
388  : QObject(spinBox),
389  m_SpinBox(spinBox),
390  m_Property(property),
391  m_Axis(axis)
392 {
393 }
394 
396 {
397  CONNECT_CHECK(QObject::connect(m_SpinBox, (void (QSpinBox::*)(int)) &QSpinBox::valueChanged,
398  this, &QxrdPowderPointPropertySpinBoxHelper::setValue, Qt::DirectConnection));
399 }
400 
401 void QxrdPowderPointPropertySpinBoxHelper::setSubValue(int axis, int value, int index)
402 {
403  if (m_Property->index() == index) {
404  if (m_Axis == axis) {
405  if (m_SpinBox->value() != value) {
406  bool block = m_SpinBox->blockSignals(true);
407  m_SpinBox->setValue(value);
408  m_SpinBox->blockSignals(block);
409  }
410  }
411  }
412 }
413 
415 {
416  emit subValueChanged(m_Axis, value, m_Property->incIndex(1));
417 }
418 
420  (QDoubleSpinBox *spinBox, QxrdPowderPointProperty *property, int axis)
421  : QObject(spinBox),
422  m_DoubleSpinBox(spinBox),
423  m_Property(property),
424  m_Axis(axis)
425 {
426 }
427 
429 {
430  CONNECT_CHECK(QObject::connect(m_DoubleSpinBox, (void (QDoubleSpinBox::*)(double)) &QDoubleSpinBox::valueChanged,
431  this, &QxrdPowderPointPropertyDoubleSpinBoxHelper::setValue, Qt::DirectConnection));
432 }
433 
434 void QxrdPowderPointPropertyDoubleSpinBoxHelper::setSubValue(int axis, double value, int index)
435 {
436  if (m_Property->index() == index) {
437  if (m_Axis == axis) {
438  if (m_DoubleSpinBox->value() != value) {
439  bool block = m_DoubleSpinBox->blockSignals(true);
440  m_DoubleSpinBox->setValue(value);
441  m_DoubleSpinBox->blockSignals(block);
442  }
443  }
444  }
445 }
446 
448 {
449  emit subValueChanged(m_Axis, value, m_Property->incIndex(1));
450 }
451 
453  : QcepProperty(saver, parent, name, toolTip),
454  m_Default(value),
455  m_Value(value)
456 {
457 }
458 
460 {
461  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
462 
463  return m_Value;
464 }
465 
467 {
468  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
469 
470  return m_Default;
471 }
472 
474 {
475  if (debug()) {
476  printMessage(tr("%1 QxrdPowderPointVectorProperty::setValue(QxrdPowderPointVector %2, int %3) [%4]")
477  .arg(name()).arg(toString(val)).arg(index).arg(this->index()));
478  }
479 
480  if (index == this->index()) {
481  setValue(val);
482  }
483 }
484 
486 {
487  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
488 
490 }
491 
493 {
494  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
495 
496  QxrdPowderPointVector list = value();
497  list.append(val);
498 
499  setValue(list);
500 }
501 
503 {
504  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
505 
506  QString res = "[";
507  int ct = val.count();
508 
509  for (int i=0; i<ct; i++) {
510  if (i<(ct-1)) {
511  res += tr("%1,\n").arg(val[i].toString());
512  } else {
513  res += tr("%1").arg(val[i].toString());
514  }
515  }
516 
517  res += "]";
518 
519  return res;
520 }
521 
523 {
524  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
525 
527  printMessage(tr("%1 QxrdPowderPointVectorProperty::setValue(QxrdPowderPointVector %2)")
528  .arg(name()).arg(toString(val)));
529  }
530 
531  if (val != m_Value) {
532  if (debug()) {
533  printMessage(tr("%1: QxrdPowderPointVectorProperty::setValue(QxrdPowderPointVector %2) [%3]")
534  .arg(name()).arg(toString(val)).arg(index()));
535  }
536 
537  m_Value = val;
538 
540 
541  if (saver) {
542  saver->changed(this);
543  }
544 
545  emit valueChanged(m_Value, incIndex(1));
546  }
547 }
548 
550 {
551  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
552 
553  m_Default = val;
554 }
555 
557 {
559  printMessage(tr("%1: QxrdPowderPointVectorProperty::resetValue").arg(name()));
560  }
561 
563 }
void appendValue(QxrdPowderPoint val)
double y() const
double az() const
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void subValueChanged(int axis, double value, int index)
void setWidgetToolTip(QWidget *widget)
void setSubValue(int axis, int value, int index)
int n2() const
double subValue(int axis) const
void subValueChanged(int axis, int value, int index)
QxrdPowderPoint value() const
QxrdPowderPointPropertySpinBoxHelper(QSpinBox *spinBox, QxrdPowderPointProperty *property, int axis)
QMutex m_Mutex
Definition: qcepproperty.h:69
QString toString(const QxrdPowderPoint &pt)
double r2() const
QString toString(const QxrdPowderPointVector &vec)
QxrdPowderPointVector defaultValue() const
int incIndex(int step)
void valueChanged(QxrdPowderPointVector val, int index)
void subValueChanged(int axis, int val, int index)
QxrdPowderPointVector value() const
void setValue(QxrdPowderPointVector val, int index)
void linkTo(QSpinBox *n1SpinBox, QSpinBox *n2SpinBox, QSpinBox *n3SpinBox, QDoubleSpinBox *xSpinBox, QDoubleSpinBox *ySpinBox, QDoubleSpinBox *r1SpinBox, QDoubleSpinBox *r2SpinBox, QDoubleSpinBox *azSpinBox)
int n3() const
void valueChanged(QxrdPowderPoint val, int index)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
QxrdPowderPointVectorProperty(QcepSettingsSaverWPtr saver, QcepObject *parent, const char *name, QxrdPowderPointVector value, QString toolTip)
QxrdPowderPointPropertyDoubleSpinBoxHelper(QDoubleSpinBox *spinBox, QxrdPowderPointProperty *property, int axis)
QxrdPowderPointProperty(QcepSettingsSaverWPtr saver, QcepObject *parent, const char *name, QxrdPowderPoint value, QString toolTip)
QxrdPowderPoint defaultValue() const
void setDefaultValue(QxrdPowderPointVector val)
QString name() const
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
void setValue(QxrdPowderPoint val, int index)
void setSubValue(int axis, double value, int index)
int debug() const
double x() const
int n1() const
#define CONNECT_CHECK(res)
Definition: qcepmacros.h:14
double r1() const
void setSubValue(int axis, int value, int index)
void setDefaultValue(QxrdPowderPoint val)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QcepSettingsSaverWPtr m_Saver
Definition: qcepproperty.h:70