casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtDBusPlotSvrAdaptor.qo.h
Go to the documentation of this file.
00001 //# QtDBusPlotSvrAdaptor.qo.h: provides viewer services via dbus
00002 //# Copyright (C) 2009
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 
00028 #ifndef QTDBUSPLOTSVRADAPTOR_QO_H_
00029 #define QTDBUSPLOTSVRADAPTOR_QO_H_
00030 
00031 #include <map>
00032 #include <casaqt/QtUtilities/QtDBusXmlApp.qo.h>
00033 #include <QVariantMap>
00034 #include <QString>
00035 #include <casaqt/QtPlotServer/QtPlotServer.qo.h>
00036 #include <qwt_plot_spectrogram.h>
00037 
00038 class QwtPlotItem;
00039 class QDockWidget;
00040 
00041 namespace casa {
00042 
00043     class QtPlotSvrPanel;
00044 
00045     class QtDBusPlotSvrAdaptor : public QDBusAbstractAdaptor, public QtDBusApp {
00046         Q_OBJECT
00047         Q_CLASSINFO("D-Bus Interface", "edu.nrao.casa.plotserver")
00048     public:
00049 
00050         // name used to initialize connection to dbus
00051         QString dbusName( ) const { return QtPlotServer::name( ); }
00052         bool connectToDBus( const QString &dbus_name="" )
00053                         { return QtDBusApp::connectToDBus( parent(), dbus_name ); }
00054 
00055         QtDBusPlotSvrAdaptor( QtPlotServer * );
00056         ~QtDBusPlotSvrAdaptor( );
00057 
00058     public slots:
00059 
00060         QDBusVariant panel( const QString &title, const QString &xlabel="", const QString &ylabel="", const QString &window_title="",
00061                             const QList<int> &size=QList<int>( ), const QString &legend="bottom", const QString &zoom="bottom",
00062                             int with_panel=0, bool new_row=false, bool hidden=false  );
00063         QStringList colors( );
00064         QStringList colormaps( );
00065         QStringList symbols( );
00066         QDBusVariant line( const QList<double> &x, const QList<double> &y, const QString &color="black",
00067                            const QString &label="", int panel=0 );
00068         QDBusVariant scatter( const QList<double> &x, const QList<double> &y, const QString &color="black",
00069                               const QString &label="", const QString &symbol="", int symbol_size=-1, int dot_size=-1, int panel=0 );
00070         QDBusVariant histogram( const QList<double> &values, int bins=0, const QString &color="blue", const QString &label="", int panel=0 );
00071         QDBusVariant raster( const QList<double> &matrix, int sizex, int sizey, const QString &colormap="Rainbow 2", int panel=0 );
00072 
00073 
00074         QDBusVariant setlabel( const QString &xlabel="", const QString &ylabel="", const QString &title="", int panel_id=0 );
00075 
00076         QDBusVariant erase( int data=0 );
00077         QDBusVariant close( int panel=0 );
00078         QDBusVariant release( int panel=0 );
00079 
00080         QDBusVariant hide( int panel );
00081         QDBusVariant show( int panel );
00082 
00083         QDBusVariant loaddock( const QString &file_or_xml, const QString &loc="top", const QStringList &dockable=QStringList( ), int panel=0 );
00084 
00085         void done( );
00086 
00087     protected slots:
00088 
00089         void emit_button( QtPlotSvrPanel*, QString name );
00090         void emit_check( QtPlotSvrPanel*, QString name, int );
00091         void emit_radio( QtPlotSvrPanel*, QString name, bool );
00092         void emit_linetext( QtPlotSvrPanel*, QString name, const QString &value );
00093         void emit_slidevalue( QtPlotSvrPanel*, QString name, int );
00094         void emit_closing( QtPlotSvrPanel*, bool gone );
00095 
00096     signals:
00097 
00098         void button( int panel, QString name );
00099         void check( int panel, QString name, int value );
00100         void radio( int panel, QString name, bool value );
00101         void linetext( int panel, QString name, const QString &value );
00102         void slidevalue( int panel, QString name, int value );
00103 
00104         void closing( int panel, bool gone );
00105         void exiting( );
00106 
00107     private:
00108 
00109         inline QDBusVariant error( const QString &message ) {
00110             QMap<QString,QVariant> err;
00111             err["*error*"] = message;
00112             return QDBusVariant(QVariant(err));
00113         }
00114 
00115         class panel_desc {
00116         public:
00117 
00118             panel_desc(QtPlotSvrPanel*p) : panel_(p) { }
00119 
00120             std::list<int> &data( ) { return data_; }
00121             const std::list<int> &data( ) const { return data_; }
00122             QtPlotSvrPanel *&panel( ) { return panel_; }
00123             const QtPlotSvrPanel *panel( ) const { return panel_; }
00124 
00125             ~panel_desc( ) { }
00126 
00127         private:
00128             std::list<int> data_;
00129             QtPlotSvrPanel *panel_;
00130         };
00131 
00132 
00133         class data_desc {
00134         public:
00135 
00136             data_desc( int index, QtPlotSvrPanel *panel, QwtPlotItem *data ) : id_(index), data_(data), panel_(panel) { }
00137 
00138             int &id( ) { return id_; }
00139             int id( ) const { return id_; }
00140             QwtPlotItem *&data( ) { return data_; }
00141             const QwtPlotItem *data( ) const { return data_; }
00142             QtPlotSvrPanel *&panel( ) { return panel_; }
00143             const QtPlotSvrPanel *panel( ) const { return panel_; }
00144             ~data_desc( ) { delete data_; }
00145 
00146         private:
00147             int id_;
00148             QwtPlotItem *data_;
00149             QtPlotSvrPanel *panel_;
00150 
00151             // QtDisplayData does not have a copy constructor...
00152             // wonder if we'll need to copy our descriptor...
00153             data_desc( const data_desc &other);
00154             data_desc &operator=( const data_desc &);
00155         };
00156 
00157         int get_id( QtPlotSvrPanel *panel );
00158         int get_id( QtPlotSvrPanel *panel, QwtPlotItem *data );
00159 
00160         void close_everything( );
00161         void release_everything( );
00162         QtPlotServer *server;
00163 
00164         typedef std::map<int,panel_desc*> panelmap;
00165         typedef std::map<int,data_desc*> datamap;
00166         typedef std::map<int,QDockWidget*> dockmap;
00167 
00168         panelmap managed_panels;
00169         datamap managed_datas;
00170         dockmap managed_docks;
00171 
00172         void release( panelmap::iterator & );
00173   };
00174 
00175 }
00176 #endif