casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtGuiEntry.qo.h
Go to the documentation of this file.
1 //# QtGuiEntry.qo.h: Individual interface elements for general-purpose
2 //# Qt options widget (QtAutoGui).
3 //# Copyright (C) 2005
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 //# $Id$
28 
29 #ifndef QTGUIENTRY_H
30 #define QTGUIENTRY_H
31 
32 #include <casa/aips.h>
33 #include <casa/BasicSL/String.h>
34 #include <casa/BasicMath/Math.h>
35 
36 #include <graphics/X11/X_enter.h>
37 # include <QDomDocument>
38 # include <QCheckBox>
39 //#dk Be careful to put ui_*.h within X_enter/exit bracket too,
40 //# because they'll have Qt includes.
41 //# E.g. <QApplication> needs the X11 definition of 'Display'
42 # include "adjustmentBottom.ui.h"
43 # include "sliderLabelItem.ui.h"
44 # include "sliderEditorItem.ui.h"
45 # include "lineEditorItem.ui.h"
46 # include "comboItem.ui.h"
47 # include "checkButtonItem.ui.h"
48 # include "pushButtonItem.ui.h"
49 # include "minMaxEditorItem.ui.h"
50 # include "pairItem.ui.h"
51 #include <graphics/X11/X_exit.h>
52 
53 #include <utility>
54 
55 
56 namespace casa { //# NAMESPACE CASA - BEGIN
57 
58 
59  class QtAutoGui;
60 
61 
62 //# //////////////// QtAdjustmentBottom //////////////////////////////////
63 
64  class QtAdjustmentTop : public QWidget, private Ui::AdjustmentBottom {
65  Q_OBJECT
66  public:
67  QtAdjustmentTop(QtAutoGui *parent=0, QString name="");
68  void setText(QString txt) {
69  dataName->setText(txt);
70  }
72  public slots:
73  void dataNameChanged(QString value);
74  void setOriginal();
75  void setDefault();
76  void setMemory();
77  void setClear();
78  void setCopy();
79  void setPaste();
80  void apply();
81  void load();
82  void save();
83  void restore();
84  void close();
85 
86  void hideDismiss(); //#dk
87 
88  private:
91  };
92 
93 
94 //# /////////////////// QtSliderBase //////////////////////////////////////
95 
96 
97 // <summary>
98 // Base class for QtAutoGui slider interface elements.
99 // </summary>
100 
101 // <synopsis>
102 // This is a base with common functionality for the two slider 'guientries':
103 // QtSliderEditor, which has a value edit box, and QtSliderLabel, with a
104 // non-editable value label. This class is abstract; its constructor can only
105 // be called by a derived class. That class should also call constructBase()
106 // after cxreating its interface elements, to complete construction.
107 // </synopsis>
108 
109  class QtSliderBase : public QWidget {
110 
111  Q_OBJECT //# Allows slot/signal definition. Must only occur in
112  //# implement/.../*.h files; also, makefile must include
113  //# name of this file in 'mocs' section.
114 
115  public:
116 
117  // Set interface label text ('listname').
118  void setLabelText(QString txt) {
119  nameLabel_->setText(txt);
120  }
121 
122  // Internal name ('dlformat')
123  QString name() {
124  return itemName;
125  }
126 
127  // Set up main state (value, etc.) and external appearance of
128  // this widget, according to options record (passed as a QDomElement).
129  // Called via constructor, and from QtAutoGui::changeOptions().
130  // Does not trigger (significant) signals; it is intended to set this
131  // interface element to library's internal value (not vice versa).
132  void reSet(QDomElement& ele);
133 
134  protected:
135 
136  // Only for use by derived classes.
137  // <group>
138  QtSliderBase(QWidget *parent=0) : QWidget(parent) { }
140  // </group>
141 
142  // Derived class should call this within its constructor, after it
143  // has a valid QSlider, name QLabel and menu QToolButton (usually,
144  // after calling setUi()), passing them down in the parameters below.
145  // ele is the QDomElement (an xml version of an option casacore::Record) used to
146  // construct the derived class.
147  void constructBase(QDomElement &ele, QSlider* slider,
148  QLabel* nameLabel, QToolButton* menuBtn);
149 
150  // Fetch numeric value of attribute of ele named attnm, into val.
151  // Does nothing if attr doesn't exist or is not valid numerically.
152  void getAttr(const QDomElement& ele, QString attnm, double& val);
153 
154  protected slots:
155 
156  // slider changed by user
157  virtual void slChg(int slval) {
158  update(externalVal(slval));
159  if ( ! onrelease_ ) emitVal( );
160  }
161  virtual void release( ) {
162  if ( onrelease_ ) emitVal( );
163  }
164 
165  // 'revert-to-original' selected in menu.
166  virtual void setOriginal();
167 
168 
169  signals:
170 
171  // Main output signal. Main parameters of interest are item name and
172  // new value.
173  void itemValueChanged(QString name, QString value, int action, bool apply);
174 
175  // class user may wish to connect to and display these.
176  void errMsg(casacore::String errmsg);
177 
178 
179  protected:
180 
181  // Derived class should implement: set value text box or label (if any)
182  // to (normalized) current value. (Should not trigger class's own slots).
183  virtual void updateText() = 0;
184 
185 
186  int round(double val) {
187  return casacore::ifloor(val + .5);
188  }
189 
190  // Integer values with in [0, slMax_] on the internal slider are scaled
191  // to external values within [dMin_, dMax_].
192  // These two routines convert between the two scalings.
193  // <group>
194  double externalVal(int sldVal) {
195  return casacore::min(dMax_, (dMin_ + casacore::max(0., dIncr_*sldVal)));
196  }
197 
198  int sliderVal(double extVal) {
199  return round(casacore::max(0., casacore::min(slMax_, (extVal-dMin_)/dIncr_)));
200  }
201  // </group>
202 
203  // These two routines convert 'external' values between double and
204  // text.
205  // <group>
206  QString toText(double val);
207  double toNumber(QString text, bool* ok=0);
208  // </group>
209 
210  // Current external value, as text.
211  QString textVal() {
212  return toText(dVal_);
213  }
214 
215  // Adjusts integer slider range (slMax_) and the increment that each
216  // unit on the slider represents (dIncr_), according to latest
217  // increment and range request (dIncr0_, dMin_, dMax_).
218  void adjSlIncr();
219 
220  // Sets slider to latest range and value (without
221  // triggering slider signals or slChg slot below).
222  void updateSlider();
223 
224  // emit current value -- widget's main output.
225  void emitVal();
226 
227  // Accepts new value (if any), updates interface (without
228  // retriggering any internal slots).
229  // New value should already have been validated.
230  void update(double dval);
231 
232 
233  // main state. Determines the float scaling for the (necessarily int)
234  // QSlider. dVal_ is the slider's 'external' value (which may be
235  // floating-point). dMin_ and dMax_ are its 'external' range.
236  // dIncr0_ is the requested 'external' slider increment ('presolution'),
237  // dIncr_ is the increment actually used (normally, these will be the same).
238  //
239  // Internally, the slider's range will be [0, slMax_]; slMax_
240  // will be a non-negative integer value. Both of the QSlider's
241  // internal increments (singleStep, pageStep) will be 1.
242 
244 
245  // Whether this element emits float values (ptype 'floatrange')
246  // vs. ints (ptype 'intrange').
247  bool floatrng_;
248 
249  // Should the event be generated only upon releasing the slider?
251 
252  // For restoring 'original' value.
253  double origVal_;
254 
255  // Relevant user interface elements. Must be created by
256  // derived class and passed in via constructBase().
257  // <group>
258  QSlider* slider_;
259  QLabel* nameLabel_;
260  QToolButton* menuBtn_;
261  // </group>
262 
263  // Internal name ('dlformat').
264  QString itemName;
265 
266  };
267 
268 
269 
270 //# //////////////////// QtSliderEditor ///////////////////////////////////
271 
272 
273  class QtSliderEditor : public QtSliderBase, private Ui::SliderEditorItem {
274 
275  Q_OBJECT //# Allows slot/signal definition. Must only occur in
276  //# implement/.../*.h files; also, makefile must include
277  //# name of this file in 'mocs' section.
278 
279  public:
280 
281  QtSliderEditor(QDomElement& ele, QWidget *parent=0);
283 
284  protected:
285 
286  // (not intended for use at present).
287  QtSliderEditor(QWidget *parent=0): QtSliderBase(parent) {
288  setupUi(this);
289  radioButton->hide();
290  }
291 
292  // Sets text box to (normalized) current value.
293  // (Should not trigger class's own slots either).
294  void updateText() {
295  lineEdit->setText(textVal());
296  }
297 
298  // main validation/update routine for changes to text version of value.
299  // strval is the candidate text, which is still to be validated/normalized.
300  void textChg(QString strval);
301 
302  protected slots:
303 
304  //# text edited by user
305  virtual void edited() {
306  textChg(lineEdit->text());
307  }
308 
309  //# // Triggered when 'revert-to-original' selected in menu
310  //# virtual void setOriginal() { textChg(toText(origVal_)); }
311  //# //# (This version _will expand slider limits, if necessary).
312 
313  };
314 
315 
316 
317 //# /////////////////////// QtSliderLabel /////////////////////////////////
318 
319 
320  class QtSliderLabel : public QtSliderBase, private Ui::SliderLabelItem {
321 
322  Q_OBJECT //# Allows slot/signal definition. Must only occur in
323  //# implement/.../*.h files; also, makefile must include
324  //# name of this file in 'mocs' section.
325 
326  public:
327 
328  QtSliderLabel(QDomElement& ele, QWidget *parent=0);
330 
331  protected:
332 
333  // (not intended for use at present).
334  QtSliderLabel(QWidget *parent=0): QtSliderBase(parent) {
335  setupUi(this);
336  }
337 
338  // Sets value label to (normalized) current value.
339  void updateText();
340 
341  };
342 
343 
344 
345 
346 //# //////////////////////// QtMinMaxEditor ///////////////////////////////
347 
348  class QtMinMaxEditor : public QWidget, private Ui::MinMaxEditorItem {
349  Q_OBJECT
350  public:
351  QtMinMaxEditor(QWidget *parent=0);
352  QtMinMaxEditor(QDomElement &ele, QWidget *parent=0);
353  ~QtMinMaxEditor();
354  bool validate(QString value);
355  void setLabelText(QString txt) {
356  nameLabel->setText(txt);
357  }
358  QString name() {
359  return itemName;
360  }
361  void reSet(QString);
362  public slots:
363  void display2();
364  void display2(int value);
365  void display2(QString value);
366  void setOriginal();
367  void setDefault();
368  void setCopy();
369  void setPaste();
370  void setHistogram();
371  signals:
372  void itemValueChanged(QString name, QString value, int action, bool apply);
373  private:
374  QString itemName;
375  double scale;
377  QString orig;
378  };
379 
380 
381 //# //////////////////////// QtLineEditor ////////////////////////////////
382 
383  class QtLineEditor : public QWidget, private Ui::LineEditorItem {
384  Q_OBJECT
385  public:
386  QtLineEditor(QWidget *parent=0);
387  QtLineEditor(QDomElement &ele, QWidget *parent=0);
388  ~QtLineEditor();
389  bool validate(QString value);
390  void setLabelText(QString txt) {
391  nameLabel->setText(txt);
392  }
393  QString name() {
394  return itemName;
395  }
396  void reSet(QString);
397  public slots:
398  void validateAndEmit(QString value);
399  void editingFinished();
400  void setOriginal();
401  void setDefault();
402  void setCopy();
403  void setPaste();
404  signals:
405  void itemValueChanged(QString name, QString value, int action, bool apply);
406  protected:
407  void leaveEvent(QEvent*);
408  private:
409  QString ptype;
410  QString itemName;
411  QString origValue;
413  };
414 
415 
416 //# //////////////////////// QtCombo ////////////////////////////////////
417 
418  class QtCombo : public QWidget, private Ui::ComboItem {
419  Q_OBJECT
420  public:
421  QtCombo(QWidget *parent=0);
422  QtCombo(QDomElement &ele, QWidget *parent=0);
423  ~QtCombo();
424  void setLabelText(QString txt) {
425  nameLabel->setText(txt);
426  }
427  QString name() {
428  return itemName;
429  }
430  void reSet(QString);
431  public slots:
432  void setOriginal();
433  void setDefault();
434  void setCopy();
435  void setPaste();
436  signals:
437  void itemValueChanged(QString name, QString value, int action, bool apply);
438  protected slots:
439  void emitValue();
440  private:
441  QString itemName;
443  QString orig;
444  };
445 
446 
447 //# //////////////////////// QtBoolean //////////////////////////////////
448 
449  class QtBool : public QWidget, private Ui::ComboItem {
450  Q_OBJECT
451  public:
452  QtBool(QWidget *parent=0);
453  QtBool(QDomElement &ele, QWidget *parent=0);
454  ~QtBool();
455  void setLabelText(QString txt) {
456  nameLabel->setText(txt);
457  }
458  QString name() {
459  return itemName;
460  }
461  void reSet(QString);
462  public slots:
463  void setOriginal();
464  void setDefault();
465  void setCopy();
466  void setPaste();
467  signals:
468  void itemValueChanged(QString name, QString value, int action, bool apply);
469  protected slots:
470  void emitValue();
471  private:
472  QString itemName;
474  QString orig;
475  };
476 
477 
478 //# //////////////////////// QtPushButton ////////////////////////////////
479 
480  class QtPushButton : public QWidget, private Ui::PushButtonItem {
481  Q_OBJECT
482  public:
483  QtPushButton(QWidget *parent=0);
484  QtPushButton(QDomElement &ele, QWidget *parent=0);
485  ~QtPushButton();
486  void setLabelText(QString txt) {
487  nameLabel->setText(txt);
488  }
489  QString name() {
490  return itemName;
491  }
492  void reSet(QString);
493  signals:
494  void itemValueChanged(QString name, QString value, int action, bool apply);
495  protected slots:
496  void emitValue();
497  private:
498  QString itemName;
500  };
501 
502 
503 //# //////////////////////// QtCheck /////////////////////////////////////
504 
505  class QtCheck : public QWidget, private Ui::CheckItem {
506  Q_OBJECT
507  public:
508  QtCheck(QWidget *parent=0);
509  QtCheck(QDomElement &ele, QWidget *parent=0);
510  ~QtCheck();
511  void setLabelText(QString txt) {
512  nameLabel->setText(txt);
513  }
514  QString name() {
515  return itemName;
516  }
517  // [Re]sets state of checkboxes and internal record of that,
518  // without emitting itemValueChanged.
519  void reSet(QString);
520 
521  public slots:
522  void setOriginal();
523  void setDefault();
524  void setCopy();
525  void setPaste();
526  signals:
527  void itemValueChanged(QString name, QString value, int action, bool apply);
528  protected slots:
529  void checkboxChanged(int newState);
530  void emitValue();
531  void reSet(QStringList);
532  void reSet();
533  private:
534  QList<QCheckBox*> checkboxes_; //# all checkboxes
535  QStringList allopts_; //# Names of all checkboxes
536  QStringList opts_; //# Names of currently checked boxes
537  QStringList orig_; //# Names of boxes checked originally
538  QString itemName;
539  };
540 
541 
542 //# //////////////////////QtRegion//////////////////////////////////////////
543 
544  class QtRegionEditor : public QWidget, private Ui::LineEditorItem {
545  Q_OBJECT
546  public:
547  QtRegionEditor(QWidget *parent=0);
548  QtRegionEditor(QDomElement &ele, QWidget *parent=0);
549  ~QtRegionEditor();
550  bool validate(QString value);
551  void setLabelText(QString txt) {
552  nameLabel->setText(txt);
553  }
554  QString name() {
555  return itemName;
556  }
557  void reSet(QString);
558  public slots:
559  void display2(QString value);
560  void editingFinished();
561  void setOriginal();
562  void setDefault();
563  void fromImg();
564  void createRegion();
565  void unset();
566  void setCopy();
567  void setPaste();
568  signals:
569  void itemValueChanged(QString name, QString value, int action, bool apply);
570 
571  private:
572  QString ptype;
573  QString itemName;
574  QString iamunset;
576  };
577 
578 
579 //# ////////////////////// QtPair ///////////////////////////////////////////
580 
581  class QtPairEditor : public QWidget, private Ui::PairItem {
582  Q_OBJECT
583 
584  public:
585  QtPairEditor(QDomElement& ele, QWidget* parent = NULL);
586 
587  ~QtPairEditor();
588 
589  void reSet(QString value);
590 
591  signals:
592  void itemValueChanged(QString name, QString value, int action, bool apply);
593 
594  protected slots:
595  void editingFinished();
596 
597  void setOriginal();
598 
599  private:
600  QString itemName;
601  bool isDouble;
602  QAbstractSpinBox* val1, *val2;
603  std::pair<int, int> origVal1;
604  std::pair<double, double> origVal2;
605 
606  std::pair<int, int> readIntPair(QString value);
607 
608  std::pair<double, double> readDoublePair(QString value);
609  };
610 
611 
612 //# ///////////////////// QtNumber ////////////////////////////////////////
613 
614 // can use PairItem because it's just a frame
615  class QtNumberEditor : public QWidget, private Ui::PairItem {
616  Q_OBJECT
617 
618  public:
619  QtNumberEditor(QDomElement& ele, QWidget* parent = NULL);
620 
621  ~QtNumberEditor();
622 
623  void reSet(QString value);
624 
625  signals:
626  void itemValueChanged(QString name, QString value, int action, bool apply);
627 
628  protected slots:
629  void editingFinished();
630 
631  void setOriginal();
632 
633  private:
634  QString itemName;
635  bool isDouble;
636  QAbstractSpinBox* val;
637  int origVal1;
638  double origVal2;
639  };
640 
641 
642 } //# NAMESPACE CASA - END
643 
644 
645 
646 #endif
void setLabelText(QString txt)
void itemValueChanged(QString name, QString value, int action, bool apply)
void setOriginal()
double toNumber(QString text, bool *ok=0)
QtCombo(QWidget *parent=0)
void updateText()
Sets text box to (normalized) current value.
QStringList opts_
void itemValueChanged(QString name, QString value, int action, bool apply)
double externalVal(int sldVal)
Integer values with in [0, slMax_] on the internal slider are scaled to external values within [dMin_...
void reSet(QDomElement &ele)
Set up main state (value, etc.) and external appearance of this widget, according to options record (...
void updateText()
Sets value label to (normalized) current value.
QtPushButton(QWidget *parent=0)
void apply(const Jones &j1, VisVector &v, const Jones &j2)
Apply a pair of Jones to a VisVector:
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
std::pair< int, int > readIntPair(QString value)
QtBool(QWidget *parent=0)
std::pair< double, double > readDoublePair(QString value)
QtPairEditor(QDomElement &ele, QWidget *parent=NULL)
bool floatrng_
Whether this element emits float values (ptype &#39;floatrange&#39;) vs.
QString itemName
Internal name (&#39;dlformat&#39;).
QtLineEditor(QWidget *parent=0)
QString name()
Internal name (&#39;dlformat&#39;)
void dataNameChanged(QString value)
void reSet(QString)
can use PairItem because it&#39;s just a frame
QToolButton * menuBtn_
General-purpose Qt options widget created from Record.
Definition: QtAutoGui.qo.h:66
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
QString textVal()
Current external value, as text.
double origVal_
For restoring &#39;original&#39; value.
virtual void slChg(int slval)
slider changed by user
virtual void updateText()=0
Derived class should implement: set value text box or label (if any) to (normalized) current value...
void setLabelText(QString txt)
void setLabelText(QString txt)
void itemValueChanged(QString name, QString value, int action, bool apply)
Main output signal.
void validateAndEmit(QString value)
void itemValueChanged(QString name, QString value, int action, bool apply)
bool onrelease_
Should the event be generated only upon releasing the slider?
QtSliderEditor(QWidget *parent=0)
(not intended for use at present).
void checkboxChanged(int newState)
void itemValueChanged(QString name, QString value, int action, bool apply)
QString itemName
QtSliderLabel(QDomElement &ele, QWidget *parent=0)
QString name()
int sliderVal(double extVal)
void getAttr(const QDomElement &ele, QString attnm, double &val)
Fetch numeric value of attribute of ele named attnm, into val.
QtCheck(QWidget *parent=0)
void setLabelText(QString txt)
QStringList allopts_
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
QAbstractSpinBox * val
void setDefault()
void constructBase(QDomElement &ele, QSlider *slider, QLabel *nameLabel, QToolButton *menuBtn)
Derived class should call this within its constructor, after it has a valid QSlider, name QLabel and menu QToolButton (usually, after calling setUi()), passing them down in the parameters below.
void reSet(QString)
QtSliderEditor(QDomElement &ele, QWidget *parent=0)
QString toText(double val)
These two routines convert &#39;external&#39; values between double and text.
QtRegionEditor(QWidget *parent=0)
void errMsg(casacore::String errmsg)
class user may wish to connect to and display these.
QStringList orig_
int round(double val)
QString itemName
void itemValueChanged(QString name, QString value, int action, bool apply)
void emitVal()
emit current value – widget&#39;s main output.
QString name()
void emitValue()
QList< QCheckBox * > checkboxes_
void reSet(QString value)
bool validate(QString value)
void updateSlider()
Sets slider to latest range and value (without triggering slider signals or slChg slot below)...
void display2(QString value)
QAbstractSpinBox * val2
virtual void edited()
void reSet(QString)
QtMinMaxEditor(QWidget *parent=0)
void setOriginal()
void itemValueChanged(QString name, QString value, int action, bool apply)
QtNumberEditor(QDomElement &ele, QWidget *parent=NULL)
void setDefault()
QSlider * slider_
Relevant user interface elements.
Base class for QtAutoGui slider interface elements.
void setText(QString txt)
Definition: QtGuiEntry.qo.h:68
void setPaste()
void setLabelText(QString txt)
Set interface label text (&#39;listname&#39;).
void leaveEvent(QEvent *)
void setDefault()
void emitValue()
bool validate(QString value)
void setLabelText(QString txt)
void update(double dval)
Accepts new value (if any), updates interface (without retriggering any internal slots).
void setLabelText(QString txt)
QString itemName
QAbstractSpinBox * val1
virtual void setOriginal()
&#39;revert-to-original&#39; selected in menu.
std::pair< int, int > origVal1
void emitValue()
void setOriginal()
void itemValueChanged(QString name, QString value, int action, bool apply)
void reSet(QString value)
double dVal_
main state.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void textChg(QString strval)
main validation/update routine for changes to text version of value.
void setCopy()
void reSet(QString)
void itemValueChanged(QString name, QString value, int action, bool apply)
QtSliderLabel(QWidget *parent=0)
(not intended for use at present).
void reSet(QString)
std::pair< double, double > origVal2
void reSet(QString)
QtSliderBase(QWidget *parent=0)
Only for use by derived classes.
virtual void release()
void itemValueChanged(QString name, QString value, int action, bool apply)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
void adjSlIncr()
Adjusts integer slider range (slMax_) and the increment that each unit on the slider represents (dInc...
QtAdjustmentTop(QtAutoGui *parent=0, QString name="")
bool validate(QString value)
void setLabelText(QString txt)
QString name()