itom  3.0.0
AbstractFigure.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 *********************************************************************** */
27 
28 #ifndef ABSTRACTFIGURE_H
29 #define ABSTRACTFIGURE_H
30 
31 #include "plotCommon.h"
32 #include "AbstractNode.h"
33 
34 #include "../common/apiFunctionsGraphInc.h"
35 #include "../common/apiFunctionsInc.h"
36 
37 #include <qmainwindow.h>
38 #include <qlabel.h>
39 #include <qtoolbar.h>
40 #include <qevent.h>
41 #include <qdockwidget.h>
42 
43 class QPropertyEditorWidget; //forward declaration
44 
45 #if !defined(Q_MOC_RUN) || defined(ITOMCOMMONPLOT_MOC) //only moc this file in itomCommonQtLib but not in other libraries or executables linking against this itomCommonQtLib
46 
47 //place this macro in the header file of the designer plugin widget class right before the first section (e.g. public:)
48 #define DESIGNER_PLUGIN_ITOM_API \
49  protected: \
50  void importItomApi(void** apiPtr) \
51  {ito::ITOM_API_FUNCS = apiPtr;} \
52  void importItomApiGraph(void** apiPtr) \
53  { ito::ITOM_API_FUNCS_GRAPH = apiPtr;} \
54  public: \
55  //.
56 
57 namespace ito {
58 
59 class AbstractFigure; //forward declaration
60 class AbstractFigurePrivate; //forward declaration
61 
62 class ITOMCOMMONPLOT_EXPORT AbstractFigure : public QMainWindow, public AbstractNode
63 {
64  Q_OBJECT
65 
66 #if QT_VERSION < 0x050500
67  //for >= Qt 5.5.0 see Q_ENUM definition below
68  Q_ENUMS(WindowMode)
69  Q_ENUMS(UnitLabelStyle)
70 #endif
71 
72  Q_PROPERTY(bool toolbarVisible READ getToolbarVisible WRITE setToolbarVisible DESIGNABLE true USER true)
73  Q_PROPERTY(bool contextMenuEnabled READ getContextMenuEnabled WRITE setContextMenuEnabled DESIGNABLE true)
74  Q_PROPERTY(bool renderLegend READ getLegendRender WRITE setLegendRender DESIGNABLE true)
75 
76  Q_CLASSINFO("prop://toolbarVisible", "Toggles the visibility of the toolbar of the plot.")
77  Q_CLASSINFO("prop://contextMenuEnabled", "Defines whether the context menu of the plot should be enabled or not.")
78  Q_CLASSINFO("prop://renderLegend", "If this property is true, the legend are included in pixelmaps renderings.")
79 
80  Q_CLASSINFO("slot://getPlotID", "Return window ID of this plot {int}.")
81  Q_CLASSINFO("slot://refreshPlot", "Triggers an update of the current plot window.")
82 
83  public:
84  enum WindowMode
85  {
86  ModeInItomFigure,
87  ModeStandaloneInUi,
88  ModeStandaloneWindow
89  };
90 
91  enum CompilerFeatures
92  {
93  tOpenCV = 0x01,
94  tPointCloudLib = 0x02
95  };
96 
97  enum tChildPlotStates
98  {
99  tNoChildPlot = 0x00,
100  tExternChild = 0x01,
101  tOwnChild = 0x02,
102  tUninitilizedExtern = 0x10,
103  tVisibleOnInit = 0x20
104  };
105 
106  enum UnitLabelStyle
107  {
108  UnitLabelSlash, // x-axis / m -> corresponds to DIN461
109  UnitLabelKeywordIn, // x-axis in m -> corresponds to DIN461
110  UnitLabelSquareBrackets // x-axis [m] -> does not correspond to DIN461
111  };
112 
113 #if QT_VERSION >= 0x050500
114  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
115  //values are always accessible.
116  Q_ENUM(WindowMode)
117  Q_ENUM(UnitLabelStyle)
118 #endif
119 
120  int getCompilerFeatures(void) const
121  {
122  int retval = tOpenCV;
123 #if defined USEPCL || ITOM_POINTCLOUDLIBRARY
124  retval |= tPointCloudLib;
125 #endif
126  return retval;
127  }
128 
129  struct ToolBarItem {
130  ToolBarItem() : toolbar(NULL), visible(1), section(0), key("") {}
131  QToolBar *toolbar;
132  bool visible;
133  int section;
134  Qt::ToolBarArea area;
135  QString key;
136  };
137 
138  struct ToolboxItem {
139  ToolboxItem() : toolbox(NULL), key("") {}
140  QDockWidget *toolbox;
141  Qt::DockWidgetArea area;
142  QString key;
143  };
144 
145  AbstractFigure(const QString &itomSettingsFile, WindowMode windowMode = ModeStandaloneInUi, QWidget *parent = 0);
146  virtual ~AbstractFigure();
147 
148  virtual bool event(QEvent *e);
149  void setApiFunctionGraphBasePtr(void **apiFunctionGraphBasePtr);
150  void setApiFunctionBasePtr(void **apiFunctionBasePtr);
151  void ** getApiFunctionGraphBasePtr(void) { return m_apiFunctionsGraphBasePtr; }
152  void ** getApiFunctionBasePtr(void) { return m_apiFunctionsBasePtr; }
153 
154  virtual RetVal addChannel(AbstractNode *child, ito::Param* parentParam, ito::Param* childParam, Channel::ChanDirection direction, bool deleteOnParentDisconnect, bool deleteOnChildDisconnect);
155  virtual RetVal addChannel(Channel *newChannel);
156  virtual RetVal removeChannelFromList(unsigned int uniqueID);
157  virtual RetVal removeChannel(Channel *delChannel);
158 
159  virtual RetVal update(void) = 0;
161  //properties
162  virtual void setToolbarVisible(bool visible);
163  virtual bool getToolbarVisible() const;
164  virtual void setContextMenuEnabled(bool show) = 0;
165  virtual bool getContextMenuEnabled() const = 0;
166 
167  QDockWidget *getPropertyDockWidget() const;
168 
169  virtual bool getLegendRender() const { return false;}
170  virtual void setLegendRender(const bool val) { return;}
171 
172  QList<QMenu*> getMenus() const;
173  QList<AbstractFigure::ToolBarItem> getToolbars() const;
174  QList<AbstractFigure::ToolboxItem> getToolboxes() const; //the first toolbox is always the property dock widget
175 
176  protected:
177 
178  virtual RetVal init() { return retOk; } //this method is called from after construction and after that the api pointers have been transmitted
179 
180  virtual void importItomApi(void** apiPtr) = 0;
181  virtual void importItomApiGraph(void** apiPtr) = 0;
183  void addToolBar(QToolBar *toolbar, const QString &key, Qt::ToolBarArea area = Qt::TopToolBarArea, int section = 1);
184  void addToolBarBreak(const QString &key, Qt::ToolBarArea area = Qt::TopToolBarArea);
186  void addToolbox(QDockWidget *toolbox, const QString &key, Qt::DockWidgetArea area = Qt::RightDockWidgetArea);
187  bool removeToolbox(const QString &key);
189  void showToolBar(const QString &key);
190  void hideToolBar(const QString &key);
192  void addMenu(QMenu *menu);
194  void updatePropertyDock();
195  void setPropertyObservedObject(QObject* obj);
197  RetVal initialize();
198 
199  RetVal registerShortcutActions();
201  WindowMode m_windowMode;
202  QString m_itomSettingsFile;
203  QWidget *m_mainParent; //the parent of this figure is only set to m_mainParent, if the stay-on-top behaviour is set to the right value
204 
205  void **m_apiFunctionsGraphBasePtr;
206  void **m_apiFunctionsBasePtr;
207 
208  ito::uint8 m_lineCutType;
209  ito::uint8 m_zSliceType;
210  ito::uint8 m_zoomCutType;
211 
212  private:
214 
215  private slots:
216  inline void mnuShowToolbar(bool /*checked*/) { setToolbarVisible(true); }
217  void mnuShowProperties(bool checked);
219  void toolBoxDestroyed(QObject *object);
220  void toolBarDestroyed(QObject *object);
221 
222  void actionChanged();
223 
224  public slots:
225  int getPlotID();
226  void refreshPlot() { update(); }
227 };
228 
229 } // namespace ito
230 
231 #endif //#if !defined(Q_MOC_RUN) || defined(ITOMCOMMONQT_MOC)
232 
233 #endif // ABSTRACTFIGURE_H
Definition: AbstractFigure.h:62
Class for managing status values (like errors or warning)
Definition: retVal.h:54
class for parameter handling e.g. to pass paramters to plugins
Definition: param.h:251
Definition: typeDefs.h:58
void mnuShowToolbar(bool)
Definition: AbstractFigure.h:216
Definition: apiFunctionsGraph.cpp:39
Definition: AbstractNode.h:203
Definition: AbstractFigure.h:138
Definition: AbstractFigure.cpp:52
Definition: AbstractFigure.h:129
Definition: AbstractNode.h:62