AbstractAspect
A description for AbstractAspect.
-
class AbstractAspect : public QObject
Base class of all persistent objects in a Project.
Before going into the details, it’s useful to understand the ideas behind the Aspect Framework.
Aspects organize themselves into trees, where a parent takes ownership of its children. Usually, though not necessarily, a Project instance will sit at the root of the tree (without a Project ancestor, project() will return 0 and undo does not work). Children are organized using addChild(), removeChild(), child(), indexOfChild() and childCount() on the parent’s side as well as the equivalent convenience methods index() and remove() on the child’s side. In contrast to the similar feature of QObject, Aspect trees are fully undo/redo aware and provide signals around object adding/removal.
AbstractAspect manages for every Aspect the properties name, comment, captionSpec and creationTime. All of these translate into the caption() as described in the documentation of setCaptionSpec().
If an undoStack() can be found (usually it is managed by Project), changes to the properties as well as adding/removing children support multi-level undo/redo. In order to support undo/redo for problem-specific data in derived classes, make sure that all changes to your data are done by handing appropriate commands to exec().
Subclassed by AbstractColumn, AbstractFilter, AbstractPart, Background, DatapickerCurve, DatapickerPoint, ErrorBar, Folder, Line, Symbol, Value, WorksheetElement
-
void setSelected(bool)
this function is called when the selection in ProjectExplorer was changed. forwards the selection/deselection to the parent aspect via emitting a signal.
-
void setUndoAware(bool value)
enables the undo awareness of the aspect (modifications are put onto the undo stack) if
valueis set totrue, disables it otherwise. Note, this function doesn’t modify the behavior of aspects’s children, the behavior of the children needs to be handled separately, if needed.
-
bool isUndoAware() const
returns
trueif the aspect is undo aware (modifications are put onto the undo stack), returnsfalseotherwise.
-
virtual QUndoStack *undoStack() const
Return the undo stack of the Project, or 0 if this Aspect is not part of a Project.
It’s also possible to construct undo-enabled Aspect trees without Project. The only requirement is that the root Aspect reimplements undoStack() to get the undo stack from somewhere (the default implementation just delegates to parentAspect()).
-
void exec(QUndoCommand*)
Execute the given command, pushing it on the undoStack() if available.
-
void exec(QUndoCommand *command, const char *preChangeSignal, const char *postChangeSignal, QGenericArgument val0 = QGenericArgument(), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument())
Execute command and arrange for signals to be sent before/after it is redone or undone.
commandThe command to be executed.preChangeSignalThe name of the signal to be triggered before re-/undoing the command.postChangeSignalThe name of the signal to be triggered after re-/undoing the command.val0,val1,val2,val3Arguments to the signals; to be given using Q_ARG().
See also
SignallingUndoCommand
-
void beginMacro(const QString &text)
Begin an undo stack macro (series of commands)
-
void endMacro()
End the current undo stack macro.
-
static QString uniqueNameFor(const QString &name, const QStringList &names)
static helper function that makes the string
nameunique and avoids duplicates in the list of stringsnames.
serialize/deserialize
-
virtual void save(QXmlStreamWriter*) const = 0
Save as XML.
-
virtual bool load(XmlStreamReader*, bool preview) = 0
Load from XML.
XmlStreamReader supports errors as well as warnings. If only warnings (non-critical errors) occur, this function must return the reader at the end element corresponding to the current element at the time the function was called.
This function is normally intended to be called directly after the ctor. If you want to call load on an aspect that has been altered, you must make sure beforehand that it is in the same state as after creation, e.g., remove all its child aspects.
- Returns:
false on error
Public Types
-
enum class ChildIndexFlag
Flags which control numbering scheme of children.
Values:
-
enumerator IncludeHidden
Include aspects marked as “hidden” in numbering or listing children.
-
enumerator Recursive
Recursively handle all descendents, not just immediate children.
-
enumerator Compress
Remove all null pointers from the result list.
-
enumerator IncludeHidden
Public Functions
-
virtual Project *project()
Return the Project this Aspect belongs to, or 0 if it is currently not part of one.
-
virtual QString path() const
Return the path that leads from the top-most Aspect (usually a Project) to me.
-
void setHidden(bool)
Set “hidden” property, i.e. whether to exclude this aspect from being shown in the explorer.
-
void setFixed(bool)
Set “fixed” property which defines whether the object can be renamed, deleted, etc.
-
virtual QIcon icon() const
Return an icon to be used for decorating my views.
-
virtual QMenu *createContextMenu()
Return a new context menu.
The caller takes ownership of the menu.
-
AbstractAspect *parentAspect() const
Return my parent Aspect or 0 if I currently don’t have one.
-
AbstractAspect *parent(AspectType) const
In the parent-child hierarchy, return the first parent of type.
- Parameters:
type – or null pointer if there is none.
-
Folder *folder()
Return the folder the Aspect is contained in or 0 if there is none.
The returned folder may be the aspect itself if it inherits Folder.
-
bool isDescendantOf(AbstractAspect *other)
Return whether the there is a path upwards to the given aspect.
This also returns true if other==this.
-
virtual bool addChild(AbstractAspect*)
Add the given Aspect to my list of children.
-
void addChildFast(AbstractAspect*)
Add the given Aspect to my list of children without any checks and without putting this step onto the undo-stack.
-
void insertChildBefore(AbstractAspect *child, AbstractAspect *before)
Insert the given Aspect at a specific position in my list of children.
-
void insertChildBeforeFast(AbstractAspect *child, AbstractAspect *before)
Insert the given Aspect at a specific position in my list of children.without any checks and without putting this step onto the undo-stack.
-
void reparent(AbstractAspect *newParent, int newIndex = -1)
Move a child to another parent aspect and transfer ownership.
-
void removeChild(AbstractAspect*)
removeChild Removing child aspect using an undo command
Remove the given Aspect from my list of children.
The ownership of the child is transferred to the undo command, i.e., the aspect is deleted by the undo command.
See also
- Parameters:
parent – If parent is not nullptr the command will not be executed, but the parent must be executed to indirectly execute the created undocommand
-
void removeAllChildren()
Remove all child Aspects.
-
virtual QVector<AbstractAspect*> dependsOn() const
returns the list of all parent aspects (folders and sub-folders)
-
virtual QVector<AspectType> pasteTypes() const
return the list of all aspect types that can be copy&pasted into the current aspect. returns an empty list on default, needs to be re-implemented in all derived classes that want to allow other aspects to be pasted into.
-
template<class T>
inline T *ancestor() const Return the closest ancestor of class T (or NULL if none found).
-
template<class T>
inline int childCount(ChildIndexFlags flags = {}) const Return the number of child Aspects inheriting from given class.
-
template<class T>
inline int indexOfChild(const AbstractAspect *child, ChildIndexFlags flags = {}) const Return (0 based) index of child in the list of children inheriting from class T.
Public Slots
-
bool setName(const QString&, NameHandling handling = NameHandling::AutoUnique, QUndoCommand *parent = nullptr)
AbstractAspect::setName sets the name of the abstract aspect.
- Parameters:
value – - the new value for the name that needs to be checked and made unique if it’s not the case yet
autoUnique – - if set to \true the new name is automatically made unique, the name is not changed and
falseis returned otherwise. default is \true.skipAutoUnique – - if set to \true, don’t check for uniqueness, the caller has to guarantee the uniqueness. default is \false.
- Returns:
returns, if the new name is valid or not
-
void remove()
Remove me from my parent’s list of children.
-
void copy()
copies the aspect to the clipboard. The standard XML-serialization via AbstractAspect::load() is used.
-
void duplicate()
duplicates the aspect in the project hierarchy, the copy of the duplicated aspect is added below the current aspect at the same level in the hierarchy.
-
void paste(bool duplicate = false, int index = -1)
in case the clipboard contains LabPlot’s specific copy&paste content, this function deserializes the XML string and adds the created aspect as a child to the current aspect (“paste”).
Signals
-
void aspectDescriptionAboutToChange(const AbstractAspect*)
Emitted before the name, comment or caption spec is changed.
-
void aspectDescriptionChanged(const AbstractAspect*)
Emitted after the name, comment or caption spec have changed.
-
void childAspectAboutToBeAdded(const AbstractAspect *parent, int index, const AbstractAspect *child)
aspectAboutToBeAdded Signal indicating a new child was added at position
index. Do not connect to both variants of aspectAboutToBeAdded!- Parameters:
parent –
index – Position of the new aspect
child –
-
void childAspectAboutToBeAdded(const AbstractAspect *parent, const AbstractAspect *before, const AbstractAspect *child)
aspectAboutToBeAdded
- Parameters:
parent –
before – aspect one position before the child
child –
-
void childAspectAboutToBeRemoved(const AbstractAspect *child)
aspectAboutToBeRemoved Called from the parent if a child is being removed
-
void aspectAboutToBeRemoved(const AbstractAspect*)
aspectAboutToBeRemoved Called by the aspect itself when it’s being removed
Emitted before an aspect is removed from its parent.
-
void aspectHiddenAboutToChange(const AbstractAspect*)
Emitted before the hidden attribute is changed.
-
void aspectHiddenChanged(const AbstractAspect*)
Emitted after the hidden attribute has changed.
-
void statusInfo(const QString&)
Emitted whenever some aspect in the tree wants to give status information to the user.
See also
info(const QString&)
Public Static Functions
-
static AspectType clipboardAspectType(QString&)
helper function determining whether the current content of the clipboard contains the labplot specific copy&paste XML content. In case valid content is available, the aspect type of the object to be pasted is returned. otherwise, AspectType::AbstractAspect is returned.
-
void setSelected(bool)