/home/docs/checkouts/readthedocs.org/user_builds/mathvizanimator/checkouts/latest/libs/mva_gui/include/items/abstractitem.h Source File

MathVizAnimator: /home/docs/checkouts/readthedocs.org/user_builds/mathvizanimator/checkouts/latest/libs/mva_gui/include/items/abstractitem.h Source File
MathVizAnimator  0.0.1
abstractitem.h
1 /* mathvizanimator
2  * Copyright (C) 2023 codingwithmagga
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef LIBS_MVA_GUI_INCLUDE_ITEMS_ABSTRACTITEM_H_
19 #define LIBS_MVA_GUI_INCLUDE_ITEMS_ABSTRACTITEM_H_
20 
21 #include <QColor>
22 #include <QFile>
23 #include <QJsonObject>
24 #include <QPair>
25 #include <QVariantMap>
26 #include <QVector>
27 #include <QtQuick/QQuickPaintedItem>
28 
29 class BasicItem;
30 
37 class PropertyMap : public QVariantMap {
38  public:
47  inline QString stringValue(const QString& property) const { return value(property).toString(); }
48 };
49 
56 class AbstractItem : public QQuickPaintedItem {
57  Q_OBJECT
58 
59  Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
60  Q_PROPERTY(QString file MEMBER m_qml_file CONSTANT)
61 
62  public:
68  explicit AbstractItem(const QString& qml_file, BasicItem* parent = nullptr);
69 
70  QString name() const;
71  void setName(const QString& name);
72 
73  virtual QJsonObject toJson() const;
74 
85  virtual inline QStringList editableProperties() const { return { "name", "opacity", "rotation" }; }
86 
98  virtual inline QStringList editablePropertiesParent() const { return { "width", "height", "x", "y" }; }
99 
100  PropertyMap allItemProperties() const;
101 
102  PropertyMap itemProperties() const;
103  PropertyMap parentItemProperties() const;
104 
110  void paintItem(QPainter* painter);
111 
112  signals:
113  void nameChanged(const QString& new_name);
114 
115  private:
116  PropertyMap fillPropertyMap(const QMetaObject* const meta_object) const;
117  PropertyMap fillPropertyMapParent(const QMetaObject* const meta_object) const;
118 
119  QString m_name;
120 
121  QString m_qml_file;
122 };
123 
124 Q_DECLARE_METATYPE(AbstractItem) // GCOVR_EXCL_LINE
125 
126 #endif // LIBS_MVA_GUI_INCLUDE_ITEMS_ABSTRACTITEM_H_
An abstract class representing a visible item like a circle or a rectangle.
Definition: abstractitem.h:56
virtual QStringList editableProperties() const
Returns the properties which can be edited by the user in a QStringList.
Definition: abstractitem.h:85
AbstractItem(const QString &qml_file, BasicItem *parent=nullptr)
Constructor for MyClass. TODO.
Definition: abstractitem.cpp:24
virtual QStringList editablePropertiesParent() const
Returns the parents properties which can be edited by the user in a QStringList.
Definition: abstractitem.h:98
void paintItem(QPainter *painter)
Short explanation.
Definition: abstractitem.cpp:93
Definition: basic_item.h:28
Map which stores key (QString) value (QVariant) pairs.
Definition: abstractitem.h:37
QString stringValue(const QString &property) const
Returns the value to the given property as QString.
Definition: abstractitem.h:47