casa
$Rev:20696$
|
00001 //# QtAutoGui.qo.h: General-purpose Qt options panel widget created from 00002 //# an options Record. 00003 //# Copyright (C) 2005 00004 //# Associated Universities, Inc. Washington DC, USA. 00005 //# 00006 //# This library is free software; you can redistribute it and/or modify it 00007 //# under the terms of the GNU Library General Public License as published by 00008 //# the Free Software Foundation; either version 2 of the License, or (at your 00009 //# option) any later version. 00010 //# 00011 //# This library is distributed in the hope that it will be useful, but WITHOUT 00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 //# License for more details. 00015 //# 00016 //# You should have received a copy of the GNU Library General Public License 00017 //# along with this library; if not, write to the Free Software Foundation, 00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00019 //# 00020 //# Correspondence concerning AIPS++ should be addressed as follows: 00021 //# Internet email: aips2-request@nrao.edu. 00022 //# Postal address: AIPS++ Project Office 00023 //# National Radio Astronomy Observatory 00024 //# 520 Edgemont Road 00025 //# Charlottesville, VA 22903-2475 USA 00026 //# 00027 //# $Id$ 00028 00029 #ifndef QTAUTOGUI_H 00030 #define QTAUTOGUI_H 00031 00032 #include <casa/aips.h> 00033 00034 #include <graphics/X11/X_enter.h> 00035 # include <QtCore> 00036 # include <QtGui> 00037 # include <QtXml/QDomDocument> 00038 #include <graphics/X11/X_exit.h> 00039 00040 #include "QtGuiEntry.qo.h" 00041 #include "QtXmlRecord.h" 00042 00043 namespace casa { //# NAMESPACE CASA - BEGIN 00044 00045 00046 // <summary> 00047 // General-purpose Qt options widget created from Record 00048 // </summary> 00049 00050 // <synopsis> 00051 // This class serves the same general purpose as the old glish 00052 // autogui.g: it creates a gui from a record whose fields describe 00053 // 'parameters' (or 'options') to be controlled by the gui. The record 00054 // used to construct the gui is passed in construction, or soon after, 00055 // via loadRecord(). Each option passed contains an initial value as 00056 // well as meta-data describing the type of input widget to be used 00057 // ('popt' field), labels, limits, choices, help texts, etc., as applicable. 00058 // 00059 // When the user operates the control for a gui option, a setOptions 00060 // signal is emitted with a similar Record indicating which option was 00061 // changed, and new value. If the 'Apply' button of the gui is pressed, 00062 // the setOptions signal contains the current value of every option. 00063 // </synopsis> 00064 00066 class QtAutoGui : public QWidget 00067 { 00068 Q_OBJECT 00069 00070 public: 00071 00072 QtAutoGui(QWidget *parent = 0); 00073 QtAutoGui(Record rec, String dataName = "", 00074 String dataType = "Unknown", QWidget *parent = 0); 00075 ~QtAutoGui(); 00076 00077 void setFileName(const QString &file_name); 00078 QString fileName() const; 00079 void setDataType(const QString &dType); 00080 QString dataType() const; 00081 bool load(QDomDocument &doc); 00082 bool load(); //from file 00083 bool save(); //to file 00084 void apply(); //to the canvas 00085 void restore(); 00086 void setMemory(); //take a snapshot 00087 void setOriginal(); //restore to the saved 00088 void setDefault(); //use the preset values 00089 void dismiss(); 00090 enum ACTIONTYPE {Set, Copy, Paste, Default, Original, Memorize, Command}; 00091 // call once only during initialization, to populate the gui, 00092 // if you used the QtAutoGui(QWidget=0) constructor. 00093 void loadRecord(Record rec); 00094 static const QString HISTOGRAM_SHOW_KEY; 00095 static const QString HISTOGRAM_RANGE_KEY; 00096 00097 signals: 00098 00099 void setOptions(Record options); 00100 //# dk note to hye: 00101 //# 00102 //# This is the signal that needs to be sent whenever a value 00103 //# is changed on the gui, or when 'apply' is pressed. When 00104 //# a gui value change occurs, send only that option; when 00105 //# 'apply' is pressed, send the current value of all options. 00106 //# The record format should be as for getOptions, although not 00107 //# all fields are always sent. You need only send the 'value' 00108 //# field of the option[s], although you can send the other fields 00109 //# too if you want. 00110 //# 00111 //# Look at the format of setoptions events sent in the current 00112 //# viewer; this is the format the C++ display library expects. 00113 //# An easy way to do this is to copy this diagnostic-version 00114 //# glish file to the directory where you run aips++: 00115 //# 00116 //# /users/dking/testcode/g/viewerdisplaydata.g 00117 //# 00118 //# Then run the aips++ viewer normally there. Each time you 00119 //# change an 'adjust' panel option or press its 'apply', it will 00120 //# print the record emitted by the setoptions event. 00121 00122 protected: 00123 void contextMenuEvent(QContextMenuEvent *e); 00124 private slots: 00125 00126 public slots: 00127 void itemValueChanged(QString name, QString value, int action, bool apply); 00128 //#dk virtual void paintEvent ( QPaintEvent * event ); 00129 void adjustHeight(); 00130 00131 virtual void changeOptions(Record changedOptions); 00132 //# dk note to hye: 00133 //# 00134 //# This slot needs to be implemented to handle changes 00135 //# requested by the C++ library to current values, allowed data 00136 //# range('pmin, pmax') and display 00137 //# label ('listname'), as appropriate, for any existing options. 00138 //# 00139 //# It would be useful to allow changes to slider increment 00140 //# ('presolution'), available choices ('popt') and the default 00141 //# value as well. Also, it would be useful to support 00142 //# (new) boolean subfields 'enabled' and 'visible'. These 00143 //# features can be postponed, if necessary, though, and we will not 00144 //# need to support changes to some of the fields sent in these 00145 //# records from the library (such as help, editable, dlformat...). 00146 //# 00147 //# If you're really ambitious, you could try supporting addition of 00148 //# new option entries, too. 00149 //# 00150 //# the 'modifygui' method in autogui.g is the glish equivalent 00151 //# of what we're trying to do here, although modifygui itself is 00152 //# rather incomplete. 00153 00154 00155 // (called only once, during or soon after construction. Sets up contents of 00156 // the gui from rec). 00157 00158 void autoApplyState( bool auto_apply ) { auto_apply_ = auto_apply; } 00159 00160 protected: 00161 bool auto_apply_; 00162 00163 private: 00164 QDomDocument m_doc; 00165 QString m_file_name; 00166 QString m_data_type; 00167 QWidget *contents_; 00168 QVBoxLayout *contentsLayout_; 00169 QVBoxLayout *vboxLayout; 00170 //#dk QFrame *line; 00171 QSpacerItem *spacerItem; 00172 //QScrollArea *scrollArea; 00173 00174 Bool recordLoaded_; 00175 QString m_lockItem; 00176 QMutex mutex; 00177 void initialize(); 00178 00179 }; 00180 00181 } //# NAMESPACE CASA - END 00182 00183 #endif