QtAutoGui.qo.h

Go to the documentation of this file.
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                 Q_OBJECT
00068 
00069         public:
00070 
00071                 QtAutoGui(QWidget *parent = 0);
00072                 QtAutoGui(Record rec, String dataName = "",
00073                           String dataType = "Unknown", QWidget *parent = 0);
00074                 ~QtAutoGui();
00075 
00076                 void setFileName(const QString &file_name);
00077                 QString fileName() const;
00078                 void setDataType(const QString &dType);
00079                 QString dataType() const;
00080                 bool load(QDomDocument &doc);
00081                 bool load(); //from file
00082                 bool save();  //to file
00083                 void apply(); //to the canvas
00084                 void restore();
00085                 void setMemory(); //take a snapshot
00086                 void setOriginal(); //restore to the saved
00087                 void setDefault(); //use the preset values
00088                 void dismiss();
00089                 enum ACTIONTYPE {Set, Copy, Paste, Default, Original, Memorize, Command};
00090                 // call once only during initialization, to populate the gui,
00091                 // if you used the QtAutoGui(QWidget=0) constructor.
00092                 void loadRecord(Record rec);
00093                 static const QString HISTOGRAM_SHOW_KEY;
00094                 static const QString HISTOGRAM_RANGE_KEY;
00095 
00096         signals:
00097 
00098                 void setOptions(Record options);
00099                 //# dk note to hye:
00100                 //#
00101                 //# This is the signal that needs to be sent whenever a value
00102                 //# is changed on the gui, or when 'apply' is pressed.  When
00103                 //# a gui value change occurs, send only that option; when
00104                 //# 'apply' is pressed, send the current value of all options.
00105                 //# The record format should be as for getOptions, although not
00106                 //# all fields are always sent.  You need only send the 'value'
00107                 //# field of the option[s], although you can send the other fields
00108                 //# too if you want.
00109                 //#
00110                 //# Look at the format of setoptions events sent in the current
00111                 //# viewer; this is the format the C++ display library expects.
00112                 //# An easy way to do this is to copy this diagnostic-version
00113                 //# glish file to the directory where you run aips++:
00114                 //#
00115                 //#  /users/dking/testcode/g/viewerdisplaydata.g
00116                 //#
00117                 //# Then run the aips++ viewer normally there.  Each time you
00118                 //# change an 'adjust' panel option or press its 'apply', it will
00119                 //# print the record emitted by the setoptions event.
00120 
00121         protected:
00122                 void contextMenuEvent(QContextMenuEvent *e);
00123         private slots:
00124 
00125         public slots:
00126                 void itemValueChanged(QString name, QString value, int action, bool apply);
00127                 //#dk virtual void paintEvent ( QPaintEvent * event );
00128                 void adjustHeight();
00129 
00130                 virtual void changeOptions(Record changedOptions);
00131                 //# dk note to hye:
00132                 //#
00133                 //# This slot needs to be implemented to handle changes
00134                 //# requested by the C++ library to current values, allowed data
00135                 //# range('pmin, pmax') and display
00136                 //# label ('listname'), as appropriate, for any existing options.
00137                 //#
00138                 //# It would be useful to allow changes to slider increment
00139                 //# ('presolution'), available choices ('popt') and the default
00140                 //# value as well.  Also, it would be useful to support
00141                 //# (new) boolean subfields 'enabled' and 'visible'.  These
00142                 //# features can be postponed, if necessary, though, and we will not
00143                 //# need to support changes to some of the fields sent in these
00144                 //# records from the library (such as help, editable, dlformat...).
00145                 //#
00146                 //# If you're really ambitious, you could try supporting addition of
00147                 //# new option entries, too.
00148                 //#
00149                 //# the 'modifygui' method in autogui.g is the glish equivalent
00150                 //# of what we're trying to do here, although modifygui itself is
00151                 //# rather incomplete.
00152 
00153 
00154                 // (called only once, during or soon after construction.  Sets up contents of
00155                 // the gui from rec).
00156 
00157                 void autoApplyState( bool auto_apply ) {
00158                         auto_apply_ = auto_apply;
00159                 }
00160 
00161         protected:
00162                 bool auto_apply_;
00163 
00164         private:
00165                 QDomDocument m_doc;
00166                 QString m_file_name;
00167                 QString m_data_type;
00168                 QWidget *contents_;
00169                 QVBoxLayout *contentsLayout_;
00170                 QVBoxLayout *vboxLayout;
00171                 //#dk QFrame *line;
00172                 QSpacerItem *spacerItem;
00173                 //QScrollArea *scrollArea;
00174 
00175                 Bool recordLoaded_;
00176                 QString m_lockItem;
00177                 QMutex mutex;
00178                 void initialize();
00179 
00180         };
00181 
00182 } //# NAMESPACE CASA - END
00183 
00184 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1