00001
00012 #include "PlotTable.h"
00013
00014 #include "CanvasView.h"
00015 #include "PlotTableEvent.h"
00016 #include "QtView.h"
00017
00018 #include "datareps/DataRep.h"
00019 #include "graphics/ViewBase.h"
00020 #include "plotters/PlotterBase.h"
00021
00022 #include <qapplication.h>
00023 #include <qpushbutton.h>
00024 #if QT_VERSION < 0x040000
00025 #include <qlistview.h>
00026 #else
00027 #include <q3listview.h>
00028 #endif
00029
00030 #include <qstring.h>
00031
00032 #include <vector>
00033
00034 using namespace hippodraw;
00035
00036 using std::string;
00037 using std::vector;
00038
00039 PlotTable::
00040 PlotTable ()
00041 : PlotTableBase (),
00042 m_observer ( 0 ),
00043 m_browser_mode ( false )
00044 {
00045 }
00046
00047 void
00048 PlotTable::
00049 setCanvas ( CanvasView * canvas )
00050 {
00051 m_canvas_view = canvas;
00052 initialize ();
00053 }
00054
00055 void
00056 PlotTable::
00057 initialize ()
00058 {
00059 m_plot_table->clear();
00060
00061 const vector < const ViewBase * > & views = m_canvas_view->views ();
00062 vector < const ViewBase * > :: const_iterator first = views.begin ();
00063
00064 while ( first != views.end () ) {
00065 const ViewBase * view = *first++;
00066 const PlotterBase * plotter = view->getPlotter ();
00067 QString title ( plotter->getTitle ().c_str() );
00068 QString x_axis ( plotter->getLabel ( Axes::X ).c_str() );
00069 QString y_axis ( plotter->getLabel ( Axes::Y ).c_str() );
00070 QString z_axis ( QString::null );
00071 if ( plotter->hasAxis ( Axes::Z ) ) {
00072 const string & z = plotter->getLabel ( Axes::Z );
00073 z_axis = z.c_str();
00074 }
00075 const DataRep * rep = plotter->getDataRep ( 0 );
00076 const string & t = rep->name ();
00077 QString type ( t.c_str() );
00078
00079 #if QT_VERSION < 0x040000
00080 QListViewItem * item
00081 = new QListViewItem ( m_plot_table,
00082 title, type,
00083 x_axis, y_axis, z_axis );
00084 m_view_map [ item ] = view;
00085 #else
00086
00087
00088
00089
00090
00091 #endif
00092 }
00093 }
00094
00095 void
00096 PlotTable::
00097 #if QT_VERSION < 0x040000
00098 selectionChanged ( QListViewItem * item )
00099 #else
00100 selectionChanged ( Q3ListViewItem * item )
00101 #endif
00102 {
00103 const ViewBase * view = m_view_map [ item ];
00104 ViewBase * v = const_cast < ViewBase * > ( view );
00105 QtView * vv = dynamic_cast < QtView * > ( v );
00106
00107 m_canvas_view -> setSelectedItem ( vv );
00108 m_canvas_view -> ensureVisible ( vv );
00109 if ( m_browser_mode ) {
00110 copyButton -> setEnabled ( true );
00111 }
00112 }
00113
00114 void
00115 PlotTable::
00116 setBrowserMode ( bool yes, QWidget * observer )
00117 {
00118 m_browser_mode = yes;
00119 m_observer = observer;
00120 if ( yes == false ) copyButton -> setEnabled ( yes );
00121 }
00122
00123 void
00124 PlotTable::
00125 on_copyButton_clicked ()
00126 {
00127 m_canvas_view -> copySelectedToPasteboard ();
00128
00129 PlotTableEvent * event = new PlotTableEvent ( PlotTableEvent::Copy );
00130 QApplication::postEvent ( m_observer, event );
00131 }
00132
00133 void
00134 PlotTable::
00135 on_closeButton_clicked ()
00136 {
00137 if ( m_browser_mode ) {
00138 PlotTableEvent * event = new PlotTableEvent ( PlotTableEvent::Close );
00139 QApplication::postEvent ( m_observer, event );
00140 }
00141 m_browser_mode = false;
00142 }