CanvasWindow.cxx
Go to the documentation of this file.
1 
14 #ifdef HAVE_CONFIG_H
15 // for have root and cfitsio
16 #include "config.h"
17 #endif
18 
19 #include "CanvasWindow.h"
20 
21 #include "CanvasView.h"
22 #include "Inspector.h"
23 #include "QtFileDialog.h"
24 #include "PlotTable.h"
25 #include "PlotTableEvent.h"
26 #include "PlotterEvent.h"
27 #include "QtGroupView.h"
28 #include "SaveAsImageEvent.h"
29 #include "WindowController.h"
30 
33 #include "plotters/PlotterBase.h"
34 #include "qtxml/QtXMLController.h"
35 
36 #include <qapplication.h>
37 #if QT_VERSION < 0x040000
38 #include <qaction.h>
39 #else
40 //Added by the Qt porting tool:
41 #include <QtGui/QCloseEvent>
42 #include <QtCore/QCustomEvent>
43 #include <QtGui/QHideEvent>
44 #include <QtGui/QResizeEvent>
45 #include <QtGui/QShowEvent>
46 #include <q3action.h>
47 #endif
48 
49 #include <qmessagebox.h>
50 #include <qfontdialog.h>
51 
52 #include <algorithm>
53 
54 #include <cassert>
55 
56 using std::exception;
57 using std::list;
58 using std::string;
59 using std::vector;
60 
61 using namespace hippodraw;
62 
64 
70 #if QT_VERSION < 0x040000
72  const char * name,
73  Qt::WFlags fl )
74  : CanvasWindowBase ( parent, name, fl ),
75 #else
76 CanvasWindow::CanvasWindow ( QWidget * parent )
77  : CanvasWindowBase ( parent ),
78 #endif
79  m_file_dialog ( 0 ),
80  m_prefix ( "HippoDraw - Canvas " ),
81  m_filename ( "UNTITLED" ),
82  m_changed (" - Not Saved " ),
83  m_hasChanged ( false ),
84  m_inhibit_close ( false ),
85  m_allow_close ( false ),
86  m_filenameExists ( false )
87 {
88 
89 #if QT_VERSION < 0x040000
90  QCanvas * canvas = new QCanvas ();
91 #else
92  Q3Canvas * canvas = new Q3Canvas ();
93 #endif
94 
96  m_canvas_view = new CanvasView ( canvas, this );
97 
99 
100  resize ( sizeHint () ) ;
101 
102  setCaption ();
103  m_file_dialog = new QtFileDialog ();
104 
105  m_canvas_view -> initFitterSettings ( m_set_fitter ); // adds the actions.
106  m_canvas_view -> initRecentFiles ( m_recent_files ); // add the actions.
107  m_canvas_view -> initDockWindows ( this ); // set the dock windows.
108 
109 
110 #if QT_VERSION < 0x040000
111 #else
112  // fix bug in uic3, it didn't add these menu items.
113  QMenu * fitter_menu = PopupMenu -> addMenu ( "Fitter" );
114  QList < QAction * > actions = m_set_fitter -> actions ();
115  QList < QAction * >::iterator first = actions.begin();
116  while ( first != actions.end() ) {
117  QAction * action = *first++;
118  fitter_menu -> addAction ( action );
119  }
120 #endif
121 
123  controller->newWindow ( this );
124 }
125 
126 
130  : CanvasWindowBase ( ) // to keep a waring away
131 {
132  assert ( false );
133 }
134 
136 {
137 #if QT_VERSION < 0x040000
138  QCanvas * canvas = m_canvas_view->canvas();
139 #else
140  Q3Canvas * canvas = m_canvas_view->canvas();
141 #endif
142 
143  delete canvas;
144 }
145 
146 void
149 {
150  QFont font = QApplication::font ();
151  int size = font.pointSize ();
152  if ( size > 10 ) {
153  font.setPointSize ( 10 );
154  QApplication::setFont ( font, true );
155  }
156 }
157 
158 void
161 {
162  SaveAsImageEvent * image_event
163  = dynamic_cast < SaveAsImageEvent * > ( event );
164 
165  if ( image_event != 0 ) {
166  const PlotterBase * plotter = image_event -> plotter ();
167  const string & filename = image_event -> filename ();
168  m_canvas_view -> savePlotAsImage ( plotter, filename );
169  return;
170  }
171 
172  PlotterEvent * pe = dynamic_cast < PlotterEvent * > ( event );
173  if ( pe != 0 ) {
174  PlotterBase * plotter = pe -> plotter ();
175  if ( plotter == 0 ) {
176  setChanged ( true );
177  setCaption ();
178  }
179  else {
180  addDisplay ( plotter );
181  }
182  }
183 
184  PlotTableEvent * ptevent = dynamic_cast < PlotTableEvent * > ( event );
185  if ( ptevent != 0 ) {
186  int type = ptevent -> type();
187 
188  if ( type == PlotTableEvent::Copy ) {
189  m_canvas_view -> addFromPasteboard ();
190  return;
191  }
192 
193  if ( type == PlotTableEvent::Close ) {
194  if ( m_browsed_canvas != 0 ) {
195  delete m_browsed_canvas;
196  }
197  s_plot_table -> setBrowserMode ( false );
198  return;
199  }
200  }
201 }
202 
204 {
205  QWidget::windowActivationChange ( oldActive );
206 
207  if ( isActiveWindow () == true ) {
209  if ( wc -> currentCanvas ( ) != this ) {
210  wc -> setCurrentCanvas ( this );
211  updateActions ();
212  m_canvas_view -> notifyObservers ();
213  }
214  }
215 }
216 
217 void
219 setAllowClose ( bool yes )
220 {
221  m_allow_close = yes;
222 }
223 
228 {
229  if ( m_allow_close ||
230  m_hasChanged == false ) return true;
231 
232  bool _allowClose = true;
233  const string & app_name = m_canvas_view -> applicationName ();
234 
235  QString message ( "The document,\n" );
236  message += m_filename.c_str();
237  message += "\ncontains unsaved changes.\n\n"
238  "Do you want to save the document before closing it?";
239 
240  int retval
241  = QMessageBox::information ( this,
242  app_name.c_str(),
243  message,
244  "&Save", "&Discard", "Cancel");
245 
246  switch (retval)
247  {
248  case 0: // save
249  fileSave ();
250  _allowClose = true;
251  break;
252 
253  case 1:
254  _allowClose = true;
255  break;
256 
257  case 2:
258  _allowClose = false;
259  break;
260 
261  default:
262  _allowClose = false;
263  break;
264  }
265 
266  return _allowClose;
267 }
268 
269 bool
271 {
272  m_allow_close = true;
273 
274  return QWidget::close ( true );
275 }
276 
278 {
279  if ( m_allow_close ) {
280  e -> accept ();
281  WindowController::instance() -> aboutToClose ( this );
282  return;
283  }
284 
285  if ( allowClose () == false ) {
286  e->ignore ();
287  return;
288  }
289 
290  if ( m_inhibit_close == true ) {
291  const string & app_name = m_canvas_view -> applicationName ();
292 
293  QString message ( "Closing the only document window will also\n"
294  "terminate the application.\n\n"
295  "Do you want to quit?" );
296  int retval = QMessageBox::information ( this,
297  app_name.c_str(),
298  message,
299  QMessageBox::Yes,
300  QMessageBox::No |
301  QMessageBox::Default |
302  QMessageBox::Escape,
303  Qt::NoButton );
304 
305  switch (retval)
306  {
307  case QMessageBox::Yes: // save
308  break;
309 
310  case QMessageBox::No:
311  e->ignore();
312  return;
313  break;
314 
315  default:
316  e->ignore();
317  return;
318  break;
319  }
320  }
321 
322  e->accept ();
323  WindowController::instance() -> aboutToClose ( this );
324 }
325 
327 {
328  WindowController::instance () -> hasBeenHidden ();
329 }
330 
332 {
333  WindowController::instance () -> unHide ( this );
334 }
335 
336 void CanvasWindow::inhibitClose ( bool flag )
337 {
338  m_inhibit_close = flag;
339 }
340 
341 void CanvasWindow::setChanged ( bool flag )
342 {
344  controller -> updateActions ();
345  if ( m_hasChanged == flag ) return;
346 
347  if ( flag == true ) {
348  m_changed = " not saved";
349  }
350  else {
351  m_changed = " saved";
352  }
353  m_hasChanged = flag;
354  setCaption ();
355 }
356 
358 {
359  XmlController * controller = QtXMLController::instance ();
360  bool no = controller -> isPasteboardEmpty ();
361  m_editPasteAction -> setEnabled ( ! no );
362 
363  const std::vector < const ViewBase * > & views
365  bool yes = ! views.empty ();
366 
368  m_editCutAction->setEnabled ( yes );
369  m_editCopyAction->setEnabled ( yes );
370  m_editDeleteAction -> setEnabled ( yes );
371  m_editUndoAction->setEnabled ( yes );
372  m_viewLockAction->setEnabled ( yes );
374  m_group->setEnabled(yes);
375 
376  /* Default for ungroup is false. */
377  m_ungroup->setEnabled(false);
378  if ( yes == false ) return;
379 
380  /* By default, group is enabled, ungroup is disabled. Disable group if only one view
381  is selected. Enable group if the only one view is a group view. */
382  if (views.size() == 1) {
383  m_group->setEnabled(false);
384  const QtGroupView * gv = dynamic_cast <const QtGroupView *> (*views.begin());
385  if (gv) {
386  m_ungroup->setEnabled(true);
387  }
388  }
389 
390 
391  bool one_locked = false;
392  bool one_unlocked = false;
393  std::vector < const ViewBase * >:: const_iterator first = views.begin ();
394  while ( first != views.end () ) {
395  const QtView * view = dynamic_cast < const QtView * > ( *first++ );
396  /* Disable group if any of the selected view is a groupview. */
397  if (!view) {
398  m_group->setEnabled(false);
399  return;
400  }
401 
402  bool locked = view->isActive ();
403  one_locked |= locked;
404  one_unlocked |= ! locked;
405  }
406  m_viewLockAction->setEnabled ( one_unlocked );
407  m_viewUnlockAction->setEnabled ( one_locked );
408 }
409 
413 void
416 {
417  m_canvas_view->print ();
418 }
419 
421 {
423 
425  controller -> updateActions();
426 }
427 
428 void
431 {
432  QString message ( "The clear operation can not be undone.\n\n" );
433  message.append ( "Are you sure you want to remove all canvas items?" );
434  int retval
435  = QMessageBox::warning ( this,
436  "Warning",
437  message,
438  QMessageBox::Yes,
439  QMessageBox::No );
440  if ( retval != QMessageBox::Yes ) return;
441 
442  clear ();
443 
445  controller -> updateActions();
446 }
447 
449 {
450  m_canvas_view->deleteSelected ( true ); // copy to pasteboard and delete
451 
453  controller -> updateActions();
454 }
455 
457 {
458  m_canvas_view->deleteSelected ( false ); // just delete
459 
461  controller -> updateActions();
462 }
463 
464 void
467 {
468  m_canvas_view->reTile ();
469 }
470 
471 void
474 {
476 }
477 
478 void
481 {
483 
485 }
486 
488 {
491  controller -> updateActions();
492 }
493 
494 void
497 {
498  m_canvas_view->setAllSelected ( true );
499 
501  controller -> updateActions();
502 }
503 
504 void
507 {
509 
510  // Will fix the size and position of the new Canvas
511  controller->createInspector();
512 
513  CanvasWindow * window = new CanvasWindow ();
514  //controller->newWindow ( window );
515  window->setCaption ();
516  window->show ();
517 }
518 
519 void
522 {
523  const string & filter = QtFileDialog::createBrowseFilter ();
524 
525  QString filename
526 #if QT_VERSION < 0x040000
527  = QFileDialog::getOpenFileName ( QString::null, // starting dir
528 #else
529  = Q3FileDialog::getOpenFileName ( QString::null, // starting dir
530 #endif
531  filter.c_str(),
532  this,
533  "Browse", // name
534  "Choose document file to browse" ); // caption
535  if ( filename != QString::null ) {
536  QString s = filename.stripWhiteSpace ();
537  const string fn = s.latin1();
538 
539  string::size_type pos = fn.find_last_of ( '.' );
540  const string suffix = fn.substr ( pos );
541 
542  if ( QtFileDialog::isDocSuffix ( suffix ) ) {
543 #if QT_VERSION < 0x040000
544  QCanvas * canvas = new QCanvas ();
545 #else
546  Q3Canvas * canvas = new Q3Canvas ();
547 #endif
548  CanvasView * m_browsed_canvas = new CanvasView ( canvas, this );
549  m_browsed_canvas -> initFromFile ( fn );
550  if ( s_plot_table == 0 ) {
551  s_plot_table = new PlotTable ();
552  }
553  s_plot_table -> setBrowserMode ( true, this );
554  s_plot_table -> setCanvas ( m_browsed_canvas );
555  s_plot_table -> show ();
556  }
557  }
558 }
559 
560 void
563 {
564  const string & filter = QtFileDialog::createOpenFilter ();
565 
566  QString filename
567 #if QT_VERSION < 0x040000
568  = QFileDialog::getOpenFileName ( QString::null, // starting dir
569 #else
570  = Q3FileDialog::getOpenFileName ( QString::null, // starting dir
571 #endif
572  filter.c_str(),
573  this,
574  "Open", // name
575  "Choose file to open" ); // caption
576  if ( filename != QString::null ) {
577  QString s = filename.stripWhiteSpace ();
578  const string fn = s.latin1();
579 
580  string suffix;
581  string::size_type pos = fn.find_last_of ( '.' );
582  if ( pos != string::npos ) {
583  suffix = fn.substr ( pos );
584  }
585 
586  if ( QtFileDialog::isDocSuffix ( suffix ) ) {
587 
589 
590  // Will fix the size and position of the new Canvas.
591  controller->createInspector();
592 
593  CanvasWindow * window = new CanvasWindow ();
594  try {
595  window -> initFromFile ( fn );
596  }
597  catch ( exception & e ) {
598  QString message ("Attempt to read file\n" );
599  message +="`";
600  message += filename;
601  message += "' led to error:\n";
602  message += e.what();
603  QMessageBox::critical ( this, // parent
604  "File error",
605  message,
606  QMessageBox::Ok,
607  0 );
608  window -> setChanged ( false );
609  window -> close ();
610  }
611  return;
612  }
613 
614  else if ( QtFileDialog::isTextSuffix ( suffix ) ) {
615  m_file_dialog -> openTextTuple ( fn );
616  m_canvas_view -> notifyObservers ();
617  m_canvas_view -> addRecentFile (s, m_recent_files);
618  return;
619  }
620 #ifdef HAVE_ROOT
621  else if ( QtFileDialog::isRootSuffix ( suffix ) ) {
622  m_file_dialog -> openRootTuple ( fn, this );
623  m_canvas_view -> notifyObservers ();
624  m_canvas_view -> addRecentFile (s, m_recent_files);
625  return;
626  }
627 #endif
628 
629 #ifdef HAVE_CFITSIO
630  else if ( QtFileDialog::isFitsSuffix ( suffix ) ) {
631  m_file_dialog -> openFitsTuple ( fn, this );
632  m_canvas_view -> notifyObservers ();
633  m_canvas_view -> addRecentFile (s, m_recent_files);
634  return;
635  }
636  else {
637  bool yes = QtFileDialog::isFitsFile ( fn );
638  if ( yes ) {
639  m_file_dialog -> openFitsTuple ( fn, this );
640  m_canvas_view -> notifyObservers ();
641  m_canvas_view -> addRecentFile (s, m_recent_files);
642  return;
643  }
644  }
645 #endif
646  // if all else fails, try text file
647  m_file_dialog -> openTextTuple ( fn );
648 
649  m_canvas_view -> notifyObservers ();
650  m_canvas_view -> addRecentFile ( s, m_recent_files );
651  }
652 }
653 
657 void
659 initFromFile ( const std::string & filename )
660 {
661  m_canvas_view -> initFromFile ( filename );
662  setTitleFileName ( filename );
663  setChanged ( false );
664 
665  show();
666 }
667 
668 void
671 {
672  m_canvas_view->clear();
673 }
674 
676 {
677  m_canvas_view->resizeEvent ( e );
678 
679  QWidget::resizeEvent ( e );
680 }
681 
683 {
685 }
686 
688 {
689  const vector < const ViewBase * > & views = m_canvas_view->views ();
690  bool yes = m_xml_controller->areDataSourcesSaved ( views );
691 
692  if ( yes == false ) {
693  const string & app_name = m_canvas_view -> applicationName ();
694 
695  QString menutext = m_exportTextTuple->menuText();
696  QString message ("Document can not be saved.\n\n"
697  "It uses data sources that were neither\n"
698  "read from nor saved to a file.\n\n"
699  "Use File menu: \"" );
700  message += menutext;
701  message += "\"\n"
702  "to save the data sources first, or\n"
703  "use the File menu: \"";
704 
705  menutext = m_fileSaveAllAction->menuText();
706  message += menutext;
707  message += "\".";
708 
709  QMessageBox::critical ( this, // parent
710  app_name.c_str(), // caption
711  message,
712  QMessageBox::Ok,
713  Qt::NoButton );
714  }
715 
716  return yes;
717 }
718 
720 {
721  bool yes = areDataSourcesSaved ();
722  if ( ! yes ) return;
723 
724  if ( m_filenameExists )
725  {
726  if ( m_hasChanged )
727  {
728  QString message ( "Document file exists\n\n" );
729  message.append ( "Over-write existing file?" );
730  int retval
731  = QMessageBox::warning ( this,
732  "Warning",
733  message,
734  QMessageBox::Yes,
735  QMessageBox::No );
736  if ( retval != QMessageBox::Yes ) return;
737  saveAs ( m_filename );
738  }
739  }
740  else
741  {
742  fileSaveAs ();
743  }
744 }
745 
746 std::string
749 {
750  const string & filter = QtFileDialog:: createDocumentFilter ();
751 
752  QString filename;
753  while ( true ) {
754  filename
755 #if QT_VERSION < 0x040000
756  = QFileDialog::getSaveFileName ( QString::null, // starting dir
757 #else
758  = Q3FileDialog::getSaveFileName ( QString::null, // starting dir
759 #endif
760  filter.c_str(), // filter
761  this, // parent
762  "save doc",
763  "Save canvas to ..." ); // caption
764 
765  if ( filename == QString::null ) return string();
766 
767  const string & suffix = QtFileDialog:: getDocSuffix ();
768  if ( filename.endsWith ( suffix.c_str() ) == false ) {
769  filename += suffix.c_str();
770  }
771 
772  QFileInfo info ( filename );
773  filename = info.absFilePath();
774 
775  bool yes = info.exists ();
776  if ( yes == false ) break;
777 
778  string message ( "File exists. \n\n" );
779  message += "Over write existing file?";
780  int result = QMessageBox::warning ( this, // parent
781  "Warning", // caption
782  message.c_str (), //
783  QMessageBox::Yes,
784  QMessageBox::No );
785  if ( result == QMessageBox::Yes ) break;
786  }
787  string name = filename.latin1();
788 
789  return name;
790 }
791 bool
794 {
796 
797  m_filenameExists = m_filename.empty () ? false : true;
798 
799  return m_filenameExists;
800 }
801 
803 {
804  bool yes = areDataSourcesSaved ();
805  if ( ! yes ) return;
806 
807 bool ok = setFilenameFromDialog ();
808  if ( ! ok ) return;
809 
810  saveAs ( m_filename );
811 }
812 
813 
814 void
817 {
818  if ( m_filenameExists == false ) {
819  fileSaveAllAs ();
820  return;
821  }
822  saveAllAs ( m_filename );
823 }
824 
825 void
828 {
829  bool ok = setFilenameFromDialog ();
830  if ( ! ok ) return;
831  saveAllAs ( m_filename );
832 }
833 
836 void
838 saveAllAs ( const std::string & filename )
839 {
840  const string & suffix = QtFileDialog:: getDocSuffix ();
841  string::size_type pos = filename.find ( suffix );
842  string prefix = filename.substr ( 0, pos );
844 
845  const string & data_suffix = QtFileDialog::getTextSuffix ();
846  controller -> saveNTuples ( prefix, data_suffix );
847  saveAs ( filename );
848 }
849 
851 {
853 }
854 
855 void CanvasWindow::fileSaveSelectedImages ( const std::string & filename )
856 {
858 }
859 
860 void
862 saveAs ( const std::string & filename )
863 {
864  m_canvas_view -> saveAs ( filename );
865 
866  setTitleFileName ( filename );
867  setChanged ( false );
868  setCaption ();
869 }
870 
871 CanvasView *
874 {
875  return m_canvas_view;
876 }
877 
878 void
881 {
882 
883  Inspector * inspector = m_canvas_view -> getInspector ();
884  const string tuple_name = inspector -> getSelectedDataSourceName ();
885 
886  string fn = QtFileDialog:: getExportTupleFilename ( this );
887  if (fn.empty()==true) return;
888 
889 
890  string::size_type pos = fn.find_last_of ( '.' );
891  const string suffix = fn.substr ( pos );
892 
893  if ( QtFileDialog:: isTextSuffix ( suffix ) ) {
894  m_file_dialog -> saveTextTuple ( fn, this );
895  m_canvas_view -> notifyObservers ();
896  return;
897  }
898 
899  else if ( QtFileDialog::isFitsSuffix ( suffix ) ||
901 #ifdef HAVE_CFITSIO
902  m_file_dialog -> saveFitsTuple ( fn, this );
903  m_canvas_view -> notifyObservers ();
904 #else
905  m_canvas_view -> showFitsError ();
906 #endif
907  return;
908  }
909 
910  else {
911  bool yes = QtFileDialog:: isFitsFile ( fn );
912  if ( yes ) {
913 #ifdef HAVE_CFITSIO
914  m_file_dialog -> saveFitsTuple ( fn, this );
915  m_canvas_view -> notifyObservers ();
916 #else
917  m_canvas_view -> showFitsError ();
918 #endif
919  return;
920  }
921  }
922 
923  // if all else fails, show error message.
924 
925  QString message = QString("The file type: %1\n").arg ( suffix.c_str() );
926  message.append("is not supported.\n\n");
927  message.append("Please use Text ntuple (.tnt)\n");
928  message.append("or FITS file (.fits).");
929 
930  QMessageBox::critical ( this, // parent
931  QString ("Unsupported file type"), // caption
932  message,
933  QMessageBox::Ok,
934  Qt::NoButton );
935 }
936 
937 void
940 {
941  m_canvas_view -> createNTuple();
942 }
943 
944 void
947 {
948  bool ok = WindowController::instance () -> okToQuit();
949 
950  if ( ok ) {
951  // save dock window and recent files
952  autosaveSettings();
953  qApp->quit ();
954  }
955 }
956 
958 {
960 }
961 
963 {
965 }
966 
967 void
970 {
972 }
973 
974 void
977 {
978  m_canvas_view->setLocked ( true );
979  updateActions ();
980 }
981 
982 void
985 {
986  m_canvas_view->setLocked ( false );
987  updateActions ();
988 }
989 
994 {
995  m_canvas_view -> helpAbout ();
996 }
997 
998 void
1001 {
1002 #ifndef HAVE_HELP
1003  const string & app_name = m_canvas_view -> applicationName ();
1004  QString message ( "The application was built without\n"
1005  "built-in help support" );
1006  QMessageBox::information ( this,
1007  app_name.c_str(),
1008  message,
1009  QMessageBox::Ok );
1010  return;
1011 #endif
1012 
1013  WindowController * controller = WindowController::instance ();
1014  controller -> openAssistant ();
1015 }
1016 
1017 void
1020 {
1021  QMessageBox::aboutQt ( this );
1022 }
1023 
1025 {
1026  QString fn = m_filename.c_str();
1028 }
1029 
1030 void
1032 setTitleFileName ( const std::string & name )
1033 {
1034  m_filename = name;
1035  m_filenameExists = true;
1036 }
1037 
1038 void
1041  const std::string & s )
1042 {
1043  m_canvas_view->addTextDisplay ( plotter, s );
1044 }
1045 
1046 void
1049  const std::string & type,
1050  const std::string & text)
1051 {
1052  m_canvas_view->addTextDisplay ( plotter, type, text );
1053 }
1054 
1055 std::pair<double, double>
1058  const std::string & type,
1059  const std::string & text,
1060  double xrel, double yrel )
1061 {
1062  return m_canvas_view->addTextDisplayAt( plotter, type, text, xrel, yrel );
1063 }
1064 
1065 void
1067 addFuncDisplay ( PlotterBase * plotter, const std::string & s )
1068 {
1069  m_canvas_view->addFuncDisplay ( plotter, s );
1070 }
1071 
1072 void CanvasWindow::addPlotDisplay ( PlotterBase * plotter, bool sel )
1073 {
1074  m_canvas_view->addPlotDisplay ( plotter, sel );
1075 }
1076 
1078 {
1079  m_canvas_view->addPlotDisplay ( plotter );
1080 }
1081 
1084 void
1087 {
1088  m_canvas_view->removeDisplay ( plotter );
1089 }
1090 
1094 {
1095  return m_canvas_view->selectedPlotter ();
1096 }
1097 
1098 const vector < const ViewBase * > & CanvasWindow::views ()
1099 {
1100  return m_canvas_view->views ();
1101 }
1102 
1103 void
1105 fillPlotterList ( std::vector < PlotterBase * > & plotters )
1106 {
1107  m_canvas_view -> fillPlotterList ( plotters );
1108 }
1109 
1110 QtView *
1112 getViewFor ( const PlotterBase * plotter ) const
1113 {
1114  return m_canvas_view->getViewFor ( plotter );
1115 }
1116 
1118 {
1120 }
1121 
1122 void
1125 {
1126  m_canvas_view -> showInspector ();
1127 }
1128 
1129 void
1132 {
1133  if ( s_plot_table == 0 ) {
1134  s_plot_table = new PlotTable ();
1135  }
1137  s_plot_table->show();
1138 }
1139 
1140 void
1143 {
1145 
1146  m_pick -> toggle (); // need to get in this mode
1147 }
1148 
1149 void
1151 savePlotAsImage ( const PlotterBase * plotter,
1152  const std::string & filename )
1153 {
1154  SaveAsImageEvent * event = new SaveAsImageEvent ( plotter, filename );
1155  QApplication::postEvent ( this, event );
1156 }
1157 
1158 void
1160 saveAsImage ( const PlotterBase * plotter,
1161  const std::string & filename )
1162 {
1163  qApp -> lock ();
1164  m_canvas_view -> savePlotAsImage ( plotter, filename );
1165  qApp -> unlock ();
1166 }
1167 
1168 void
1170 setAllSelected ( bool flag )
1171 {
1172  m_canvas_view->setAllSelected( flag );
1173 }
1174 
1175 void
1178 {
1179  m_canvas_view->setSelectedItem( view );
1180 }
1181 
1182 void
1185 {
1186  PlotterBase * currentPlotter = selectedPlotter();
1187  if (currentPlotter) {
1188  if ( ! ( currentPlotter->getCurrentRangeSaved () ) ) {
1189  m_canvas_view -> setCurrentRange();
1190  }
1191 
1192  selectedPlotter() -> nextView (false );
1193  m_canvas_view -> canvas () -> update();
1194  }
1195 }
1196 
1197 void
1200 {
1201  PlotterBase * currentPlotter = selectedPlotter();
1202  if (currentPlotter) {
1203  if ( !(currentPlotter->getCurrentRangeSaved()) ) {
1205  }
1206 
1207  selectedPlotter() -> nextView ( true );
1208  m_canvas_view->canvas()->update();
1209  }
1210 }
1211 
1212 
1213 void
1215 setZoomMode ( bool on )
1216 {
1217  m_canvas_view -> setZoomMode ( on );
1218 }
1219 
1220 const std::vector<double> &
1223 {
1224  return m_canvas_view->mouseEventData();
1225 }
1226 
1227 void
1230 {
1231  m_canvas_view -> setPrinterSettings ();
1232 }
1233 
1234 void
1237 {
1238  m_canvas_view -> setup ();
1239 }
1240 
1241 void
1244 {
1245  bool ok;
1246 
1247  // From the Qt documentation - "The usual way to use QFontDialog class is
1248  // to call one of the static convenience functions"
1249  QFont font
1250  = QFontDialog::getFont ( &ok, QFont( "Helvetica [Cronyx]", 10), this);
1251 
1252  m_canvas_view -> setFonts( font );
1253 }
1254 
1255 void
1257 print ( const std::string & filename )
1258 {
1259  m_canvas_view -> print ( filename );
1260 }
1261 
1262 void
1264 setPlotMatrix ( unsigned int columns, unsigned int rows )
1265 {
1266  m_canvas_view -> setPlotMatrix ( columns, rows );
1267  m_canvas_view -> reTile ();
1268 }
1269 
1270 const QString &
1272 getAppKey ( ) const
1273 {
1274  return m_canvas_view -> getAppKey ();
1275 }
1276 
1277 void
1279 setFitter ( QAction * action )
1280 {
1281  QString name = action -> menuText ();
1282  m_canvas_view -> setFitterDefault ( name );
1283 }
1284 
1285 void
1287 setAddedSelected ( bool yes )
1288 {
1289  m_canvas_view -> setAddedSelected ( yes );
1290 }
1291 
1292 void
1294 setCutMode ( QAction * action )
1295 {
1296  if ( action == m_cut1 )
1297  m_canvas_view -> setCutMode (1);
1298  else if ( action == m_cut2 )
1299  m_canvas_view -> setCutMode (2);
1300  else if ( action == m_cut3 )
1301  m_canvas_view -> setCutMode (3);
1302  else
1303  m_canvas_view -> setCutMode (0); // pick mode
1304 }
1305 
1306 NTuple *
1309 {
1310  return m_canvas_view -> getPickTable();
1311 }
1312 
1313 NTuple *
1315 getPickTable ( const PlotterBase * plotter ) const
1316 {
1317  return m_canvas_view -> getPickTable ( plotter );
1318 }
1319 
1320 void
1323 {
1324  m_canvas_view -> groupView ();
1325  updateActions();
1326 }
1327 
1328 void
1331 {
1332  m_canvas_view -> ungroupView ();
1333  updateActions();
1334 }
1335 
1336 void
1339 {
1340  QString filename = action -> menuText ();
1341 
1342  const string fn = filename.latin1();
1343  string::size_type pos = fn.find_last_of ( '.' );
1344  const string suffix = fn.substr ( pos );
1345 
1346 
1347  if ( QtFileDialog::isTextSuffix ( suffix ) ) {
1349  action -> setToggleAction ( false );
1350  action -> setToggleAction ( true );
1351  m_canvas_view -> notifyObservers ();
1352  return;
1353  }
1354 
1355  if ( QtFileDialog::isFitsSuffix ( suffix ) ) {
1356  m_file_dialog ->openFitsTuple ( fn, this );
1357  action -> setToggleAction ( false );
1358  action -> setToggleAction ( true );
1359  m_canvas_view -> notifyObservers ();
1360  return;
1361  }
1362 
1363  if ( QtFileDialog::isRootSuffix ( suffix ) ) {
1364  m_file_dialog ->openRootTuple ( fn, this );
1365  action -> setToggleAction ( false );
1366  action -> setToggleAction ( true );
1367  m_canvas_view -> notifyObservers ();
1368  return;
1369  }
1370 
1371  m_file_dialog -> openTextTuple ( fn );
1372 
1373  // Should use normal menu item.
1374  action -> setToggleAction ( false );
1375  action -> setToggleAction ( true );
1376  m_canvas_view -> notifyObservers ();
1377 }
1378 
1379 void
1381 {
1382  m_canvas_view -> autosaveSettings ( this );
1383 }

Generated for HippoDraw Class Library by doxygen