casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QtRegionShapeManager.qo.h
Go to the documentation of this file.
1 //# QtRegionShapeManager.qo.h: Classes for managing/loading region shapes.
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 QTREGIONSHAPEMANAGER_QO_H_
28 #define QTREGIONSHAPEMANAGER_QO_H_
29 
30 #include <QDialog>
31 #include <QStackedLayout>
32 #include <QtXml>
33 
34 #include <display/RegionShapes/QtRegionShapeManager.ui.h>
35 #include <display/RegionShapes/QtRSFileLoader.ui.h>
36 #include <display/RegionShapes/QtRSFileSaver.ui.h>
37 
39 
40 #include <casa/namespace.h>
41 
42 namespace casa {
43 
44  class QtDisplayPanel;
45  class RSFileReader;
46  class RSFileWriter;
47  class QtSingleRegionShape;
48 
49 // Region Shape Manager. Main interaction between region shapes and user.
50 // Provides functionality to:
51 // <ul><li>Load region shapes from a file</li>
52 // <li>Display loaded region shapes</li>
53 // <li>Show/hide loaded region shapes</li>
54 // <li>Delete loaded region shapes</li>
55 // <li>Edit region shapes</li></ul>
56  class QtRegionShapeManager : public QWidget, Ui::RegionShapeManager {
57  Q_OBJECT
58 
59  public:
60  // Constant message used when a error was reported during a shape drawing.
62 
63 
64  // Constructor which takes the parent panel.
66 
67  // Destructor.
69 
70  // Returns the parent panel.
71  QtDisplayPanel* panel() const;
72 
73  // Appends an XML state representation of loaded shapes to the given
74  // document.
75  void saveState(QDomDocument& document);
76 
77  // Restores loaded shapes from the given document.
78  void restoreState(QDomDocument& document);
79 
80  // Returns the number of shapes in the manager. If includeComposites is
81  // false, composites are not counted towards the return total. Composite
82  // children are not included.
83  unsigned int numShapes(bool includeComposites = true) const;
84 
85  // Returns the shapes in the manager. If include composites is false,
86  // composites are not included. Composite children are not included.
87  std::vector<RegionShape*> shapes(bool includeComposites = true) const;
88 
89  // Returns the QtSingleRegionShape wrapper for the given shape, or NULL
90  // for invalid.
92 
93  // Shows the given error message (should be short).
94  void showSimpleError(const casacore::String& message, bool warn = true) const;
95 
96  // Shows the given detailed error message. "message" should contain a
97  // short overview while "details" should contain longer information.
98  void showDetailedError(const casacore::String& message, const casacore::String& details,
99  bool warn = true) const;
100 
101  public slots:
102  // Adds the given shape to the manager. Should only be used for individual
103  // shapes, since the display panel will refresh after every call which can
104  // get very slow with many shapes. For multiple shapes, use addShapes().
105  // The given shape becomes owned by the manager which is responsible for
106  // its deletion.
107  void addShape(RegionShape* shape);
108 
109  // Adds the given shapes to the manager. Holds the drawing until all
110  // shapes have been added. The given shapes become owned by the manager
111  // which is responsible for their deletion.
112  void addShapes(const std::vector<RegionShape*>& shapes);
113 
114  // Removes and (optionally) deletes the given shape from the manager.
115  void removeShape(RegionShape* shape, bool deleteShape = true);
116 
117  // Delete all loaded region shapes.
118  void deleteAll();
119 
120  // Enables the manager.
121  void enable() {
122  setEnabled(true);
123  }
124 
125  private:
126  QtDisplayPanel* m_panel; // Parent panel.
127  vector<QtSingleRegionShape*> m_shapes; // Loaded region shapes.
128  casacore::String m_lastDirectory, // Last loaded directory, file,
129  m_lastFile, // and format. Initially empty.
130  m_lastFormat;
131 
132  // Adds the given shape with the given composite parent (or NULL if the
133  // shape is not a composite child) to the manager.
134  void addShape(RegionShape* shape, RegionShape* compositeParent);
135 
136  // Adds the given shapes with the given composite parents (or NULL if the
137  // shapes do not not parents) to the manager.
138  void addShapes(const std::vector<RegionShape*>& shapes,
139  const std::vector<RegionShape*>& compositeParents);
140 
141 
142  // XML attributes.
143  // <group>
144  static const QString HIDDEN;
145  static const QString LAST_DIRECTORY;
146  static const QString LAST_FILE;
147  static const QString LAST_FORMAT;
148  static const QString WINDOW_VISIBLE;
149  // </group>
150 
151  private slots:
152  // Show or hide all loaded region shapes.
153  void showHideAll(bool checked);
154 
155  // Load region shapes from a file.
156  void load();
157 
158  // Saves loaded region shapes from a file.
159  void save();
160 
161  // Create a new shape.
162  void newShape();
163 
164  // Dismiss/close window.
165  void dismiss();
166  };
167 
168 
169 // Class for loading region shape files. The main use is
170 // QtRSFileLoader::getFileReader(), which prompts the user for a filename
171 // (with file chooser dialog) and a file format and then returns a RSFileReader
172 // appropriate for reading that file.
173  class QtRSFileLoader : public QDialog, Ui::RSFileLoader {
174  Q_OBJECT
175 
176  public:
177  // Constructor. The initial file and format will be set to the given, and
178  // if a filechooser is opened the starting directory will be set to the
179  // given.
181 
182  // Destructor.
183  ~QtRSFileLoader();
184 
185 
186  // Opens a new QtRSFileLoader so that the user can input a filename and
187  // file format, and then returns a RSFileReader appropriate for reading
188  // that file. Returns NULL if the user cancels or if an error occurs
189  // (shouldn't happen). If the casacore::String* arguments are given, they will be
190  // used for the initial settings and then updated to show the opened
191  // file, format, and directory, respectively.
193  casacore::String* format = NULL,
194  casacore::String* directory = NULL);
195 
196  private:
197  QString m_lastDir; // directory to start filechooser
198 
199  // Gets the current filename chosen by the user.
201 
202  // Gets the directory of the filename chosen by the user.
204 
205  // Gets the current region file format chosen by the user.
206  // Guaranteed to be one of the values in
207  // RegionFileReader::supportedTypesStrings().
209 
210  private slots:
211  // Show a file chooser dialog.
212  void browse();
213 
214  // Check that the entered file is valid, then accept().
215  void ok();
216  };
217 
218 
219 // Class for saving region files. The main use is
220 // QtRSFileSaver::getFileWriter(), which prompts the user for a filename
221 // (with file chooser dialog), a file format, and options specific to the file
222 // format, and then returns a RSFileWriter appropriate for writing that file.
223  class QtRSFileSaver : public QDialog, Ui::RSFileSaver {
224  Q_OBJECT
225 
226  public:
227  // Constructor. The initial file and format will be set to the given, and
228  // if a filechooser is opened the starting directory will be set to the
229  // given.
231 
232  // Destructor.
233  ~QtRSFileSaver();
234 
235 
236  // Opens a new QtRegionFileSaver so that the user can input a filename,
237  // file format, and format options, and then returns a RegionFileWriter
238  // appropriate for writing that file. Returns NULL if the user cancels or
239  // an error occurs (shouldn't happen). If the casacore::String* arguments are given,
240  // they will be used for the initial settings and then updated to show the
241  // saved file, format, and directory, respectively.
243  casacore::String* format = NULL,
244  casacore::String* directory = NULL);
245 
246  private:
247  QString m_lastDir; // directory to start filechooser
248 
249  // Layout holding widgets for specialized format options.
250  QStackedLayout* m_formatOptions;
251 
252  // Gets the current filename chosen by the user.
254 
255  // Gets the directory of the filename chosen by the user.
257 
258  // Gets the current region file format chosen by the user.
259  // Guaranteed to be one of the values in
260  // RegionFileReader::supportedTypesStrings().
262 
263  // Gets the current options widget.
264  QWidget* getOptions();
265 
266  private slots:
267  // Show a file chooser dialog.
268  void browse();
269 
270  // Show/hide the region-specific options frame.
271  void showHideOptions(bool show);
272 
273  // Check that the entered file is valid, then accept().
274  void ok();
275  };
276 
277 }
278 
279 #endif /* QTREGIONSHAPEMANAGER_QO_H_ */
Class for loading region shape files.
casacore::String getFilename()
Gets the current filename chosen by the user.
QStackedLayout * m_formatOptions
Layout holding widgets for specialized format options.
casacore::String getFormat()
Gets the current region file format chosen by the user.
void save()
Saves loaded region shapes from a file.
void addShape(RegionShape *shape)
Adds the given shape to the manager.
void ok()
Check that the entered file is valid, then accept().
void addShapes(const std::vector< RegionShape * > &shapes)
Adds the given shapes to the manager.
void showHideOptions(bool show)
Show/hide the region-specific options frame.
static const casacore::String DRAWERRORMSG
Constant message used when a error was reported during a shape drawing.
void saveState(QDomDocument &document)
Appends an XML state representation of loaded shapes to the given document.
void restoreState(QDomDocument &document)
Restores loaded shapes from the given document.
void showSimpleError(const casacore::String &message, bool warn=true) const
Shows the given error message (should be short).
void browse()
Show a file chooser dialog.
QtRSFileSaver(casacore::String file="", casacore::String format="", casacore::String dir="")
Constructor.
void enable()
Enables the manager.
Abstract superclass for any class that reads a format that produces RegionShapes from a file...
QWidget * getOptions()
Gets the current options widget.
~QtRegionShapeManager()
Destructor.
void dismiss()
Dismiss/close window.
QtRSFileLoader(casacore::String file="", casacore::String format="", casacore::String dir="")
Constructor.
void show(const variant &v)
~QtRSFileSaver()
Destructor.
Abstract superclass for any class that writes RegionShapes to a region file format.
vector< QtSingleRegionShape * > m_shapes
void newShape()
Create a new shape.
void removeShape(RegionShape *shape, bool deleteShape=true)
Removes and (optionally) deletes the given shape from the manager.
static RSFileReader * getFileReader(casacore::String *file=NULL, casacore::String *format=NULL, casacore::String *directory=NULL)
Opens a new QtRSFileLoader so that the user can input a filename and file format, and then returns a ...
Widget for displaying a single region in the list of a QtRegionShapeManager.
Parent class for all RegionShapes.
Definition: RegionShape.h:223
casacore::String getDirectory()
Gets the directory of the filename chosen by the user.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
QtDisplayPanel * panel() const
Returns the parent panel.
void load()
Load region shapes from a file.
casacore::String getDirectory()
Gets the directory of the filename chosen by the user.
static const QString HIDDEN
XML attributes.
casacore::String getFormat()
Gets the current region file format chosen by the user.
static RSFileWriter * getFileWriter(casacore::String *file=NULL, casacore::String *format=NULL, casacore::String *directory=NULL)
Opens a new QtRegionFileSaver so that the user can input a filename, file format, and format options...
unsigned int numShapes(bool includeComposites=true) const
Returns the number of shapes in the manager.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
std::vector< RegionShape * > shapes(bool includeComposites=true) const
Returns the shapes in the manager.
void browse()
Show a file chooser dialog.
void ok()
Check that the entered file is valid, then accept().
~QtRSFileLoader()
Destructor.
void deleteAll()
Delete all loaded region shapes.
void showDetailedError(const casacore::String &message, const casacore::String &details, bool warn=true) const
Shows the given detailed error message.
Class for saving region files.
QtSingleRegionShape * shapeWidget(RegionShape *shape) const
Returns the QtSingleRegionShape wrapper for the given shape, or NULL for invalid. ...
casacore::String getFilename()
Gets the current filename chosen by the user.
void showHideAll(bool checked)
Show or hide all loaded region shapes.
QtRegionShapeManager(QtDisplayPanel *panel)
Constructor which takes the parent panel.
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100