QtRegionShapeManager.qo.h

Go to the documentation of this file.
00001 //# QtRegionShapeManager.qo.h: Classes for managing/loading region shapes.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 #ifndef QTREGIONSHAPEMANAGER_QO_H_
00028 #define QTREGIONSHAPEMANAGER_QO_H_
00029 
00030 #include <QDialog>
00031 #include <QStackedLayout>
00032 #include <QtXml>
00033 
00034 #include <display/RegionShapes/QtRegionShapeManager.ui.h>
00035 #include <display/RegionShapes/QtRSFileLoader.ui.h>
00036 #include <display/RegionShapes/QtRSFileSaver.ui.h>
00037 
00038 #include <display/RegionShapes/RegionShape.h>
00039 
00040 #include <casa/namespace.h>
00041 
00042 namespace casa {
00043 
00044         class QtDisplayPanel;
00045         class RSFileReader;
00046         class RSFileWriter;
00047         class QtSingleRegionShape;
00048 
00049 // Region Shape Manager.  Main interaction between region shapes and user.
00050 // Provides functionality to:
00051 // <ul><li>Load region shapes from a file</li>
00052 //     <li>Display loaded region shapes</li>
00053 //     <li>Show/hide loaded region shapes</li>
00054 //     <li>Delete loaded region shapes</li>
00055 //     <li>Edit region shapes</li></ul>
00056         class QtRegionShapeManager : public QWidget, Ui::RegionShapeManager {
00057                 Q_OBJECT
00058 
00059         public:
00060                 // Constant message used when a error was reported during a shape drawing.
00061                 static const String DRAWERRORMSG;
00062 
00063 
00064                 // Constructor which takes the parent panel.
00065                 QtRegionShapeManager(QtDisplayPanel* panel);
00066 
00067                 // Destructor.
00068                 ~QtRegionShapeManager();
00069 
00070                 // Returns the parent panel.
00071                 QtDisplayPanel* panel() const;
00072 
00073                 // Appends an XML state representation of loaded shapes to the given
00074                 // document.
00075                 void saveState(QDomDocument& document);
00076 
00077                 // Restores loaded shapes from the given document.
00078                 void restoreState(QDomDocument& document);
00079 
00080                 // Returns the number of shapes in the manager.  If includeComposites is
00081                 // false, composites are not counted towards the return total.  Composite
00082                 // children are not included.
00083                 unsigned int numShapes(bool includeComposites = true) const;
00084 
00085                 // Returns the shapes in the manager.  If include composites is false,
00086                 // composites are not included.  Composite children are not included.
00087                 vector<RegionShape*> shapes(bool includeComposites = true) const;
00088 
00089                 // Returns the QtSingleRegionShape wrapper for the given shape, or NULL
00090                 // for invalid.
00091                 QtSingleRegionShape* shapeWidget(RegionShape* shape) const;
00092 
00093                 // Shows the given error message (should be short).
00094                 void showSimpleError(const String& message, bool warn = true) const;
00095 
00096                 // Shows the given detailed error message.  "message" should contain a
00097                 // short overview while "details" should contain longer information.
00098                 void showDetailedError(const String& message, const String& details,
00099                                        bool warn = true) const;
00100 
00101         public slots:
00102                 // Adds the given shape to the manager.  Should only be used for individual
00103                 // shapes, since the display panel will refresh after every call which can
00104                 // get very slow with many shapes.  For multiple shapes, use addShapes().
00105                 // The given shape becomes owned by the manager which is responsible for
00106                 // its deletion.
00107                 void addShape(RegionShape* shape);
00108 
00109                 // Adds the given shapes to the manager.  Holds the drawing until all
00110                 // shapes have been added.  The given shapes become owned by the manager
00111                 // which is responsible for their deletion.
00112                 void addShapes(const vector<RegionShape*>& shapes);
00113 
00114                 // Removes and (optionally) deletes the given shape from the manager.
00115                 void removeShape(RegionShape* shape, bool deleteShape = true);
00116 
00117                 // Delete all loaded region shapes.
00118                 void deleteAll();
00119 
00120                 // Enables the manager.
00121                 void enable() {
00122                         setEnabled(true);
00123                 }
00124 
00125         private:
00126                 QtDisplayPanel* m_panel;               // Parent panel.
00127                 vector<QtSingleRegionShape*> m_shapes; // Loaded region shapes.
00128                 String m_lastDirectory,                // Last loaded directory, file,
00129                        m_lastFile,                     // and format.  Initially empty.
00130                        m_lastFormat;
00131 
00132                 // Adds the given shape with the given composite parent (or NULL if the
00133                 // shape is not a composite child) to the manager.
00134                 void addShape(RegionShape* shape, RegionShape* compositeParent);
00135 
00136                 // Adds the given shapes with the given composite parents (or NULL if the
00137                 // shapes do not not parents) to the manager.
00138                 void addShapes(const vector<RegionShape*>& shapes,
00139                                const vector<RegionShape*>& compositeParents);
00140 
00141 
00142                 // XML attributes.
00143                 // <group>
00144                 static const QString HIDDEN;
00145                 static const QString LAST_DIRECTORY;
00146                 static const QString LAST_FILE;
00147                 static const QString LAST_FORMAT;
00148                 static const QString WINDOW_VISIBLE;
00149                 // </group>
00150 
00151         private slots:
00152                 // Show or hide all loaded region shapes.
00153                 void showHideAll(bool checked);
00154 
00155                 // Load region shapes from a file.
00156                 void load();
00157 
00158                 // Saves loaded region shapes from a file.
00159                 void save();
00160 
00161                 // Create a new shape.
00162                 void newShape();
00163 
00164                 // Dismiss/close window.
00165                 void dismiss();
00166         };
00167 
00168 
00169 // Class for loading region shape files.  The main use is
00170 // QtRSFileLoader::getFileReader(), which prompts the user for a filename
00171 // (with file chooser dialog) and a file format and then returns a RSFileReader
00172 // appropriate for reading that file.
00173         class QtRSFileLoader : public QDialog, Ui::RSFileLoader {
00174                 Q_OBJECT
00175 
00176         public:
00177                 // Constructor.  The initial file and format will be set to the given, and
00178                 // if a filechooser is opened the starting directory will be set to the
00179                 // given.
00180                 QtRSFileLoader(String file = "", String format = "", String dir = "");
00181 
00182                 // Destructor.
00183                 ~QtRSFileLoader();
00184 
00185 
00186                 // Opens a new QtRSFileLoader so that the user can input a filename and
00187                 // file format, and then returns a RSFileReader appropriate for reading
00188                 // that file.  Returns NULL if the user cancels or if an error occurs
00189                 // (shouldn't happen).  If the String* arguments are given, they will be
00190                 // used for the initial settings and then updated to show the opened
00191                 // file, format, and directory, respectively.
00192                 static RSFileReader* getFileReader(String* file = NULL,
00193                                                    String* format = NULL,
00194                                                    String* directory = NULL);
00195 
00196         private:
00197                 QString m_lastDir;   // directory to start filechooser
00198 
00199                 // Gets the current filename chosen by the user.
00200                 String getFilename();
00201 
00202                 // Gets the directory of the filename chosen by the user.
00203                 String getDirectory();
00204 
00205                 // Gets the current region file format chosen by the user.
00206                 // Guaranteed to be one of the values in
00207                 // RegionFileReader::supportedTypesStrings().
00208                 String getFormat();
00209 
00210         private slots:
00211                 // Show a file chooser dialog.
00212                 void browse();
00213 
00214                 // Check that the entered file is valid, then accept().
00215                 void ok();
00216         };
00217 
00218 
00219 // Class for saving region files.  The main use is
00220 // QtRSFileSaver::getFileWriter(), which prompts the user for a filename
00221 // (with file chooser dialog), a file format, and options specific to the file
00222 // format, and then returns a RSFileWriter appropriate for writing that file.
00223         class QtRSFileSaver : public QDialog, Ui::RSFileSaver {
00224                 Q_OBJECT
00225 
00226         public:
00227                 // Constructor.  The initial file and format will be set to the given, and
00228                 // if a filechooser is opened the starting directory will be set to the
00229                 // given.
00230                 QtRSFileSaver(String file = "", String format = "", String dir = "");
00231 
00232                 // Destructor.
00233                 ~QtRSFileSaver();
00234 
00235 
00236                 // Opens a new QtRegionFileSaver so that the user can input a filename,
00237                 // file format, and format options, and then returns a RegionFileWriter
00238                 // appropriate for writing that file.  Returns NULL if the user cancels or
00239                 // an error occurs (shouldn't happen).  If the String* arguments are given,
00240                 // they will be used for the initial settings and then updated to show the
00241                 // saved file, format, and directory, respectively.
00242                 static RSFileWriter* getFileWriter(String* file = NULL,
00243                                                    String* format = NULL,
00244                                                    String* directory = NULL);
00245 
00246         private:
00247                 QString m_lastDir;  // directory to start filechooser
00248 
00249                 // Layout holding widgets for specialized format options.
00250                 QStackedLayout* m_formatOptions;
00251 
00252                 // Gets the current filename chosen by the user.
00253                 String getFilename();
00254 
00255                 // Gets the directory of the filename chosen by the user.
00256                 String getDirectory();
00257 
00258                 // Gets the current region file format chosen by the user.
00259                 // Guaranteed to be one of the values in
00260                 // RegionFileReader::supportedTypesStrings().
00261                 String getFormat();
00262 
00263                 // Gets the current options widget.
00264                 QWidget* getOptions();
00265 
00266         private slots:
00267                 // Show a file chooser dialog.
00268                 void browse();
00269 
00270                 // Show/hide the region-specific options frame.
00271                 void showHideOptions(bool show);
00272 
00273                 // Check that the entered file is valid, then accept().
00274                 void ok();
00275         };
00276 
00277 }
00278 
00279 #endif /* QTREGIONSHAPEMANAGER_QO_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1