casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtNewRegionShape.qo.h
Go to the documentation of this file.
1 //# QtNewRegionShape.qo.h: Widgets for creating a new region shape(s).
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 QTNEWREGIONSHAPE_QO_H
28 #define QTNEWREGIONSHAPE_QO_H
29 
30 #include <QDialog>
31 #include <QStackedLayout>
32 #include <QListWidget>
33 #include <QRadioButton>
34 #include <QLabel>
35 
36 #include <display/RegionShapes/QtNewRegionShape.ui.h>
38 
39 #include <casa/namespace.h>
40 
41 namespace casa {
42 
43  class QtRegionShapeManager;
44  class QtEditRegionShape;
45 
46 // Dialog for creating a new region shape. For now basically a wrapper with
47 // a shape chooser around a QtEditRegionShape widget. For more complex shapes
48 // (polygon, composite) this will have to be changed.
49  class QtNewRegionShape : public QWidget, Ui::NewRegionShape {
50  Q_OBJECT
51 
52  public:
53  // Static Members //
54 
55  // Returns creation widgets.
56  static std::vector<std::pair<casacore::String, RegionShape*> >
57  creationShapes(bool includeComposite = true) {
58  std::vector<std::pair<casacore::String, RegionShape*> > v(includeComposite ? 9 : 8);
59  for(unsigned int i = 0; i < v.size(); i++)
60  v[i] = std::pair<casacore::String,RegionShape*>(creationName(i),creationShape(i));
61  return v;
62  }
63 
64 
65  // Non-Static Members //
66 
67  std::string errorMessage( ) const { return ""; }
68  // Constructor that takes parent.
70  bool includeComposite = true, bool deleteOnClose = true);
71 
72  // Destructor.
74 
75  // Shows/hides the close button.
76  void showCloseButton(bool show = true);
77 
78  signals:
79  // Emitted whenever the user creates a shape. After this signal is
80  // emitted the newly created shape is replaced in the widget with a
81  // blank one.
82  void shapeCreated(RegionShape* createdShape);
83 
84  private:
86  vector<RegionShape*> m_shapes; // Shapes
87  QStackedLayout* m_widgets; // Edit widgets
88 
89  static RegionShape* creationShape(int i) {
90  if(i < 0) return NULL;
91  else if(i == 0) return new RSEllipse(0,0,0,0);
92  else if(i == 1) return new RSCircle(0,0,0);
93  else if(i == 2) return new RSRectangle(0,0,0,0);
94  else if(i == 3)return new RSPolygon(casacore::Vector<double>(),casacore::Vector<double>());
95  else if(i == 4) return new RSLine(0,0,0,0,7);
96  else if(i == 5) return new RSVector(0,0,0,0,7);
97  else if(i == 6) return new RSMarker(0,0,Display::X,10);
98  else if(i == 7) return new RSText(0,0,"");
99  else if(i == 8) return new RSComposite();
100  else return NULL;
101  }
102  static RegionShape* creationShape(unsigned int i) {
103  return creationShape((int)i);
104  }
105 
107  if(i < 0) return "";
108  else if(i == 0) return "ellipse";
109  else if(i == 1) return "circle";
110  else if(i == 2) return "rectangle";
111  else if(i == 3) return "polygon";
112  else if(i == 4) return "line";
113  else if(i == 5) return "vector";
114  else if(i == 6) return "marker";
115  else if(i == 7) return "text";
116  else if(i == 8) return "composite";
117  else return "";
118  }
119  static casacore::String creationName(unsigned int i) {
120  return creationName((int)i);
121  }
122 
123  private slots:
124  // When the "create" button is clicked.
125  void create();
126  };
127 
128 
129 // Specialized widget for creating a new polygon.
130  class QtNewRSPolygon : public QWidget {
131  Q_OBJECT
132 
133  public:
134  // Constructor which takes the polygon to modify.
136 
137  // Destructor.
138  ~QtNewRSPolygon();
139 
140  // See QtEditRegionShape::enteredCoordinatesAreValid.
141  bool enteredCoordinatesAreValid(casacore::String& reason) const;
142 
143  public slots:
144  // Applies the entered values to the RSPolygon.
145  void apply();
146 
147  private:
148  RSPolygon* m_polygon; // Polygon.
149  QtEditRegionShape* m_editor; // Region shape editor.
150  QListWidget* m_coordList; // casacore::List widget for displaying entered coordinates
151  QFrame* m_coordFrame; // Frame that holds list widget and buttons.
152  vector<std::pair<QString, QString> > m_enteredCoords; // Entered coordinates
153  QLineEdit* m_coordXEdit, *m_coordYEdit; // casacore::Coordinate edits.
154 
155  private slots:
156  // Add the values entered in the line edits to the coord list.
157  void addCoordinates();
158 
159  // Moves the selected coordinate up in the list.
160  void listMoveUp();
161 
162  // Moves the selected coordinate down in the list.
163  void listMoveDown();
164 
165  // Deletes the selected coordinate in the list.
166  void listDelete();
167  };
168 
169 
170 // Specialized widget for creating a new composite.
171  class QtNewRSComposite : public QWidget {
172  Q_OBJECT
173 
174  public:
175  // Constructor which takes the composite to modify.
177 
178  // Destructor.
180 
181  // Returns whether the entered values are valid or not. Returns true if
182  // at least one child is entered, and all children have valid coordinates.
183  bool enteredValuesAreValid(casacore::String& reason) const;
184 
185  public slots:
186  // Applies the entered values to the RSComposite.
187  void apply();
188 
189  private:
190  // Top-lebel members.
191  // <group>
194  std::vector<RegionShape*> m_children;
195  QStackedLayout* m_layout;
196  // </group>
197 
198  // First screen
199  // <group>
200  QRadioButton* m_dependentChildren;
201  QRadioButton* m_newShapes;
203  // </group>
204 
205  // Second screen: new shapes
206  // <group>
207  QListWidget* m_newShapeList;
208  QComboBox* m_editChooser;
209  QStackedLayout* m_editWidgets;
210  // </group>
211 
212  // Second screen: existing shapes
213  // <group>
214  QListWidget* m_existingList, *m_moveList;
215  std::vector<RegionShape*> m_existingShapes, m_moveShapes;
216  // </group>
217 
218 
219  // GUI initialization methods.
220  // <group>
221  QWidget* initFirstScreen();
222  QWidget* initSecondScreen1();
223  QWidget* initSecondScreen2();
224  // </group>
225 
226  // Updated m_existingList and m_moveList based on m_existingShapes and
227  // m_movesshapes.
228  void updateLists();
229 
230  // Returns the adjusted index (m_existingList => m_existingShapes).
231  unsigned int adjustedIndex(int row);
232 
233  private slots:
234  // Switches to second page.
235  void next();
236 
237  // New shapes
238 
239  // Adds a new shape to the composite.
240  void nAddShape(RegionShape* shape);
241 
242  // Moves the selected shape up in the list.
243  void nListUp();
244 
245  // Moves the selected shape down in the list.
246  void nListDown();
247 
248  // Deletes the selected shape in the list.
249  void nListDelete();
250 
251  // Existing shapes
252 
253  // Adds the selected existing shape to the composite.
254  void eAddShape();
255 
256  // Remove the selected shape from the composite.
257  void eRemoveShape();
258 
259  // Moves the selected shape up in the list.
260  void eListUp();
261 
262  // Moves the selected shape down in the list.
263  void eListDown();
264  };
265 
266 }
267 
268 #endif /* QTNEWREGIONSHAPE_QO_H */
std::vector< RegionShape * > m_existingShapes
void listDelete()
Deletes the selected coordinate in the list.
~QtNewRSComposite()
Destructor.
QListWidget * m_existingList
Second screen: existing shapes.
QtNewRSComposite(RSComposite *comp, QtRegionShapeManager *manager)
Constructor which takes the composite to modify.
void shapeCreated(RegionShape *createdShape)
Emitted whenever the user creates a shape.
QtRegionShapeManager * m_manager
Top-lebel members.
Specialized widget for creating a new polygon.
vector< std::pair< QString, QString > > m_enteredCoords
QListWidget * m_newShapeList
Second screen: new shapes.
QStackedLayout * m_editWidgets
void eRemoveShape()
Remove the selected shape from the composite.
void next()
Switches to second page.
static casacore::String creationName(int i)
std::vector< RegionShape * > m_children
void eAddShape()
Existing shapes.
Subclass of RegionShape used for drawing lines.
Definition: RegionShapes.h:451
std::vector< RegionShape * > m_moveShapes
Subclass of RegionShape used for drawing composite regions.
std::string errorMessage() const
Non-Static Members //.
void updateLists()
Updated m_existingList and m_moveList based on m_existingShapes and m_movesshapes.
void show(const variant &v)
void nListDelete()
Deletes the selected shape in the list.
Specialized widget for creating a new composite.
~QtNewRegionShape()
Destructor.
~QtNewRSPolygon()
Destructor.
Dialog for editing a single region shape.
void addCoordinates()
Add the values entered in the line edits to the coord list.
void nListDown()
Moves the selected shape down in the list.
void apply()
Applies the entered values to the RSComposite.
QtRegionShapeManager * m_manager
bool enteredValuesAreValid(casacore::String &reason) const
Returns whether the entered values are valid or not.
Subclass of RegionShape used for drawing rectangles.
Definition: RegionShapes.h:202
Subclass of RegionShape used for drawing ellipses.
Definition: RegionShapes.h:43
QtNewRegionShape(QtRegionShapeManager *manager, bool includeComposite=true, bool deleteOnClose=true)
Constructor that takes parent.
unsigned int adjustedIndex(int row)
Returns the adjusted index (m_existingList =&gt; m_existingShapes).
QtNewRSPolygon(RSPolygon *poly, QtRegionShapeManager *manager)
Constructor which takes the polygon to modify.
void listMoveUp()
Moves the selected coordinate up in the list.
void listMoveDown()
Moves the selected coordinate down in the list.
Subclass of RegionShape used for drawing markers.
Definition: RegionShapes.h:722
bool enteredCoordinatesAreValid(casacore::String &reason) const
See QtEditRegionShape::enteredCoordinatesAreValid.
QtEditRegionShape * m_editor
void apply()
Applies the entered values to the RSPolygon.
vector< RegionShape * > m_shapes
Parent class for all RegionShapes.
Definition: RegionShape.h:223
QRadioButton * m_dependentChildren
First screen.
void eListUp()
Moves the selected shape up in the list.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
static RegionShape * creationShape(int i)
QWidget * initSecondScreen2()
static std::vector< std::pair< casacore::String, RegionShape * > > creationShapes(bool includeComposite=true)
Static Members //.
Subclass of RSLine that takes a length and angle instead of a second point.
Definition: RegionShapes.h:633
static casacore::String creationName(unsigned int i)
QWidget * initSecondScreen1()
Subclass of RSEllipse used for drawing circles.
Definition: RegionShapes.h:142
void showCloseButton(bool show=true)
Shows/hides the close button.
Dialog for creating a new region shape.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
QWidget * initFirstScreen()
GUI initialization methods.
void nAddShape(RegionShape *shape)
New shapes.
QStackedLayout * m_widgets
void nListUp()
Moves the selected shape up in the list.
void create()
When the &quot;create&quot; button is clicked.
Subclass of RegionShape used for drawing text.
Definition: RegionShapes.h:923
void eListDown()
Moves the selected shape down in the list.
Subclass of RegionShape used for drawing polygons.
Definition: RegionShapes.h:329
static RegionShape * creationShape(unsigned int i)