labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

AbstractAspect.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : AbstractAspect.h
3  Project : LabPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2007-2009 by Tilman Benkert (thzs@gmx.net)
6  Copyright : (C) 2007-2010 by Knut Franke (knut.franke@gmx.de)
7  Copyright : (C) 2011-2015 by Alexander Semke (alexander.semke@web.de)
8  Description : Base class for all objects in a Project.
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the Free Software *
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27  * Boston, MA 02110-1301 USA *
28  * *
29  ***************************************************************************/
30 #ifndef ABSTRACT_ASPECT_H
31 #define ABSTRACT_ASPECT_H
32 
33 #include <QObject>
34 #include <QVector>
35 
37 class Folder;
38 class Project;
39 class XmlStreamReader;
40 
41 class QDateTime;
42 class QIcon;
43 class QMenu;
44 class QUndoCommand;
45 class QUndoStack;
46 class QXmlStreamWriter;
47 
48 /// Information about class inheritance
49 /// enum values are chosen such that @verbatim inherits(base)@endverbatim
50 /// returns true iff the class inherits from @verbatim base@endverbatim.
51 ///
52 /// AspectType is used in GuiObserver to select the correct dock widget.
53 enum class AspectType : quint64 {
54  AbstractAspect = 0,
55 
56  // classes without inheriters
57  AbstractFilter = 0x0100001,
58  DatapickerCurve = 0x0100002,
59  DatapickerPoint = 0x0100004,
60 
61  WorksheetElement = 0x0200000,
62  Axis = 0x0210001,
63  CartesianPlotLegend = 0x0210002,
64  CustomPoint = 0x0210004,
65  Histogram = 0x0210008,
66  PlotArea = 0x0210010,
67  TextLabel = 0x0210020,
68  Image = 0x0210030,
69  ReferenceLine = 0x0210040,
70  WorksheetElementContainer = 0x0220000,
71  AbstractPlot = 0x0221000,
72  CartesianPlot = 0x0221001,
73  WorksheetElementGroup = 0x0222000,
74  XYCurve = 0x0240000,
75  XYEquationCurve = 0x0240001,
76  XYAnalysisCurve = 0x0280000,
77  XYConvolution = 0x0280001,
78  XYCorrelationCurve = 0x0280002,
79  XYDataReductionCurve = 0x0280004,
80  XYDifferentiationCurve = 0x0280008,
81  XYFitCurve = 0x0280010,
82  XYFourierFilterCurve = 0x0280020,
83  XYFourierTransformCurve = 0x0280040,
84  XYInterpolationCurve = 0x0280080,
85  XYIntegrationCurve = 0x0280100,
86  XYSmoothCurve = 0x0280200,
87 
88  AbstractPart = 0x0400000,
89  AbstractDataSource = 0x0410000,
90  Matrix = 0x0411000,
91  Spreadsheet = 0x0412000,
92  LiveDataSource = 0x0412001,
93  MQTTTopic = 0x0412002,
94  CantorWorksheet = 0x0420001,
95  Datapicker = 0x0420002,
96  DatapickerImage = 0x0420004,
97  Note = 0x0420008,
98  Workbook = 0x0420010,
99  Worksheet = 0x0420020,
100 
101  AbstractColumn = 0x1000000,
102  Column = 0x1000001,
103  SimpleFilterColumn = 0x1000002,
104  ColumnStringIO = 0x1000004,
105 
106  Folder = 0x2000000,
107  Project = 0x2000001,
108  MQTTClient = 0x2000002,
109  MQTTSubscription = 0x2000004,
110 };
111 
112 class AbstractAspect : public QObject {
113  Q_OBJECT
114 
115 public:
116  enum class ChildIndexFlag {
117  IncludeHidden = 0x01,
118  Recursive = 0x02,
119  Compress = 0x04
120  };
121 
122  Q_DECLARE_FLAGS(ChildIndexFlags, ChildIndexFlag)
123 
124  friend class AspectChildAddCmd;
125  friend class AspectChildRemoveCmd;
126  friend class AbstractAspectPrivate;
127 
128  AbstractAspect(const QString& name, AspectType type);
129  ~AbstractAspect() override;
130 
131  QString name() const;
132  QString comment() const;
133  void setCreationTime(const QDateTime&);
134  QDateTime creationTime() const;
135  virtual Project* project();
136  virtual QString path() const;
137  void setHidden(bool);
138  bool hidden() const;
139  void setSelected(bool);
140  void setIsLoading(bool);
141  bool isLoading() const;
142  virtual QIcon icon() const;
143  virtual QMenu* createContextMenu();
144 
145  AspectType type() const;
146  bool inherits(AspectType type) const;
147 
148  //functions related to the handling of the tree-like project structure
149  AbstractAspect* parentAspect() const;
152  Folder* folder();
153  bool isDescendantOf(AbstractAspect* other);
154  void addChild(AbstractAspect*);
156  virtual void finalizeAdd() {};
157  QVector<AbstractAspect*> children(AspectType type, ChildIndexFlags flags = {}) const;
160  void reparent(AbstractAspect* newParent, int newIndex = -1);
162  void removeAllChildren();
163  virtual QVector<AbstractAspect*> dependsOn() const;
164 
165  virtual bool isDraggable() const;
166  virtual QVector<AspectType> dropableOn() const;
167  virtual void processDropEvent(const QVector<quintptr>&) {};
168 
169  template <class T> T* ancestor() const {
171  while (parent) {
172  T* ancestorAspect = dynamic_cast<T*>(parent);
173  if (ancestorAspect)
174  return ancestorAspect;
176  }
177  return nullptr;
178  }
179 
180  template <class T> QVector<T*> children(ChildIndexFlags flags = {}) const {
181  QVector<T*> result;
182  for (auto* child: children()) {
183  if (flags & ChildIndexFlag::IncludeHidden || !child->hidden()) {
184  T* i = dynamic_cast<T*>(child);
185  if (i)
186  result << i;
187 
188  if (child && flags & ChildIndexFlag::Recursive)
189  result << child->template children<T>(flags);
190  }
191  }
192  return result;
193  }
194 
195  template <class T> T* child(int index, ChildIndexFlags flags = {}) const {
196  int i = 0;
197  for (auto* child: children()) {
198  T* c = dynamic_cast<T*>(child);
199  if (c && (flags & ChildIndexFlag::IncludeHidden || !child->hidden()) && index == i++)
200  return c;
201  }
202  return nullptr;
203  }
204 
205  template <class T> T* child(const QString& name) const {
206  for (auto* child: children()) {
207  T* c = dynamic_cast<T*>(child);
208  if (c && child->name() == name)
209  return c;
210  }
211  return nullptr;
212  }
213 
214  template <class T> int childCount(ChildIndexFlags flags = {}) const {
215  int result = 0;
216  for (auto* child: children()) {
217  T* i = dynamic_cast<T*>(child);
218  if (i && (flags & ChildIndexFlag::IncludeHidden || !child->hidden()))
219  result++;
220  }
221  return result;
222  }
223 
224  template <class T> int indexOfChild(const AbstractAspect* child, ChildIndexFlags flags = {}) const {
225  int index = 0;
226  for (auto* c: children()) {
227  if (child == c) return index;
228  T* i = dynamic_cast<T*>(c);
229  if (i && (flags & ChildIndexFlag::IncludeHidden || !c->hidden()))
230  index++;
231  }
232  return -1;
233  }
234 
235  //undo/redo related functions
236  void setUndoAware(bool);
237  virtual QUndoStack* undoStack() const;
238  void exec(QUndoCommand*);
239  void exec(QUndoCommand* command, const char* preChangeSignal, const char* postChangeSignal,
240  QGenericArgument val0 = QGenericArgument(), QGenericArgument val1 = QGenericArgument(),
241  QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument());
242  void beginMacro(const QString& text);
243  void endMacro();
244 
245  //save/load
246  virtual void save(QXmlStreamWriter*) const = 0;
247  virtual bool load(XmlStreamReader*, bool preview) = 0;
248 
249 protected:
250  void info(const QString& text) { emit statusInfo(text); }
251 
252  //serialization/deserialization
254  void writeBasicAttributes(QXmlStreamWriter*) const;
255  void writeCommentElement(QXmlStreamWriter*) const;
257 
259 
260 private:
262 
263  QString uniqueNameFor(const QString&) const;
264  const QVector<AbstractAspect*>& children() const;
266 
267 public slots:
268  bool setName(const QString&, bool autoUnique = true);
269  void setComment(const QString&);
270  void remove();
271 
272 protected slots:
273  virtual void childSelected(const AbstractAspect*);
274  virtual void childDeselected(const AbstractAspect*);
275 
276 signals:
285  void statusInfo(const QString&);
287 
288  //selection/deselection in model (project explorer)
289  void selected(const AbstractAspect*);
291 
292  //selection/deselection in view
295 };
296 
297 Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractAspect::ChildIndexFlags)
298 
299 #endif // ifndef ABSTRACT_ASPECT_H
AspectType
Base class of all persistent objects in a Project.
void setIsLoading(bool)
virtual bool load(XmlStreamReader *, bool preview)=0
Load from XML.
void info(const QString &text)
Implementations should call this whenever status information should be given to the user.
virtual QIcon icon() const
Return an icon to be used for decorating my views.
AspectType type() const
void setUndoAware(bool)
void aspectAdded(const AbstractAspect *)
Emitted after a new Aspect has been added to the tree.
bool readCommentElement(XmlStreamReader *)
Load comment from an XML element.
void reparent(AbstractAspect *newParent, int newIndex=-1)
Move a child to another parent aspect and transfer ownership.
int indexOfChild(const AbstractAspect *child, ChildIndexFlags flags={}) const
Return (0 based) index of child in the list of children inheriting from class T.
Folder * folder()
Return the folder the Aspect is contained in or 0 if there is none.
ChildIndexFlag
Flags which control numbering scheme of children.
@ Recursive
Recursively handle all descendents, not just immediate children.
@ IncludeHidden
Include aspects marked as "hidden" in numbering or listing children.
@ Compress
Remove all null pointers from the result list.
void aspectHiddenAboutToChange(const AbstractAspect *)
Emitted before the hidden attribute is changed.
void aspectDescriptionChanged(const AbstractAspect *)
Emitted after the name, comment or caption spec have changed.
virtual void childDeselected(const AbstractAspect *)
void addChildFast(AbstractAspect *)
Add the given Aspect to my list of children without any checks and without putting this step onto the...
void addChild(AbstractAspect *)
Add the given Aspect to my list of children.
bool isDescendantOf(AbstractAspect *other)
Return whether the there is a path upwards to the given aspect.
void childAspectSelectedInView(const AbstractAspect *)
AbstractAspect * parent(AspectType type) const
In the parent-child hierarchy, return the first parent of type.
void childAspectDeselectedInView(const AbstractAspect *)
void aspectAboutToBeRemoved(const AbstractAspect *)
Emitted before an aspect is removed from its parent.
void remove()
Remove me from my parent's list of children.
virtual bool isDraggable() const
void deselected(const AbstractAspect *)
virtual void finalizeAdd()
void setCreationTime(const QDateTime &)
void aspectHiddenChanged(const AbstractAspect *)
Emitted after the hidden attribute has changed.
T * ancestor() const
Return the closest ancestor of class T (or NULL if none found).
QString name() const
const QVector< AbstractAspect * > & children() const
void aspectAboutToBeAdded(const AbstractAspect *parent, const AbstractAspect *before, const AbstractAspect *child)
Emitted before a new child is inserted.
void statusInfo(const QString &)
Emitted whenever some aspect in the tree wants to give status information to the user.
int childCount(ChildIndexFlags flags={}) const
Return the number of child Aspects inheriting from given class.
void connectChild(AbstractAspect *)
virtual QMenu * createContextMenu()
Return a new context menu.
QString comment() const
bool hidden() const
void writeBasicAttributes(QXmlStreamWriter *) const
Save name and creation time to XML.
void renameRequested()
void selected(const AbstractAspect *)
virtual void save(QXmlStreamWriter *) const =0
Save as XML.
bool inherits(AspectType type) const
QString uniqueNameFor(const QString &) const
Make the specified name unique among my children by incrementing a trailing number.
T * child(int index, ChildIndexFlags flags={}) const
bool setName(const QString &, bool autoUnique=true)
AbstractAspect::setName sets the name of the abstract aspect.
void setParentAspect(AbstractAspect *)
void aspectRemoved(const AbstractAspect *parent, const AbstractAspect *before, const AbstractAspect *child)
Emitted from the parent after removing a child.
AbstractAspect * parentAspect() const
Return my parent Aspect or 0 if I currently don't have one.
void beginMacro(const QString &text)
Begin an undo stack macro (series of commands)
void insertChildBeforeFast(AbstractAspect *child, AbstractAspect *before)
Insert the given Aspect at a specific position in my list of children.without any checks and without ...
QDateTime creationTime() const
void setSelected(bool)
virtual QString path() const
Return the path that leads from the top-most Aspect (usually a Project) to me.
void exec(QUndoCommand *)
Execute the given command, pushing it on the undoStack() if available.
bool isLoading() const
QVector< T * > children(ChildIndexFlags flags={}) const
bool readBasicAttributes(XmlStreamReader *)
Load name and creation time from XML.
T * child(const QString &name) const
Get child by name and class.
void writeCommentElement(QXmlStreamWriter *) const
Save the comment to XML.
void insertChildBefore(AbstractAspect *child, AbstractAspect *before)
Insert the given Aspect at a specific position in my list of children.
virtual void processDropEvent(const QVector< quintptr > &)
virtual QVector< AbstractAspect * > dependsOn() const
const AspectType m_type
void removeChild(AbstractAspect *)
Remove the given Aspect from my list of children.
virtual void childSelected(const AbstractAspect *)
virtual QUndoStack * undoStack() const
Return the undo stack of the Project, or 0 if this Aspect is not part of a Project.
void aspectDescriptionAboutToChange(const AbstractAspect *)
Emitted before the name, comment or caption spec is changed.
virtual Project * project()
Return the Project this Aspect belongs to, or 0 if it is currently not part of one.
void setComment(const QString &)
AbstractAspectPrivate * d
void endMacro()
End the current undo stack macro.
void setHidden(bool)
Set "hidden" property, i.e. whether to exclude this aspect from being shown in the explorer.
void removeAllChildren()
Remove all child Aspects.
virtual QVector< AspectType > dropableOn() const
Interface definition for data with column logic.
Interface for the data sources.
Base class for all analysis operations.
Base class of Aspects with MDI windows as views (AspectParts).
Definition: AbstractPart.h:36
Second level container in a Worksheet for logical grouping.
Definition: AbstractPlot.h:41
Axis for cartesian coordinate systems.
Definition: Axis.h:42
Legend for the cartesian plot.
A xy-plot.
Definition: CartesianPlot.h:58
String-IO interface of Column.
Aspect that manages a column.
Definition: Column.h:42
A customizable point.
Definition: CustomPoint.h:41
Top-level container for Curve-Point and Datasheet/Spreadsheet of datapicker.
container to open image/plot.
Top-level container for DatapickerCurve and DatapickerImage.
Definition: Datapicker.h:45
Folder in a project.
Definition: Folder.h:35
A 2D-curve, provides an interface for editing many properties of the curve.
Definition: Histogram.h:42
A label supporting rendering of html- and tex-formatted texts.
Definition: Image.h:41
Represents data stored in a file. Reading and writing is done with the help of appropriate I/O-filter...
The MQTT Client connects to the broker set in ImportFileWidget. It manages the MQTTSubscriptions,...
Definition: MQTTClient.h:48
Represents a subscription made in a MQTTClient object. It plays a role in managing MQTTTopic objects ...
Represents a topic of a subscription made in MQTTClient.
Definition: MQTTTopic.h:39
Definition: Matrix.h:41
Definition: Note.h:41
Plot area (for background filling and clipping).
Definition: PlotArea.h:38
Represents a project.
Definition: Project.h:42
A customizable point.
Definition: ReferenceLine.h:39
Aspect providing a spreadsheet table with column logic.
Definition: Spreadsheet.h:40
A label supporting rendering of html- and tex-formatted texts.
Definition: TextLabel.h:44
Top-level container for Spreadsheet and Matrix.
Definition: Workbook.h:40
Worksheet element container - parent of multiple elements This class provides the functionality for a...
Groups worksheet elements for collective operations.
Base class for all Worksheet children.
Top-level container for worksheet elements like plot, labels, etc.
Definition: Worksheet.h:46
Base class for all analysis curves.
A xy-curve defined by a correlation.
A 2D-curve, provides an interface for editing many properties of the curve.
Definition: XYCurve.h:46
A xy-curve defined by a data reduction.
A xy-curve defined by an differentiation.
A xy-curve defined by a mathematical equation.
A xy-curve defined by a fit model.
Definition: XYFitCurve.h:43
A xy-curve defined by a Fourier filter.
A xy-curve defined by a Fourier transform.
A xy-curve defined by an integration.
A xy-curve defined by an interpolation.
A xy-curve defined by a smooth.
Definition: XYSmoothCurve.h:41
XML stream parser that supports errors as well as warnings. This class also adds line and column numb...