casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtPlotSvrPanel.qo.h
Go to the documentation of this file.
00001 //# QtPlotSvrPanel.qo.h: Qt implementation of main 2D plot server display window.
00002 //# with surrounding Gui functionality
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: QtDisplayPanelGui.qo.h,v 1.7 2006/10/10 21:42:05 dking Exp $
00028 
00029 #ifndef CASAQT_QTPLOTSRVPANEL_H
00030 #define CASAQT_QTPLOTSRVPANEL_H
00031 
00032 #include <map>
00033 #include <QMainWindow>
00034 #include <QStringList>
00035 #include <qwt_plot_curve.h>
00036 #include <qwt_color_map.h>
00037 #include <casaqt/QtUtilities/QtId.h>
00038 #include <casaqt/QtUtilities/QtPanelBase.qo.h>
00039 #include <casaqt/QtPlotServer/QtPlotHistogram.h>
00040 #include <casadbus/types/ptr.h>
00041 
00042 class QwtPlotCurve;
00043 class QwtPlotSpectrogram;
00044 class QVBoxLayout;
00045 class QHBoxLayout;
00046 class QSlider;
00047 class QwtPlotZoomer;
00048 
00049 namespace casa {
00050 
00051     class QtPlotFrame;
00052 
00053     class QtPlotSvrMain : public QtPanelBase {
00054     Q_OBJECT
00055         public:
00056             QtPlotSvrMain( QWidget *parent=0 ) : QtPanelBase( ) { }
00057 
00058         signals:
00059             void closing( bool );
00060 
00061         protected: 
00062             // scripted (via dbus) panels should override the closeEvent( ) and hide the gui
00063             // instead of deleting it when it was created via a dbus script...
00064             void closeEvent(QCloseEvent *event);
00065     };
00066 
00067     class QtPlotSvrPanel : public QObject {
00068     Q_OBJECT
00069         public:
00070 
00071             void hide( );
00072             void show( );
00073             void closeMainPanel( );
00074             bool isVisible( );
00075             void releaseMainPanel( );
00076 
00077             QtPlotSvrPanel( QWidget *parent=0 );
00078             QtPlotSvrPanel( const QString &title,  const QString &xlabel="", const QString &ylabel="", const QString &window_title="",
00079                             const QList<int> &size=QList<int>( ), const QString &legend="bottom", const QString &zoom="bottom",
00080                             QtPlotSvrPanel *with_panel=0, bool new_row=false, QWidget *parent=0 );
00081 
00082             static QStringList colors( );
00083             static QStringList colormaps( );
00084             static QStringList symbols( );
00085 
00086             QwtPlotCurve *line( const QList<double> &x, const QList<double> &y, const QString &color="black", const QString &label="" );
00087             QwtPlotCurve *scatter( const QList<double> &x, const QList<double> &y, const QString &color="black", const QString &label="",
00088                                    const QString &symbol="", int symbol_size=-1, int dot_size=-1 );
00089             QtPlotHistogram *histogram( const QList<double> &y, int bins=0, const QString &color="blue", const QString &label="" );
00090             QwtPlotSpectrogram *raster( const QList<double> &matrix, int sizex, int sizey, const QString &colormap="Rainbow 2" );
00091 
00092             void replot( );
00093 
00094             void setxlabel( const QString &xlabel );
00095             void setylabel( const QString &ylabel );
00096             void settitle( const QString &title );
00097             
00098             std::pair<QDockWidget*,QString> loaddock( const QString &file_or_xml, const QString &loc, const QStringList &dockable );
00099 
00100             virtual ~QtPlotSvrPanel( ) { }
00101 
00102         signals:
00103 
00104             void button( QtPlotSvrPanel *, QString );
00105             void check( QtPlotSvrPanel *, QString, int );
00106             void radio( QtPlotSvrPanel *, QString, bool );
00107             void linetext( QtPlotSvrPanel *, QString, const QString &text );
00108             void slidevalue( QtPlotSvrPanel *, QString, int );
00109 
00110             void closing( QtPlotSvrPanel *, bool );
00111 
00112         protected slots:
00113 
00114             void emit_button( );
00115             void emit_check( int );
00116             void emit_radio( bool );
00117             void emit_linetext( const QString &text );
00118             void emit_slidevalue( int );
00119 
00120             void emit_closing( bool );
00121 
00122             void zoom( int x=-1 );
00123             void zoomed( const QwtDoubleRect & );
00124 
00125         protected: 
00126 
00127             QWidget *loaddock( QString file );
00128             QFont defaultfont;
00129 
00130             typedef std::map<QString,memory::cptr<QwtLinearColorMap> > colormap_map;
00131             static void load_colormaps( );
00132             static colormap_map *colormaps_;
00133 
00134         private:
00135 
00136             class row_desc {
00137             public:
00138 
00139                 class plot_desc {
00140                 public:
00141                     plot_desc( QWidget *c, QLayout *l, QtPlotFrame *p, QSlider *s ) :
00142                         container_(c), layout_(l), plot_(p), slider_(s) { }
00143                     QWidget *&container( ) { return container_; }
00144                     QLayout *&layout( ) { return layout_; }
00145                     QtPlotFrame *&plot( ) { return plot_; }
00146                     QSlider *&slider( ) { return slider_; }
00147 
00148                 private:
00149                     QWidget *container_;
00150                     QLayout *layout_;
00151                     QtPlotFrame *plot_;
00152                     QSlider *slider_;
00153                 };
00154 
00155                 row_desc( QWidget *c, QHBoxLayout *l ) : container_(c), layout_(l), id_(QtId::get_id( )) { }
00156                 QWidget *container( ) { return container_; }
00157                 QHBoxLayout *layout( ) { return layout_; }
00158                 void addplot( QWidget *container, QLayout *layout, QtPlotFrame *plot, QSlider *slider )
00159                                 { plots.push_back( new plot_desc(container, layout, plot, slider ) ); }
00160                 int id( ) { return id_; }
00161             private:
00162                 typedef std::list<plot_desc*> plotlist;
00163                 plotlist plots;
00164                 QWidget *container_;
00165                 QHBoxLayout *layout_;
00166                 int id_;
00167             };
00168 
00169             class win_desc {
00170             public:
00171                 win_desc( QtPlotSvrMain *b, QWidget *c, QVBoxLayout *l ) : base_(b), container_(c), layout_(l) { }
00172                 QtPlotSvrMain *& base( ) { return base_; }
00173                 QWidget *&container( ) { return container_; }
00174                 QVBoxLayout *&layout( ) { return layout_; }
00175             private:
00176                 QtPlotSvrMain *base_;
00177                 QWidget *container_;
00178                 QVBoxLayout *layout_;
00179             };
00180 
00181             typedef std::map<QtPlotSvrPanel*,memory::cptr<row_desc> > rowmap;
00182             memory::cptr<rowmap> rows_;
00183 
00184             memory::cptr<win_desc> window_;
00185 
00186             QSlider *slider;
00187             QtPlotFrame *plot;
00188             QwtPlotZoomer *zoomer;
00189             double current_zoom_level;
00190             int slider_last_value;
00191     };
00192 }
00193 
00194 #endif