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
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
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 }
CanvasView * m_canvas_view
The CanvasView object which is the central widget.
Definition: CanvasWindow.h:122
void notifyObservers()
Notifies observers of a change in CanvasView.
Definition: CanvasView.cxx:631
hippodraw::QtFileDialog class interface
void openRootTuple(const std::string &filename, QWidget *parent)
Opens a ROOT DataSource file.
virtual void viewZoomOut()
Reduces the view of the canvas.
const std::vector< const ViewBase * > & selectedViews() const
Returns temporary list of selected QtView objects on the canvas.
virtual void settingPrinter()
Sets the printer settings.
QAction * m_editDeleteAction
QString m_changed
The changed status part of the window title.
Definition: CanvasWindow.h:139
bool areDataSourcesSaved()
Returns true if all the data sources used by the document have been saved to or read from a file...
void removeDisplay(PlotterBase *plotter)
Removes the plotter and its view from the canvas.
virtual void setFitter(QAction *)
Responds to change in fitter settings.
virtual void fileBrowse()
Browse a document file, without opening a window for it.
hippodraw::CanvasWindow class interface.
setPointSize(int pointSize)
void setIntervalEnabled(bool yes=true)
Sets the display interval feature to enabled if yes is true, otherwise sets it to disabled...
virtual void settingFonts()
Sets the font settings.
static bool isFitsFile(const std::string &filename)
Returns true if the file filename is a FITS file.
bool areDataSourcesSaved(const std::vector< const ViewBase * > &views)
Returns true if all the NTuple objects used by the views have been saved to or read from a file...
void deleteSelected(bool paste)
Removes the selected items from canvas and copies them to the pasteboard.
Definition: CanvasView.cxx:530
virtual void editReTilePage()
Re tiles only the current page.
QActionGroup * m_recent_files
void addPlotDisplay(PlotterBase *plotter, bool select)
Creates a QtView object for the display and inserts it onto the canvas in the next available free pla...
Definition: CanvasView.cxx:837
void setAllSelected(bool flag=true)
Sets selection flag on all QCanvasItem objects.
virtual void editReTile()
Re tiles the entire document.
virtual void groupView()
Group the views.
void previousView()
Switches View to the previous view for the selected item on the canvas.
A singleton class for keeping track the window components of HippoDraw.
static bool isFitsSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to FITS DataSource file.
virtual void fileOpen()
Opens an existing file.
hippodraw::PlotTable class interface
virtual void viewZoomIn()
Enlarges the view of the canvas.
void setAddedSelected(bool yes)
Sets to flag to make plots in their selected state when added to the canvas.
void fillPlotterList(std::vector< PlotterBase * > &plotter_list)
Clears and fills plotter_list with all the PlotterBase objects on the canvas.
A derived class of QCustomEvent PlotTable events.
virtual void editClear()
Responds to &quot;Clear&quot; menu item.
setFont(const QFont &font, bool informWidgets=FALSE, const char *className=0)
This class implements additional FigureEditor functionality particular to QtView objects.
Definition: CanvasView.h:96
virtual void fileSaveAllAs()
Saves the canvas document and its NTuple.
PlotterBase * selectedPlotter() const
Returns the selected PlotterBase object.
Definition: CanvasView.cxx:675
virtual void viewAddPage()
Adds a page to the canvas.
virtual void fileExportTextTuple()
arg(long a, int fieldWidth=0, int base=10) const
void setCanvas(CanvasView *canvas)
Sets the canvas to be used by the table.
Definition: PlotTable.cxx:49
hippodraw::WindowController class interface
void resizeEvent(QResizeEvent *e)
Re-sizes the QCanvas in response to parent window receiving QResizeEvent.
virtual void editCut()
Removes selected items from canvas and add them to the pasteboard.
virtual void fileExit()
Responds to the Quit item in the File menu.
virtual void print()
Prints the canvas.
QAction * m_editCutAction
void fileSave()
Saves the document.
std::pair< double, double > addTextDisplayAt(PlotterBase *plotter, const std::string &type, const std::string &text, double xrel, double yrel)
Adds a text display at the relative position (xrel, yrel) in the selected item&#39;s coordinates.
PlotterBase * selectedPlotter()
Returns the selected plotter.
void saveAllAs(const std::string &filename)
Saves the document along with its NTuple objects.
bool setFilenameFromDialog()
Sets the file name of document.
void saveAs(const std::string &filename)
Saves the document to the specified file.
void setLocked(bool flag)
Sets the selected QCanvasItem to be locked in size and position.
virtual void openRecentFile(QAction *)
Responds to open recent file.
virtual void aboutQt()
Brings up Qt&#39;s about message box.
QAction * m_editCopyAction
bool allowClose()
If document has changed and not saved, opens a dialog box for user to choose to save, discard or cancel.
void setSelectedItem(QCanvasItem *)
Set the selected QCanvasItem.
information(QWidget *parent, const QString &caption, const QString &text, int button0, int button1=0, int button2=0)
void newWindow(CanvasWindow *)
Registers the new CanvasWindow and finishes its initialization.
virtual bool closeNoPrompt()
Closes the window.
static void resetFontSize()
Resets the font size to be no larger than 10.
void restoreFromSelectCopy()
Restores the selected views from the selection copy.
virtual void editPaste()
A derived class of QCustomEvent to handle saving a PlotterBase object as image file events...
QAction * m_fileSaveSelected
NTuple * getPickTable() const
Gets the pick table the selected plotter.
hippodraw::CanvasView class interface
The base class for the CanvasWindow class.
else
Definition: CanvasView.cxx:879
void savePlotAsImage(const PlotterBase *plotter, const std::string &filename)
Saves the plotter as image file.
void createInspector()
Creates the Inspector object and positions it on the desktop.
void addPage()
Adds a page to the canvas.
QString fn
virtual void settingCanvas()
Sets the canvas settings.
void addTextDisplay(PlotterBase *plotter, const std::string &type)
Adds a textual display to the canvas of type type.
postEvent(QObject *receiver, QEvent *event)
latin1() const
virtual void windowActivationChange(bool oldActive)
Informs the application object if this window has become the active one.
append(char ch)
virtual void hideEvent(QHideEvent *e)
Informs the application object that the window has been hidden.
void reTilePage()
Re-tiles the current page.
Definition: CanvasView.cxx:969
virtual void showEvent(QShowEvent *e)
Informs the application object that the window has been shown.
void setIntervalEnabled(bool yes=true)
Sets the display interval feature of all views to enabled if yes is true, otherwise sets the feature ...
font(const QWidget *w=0)
QAction * m_viewLockAction
virtual void editUndo()
Responds to the undo action.
return yes
Definition: CanvasView.cxx:883
absFilePath() const
menuText() const
QActionGroup * m_set_fitter
SaveAsImageEvent class interface.
void addFuncDisplay(PlotterBase *plotter, const std::string &name)
Adds function textual display to the canvas.
The base class for the PlotterBase hierarchy.
Definition: PlotterBase.h:55
hippodraw::Inspector class interface.
static bool isTextSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to text NTuple file.
CanvasView * m_browsed_canvas
The CanvasView object that is being browsed.
Definition: CanvasWindow.h:126
const std::vector< const ViewBase * > & views() const
Returns temporary list of all QtView objects on the canvas.
QAction * m_editPasteAction
std::pair< double, double > addTextDisplayAt(PlotterBase *plotter, const std::string &type, const std::string &text, double xrel, double yrel)
Adds a text display at the relative position (xrel, yrel) in the selected item&#39;s coordinates.
bool ok
Definition: CanvasView.cxx:163
bool m_filenameExists
True if filename has been assigned, false if not.
Definition: CanvasWindow.h:160
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
QAction * m_editUndoAction
void reTile()
Re-tiles the canvas.
Definition: CanvasView.cxx:888
static const std::string & getDocSuffix()
Returns the suffix for a document.
virtual void editDelete()
Removes selected items from canvas without copying them to the pasteboard.
static WindowController * instance()
Returns the application instance.
virtual void viewZoomReset()
Returns the view of the canvas to normal.
endsWith(const QString &s, bool cs=TRUE) const
static const std::string & getTextSuffix()
Returns the suffix for a text data source files.
A class to handle various file types.
Definition: QtFileDialog.h:49
QAction * m_fileSaveAllAction
A derived class of PlotTableBase class which is generated by the Qt designer.
Definition: PlotTable.h:49
virtual void viewShowInspector()
Shows the Inspector window.
setCentralWidget(QWidget *w)
virtual void fileNew()
Creates a new document CanvasWindow.
void autosaveSettings()
Automatically save dock windows and recently opened files.
A singleton class that is the interface between GUI and the NTuple objects.
PlotTableEvent class interface.
void setAllSelected(bool flag=true)
Select or deselect all views in the window.
QtView * getViewFor(const PlotterBase *plotter) const
Returns the QtView object that is the Observer of the plotter.
virtual void viewLock()
Locks a canvas item.
intp size(numeric::array arr)
Definition: num_util.cpp:296
canvas() const
bool m_inhibit_close
A flag set to true if the CanvasWindow should not accept a close event.
Definition: CanvasWindow.h:152
void setPlotMatrix(unsigned int columns, unsigned int rows)
Sets the number of columns and rows of plots on each page.
void addTextDisplay(PlotterBase *plotter, const std::string &s, const std::string &text=std::string())
Add a display of text Adds a display of text to that will be associated with plotter.
const std::vector< const ViewBase * > & views()
Returns the list of ViewBase objects on the canvas.
void copySelectedToPasteboard()
Copies selected items to pasteboard.
Definition: CanvasView.cxx:486
std::string getSaveDocFilename()
Returns the chosen file name from a save canvas dialog.
void viewZoomOut()
Reduces the view of the canvas.
A derived class of QCustomEvent to handle updates from PlotterBase.
Definition: PlotterEvent.h:39
void addDisplay(PlotterBase *plotter)
Adds a new plot to the canvas and selects it.
void setCaption()
Sets the Windows title.
virtual void filePrint()
Prints the canvas to a Postscript file.
virtual void editSelectAll()
Sets all QCanvasItem objects to selected.
void setSelected(QtView *view)
Select a specific view in the window.
setEnabled(bool)
void openFitsTuple(const std::string &filename, QWidget *parent)
Opens a FITS DataSource file.
exists() const
CanvasWindow(QWidget *parent=0, const char *name=0, Qt::WFlags fl=Qt::WType_TopLevel)
constructor.
virtual void customEvent(QCustomEvent *event)
Responds to QCustomEvents.
void clear()
Removes all items from the canvas.
static const std::string & createBrowseFilter()
Creates the open file filter.
The class of derived from ViewBase and QCanvasRectangle for drawing on a QCanvas. ...
Definition: QtView.h:41
QPopupMenu * PopupMenu
bool m_hasChanged
The current changed status.
Definition: CanvasWindow.h:148
static NTupleController * instance()
Returns the pointer to the singleton instance.
virtual void fileCreateNTuple()
Create a new NTuple from selected cut and column.
QString m_prefix
The prefix part of the window title.
Definition: CanvasWindow.h:133
void print(const std::string &filename)
Prints the view to Postscript file without prompting user.
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
hippodraw::PlotterEvent class interface
static bool isDocSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to document file.
void viewZoomIn()
Enlarges the view of the canvas.
void nextView()
Switches View to the next view for the selected item on the canvas.
void addFuncDisplay(PlotterBase *plotter, const std::string &s)
Add a text display which displays functions parameters.
void saveSelectedImages()
Saves the selected QCanvasItem objects to a image file.
hippodraw::QtGroupView class interface
void setAllowClose(bool yes=true)
Sets the window to allowed to be closed by user without prompting.
virtual void viewShowPickTable()
Shows the pick table window.
void saveAsImage(const PlotterBase *plotter, const std::string &filename)
Saves the plotter as image file.
void addPlotDisplay(PlotterBase *plotter, bool select)
Adds a new plot display to the canvas.
virtual bool getCurrentRangeSaved()
Returns current_range_saved member t.
virtual void helpAbout()
Brings up standard window showing version, authors, etc.
static const std::string & createDocumentFilter()
Creates a filter for saving a document.
windowActivationChange(bool oldActive)
getSaveFileName(const QString &startWith=QString::null, const QString &filter=QString::null, QWidget *parent=0, const char *name=0, const QString &caption=QString::null, QString *selectedFilter=0, bool resolveSymlinks=TRUE)
virtual void fileSaveSelectedImages()
Saves the selected ViewBase object as an image file.
critical(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
static std::string getExportTupleFilename(QWidget *widget)
Returns a filename for exporting a DataSource.
std::string m_filename
The file name part of the window title.
Definition: CanvasWindow.h:136
The class of derived from GroupViewBase, QtViewImp and QCanvasRectangle for drawing a grouped view on...
Definition: QtGroupView.h:45
const std::vector< double > & mouseEventData()
Retrieve a vector (x, y, z) points from the next mouse event.
warning(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
virtual void closeEvent(QCloseEvent *e)
Informs the application object that is window is about to close.
static bool isZippedFitsSuffix(const std::string &suffix)
Returns true if the file filename is a compressed FITS file.
XmlController * m_xml_controller
The controller object capable of serializing the canvas contents as XML and serializing them...
Definition: CanvasWindow.h:119
hippodraw::NTupleController class interface
QAction * m_exportTextTuple
getOpenFileName(const QString &startWith=QString::null, const QString &filter=QString::null, QWidget *parent=0, const char *name=0, const QString &caption=QString::null, QString *selectedFilter=0, bool resolveSymlinks=TRUE)
static const std::string & createOpenFilter()
Creates the open file filter.
void clear()
Removes all the QCanvasItem objects from the canvas.
Definition: CanvasView.cxx:570
void setCurrentRange()
Saves the current range of the selected plotter.
resizeEvent(QResizeEvent *)
void copyFromPasteboard()
Copies from the pasteboard.
Definition: CanvasView.cxx:500
CanvasView * getCanvasView()
Returns the CanvasView object.
DataSourceController class interface.
const std::vector< double > & mouseEventData()
Retrieve a vector of (x, y, z) points from the next mouse event.
bool m_allow_close
A flag set to true to allow the window to close without prompting the user.
Definition: CanvasWindow.h:157
void viewShowPickTable()
Show the pick table.
virtual void viewUnlock()
Unlocks a canvas item.
aboutQt(QWidget *parent, const QString &caption=QString::null)
void initFromFile(const std::string &filename)
Initializes this object from contents of file.
QtView * getViewFor(const PlotterBase *plotter) const
Returns the QtView object that is the Observer of the plotter.
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
virtual void viewShowPlotTable()
Shows the plot table.
QAction * m_viewUnlockAction
virtual void helpHelp()
Brings up a QAssistant client.
setCaption(const QString &)
virtual void ungroupView()
Ungroup the views.
QtFileDialog * m_file_dialog
The open file dialog for this window.
Definition: CanvasWindow.h:130
virtual void setZoomMode(bool on)
Sets the zoom mode to true or false.
static bool isRootSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to ROOT DataSource files.
A concrete window class that contains the canvas and responds to menu item and tool bar events from t...
Definition: CanvasWindow.h:106
void setTitleFileName(const std::string &name)
Sets the file name component of the window&#39;s title.
virtual void setCutMode(QAction *)
Sets the cut mode.
void inhibitClose(bool yes=true)
If yes is true, sets a flag so that this object will not accept close events.
const QString & getAppKey() const
Returns a reference the application&#39;s QSettings key.
virtual void resizeEvent(QResizeEvent *)
Informs the Canvas to re-size as well.
static PlotTable * s_plot_table
The singleton instance of PlotTable.
Definition: CanvasWindow.h:143
A derived class of InspectorBase class which is generated by the Qt designer.
Definition: Inspector.h:234
pointSize() const
static QtXMLController * instance()
Returns the pointer to the singleton instance.
void updateActions()
Update Action objects.
stripWhiteSpace() const
void removeDisplay(PlotterBase *plotter)
Removes the display from the canvas.
hippodraw::PlotterBase class interface.
void setChanged(bool flag=true)
Sets the changed flag.
virtual void fileSaveAll()
Saves the canvas document and any NTuple that were not read from or written to a file.
getFont(bool *ok, const QFont &initial, QWidget *parent=0, const char *name=0)
virtual void fileSaveAs()
Saves the document after display a file dialog to the user.
static void openTextTuple(const std::string &filename)
Opens a text NTuple file.

Generated for HippoDraw Class Library by doxygen