00001
00002
00016 #ifndef CanvasView_H
00017 #define CanvasView_H
00018
00019 #include "FigureEditor.h"
00020
00021 #if QT_VERSION < 0x040000
00022 #else
00023
00024 #include <QtGui/QMouseEvent>
00025 #endif
00026
00027
00028 #ifdef _MSC_VER
00029 #include <msdevstudio/MSconfig.h>
00030 #endif
00031
00032 #include <list>
00033 #include <map>
00034
00035 #if QT_VERSION < 0x040000
00036 class QFileDialog;
00037 #else
00038 class Q3FileDialog;
00039 class Q3MainWindow;
00040 #endif
00041
00042 class QActionGroup;
00043 class QFont;
00044 class QMainWindow;
00045 class QAction;
00046
00047 namespace hippodraw {
00048
00049 class Inspector;
00050 class PlotterBase;
00051 class QtView;
00052 class ViewBase;
00053 class XmlController;
00054 class NTuple;
00055 class PickTable;
00056 class CreateNTuple;
00057 class QtGroupView;
00058
00094 class MDL_QTHIPPOPLOT_API CanvasView : public FigureEditor
00095 {
00096
00097 Q_OBJECT
00098
00099 private:
00100
00102 std::list <QAction *> m_recent_list;
00103
00105 mutable std::vector < const ViewBase * > m_views;
00106
00108 mutable std::vector < const ViewBase * > m_sel_views;
00109
00111 std::map < const QtView *, PickTable * > m_table_map;
00112
00114 static XmlController * s_xml_controller;
00115
00117 Inspector * m_inspector;
00118
00121 static const std::string s_app_name;
00122
00124 static std::string s_image_filters;
00125
00128 #if QT_VERSION < 0x040000
00129 QCanvasRectangle * m_drag_rect;
00130 #else
00131 Q3CanvasRectangle * m_drag_rect;
00132 #endif
00133
00139 #if QT_VERSION < 0x040000
00140 QFileDialog * m_image_dialog;
00141 #else
00142 Q3FileDialog * m_image_dialog;
00143 #endif
00144
00146 std::vector<double> m_mouseData;
00147
00149 bool fillPickedPoint(QMouseEvent * e, std::vector<double> & picked);
00150
00153 void fillMouseData(const std::vector<double> & picked);
00154
00155 void updatePickTable(QtView * qtview, std::vector<double> & picked);
00156
00157 void setPlotZoom(const std::vector<double> & start_picked,
00158 const std::vector<double> & picked);
00159
00162 int m_num_width;
00163
00166 int m_num_height;
00167
00170 bool m_add_selected;
00171
00174 int m_cut_mode;
00175
00181 int m_edge;
00182
00185 bool m_clicked;
00186
00189 double old_pos, old_pos_x, old_pos_y;
00190
00191
00194 std::vector<double> m_current_range;
00195
00198 void initSettings ();
00199
00202 void saveSettings () const;
00203
00206 void initFitterDefault ();
00207
00210 void setFitterDefault ( const std::string & name );
00211
00214 void initFitterMenu ( QActionGroup * group );
00215
00218 static void createImageFilters ();
00219
00223 static bool isValidImageFormat ( const std::string & suffix );
00224
00228 #if QT_VERSION < 0x040000
00229 QFileDialog * createImageDialog ();
00230 #else
00231 Q3FileDialog * createImageDialog ();
00232 #endif
00233
00235 void setChanged ( bool yes = true );
00236
00239 void addView ( QtView * view, bool select );
00240
00243 #if QT_VERSION < 0x040000
00244 void placeItems ( const std::vector < QCanvasItem * > & items );
00245 #else
00246 void placeItems ( const std::vector < Q3CanvasItem * > & items );
00247 #endif
00248
00251 virtual void calcDefaultSize ( QtView * view, double aspect_ratio = 0.0);
00252
00256 void moveToPlotter ( const PlotterBase * plotter, QtView * view );
00257
00260 void sizeAndPlace ( QtView * view );
00261
00265 std::pair<double, double> moveToPlotterAt ( const PlotterBase * plotter,
00266 QtView * view,
00267 double x, double y );
00268
00272 void fillSelectedWithObservers ( std::vector < const ViewBase * > & );
00273
00274 PlotterBase * getRightClickedPlotter();
00275
00276
00277
00278 protected:
00279
00281 virtual void contentsMouseMoveEvent ( QMouseEvent * );
00282 virtual void contentsMousePressEvent ( QMouseEvent * );
00283
00287 virtual void controlMousePressEvent ();
00288
00292 virtual void contentsMouseReleaseEvent(QMouseEvent*);
00293
00294 public:
00295
00296 #if QT_VERSION < 0x040000
00297 CanvasView ( QCanvas *, QWidget * parent = 0,
00298 const char * name = 0, Qt::WFlags f = 0 );
00299 #else
00300 CanvasView ( Q3Canvas *, QWidget * parent = 0,
00301 const char * name = 0, Qt::WFlags f = 0 );
00302 #endif
00303
00304 void initFrom ( const std::list < ViewBase * > & views );
00305
00307 void initFromFile ( const std::string & filename );
00308
00314 void initFitterSettings ( QActionGroup * group);
00315
00318 void initRecentFiles ( QActionGroup * ag );
00319
00322 #if QT_VERSION < 0x040000
00323 void initDockWindows ( QMainWindow * mw );
00324 #else
00325 void initDockWindows ( Q3MainWindow * mw );
00326 #endif
00327
00329 void addRecentFile (const QString & filename, QActionGroup * ag );
00330
00333 void setFitterDefault ( const QString & name );
00334
00336 void copySelectedToPasteboard ();
00337
00340 void copyFromPasteboard ();
00341
00345 void addFromPasteboard ();
00346
00350 void deleteSelected ( bool paste );
00351
00354 void pasteViews ( const std::list < ViewBase * > & views );
00355
00357 void restoreFromSelectCopy ();
00358
00360 void setCurrentRange();
00361
00363 std::vector<double>& getCurrentRange() ;
00364
00367 void setInspector ( Inspector * inspector );
00368
00370 Inspector * getInspector ();
00371
00379 void notifyObservers ();
00380
00382 PlotterBase * selectedPlotter () const;
00383
00386 std::vector < PlotterBase * > getSelectedPlotters () const;
00387
00391 void addPlotDisplay ( PlotterBase * plotter, bool select);
00392
00394 #if QT_VERSION < 0x040000
00395 void autosaveSettings ( QMainWindow * mw);
00396 #else
00397 void autosaveSettings ( Q3MainWindow * mw);
00398 #endif
00399 public:
00400
00404 void addTextDisplay ( PlotterBase * plotter,
00405 const std::string & s,
00406 const std::string & text = std::string () );
00407
00412 std::pair<double, double> addTextDisplayAt ( PlotterBase * plotter,
00413 const std::string & type,
00414 const std::string & text,
00415 double xrel, double yrel);
00416
00417
00419 void addFuncDisplay ( PlotterBase * plotter, const std::string & s );
00420
00423 void removeDisplay ( PlotterBase * plotter );
00424
00428 const std::vector < const ViewBase * > & selectedViews () const;
00429
00434 const std::vector < const ViewBase * > & views () const;
00435
00439 void fillPlotterList ( std::vector < PlotterBase * > & plotter_list );
00440
00443 QtView * getViewFor ( const PlotterBase * plotter ) const;
00444
00448 void previousView ();
00449
00452 virtual void print ();
00453
00456 virtual void print ( const std::string & filename );
00457
00460 void reTile ();
00461
00464 void reTilePage ();
00465
00468 void setIntervalEnabled ( bool yes = true );
00469
00471 void removeSelected ();
00472
00474 void hideSelected ();
00475
00480 void saveSelectedImages ();
00481
00483 void saveSelectedImages ( const std::string & filename );
00484
00487 void savePlotAsEps ( const PlotterBase * plotter,
00488 const std::string & filename ) const;
00489
00495 void savePlotAsFits ( const PlotterBase * plotter,
00496 const std::string & filename ) const;
00497
00500 void saveAs ( const std::string & filename ) const;
00501
00504 static void saveAs ( const std::vector < const ViewBase * > & views,
00505 const std::string & filename );
00506
00509 static void saveAs ( const std::vector < PlotterBase * > & plotters,
00510 const std::string & filename );
00511
00516 void exportTextTuple ( const std::string & suffix );
00517
00520 void showInspector ();
00521
00523 void viewShowPickTable();
00524
00527 const std::vector<double> & mouseEventData();
00528
00532 void setPlotMatrix ( unsigned int columns, unsigned int rows );
00533
00535 void createNTuple();
00536
00538 void setup ();
00539
00540
00542 void setFonts( const QFont & font );
00543
00545 void helpAbout ();
00546
00549 const std::string & applicationName () const;
00550
00553 void setAddedSelected ( bool yes );
00554
00555 void setCutMode ( int mode );
00556
00559 NTuple * getPickTable ();
00560
00563 NTuple * getPickTable ( const PlotterBase * plotter );
00564
00566 void groupView ();
00567
00569 void ungroupView ();
00570
00571 private:
00572
00575 bool existingFileWarning ( const std::string & filename );
00576
00579 void invalidImageFormatError ( const std::string & filename );
00580
00582 void saveSelectedAsEps ( const std::string & filename );
00583
00584
00590 void saveSelectedAsFits ( const std::string & filename );
00591 public:
00595 void showFitsError () const;
00596 private:
00597
00601 void setVisibleNonViews ( bool visible );
00602
00610 void saveSelectedImages ( const std::string & filename,
00611 bool check_existing );
00612
00615 static void toLower ( std::string & upper );
00616
00617 public slots:
00618
00623 void addPlotDisplay ( PlotterBase * plotter );
00624
00626 void clear ();
00627
00633 void savePlotAsImage ( const PlotterBase * plotter,
00634 const std::string & filename );
00635
00638 void swapOrientation ();
00639
00642 static QtView * wrapPlotter ( PlotterBase * plotter );
00643
00644 };
00645
00646 }
00647
00648 #endif // CanvasView_H