casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtSingleRegionShape.qo.h
Go to the documentation of this file.
1 //# QtSingleRegionShape.qo.h: Classes for viewing/editing a single RegionShape.
2 //# Copyright (C) 2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 #ifndef QTSINGLEREGIONSHAPE_QO_H
28 #define QTSINGLEREGIONSHAPE_QO_H
29 
30 #include <QWidget>
31 
32 #include <display/RegionShapes/QtSingleRegionShape.ui.h>
33 #include <display/RegionShapes/QtEditRegionShape.ui.h>
34 
37 
38 #include <casa/namespace.h>
39 
40 namespace casa {
41 
42  class QtRegionShapeManager;
43  class QtDisplayPanel;
44 
45 // Widget for displaying a single region in the list of a QtRegionShapeManager.
46 // QtSingleRegionShape is the main interaction between the GUI classes and the
47 // underlying RegionShape. Provides widgets for:
48 // <ul><li>showing/hiding the region shape</li>
49 // <li>deleting the region shape</li>
50 // <li>editing the region shape</li></ul>
51 // Is also responsible for registering/unregistering the region shape on the
52 // parent QtDisplayPanel as necessary.
53  class QtSingleRegionShape : public QWidget, Ui::SingleRegionShape {
54  Q_OBJECT
55 
56  friend class QtEditRegionShape;
57 
58  public:
59  // Constructor which takes the RegionShape, the manager parent, and the
60  // optional composite parent. If a composite parent is given, some
61  // behaviors are different. The constructor will register the RegionShape
62  // IF compositeParent is NULL.
64  bool reportDrawErrors = false,
66 
67  // Destructor.
69 
70  // Returns the RegionShape.
71  RegionShape* shape();
72 
73  // Returns this shape's composite parent, or NULL if it has none.
75 
76  // Returns the parent manager.
78 
79  // Returns the display panel.
81 
82  // Sets whether the QtSingleRegionShape should delete its RegionShape
83  // during destruction or not.
84  void setShouldDelete(bool shouldDelete = true);
85 
86  // Refreshes the GUI display.
87  void refresh();
88 
89  // Returns whether this shape is currently showing (registered) on the
90  // panel or not.
91  bool isShown() const;
92 
93  // Show/hide the region shape by registering/unregistering.
94  void showHide(bool show, bool reportErrors = true);
95 
96  public slots:
97  // Show a QtEditRegionShape for editing.
98  void edit();
99 
100  private:
101  RegionShape* m_shape; // Shape (deletes on deconstruction).
102  RegionShape* m_compositeParent; // Composite parent, or NULL.
105  bool m_shouldDelete; // Should delete shape on destruction.
106 
107  // Sets up the GUI widgets to display information from the underlying
108  // region shape.
109  void setupGUI();
110 
111  // Registers the shape on the underlying display panel, if applicable.
112  void registerShape();
113 
114  // Unregisters the shape on the underlying display panel, if applicable.
115  void unregisterShape();
116 
117  private slots:
118  // Slot for checkbox.
119  void showHide_(bool show) {
120  showHide(show, true);
121  }
122 
123  // Deletes this shape by unregistering the region shape and then calling
124  // the manager's delete method.
125  void deleteShape();
126  };
127 
128 
129 // Widget that can be used to input a casacore::String, casacore::String choice, double, bool,
130 // casacore::String array, or casacore::String choice array.
131  class QtRSOption : public QHBoxLayout {
132  Q_OBJECT
133 
134  public:
135  // Constructor.
137  const RSOption& value, const std::vector<casacore::String>& choices);
138 
139  // Destructor.
140  ~QtRSOption();
141 
142  // Returns entered value.
143  RSOption value() const;
144 
145  private:
146  // Type.
148 
149  // Value widgets.
150  // <group>
151  QLineEdit* m_string;
152  QComboBox* m_choice;
153  QDoubleSpinBox* m_double;
154  QCheckBox* m_bool;
155  std::vector<QLineEdit*> m_stringArray;
156  std::vector<QComboBox*> m_choiceArray;
157  std::vector<casacore::String> m_choices;
158  QToolButton* m_lessButton, *m_moreButton;
159  // </group>
160 
161  private slots:
162  // Add another array widget.
163  void moreArray();
164 
165  // Remove an array widget.
166  void lessArray();
167  };
168 
169 
170 // Dialog for editing a single region shape. Can either be used in editing
171 // or creation mode. Currently there are three sections:
172 // <ol><li>casacore::Coordinate editing. Using the RegionShape's coordinate parameter
173 // methods, the shape's current coordinates are displayed and can be
174 // changed (both value and system/unit).</li>
175 // <li>General options. Line width/color, label text/font, linethrough,
176 // etc.</li>
177 // <li>Specific options. Customization specific to each shape
178 // type.</li></ol>
179  class QtEditRegionShape : public QWidget, Ui::EditRegionShape {
180  Q_OBJECT
181 
182  public:
183  // Static Members //
184 
185  // System/casacore::Unit constants.
186  // <group>
188  static const casacore::String UNKNOWN;
189  // </group>
190 
191  // Returns available systems for the system chooser.
192  static std::vector<casacore::String> systems() {
193  static std::vector<casacore::String> v(6);
199  v[5] = RSUtils::PIXEL;
200  return v;
201  }
202 
203  static QComboBox* systemsChooser() {
204  std::vector<casacore::String> v = systems();
205  QComboBox* b = new QComboBox();
206  for(unsigned int i = 0; i < v.size(); i++) b->addItem(v[i].c_str());
207  return b;
208  }
209 
210 
211  // Non-Static Members //
212 
213  // Editing mode constructor.
215 
216  // Creation mode constructor. showPosition, showSize, and applyButtonText
217  // are only used if coordWidget is not NULL.
219  QWidget* coordWidget = NULL, bool showPosition = true,
220  bool showSize = true, casacore::String applyButtonText = "");
221 
222  // Destructor.
224 
225 
226  // Methods used for accessing what coordinate system/unit the user has
227  // chosen.
228  // <group>
232  // </group>
233 
234  // Returns true if the entered coordinates are valid, false otherwise.
235  // Has no effect if a custom coordinate widget is provided.
236  // Entered coordinates are valid if:
237  // 1) Non-empty
238  // 2) For non-sexagesimal, contains a number
239  // 3) For sexagesimal, contains three numbers separated by :'s.
240  // If invalid, a reason is given.
241  bool enteredCoordinatesAreValid(casacore::String& reason) const;
242 
243  public slots:
244  // Apply changes to the underlying region shape.
245  void apply();
246 
247  signals:
248  // Only emitted when widget is in creation mode, the apply button is shown,
249  // and the apply button is clicked.
250  void applyClicked();
251 
252  private:
253  // Indicates whether the widget is being used in creation or editing mode.
255 
256  // Shape being edited.
258 
259  // Shape being created.
261 
262  // Shape manager.
264 
265  // casacore::Coordinate editing fields.
266  std::vector<QLineEdit*> m_coordEdits;
267 
268  // Coord types.
269  std::vector<RegionShape::CoordinateParameterType> m_coordTypes;
270 
271  // Last chosen system, position unit, and size unit.
273 
274  // Line color widget.
276 
277  // Linethrough color widget.
279 
280  // Label color widget.
282 
283  // Option widgets.
284  std::vector<QtRSOption*> m_optWidgets;
285 
286  // Option types.
287  std::vector<RegionShape::OptionType> m_optTypes;
288 
289 
290  // Initial GUI setup, depending on creation/edit mode.
291  void init(QWidget* coordWidget = NULL, bool showPosition = true,
292  bool showSize = true, casacore::String applyButtonText = "");
293 
294  // Sets up the GUI to reflect values/properties of the underlying region
295  // shape.
296  void setupGui();
297 
298  // Takes the value entered in the coordinate at the given index of
299  // m_coordEdits and converts it into a number that can be sent to the
300  // shape's coordinate parameter methods.
301  double convertToRS(int index, bool& ok) const;
302 
303  // Displays the given coordinates with the proper unit. Assumes that the
304  // world system matches the GUI and the unit matches RegionShape::UNIT.
305  void displayCoordinates(const std::vector<double>& coords);
306 
307 
308  // Private Static Methods //
309 
310  // Returns available units for the position unit chooser.
311  static std::vector<casacore::String> positionUnits() {
312  static std::vector<casacore::String> v(5);
313  v[0] = RSValue::DEG;
314  v[1] = RSValue::RAD;
315  v[2] = SEXAGESIMAL;
316  v[3] = RSValue::HMS;
317  v[4] = RSValue::DMS;
318  return v;
319  }
320 
321  // Returns available units for the size unit chooser.
322  static std::vector<casacore::String> sizeUnits() {
323  static std::vector<casacore::String> v(4);
324  v[0] = RSValue::DEG;
325  v[1] = RSValue::RAD;
326  v[2] = RSValue::ARCSEC;
327  v[3] = RSValue::ARCMIN;
328  return v;
329  }
330 
331  private slots:
332  // Update the displayed values to reflect the coordinate system, position
333  // unit, and size unit chosen by the user.
334  void coordSystemChanged();
335 
336  // Resets the values, system, and units to that of the underlying shape.
337  void coordReset();
338 
339  // Enable/disable the linethrough options.
340  void linethrough();
341 
342  // Call apply() if in edit mode, otherwise emit applyClicked() signal.
343  void applySlot() {
344  if(m_creation) emit applyClicked();
345  else apply();
346  }
347  };
348 
349 }
350 
351 #endif /* QTSINGLEREGIONSHAPE_QO_H */
casacore::String chosenPositionUnit() const
bool enteredCoordinatesAreValid(casacore::String &reason) const
Returns true if the entered coordinates are valid, false otherwise.
~QtRSOption()
Destructor.
void showHide(bool show, bool reportErrors=true)
Show/hide the region shape by registering/unregistering.
std::vector< RegionShape::CoordinateParameterType > m_coordTypes
Coord types.
std::vector< casacore::String > m_choices
QtColorWidget * m_lineColor
Line color widget.
void registerShape()
Registers the shape on the underlying display panel, if applicable.
void linethrough()
Enable/disable the linethrough options.
bool m_creation
Indicates whether the widget is being used in creation or editing mode.
void setShouldDelete(bool shouldDelete=true)
Sets whether the QtSingleRegionShape should delete its RegionShape during destruction or not...
casacore::String m_lastSystem
Last chosen system, position unit, and size unit.
RegionShape * shape()
Returns the RegionShape.
void edit()
Show a QtEditRegionShape for editing.
virtual Type type()
Return the type enum.
void init(QWidget *coordWidget=NULL, bool showPosition=true, bool showSize=true, casacore::String applyButtonText="")
Initial GUI setup, depending on creation/edit mode.
static const casacore::String UNKNOWN
Convenience class for a casacore::String, bool, or double.
Definition: RSUtils.qo.h:386
static const casacore::String HMS
Definition: RSUtils.qo.h:360
static const casacore::String ARCMIN
Definition: RSUtils.qo.h:359
std::vector< QComboBox * > m_choiceArray
std::vector< RegionShape::OptionType > m_optTypes
Option types.
std::vector< QtRSOption * > m_optWidgets
Option widgets.
RegionShape::OptionType m_type
Type.
void deleteShape()
Deletes this shape by unregistering the region shape and then calling the manager&#39;s delete method...
void applySlot()
Call apply() if in edit mode, otherwise emit applyClicked() signal.
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
std::vector< QLineEdit * > m_stringArray
static const casacore::String RAD
Definition: RSUtils.qo.h:357
void coordReset()
Resets the values, system, and units to that of the underlying shape.
void show(const variant &v)
void applyClicked()
Only emitted when widget is in creation mode, the apply button is shown, and the apply button is clic...
static const casacore::String DMS
Definition: RSUtils.qo.h:361
static std::vector< casacore::String > systems()
Returns available systems for the system chooser.
QtRSOption(RegionShape::OptionType type, const casacore::String &name, const RSOption &value, const std::vector< casacore::String > &choices)
Constructor.
Dialog for editing a single region shape.
casacore::String chosenSizeUnit() const
QtColorWidget * m_ltColor
Linethrough color widget.
QtDisplayPanel * panel()
Returns the display panel.
void displayCoordinates(const std::vector< double > &coords)
Displays the given coordinates with the proper unit.
void coordSystemChanged()
Update the displayed values to reflect the coordinate system, position unit, and size unit chosen by ...
QDoubleSpinBox * m_double
RSOption value() const
Returns entered value.
QtSingleRegionShape * m_shape
Shape being edited.
static std::vector< casacore::String > positionUnits()
Private Static Methods //.
void moreArray()
Add another array widget.
RegionShape * m_cShape
Shape being created.
static QComboBox * systemsChooser()
A widget that lets the user select a color: either one from a list, or a custom color.
Definition: RSUtils.qo.h:253
void showHide_(bool show)
Slot for checkbox.
~QtSingleRegionShape()
Destructor.
void apply()
Apply changes to the underlying region shape.
QtEditRegionShape(QtSingleRegionShape *shape)
Non-Static Members //.
void setupGui()
Sets up the GUI to reflect values/properties of the underlying region shape.
QtColorWidget * m_labelColor
Label color widget.
void refresh()
Refreshes the GUI display.
QtSingleRegionShape(RegionShape *shape, QtRegionShapeManager *parent, bool reportDrawErrors=false, RegionShape *compositeParent=NULL)
Constructor which takes the RegionShape, the manager parent, and the optional composite parent...
~QtEditRegionShape()
Destructor.
Widget for displaying a single region in the list of a QtRegionShapeManager.
Parent class for all RegionShapes.
Definition: RegionShape.h:223
static std::vector< casacore::String > sizeUnits()
Returns available units for the size unit chooser.
void unregisterShape()
Unregisters the shape on the underlying display panel, if applicable.
void lessArray()
Remove an array widget.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
QtRegionShapeManager * m_manager
Shape manager.
static const String & showType(MDirection::Types tp)
double convertToRS(int index, bool &ok) const
Takes the value entered in the coordinate at the given index of m_coordEdits and converts it into a n...
Widget that can be used to input a casacore::String, casacore::String choice, double, bool, casacore::String array, or casacore::String choice array.
void setupGUI()
Sets up the GUI widgets to display information from the underlying region shape.
static const casacore::String PIXEL
Pixel coordinate system.
Definition: RSUtils.qo.h:79
static const casacore::String ARCSEC
Definition: RSUtils.qo.h:358
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool isShown() const
Returns whether this shape is currently showing (registered) on the panel or not. ...
static const casacore::String SEXAGESIMAL
Static Members //.
RegionShape * compositeParent()
Returns this shape&#39;s composite parent, or NULL if it has none.
OptionType
Different types for options.
Definition: RegionShape.h:281
QtRegionShapeManager * manager()
Returns the parent manager.
casacore::String chosenCoordinateSystem() const
Methods used for accessing what coordinate system/unit the user has chosen.
QLineEdit * m_string
Value widgets.
QtRegionShapeManager * m_parent
static const casacore::String DEG
casacore::Conversion methods/constants //
Definition: RSUtils.qo.h:356
std::vector< QLineEdit * > m_coordEdits
casacore::Coordinate editing fields.