36 #include <qapplication.h>
37 #if QT_VERSION < 0x040000
41 #include <QtGui/QCloseEvent>
42 #include <QtCore/QCustomEvent>
43 #include <QtGui/QHideEvent>
44 #include <QtGui/QResizeEvent>
45 #include <QtGui/QShowEvent>
49 #include <qmessagebox.h>
50 #include <qfontdialog.h>
61 using namespace hippodraw;
70 #if QT_VERSION < 0x040000
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 )
89 #if QT_VERSION < 0x040000
92 Q3Canvas * canvas =
new Q3Canvas ();
100 resize ( sizeHint () ) ;
110 #if QT_VERSION < 0x040000
113 QMenu * fitter_menu =
PopupMenu -> addMenu (
"Fitter" );
116 while ( first != actions.end() ) {
118 fitter_menu -> addAction ( action );
137 #if QT_VERSION < 0x040000
165 if ( image_event != 0 ) {
166 const PlotterBase * plotter = image_event -> plotter ();
167 const string & filename = image_event -> filename ();
175 if ( plotter == 0 ) {
185 if ( ptevent != 0 ) {
207 if ( isActiveWindow () ==
true ) {
209 if ( wc -> currentCanvas ( ) !=
this ) {
210 wc -> setCurrentCanvas (
this );
232 bool _allowClose =
true;
233 const string & app_name =
m_canvas_view -> applicationName ();
235 QString message (
"The document,\n" );
237 message +=
"\ncontains unsaved changes.\n\n"
238 "Do you want to save the document before closing it?";
244 "&Save",
"&Discard",
"Cancel");
291 const string & app_name =
m_canvas_view -> applicationName ();
293 QString message (
"Closing the only document window will also\n"
294 "terminate the application.\n\n"
295 "Do you want to quit?" );
301 QMessageBox::Default |
307 case QMessageBox::Yes:
310 case QMessageBox::No:
347 if ( flag ==
true ) {
360 bool no = controller -> isPasteboardEmpty ();
363 const std::vector < const ViewBase * > &
views
365 bool yes = ! views.empty ();
378 if ( yes ==
false )
return;
382 if (views.size() == 1) {
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++ );
402 bool locked = view->isActive ();
403 one_locked |= locked;
404 one_unlocked |= ! locked;
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?" );
440 if ( retval != QMessageBox::Yes )
return;
526 #if QT_VERSION < 0x040000
529 = Q3FileDialog::getOpenFileName ( QString::null,
534 "Choose document file to browse" );
535 if ( filename != QString::null ) {
537 const string fn = s.
latin1();
539 string::size_type pos = fn.find_last_of (
'.' );
540 const string suffix = fn.substr ( pos );
543 #if QT_VERSION < 0x040000
546 Q3Canvas * canvas =
new Q3Canvas ();
567 #if QT_VERSION < 0x040000
570 = Q3FileDialog::getOpenFileName ( QString::null,
575 "Choose file to open" );
576 if ( filename != QString::null ) {
578 const string fn = s.
latin1();
581 string::size_type pos = fn.find_last_of (
'.' );
582 if ( pos != string::npos ) {
583 suffix = fn.substr ( pos );
597 catch ( exception & e ) {
598 QString message (
"Attempt to read file\n" );
601 message +=
"' led to error:\n";
692 if ( yes ==
false ) {
693 const string & app_name =
m_canvas_view -> applicationName ();
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: \"" );
702 "to save the data sources first, or\n"
703 "use the File menu: \"";
728 QString message (
"Document file exists\n\n" );
729 message.
append (
"Over-write existing file?" );
736 if ( retval != QMessageBox::Yes )
return;
755 #if QT_VERSION < 0x040000
758 = Q3FileDialog::getSaveFileName ( QString::null,
763 "Save canvas to ..." );
765 if ( filename == QString::null )
return string();
768 if ( filename.
endsWith ( suffix.c_str() ) ==
false ) {
769 filename += suffix.c_str();
775 bool yes = info.
exists ();
776 if ( yes ==
false )
break;
778 string message (
"File exists. \n\n" );
779 message +=
"Over write existing file?";
785 if ( result == QMessageBox::Yes )
break;
787 string name = filename.
latin1();
841 string::size_type pos = filename.find ( suffix );
842 string prefix = filename.substr ( 0, pos );
846 controller -> saveNTuples ( prefix, data_suffix );
884 const string tuple_name = inspector -> getSelectedDataSourceName ();
887 if (fn.empty()==
true)
return;
890 string::size_type pos = fn.find_last_of (
'.' );
891 const string suffix = fn.substr ( pos );
926 message.
append(
"is not supported.\n\n");
927 message.
append(
"Please use Text ntuple (.tnt)\n");
928 message.
append(
"or FITS file (.fits).");
931 QString (
"Unsupported file type"),
1003 const string & app_name =
m_canvas_view -> applicationName ();
1004 QString message (
"The application was built without\n"
1005 "built-in help support" );
1014 controller -> openAssistant ();
1041 const std::string & s )
1049 const std::string &
type,
1050 const std::string & text)
1055 std::pair<double, double>
1058 const std::string &
type,
1059 const std::string & text,
1060 double xrel,
double yrel )
1152 const std::string & filename )
1161 const std::string & filename )
1187 if (currentPlotter) {
1202 if (currentPlotter) {
1220 const std::vector<double> &
1281 QString name = action -> menuText ();
1298 else if ( action ==
m_cut2 )
1300 else if ( action ==
m_cut3 )
1340 QString filename = action -> menuText ();
1342 const string fn = filename.
latin1();
1343 string::size_type pos = fn.find_last_of (
'.' );
1344 const string suffix = fn.substr ( pos );
1349 action -> setToggleAction (
false );
1350 action -> setToggleAction (
true );
1357 action -> setToggleAction (
false );
1358 action -> setToggleAction (
true );
1365 action -> setToggleAction (
false );
1366 action -> setToggleAction (
true );
1374 action -> setToggleAction (
false );
1375 action -> setToggleAction (
true );
static const std::string & createOpenFilter()
Creates the open file filter.
void deleteSelected(bool paste)
Removes the selected items from canvas and copies them to the pasteboard.
void removeDisplay(PlotterBase *plotter)
Removes the display from the canvas.
virtual void viewZoomReset()
Returns the view of the canvas to normal.
void setLocked(bool flag)
Sets the selected QCanvasItem to be locked in size and position.
CanvasView * m_canvas_view
The CanvasView object which is the central widget.
virtual void viewShowInspector()
Shows the Inspector window.
setPointSize(int pointSize)
void clear()
Removes all items from the canvas.
static bool isTextSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to text NTuple file.
void notifyObservers()
Notifies observers of a change in CanvasView.
virtual void showEvent(QShowEvent *e)
Informs the application object that the window has been shown.
const std::vector< const ViewBase * > & selectedViews() const
Returns temporary list of selected QtView objects on the canvas.
void removeDisplay(PlotterBase *plotter)
Removes the plotter and its view from the canvas.
virtual void viewShowPickTable()
Shows the pick table window.
void setSelectedItem(QCanvasItem *)
Set the selected QCanvasItem.
hippodraw::QtGroupView class interface
hippodraw::NTupleController class interface
virtual void windowActivationChange(bool oldActive)
Informs the application object if this window has become the active one.
static bool isFitsSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to FITS DataSource file.
void restoreFromSelectCopy()
Restores the selected views from the selection copy.
void setPlotMatrix(unsigned int columns, unsigned int rows)
Sets the number of columns and rows of plots on each page.
QAction * m_editUndoAction
QAction * m_exportTextTuple
void setSelected(QtView *view)
Select a specific view in the window.
DataSourceController class interface.
void setCurrentRange()
Saves the current range of the selected plotter.
virtual void openRecentFile(QAction *)
Responds to open recent file.
const std::vector< double > & mouseEventData()
Retrieve a vector of (x, y, z) points from the next mouse event.
virtual void viewShowPlotTable()
Shows the plot table.
A base class that is the interface between GUI and the XML serialization and deserialization.
void updateActions()
Update Action objects.
void viewShowPickTable()
Show the pick table.
virtual void fileNew()
Creates a new document CanvasWindow.
void setIntervalEnabled(bool yes=true)
Sets the display interval feature to enabled if yes is true, otherwise sets it to disabled...
virtual void helpHelp()
Brings up a QAssistant client.
NTuple * getPickTable() const
Gets the pick table the selected plotter.
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...
A concrete window class that contains the canvas and responds to menu item and tool bar events from t...
virtual void setCutMode(QAction *)
Sets the cut mode.
setFont(const QFont &font, bool informWidgets=FALSE, const char *className=0)
virtual void closeEvent(QCloseEvent *e)
Informs the application object that is window is about to close.
virtual void fileOpen()
Opens an existing file.
The class of derived from GroupViewBase, QtViewImp and QCanvasRectangle for drawing a grouped view on...
QString m_prefix
The prefix part of the window title.
bool m_inhibit_close
A flag set to true if the CanvasWindow should not accept a close event.
void viewZoomOut()
Reduces the view of the canvas.
arg(long a, int fieldWidth=0, int base=10) const
const QString & getAppKey() const
Returns a reference the application's QSettings key.
static QtXMLController * instance()
Returns the pointer to the singleton instance.
bool m_allow_close
A flag set to true to allow the window to close without prompting the user.
hippodraw::PlotterBase class interface.
std::string m_filename
The file name part of the window title.
virtual void viewZoomIn()
Enlarges the view of the canvas.
PlotterBase * selectedPlotter() const
Returns the selected PlotterBase object.
virtual void fileSaveAllAs()
Saves the canvas document and its NTuple.
void setCanvas(CanvasView *canvas)
Sets the canvas to be used by the table.
virtual void viewAddPage()
Adds a page to the canvas.
virtual void aboutQt()
Brings up Qt's about message box.
SaveAsImageEvent class interface.
bool allowClose()
If document has changed and not saved, opens a dialog box for user to choose to save, discard or cancel.
hippodraw::CanvasWindow class interface.
void addPlotDisplay(PlotterBase *plotter, bool select)
Adds a new plot display to the canvas.
void fillPlotterList(std::vector< PlotterBase * > &plotter_list)
Clears and fills plotter_list with all the PlotterBase objects on the canvas.
void setCaption()
Sets the Windows title.
bool m_filenameExists
True if filename has been assigned, false if not.
static const std::string & getTextSuffix()
Returns the suffix for a text data source files.
virtual void editUndo()
Responds to the undo action.
void viewZoomIn()
Enlarges the view of the canvas.
void setAllowClose(bool yes=true)
Sets the window to allowed to be closed by user without prompting.
virtual void customEvent(QCustomEvent *event)
Responds to QCustomEvents.
QAction * m_fileSaveAllAction
PlotterBase * selectedPlotter()
Returns the selected plotter.
A derived class of InspectorBase class which is generated by the Qt designer.
void setAllSelected(bool flag=true)
Sets selection flag on all QCanvasItem objects.
void saveAsImage(const PlotterBase *plotter, const std::string &filename)
Saves the plotter as image file.
CanvasWindow(QWidget *parent=0, const char *name=0, Qt::WFlags fl=Qt::WType_TopLevel)
constructor.
void reTilePage()
Re-tiles the current page.
void newWindow(CanvasWindow *)
Registers the new CanvasWindow and finishes its initialization.
void setAddedSelected(bool yes)
Sets to flag to make plots in their selected state when added to the canvas.
hippodraw::PlotTable class interface
static const std::string & createDocumentFilter()
Creates a filter for saving a document.
PyArray_TYPES type(numeric::array arr)
hippodraw::QtFileDialog class interface
CanvasView * getCanvasView()
Returns the CanvasView object.
void setChanged(bool flag=true)
Sets the changed flag.
postEvent(QObject *receiver, QEvent *event)
void savePlotAsImage(const PlotterBase *plotter, const std::string &filename)
Saves the plotter as image file.
virtual void editDelete()
Removes selected items from canvas without copying them to the pasteboard.
virtual void ungroupView()
Ungroup the views.
void setAllSelected(bool flag=true)
Select or deselect all views in the window.
virtual void editReTilePage()
Re tiles only the current page.
void addFuncDisplay(PlotterBase *plotter, const std::string &name)
Adds function textual display to the canvas.
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's coordinates.
static NTupleController * instance()
Returns the pointer to the singleton instance.
virtual void fileBrowse()
Browse a document file, without opening a window for it.
QtFileDialog * m_file_dialog
The open file dialog for this window.
void setIntervalEnabled(bool yes=true)
Sets the display interval feature of all views to enabled if yes is true, otherwise sets the feature ...
virtual void hideEvent(QHideEvent *e)
Informs the application object that the window has been hidden.
virtual void print()
Prints the canvas.
bool areDataSourcesSaved()
Returns true if all the data sources used by the document have been saved to or read from a file...
static const std::string & getDocSuffix()
Returns the suffix for a document.
virtual void resizeEvent(QResizeEvent *)
Informs the Canvas to re-size as well.
void fileSave()
Saves the document.
std::string getSaveDocFilename()
Returns the chosen file name from a save canvas dialog.
A singleton class for keeping track the window components of HippoDraw.
void autosaveSettings()
Automatically save dock windows and recently opened files.
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's coordinates.
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...
A DataSource class implemented with std::vector<double> to store the column data. ...
virtual void editClear()
Responds to "Clear" menu item.
virtual void setZoomMode(bool on)
Sets the zoom mode to true or false.
bool m_hasChanged
The current changed status.
QAction * m_viewUnlockAction
QAction * m_editCopyAction
This class implements additional FigureEditor functionality particular to QtView objects.
endsWith(const QString &s, bool cs=TRUE) const
A derived class of QCustomEvent PlotTable events.
void addDisplay(PlotterBase *plotter)
Adds a new plot to the canvas and selects it.
void copySelectedToPasteboard()
Copies selected items to pasteboard.
void previousView()
Switches View to the previous view for the selected item on the canvas.
setCentralWidget(QWidget *w)
void reTile()
Re-tiles the canvas.
A derived class of QCustomEvent to handle saving a PlotterBase object as image file events...
hippodraw::WindowController class interface
virtual void fileCreateNTuple()
Create a new NTuple from selected cut and column.
hippodraw::CanvasView class interface
void initFromFile(const std::string &filename)
Initializes this object from contents of file.
The base class for the CanvasWindow class.
virtual void fileSaveAs()
Saves the document after display a file dialog to the user.
void openRootTuple(const std::string &filename, QWidget *parent)
Opens a ROOT DataSource file.
const std::vector< double > & mouseEventData()
Retrieve a vector (x, y, z) points from the next mouse event.
void addTextDisplay(PlotterBase *plotter, const std::string &type)
Adds a textual display to the canvas of type type.
QAction * m_editDeleteAction
void resizeEvent(QResizeEvent *e)
Re-sizes the QCanvas in response to parent window receiving QResizeEvent.
void print(const std::string &filename)
Prints the view to Postscript file without prompting user.
virtual bool closeNoPrompt()
Closes the window.
QAction * m_editCutAction
intp size(numeric::array arr)
static WindowController * instance()
Returns the application instance.
void copyFromPasteboard()
Copies from the pasteboard.
virtual void helpAbout()
Brings up standard window showing version, authors, etc.
QtView * getViewFor(const PlotterBase *plotter) const
Returns the QtView object that is the Observer of the plotter.
static bool isDocSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to document file.
QActionGroup * m_set_fitter
The base class for the PlotterBase hierarchy.
virtual void editSelectAll()
Sets all QCanvasItem objects to selected.
hippodraw::Inspector class interface.
static const std::string & createBrowseFilter()
Creates the open file filter.
bool setFilenameFromDialog()
Sets the file name of document.
virtual void settingPrinter()
Sets the printer settings.
const std::vector< const ViewBase * > & views() const
Returns temporary list of all QtView objects on the canvas.
static void resetFontSize()
Resets the font size to be no larger than 10.
QAction * m_editPasteAction
CanvasView * m_browsed_canvas
The CanvasView object that is being browsed.
static bool isZippedFitsSuffix(const std::string &suffix)
Returns true if the file filename is a compressed FITS file.
void inhibitClose(bool yes=true)
If yes is true, sets a flag so that this object will not accept close events.
A class to handle various file types.
static PlotTable * s_plot_table
The singleton instance of PlotTable.
virtual void fileSaveAll()
Saves the canvas document and any NTuple that were not read from or written to a file.
virtual void settingFonts()
Sets the font settings.
void createInspector()
Creates the Inspector object and positions it on the desktop.
PlotTableEvent class interface.
void saveSelectedImages()
Saves the selected QCanvasItem objects to a image file.
void setTitleFileName(const std::string &name)
Sets the file name component of the window's title.
void addPage()
Adds a page to the canvas.
QtView * getViewFor(const PlotterBase *plotter) const
Returns the QtView object that is the Observer of the plotter.
static bool isRootSuffix(const std::string &suffix)
Returns true if suffix is one corresponding to ROOT DataSource files.
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 settingCanvas()
Sets the canvas settings.
critical(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
virtual void editCut()
Removes selected items from canvas and add them to the pasteboard.
A derived class of QCustomEvent to handle updates from PlotterBase.
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.
QString m_changed
The changed status part of the window title.
void saveAllAs(const std::string &filename)
Saves the document along with its NTuple objects.
warning(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
void openFitsTuple(const std::string &filename, QWidget *parent)
Opens a FITS DataSource file.
static std::string getExportTupleFilename(QWidget *widget)
Returns a filename for exporting a DataSource.
QActionGroup * m_recent_files
virtual void fileExportTextTuple()
void saveAs(const std::string &filename)
Saves the document to the specified file.
The class of derived from ViewBase and QCanvasRectangle for drawing on a QCanvas. ...
static void openTextTuple(const std::string &filename)
Opens a text NTuple file.
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)
virtual void editReTile()
Re tiles the entire document.
A derived class of PlotTableBase class which is generated by the Qt designer.
virtual void fileExit()
Responds to the Quit item in the File menu.
aboutQt(QWidget *parent, const QString &caption=QString::null)
A singleton class that is the interface between GUI and the NTuple objects.
hippodraw::PlotterEvent class interface
virtual void filePrint()
Prints the canvas to a Postscript file.
virtual void viewZoomOut()
Reduces the view of the canvas.
void nextView()
Switches View to the next view for the selected item on the canvas.
XmlController * m_xml_controller
The controller object capable of serializing the canvas contents as XML and serializing them...
void clear()
Removes all the QCanvasItem objects from the canvas.
virtual void viewUnlock()
Unlocks a canvas item.
QAction * m_fileSaveSelected
static bool isFitsFile(const std::string &filename)
Returns true if the file filename is a FITS file.
void addFuncDisplay(PlotterBase *plotter, const std::string &s)
Add a text display which displays functions parameters.
virtual void viewLock()
Locks a canvas item.
virtual void groupView()
Group the views.
virtual bool getCurrentRangeSaved()
Returns current_range_saved member t.
QAction * m_viewLockAction
getFont(bool *ok, const QFont &initial, QWidget *parent=0, const char *name=0)
virtual void fileSaveSelectedImages()
Saves the selected ViewBase object as an image file.
virtual void setFitter(QAction *)
Responds to change in fitter settings.
const std::vector< const ViewBase * > & views()
Returns the list of ViewBase objects on the canvas.