QtSingleRegionShape.qo.h

Go to the documentation of this file.
00001 //# QtSingleRegionShape.qo.h: Classes for viewing/editing a single RegionShape.
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 QTSINGLEREGIONSHAPE_QO_H
00028 #define QTSINGLEREGIONSHAPE_QO_H
00029 
00030 #include <QWidget>
00031 
00032 #include <display/RegionShapes/QtSingleRegionShape.ui.h>
00033 #include <display/RegionShapes/QtEditRegionShape.ui.h>
00034 
00035 #include <display/RegionShapes/RegionShape.h>
00036 #include <display/RegionShapes/RSUtils.qo.h>
00037 
00038 #include <casa/namespace.h>
00039 
00040 namespace casa {
00041 
00042         class QtRegionShapeManager;
00043         class QtDisplayPanel;
00044 
00045 // Widget for displaying a single region in the list of a QtRegionShapeManager.
00046 // QtSingleRegionShape is the main interaction between the GUI classes and the
00047 // underlying RegionShape.  Provides widgets for:
00048 // <ul><li>showing/hiding the region shape</li>
00049 //     <li>deleting the region shape</li>
00050 //     <li>editing the region shape</li></ul>
00051 // Is also responsible for registering/unregistering the region shape on the
00052 // parent QtDisplayPanel as necessary.
00053         class QtSingleRegionShape : public QWidget, Ui::SingleRegionShape {
00054                 Q_OBJECT
00055 
00056                 friend class QtEditRegionShape;
00057 
00058         public:
00059                 // Constructor which takes the RegionShape, the manager parent, and the
00060                 // optional composite parent.  If a composite parent is given, some
00061                 // behaviors are different.  The constructor will register the RegionShape
00062                 // IF compositeParent is NULL.
00063                 QtSingleRegionShape(RegionShape* shape, QtRegionShapeManager* parent,
00064                                     bool reportDrawErrors = false,
00065                                     RegionShape* compositeParent = NULL);
00066 
00067                 // Destructor.
00068                 ~QtSingleRegionShape();
00069 
00070                 // Returns the RegionShape.
00071                 RegionShape* shape();
00072 
00073                 // Returns this shape's composite parent, or NULL if it has none.
00074                 RegionShape* compositeParent();
00075 
00076                 // Returns the parent manager.
00077                 QtRegionShapeManager* manager();
00078 
00079                 // Returns the display panel.
00080                 QtDisplayPanel* panel();
00081 
00082                 // Sets whether the QtSingleRegionShape should delete its RegionShape
00083                 // during destruction or not.
00084                 void setShouldDelete(bool shouldDelete = true);
00085 
00086                 // Refreshes the GUI display.
00087                 void refresh();
00088 
00089                 // Returns whether this shape is currently showing (registered) on the
00090                 // panel or not.
00091                 bool isShown() const;
00092 
00093                 // Show/hide the region shape by registering/unregistering.
00094                 void showHide(bool show, bool reportErrors = true);
00095 
00096         public slots:
00097                 // Show a QtEditRegionShape for editing.
00098                 void edit();
00099 
00100         private:
00101                 RegionShape* m_shape;           // Shape (deletes on deconstruction).
00102                 RegionShape* m_compositeParent; // Composite parent, or NULL.
00103                 QtRegionShapeManager* m_parent; // Manager.
00104                 QtDisplayPanel* m_panel;        // Panel.
00105                 bool m_shouldDelete;            // Should delete shape on destruction.
00106 
00107                 // Sets up the GUI widgets to display information from the underlying
00108                 // region shape.
00109                 void setupGUI();
00110 
00111                 // Registers the shape on the underlying display panel, if applicable.
00112                 void registerShape();
00113 
00114                 // Unregisters the shape on the underlying display panel, if applicable.
00115                 void unregisterShape();
00116 
00117         private slots:
00118                 // Slot for checkbox.
00119                 void showHide_(bool show) {
00120                         showHide(show, true);
00121                 }
00122 
00123                 // Deletes this shape by unregistering the region shape and then calling
00124                 // the manager's delete method.
00125                 void deleteShape();
00126         };
00127 
00128 
00129 // Widget that can be used to input a String, String choice, double, bool,
00130 // String array, or String choice array.
00131         class QtRSOption : public QHBoxLayout {
00132                 Q_OBJECT
00133 
00134         public:
00135                 // Constructor.
00136                 QtRSOption(RegionShape::OptionType type, const String& name,
00137                            const RSOption& value, const vector<String>& choices);
00138 
00139                 // Destructor.
00140                 ~QtRSOption();
00141 
00142                 // Returns entered value.
00143                 RSOption value() const;
00144 
00145         private:
00146                 // Type.
00147                 RegionShape::OptionType m_type;
00148 
00149                 // Value widgets.
00150                 // <group>
00151                 QLineEdit* m_string;
00152                 QComboBox* m_choice;
00153                 QDoubleSpinBox* m_double;
00154                 QCheckBox* m_bool;
00155                 vector<QLineEdit*> m_stringArray;
00156                 vector<QComboBox*> m_choiceArray;
00157                 vector<String> m_choices;
00158                 QToolButton* m_lessButton, *m_moreButton;
00159                 // </group>
00160 
00161         private slots:
00162                 // Add another array widget.
00163                 void moreArray();
00164 
00165                 // Remove an array widget.
00166                 void lessArray();
00167         };
00168 
00169 
00170 // Dialog for editing a single region shape.  Can either be used in editing
00171 // or creation mode.  Currently there are three sections:
00172 // <ol><li>Coordinate editing.  Using the RegionShape's coordinate parameter
00173 //         methods, the shape's current coordinates are displayed and can be
00174 //         changed (both value and system/unit).</li>
00175 //     <li>General options.  Line width/color, label text/font, linethrough,
00176 //         etc.</li>
00177 //     <li>Specific options.  Customization specific to each shape
00178 //         type.</li></ol>
00179         class QtEditRegionShape : public QWidget, Ui::EditRegionShape {
00180                 Q_OBJECT
00181 
00182         public:
00183                 // Static Members //
00184 
00185                 // System/Unit constants.
00186                 // <group>
00187                 static const String SEXAGESIMAL;
00188                 static const String UNKNOWN;
00189                 // </group>
00190 
00191                 // Returns available systems for the system chooser.
00192                 static vector<String> systems() {
00193                         static vector<String> v(6);
00194                         v[0] = MDirection::showType(MDirection::B1950);
00195                         v[1] = MDirection::showType(MDirection::J2000);
00196                         v[2] = MDirection::showType(MDirection::GALACTIC);
00197                         v[3] = MDirection::showType(MDirection::SUPERGAL);
00198                         v[4] = MDirection::showType(MDirection::ECLIPTIC);
00199                         v[5] = RSUtils::PIXEL;
00200                         return v;
00201                 }
00202 
00203                 static QComboBox* systemsChooser() {
00204                         vector<String> v = systems();
00205                         QComboBox* b = new QComboBox();
00206                         for(unsigned int i = 0; i < v.size(); i++) b->addItem(v[i].c_str());
00207                         return b;
00208                 }
00209 
00210 
00211                 // Non-Static Members //
00212 
00213                 // Editing mode constructor.
00214                 QtEditRegionShape(QtSingleRegionShape* shape);
00215 
00216                 // Creation mode constructor.  showPosition, showSize, and applyButtonText
00217                 // are only used if coordWidget is not NULL.
00218                 QtEditRegionShape(RegionShape* shape, QtRegionShapeManager* manager,
00219                                   QWidget* coordWidget = NULL, bool showPosition = true,
00220                                   bool showSize = true, String applyButtonText = "");
00221 
00222                 // Destructor.
00223                 ~QtEditRegionShape();
00224 
00225 
00226                 // Methods used for accessing what coordinate system/unit the user has
00227                 // chosen.
00228                 // <group>
00229                 String chosenCoordinateSystem() const;
00230                 String chosenPositionUnit() const;
00231                 String chosenSizeUnit() const;
00232                 // </group>
00233 
00234                 // Returns true if the entered coordinates are valid, false otherwise.
00235                 // Has no effect if a custom coordinate widget is provided.
00236                 // Entered coordinates are valid if:
00237                 // 1) Non-empty
00238                 // 2) For non-sexagesimal, contains a number
00239                 // 3) For sexagesimal, contains three numbers separated by :'s.
00240                 // If invalid, a reason is given.
00241                 bool enteredCoordinatesAreValid(String& reason) const;
00242 
00243         public slots:
00244                 // Apply changes to the underlying region shape.
00245                 void apply();
00246 
00247         signals:
00248                 // Only emitted when widget is in creation mode, the apply button is shown,
00249                 // and the apply button is clicked.
00250                 void applyClicked();
00251 
00252         private:
00253                 // Indicates whether the widget is being used in creation or editing mode.
00254                 bool m_creation;
00255 
00256                 // Shape being edited.
00257                 QtSingleRegionShape* m_shape;
00258 
00259                 // Shape being created.
00260                 RegionShape* m_cShape;
00261 
00262                 // Shape manager.
00263                 QtRegionShapeManager* m_manager;
00264 
00265                 // Coordinate editing fields.
00266                 vector<QLineEdit*> m_coordEdits;
00267 
00268                 // Coord types.
00269                 vector<RegionShape::CoordinateParameterType> m_coordTypes;
00270 
00271                 // Last chosen system, position unit, and size unit.
00272                 String m_lastSystem, m_lastPosUnit, m_lastSizeUnit;
00273 
00274                 // Line color widget.
00275                 QtColorWidget* m_lineColor;
00276 
00277                 // Linethrough color widget.
00278                 QtColorWidget* m_ltColor;
00279 
00280                 // Label color widget.
00281                 QtColorWidget* m_labelColor;
00282 
00283                 // Option widgets.
00284                 vector<QtRSOption*> m_optWidgets;
00285 
00286                 // Option types.
00287                 vector<RegionShape::OptionType> m_optTypes;
00288 
00289 
00290                 // Initial GUI setup, depending on creation/edit mode.
00291                 void init(QWidget* coordWidget = NULL, bool showPosition = true,
00292                           bool showSize = true, String applyButtonText = "");
00293 
00294                 // Sets up the GUI to reflect values/properties of the underlying region
00295                 // shape.
00296                 void setupGui();
00297 
00298                 // Takes the value entered in the coordinate at the given index of
00299                 // m_coordEdits and converts it into a number that can be sent to the
00300                 // shape's coordinate parameter methods.
00301                 double convertToRS(int index, bool& ok) const;
00302 
00303                 // Displays the given coordinates with the proper unit.  Assumes that the
00304                 // world system matches the GUI and the unit matches RegionShape::UNIT.
00305                 void displayCoordinates(const vector<double>& coords);
00306 
00307 
00308                 // Private Static Methods //
00309 
00310                 // Returns available units for the position unit chooser.
00311                 static vector<String> positionUnits() {
00312                         static vector<String> v(5);
00313                         v[0] = RSValue::DEG;
00314                         v[1] = RSValue::RAD;
00315                         v[2] = SEXAGESIMAL;
00316                         v[3] = RSValue::HMS;
00317                         v[4] = RSValue::DMS;
00318                         return v;
00319                 }
00320 
00321                 // Returns available units for the size unit chooser.
00322                 static vector<String> sizeUnits() {
00323                         static vector<String> v(4);
00324                         v[0] = RSValue::DEG;
00325                         v[1] = RSValue::RAD;
00326                         v[2] = RSValue::ARCSEC;
00327                         v[3] = RSValue::ARCMIN;
00328                         return v;
00329                 }
00330 
00331         private slots:
00332                 // Update the displayed values to reflect the coordinate system, position
00333                 // unit, and size unit chosen by the user.
00334                 void coordSystemChanged();
00335 
00336                 // Resets the values, system, and units to that of the underlying shape.
00337                 void coordReset();
00338 
00339                 // Enable/disable the linethrough options.
00340                 void linethrough();
00341 
00342                 // Call apply() if in edit mode, otherwise emit applyClicked() signal.
00343                 void applySlot() {
00344                         if(m_creation) emit applyClicked();
00345                         else           apply();
00346                 }
00347         };
00348 
00349 }
00350 
00351 #endif /* QTSINGLEREGIONSHAPE_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