casa
$Rev:20696$
|
00001 //# ValuePanel.qo.h: Panel for inputing a data value. 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 VALUEPANEL_QO_H_ 00028 #define VALUEPANEL_QO_H_ 00029 00030 #include <casaqt/QtParamGui/ValuePanel.ui.h> 00031 00032 #include <casa/Containers/Record.h> 00033 00034 #include <casa/namespace.h> 00035 using namespace std; 00036 00037 namespace casa { 00038 00039 class RecordItemPanel; 00040 00041 // Abstract parent class of any panels that accept user input for values. 00042 class ValuePanel : public QWidget { 00043 Q_OBJECT 00044 00045 public: 00046 // Constructor that takes the parameter name and a reference to the 00047 // record detailing its properties. 00048 ValuePanel(String paramName, const RecordInterface& paramRecord); 00049 00050 // Destructor. 00051 virtual ~ValuePanel(); 00052 00053 00054 // Abstract Methods // 00055 00056 // Returns whether or not the currently inputted value is true or not. 00057 // If invalid, the String contains the reason(s), newline-separated. 00058 virtual pair<bool, String> valueIsValid() = 0; 00059 00060 // Returns the type of the current value. 00061 virtual DataType type() = 0; 00062 00063 // Inserts the entered value into the given record with the given name. 00064 virtual void getValue(String name, Record& record) = 0; 00065 00066 // Sets the current value to the one given in the record with the given id. 00067 virtual void setValue(const RecordInterface& rec, RecordFieldId id) = 0; 00068 00069 00070 // Factory Methods // 00071 00072 // Creates and returns a ValuePanel subclass instance appropriate for the 00073 // given parameter. Right now, it only returns a StandardValuePanel, but 00074 // in the future when specialized panels are used, this will be where the 00075 // correct type is transparently created and returned. 00076 static ValuePanel* create(String paramName, 00077 const RecordInterface& paramRecord); 00078 00079 protected: 00080 // Parameter name. 00081 String m_paramName; 00082 00083 // Parameter record. 00084 const RecordInterface& m_paramRecord; 00085 00086 // Returns the allowed vector in m_paramRecord in a useful format. 00087 vector<String> allowedVector(); 00088 }; 00089 00090 00091 // Standard subclass of ValuePanel that controls widget(s) to allow the user 00092 // to input a standard value. StandardValuePanel can handle values of all 00093 // "normal" types defined in the DataType. StandardValuePanel can also handle 00094 // values of type "any" (variant) by providing a combo box to allow the user 00095 // to switch between value types. 00096 class StandardValuePanel : public casa::ValuePanel, Ui::ValuePanel { 00097 Q_OBJECT 00098 00099 public: 00100 // Constructor that takes the parameter name and specification record. 00101 StandardValuePanel(String paramName, const RecordInterface& paramRecord); 00102 00103 // Destructor. 00104 ~StandardValuePanel(); 00105 00106 00107 // ValuePanel methods 00108 00109 // See ValuePanel::valueIsValid 00110 pair<bool, String> valueIsValid(); 00111 00112 // See ValuePanel::type 00113 DataType type(); 00114 00115 // See ValuePanel::getValue 00116 void getValue(String name, Record& record); 00117 00118 // See ValuePanel::setValue 00119 void setValue(const RecordInterface& rec, RecordFieldId id); 00120 00121 signals: 00122 // Emitted when the user changes the value. 00123 void valueChanged(); 00124 00125 private: 00126 // Current type. 00127 DataType m_type; 00128 00129 // Whether a value is a filename that must exist for it to be valid. 00130 bool m_mustExist; 00131 00132 // Array widgets (for array types only). 00133 vector<QWidget*> m_aWidgets; 00134 00135 // Record item panels (for records only). 00136 vector<RecordItemPanel*> m_rPanels; 00137 00138 // Allowed values, or empty if N/A. 00139 vector<String> m_allowed; 00140 00141 // Holds whether the value is a variant or not. 00142 bool m_isVariant; 00143 00144 // Current int bounds. The second element holds whether it has been set. 00145 pair<int, bool> m_intFrom, m_intTo; 00146 00147 // Current double bounds. The second element holds whether it has been set. 00148 pair<double, bool> m_doubleFrom, m_doubleTo; 00149 00150 00151 // Set the type of this ValuePanel to the given. May change the displayed 00152 // input widgets. 00153 void setType(DataType type); 00154 00155 // Limit the chooseable types to the given, for variant values. May not 00156 // have a noticeable effect if the type is incompatible. 00157 void limitTypes(vector<String> types); 00158 00159 // Set the lower bound for inputted int values. May not have a 00160 // noticeable effect if the type is incompatible. 00161 void setIntRangeFrom(int from); 00162 00163 // Set the upper bound for inputted int values. May not have a 00164 // noticeable effect if the type is incompatible. 00165 void setIntRangeTo(int to); 00166 00167 // Set the lower bound for inputted double values. May not have a 00168 // noticeable effect if the type is incompatible. 00169 void setDoubleRangeFrom(double from); 00170 00171 // Set the upper bound for inputted double values. May not have a 00172 // noticeable effect if the type is incompatible. 00173 void setDoubleRangeTo(double to); 00174 00175 // Set the string value to the given. May not have a noticeable 00176 // effect if the type is incompatible. 00177 void setStringValue(String val); 00178 00179 // Set the bool value to the given. May not have a noticeable 00180 // effect if the type is incompatible. 00181 void setBoolValue(bool val); 00182 00183 // Set the double value to the given. May not have a noticeable 00184 // effect if the type is incompatible. 00185 void setDoubleValue(double val); 00186 00187 // Set the int value to the given. May not have a noticeable 00188 // effect if the type is incompatible. 00189 void setIntValue(int val); 00190 00191 // Set the complex value to the given. May not have a noticeable 00192 // effect if the type is incompatible. 00193 void setComplexValue(double val1, double val2); 00194 00195 // Set the record value to the given. May not have a noticeable 00196 // effect if the type is incompatible. 00197 void setRecordValue(const RecordInterface& record); 00198 00199 // Set the value to the given allowed value. May not have a noticeable 00200 // effect if the type is incompatible. 00201 void setAllowedValue(String val); 00202 00203 // Set the string array value to the given. May not have a noticeable 00204 // effect if the type is incompatible. 00205 void setStringArrayValue(const vector<String>& array); 00206 00207 // Set the bool array value to the given. May not have a noticeable 00208 // effect if the type is incompatible. 00209 void setBoolArrayValue(const vector<bool>& array); 00210 00211 // Set the double array value to the given. May not have a noticeable 00212 // effect if the type is incompatible. 00213 void setDoubleArrayValue(const vector<double>& array); 00214 00215 // Set the int array value to the given. May not have a noticeable 00216 // effect if the type is incompatible. 00217 void setIntArrayValue(const vector<int>& array); 00218 00219 // Set the complex array value to the given. May not have a noticeable 00220 // effect if the type is incompatible. 00221 void setComplexArrayValue(const vector<DComplex>& array); 00222 00223 // Returns a new array widget based on the current type. Used for adding 00224 // an item to an array list. 00225 QWidget* arrayWidget(); 00226 00227 // Holds the types supported by the variant panel. 00228 static vector<DataType> supportedTypes() { 00229 vector<DataType> v(11); 00230 v[0] = TpBool; v[1] = TpArrayBool; 00231 v[2] = TpInt; v[3] = TpArrayInt; 00232 v[4] = TpDouble; v[5] = TpArrayDouble; 00233 v[6] = TpString; v[7] = TpArrayString; 00234 v[8] = TpDComplex; v[9] = TpArrayDComplex; 00235 v[10] = TpRecord; 00236 return v; 00237 } 00238 00239 private slots: 00240 // Slot for when the user chooses a different type (for variants). 00241 void typeChanged(QString newType); 00242 00243 // Decrease array widgets by one. 00244 void lessArray(); 00245 00246 // Increase array widgets by one. 00247 void moreArray(); 00248 00249 // Decrease record items by one. 00250 void lessRecord(); 00251 00252 // Increase record items by one. 00253 void moreRecord(); 00254 00255 // Show a file dialog and put the result in the string value. 00256 void browse(); 00257 00258 // Connecting the various widgets to emit the valueChanged signal. 00259 void changedValue() { emit valueChanged(); } 00260 }; 00261 00262 00263 // Panel to hold one item in a record (i.e., a key and a value). A 00264 // RecordItemPanel basically consists of a QLineEdit and a StandardValuePanel 00265 // set to be a variant. 00266 class RecordItemPanel : public QHBoxLayout { 00267 Q_OBJECT 00268 00269 public: 00270 // Default constructor. 00271 RecordItemPanel(String paramName); 00272 00273 // Destructor. 00274 ~RecordItemPanel(); 00275 00276 // Returns the current key name entered. 00277 String name(); 00278 00279 // Returns the value panel used. 00280 StandardValuePanel* value(); 00281 00282 // Insert the key/value pair into the given record. 00283 void getValue(Record& record); 00284 00285 signals: 00286 // Emitted when the user changes the value. 00287 void valueChanged(); 00288 00289 private: 00290 // Key line edit. 00291 QLineEdit* m_name; 00292 00293 // Value panel. 00294 StandardValuePanel* m_value; 00295 00296 private slots: 00297 // Connecting the various widgets to emit the valueChanged signal. 00298 void changedValue() { emit valueChanged(); } 00299 }; 00300 00301 } 00302 00303 #endif /*VALUEPANEL_QO_H_*/