Seamly2D
Code documentation
vobjectproperty.h
Go to the documentation of this file.
1 /******************************************************************************
2  * @file vobjectproperty.h
3  ** @author DS Caskey
4  ** @date Feb 7, 2023
5  **
6  ** @brief
7  ** @copyright
8  ** This source code is part of the Seamly2D project, a pattern making
9  ** program, whose allow create and modeling patterns of clothing.
10  ** Copyright (C) 2017-2023 Seamly2D project
11  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
12  **
13  ** Seamly2D is free software: you can redistribute it and/or modify
14  ** it under the terms of the GNU General Public License as published by
15  ** the Free Software Foundation, either version 3 of the License, or
16  ** (at your option) any later version.
17  **
18  ** Seamly2D is distributed in the hope that it will be useful,
19  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  ** GNU General Public License for more details.
22  **
23  ** You should have received a copy of the GNU General Public License
24  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
25  **
26  *************************************************************************/
27 
28 #ifndef VOBJECTPROPERTY_H
29 #define VOBJECTPROPERTY_H
30 
31 #include <qcompilerdetection.h>
32 #include <QMap>
33 #include <QMetaObject>
34 #include <QObject>
35 #include <QString>
36 #include <QStringList>
37 #include <QStyleOptionViewItem>
38 #include <QVariant>
39 #include <Qt>
40 #include <QtGlobal>
41 
42 #include "../vproperty.h"
43 
44 class QComboBox;
45 
46 namespace VPE
47 {
48 
49 class VObjectProperty : public VProperty
50 {
51  Q_OBJECT
52 public:
53  //! Constructor
54  explicit VObjectProperty(const QString& name);
55 
56  //! Destructor
57  virtual ~VObjectProperty() Q_DECL_OVERRIDE {}
58 
59  //! Get the data how it should be displayed
60  virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
61 
62  //! Returns an editor widget, or NULL if it doesn't supply one
63  //! \param parent The widget to which the editor will be added as a child
64  //! \options Render options
65  //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
66  //! slots.
67  virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options,
68  const QAbstractItemDelegate* delegate) Q_DECL_OVERRIDE;
69 
70  //! Gets the data from the widget
71  virtual QVariant getEditorData(const QWidget* editor) const Q_DECL_OVERRIDE;
72 
73  //! Sets the objects list
74  void setObjectsList(const QMap<QString, quint32> &objects);
75 
76  //! Get the settings. This function has to be implemented in a subclass in order to have an effect
77  virtual QMap<QString, quint32> getObjects() const;
78 
79  //! Sets the value of the property
80  virtual void setValue(const QVariant& value) Q_DECL_OVERRIDE;
81 
82  //! Returns a string containing the type of the property
83  virtual QString type() const Q_DECL_OVERRIDE;
84 
85  //! Clones this property
86  //! \param include_children Indicates whether to also clone the children
87  //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
88  //! to fill all the data into container. This can also be used when subclassing this function.
89  //! \return Returns the newly created property (or container, if it was not NULL)
90  Q_REQUIRED_RESULT virtual VProperty* clone(bool include_children = true,
91  VProperty* container = nullptr) const Q_DECL_OVERRIDE;
92 
93  static int indexOfObject(const QMap<QString, quint32> &objects, const QString &object);
94 
95 public slots:
96  void currentIndexChanged(int index);
97 
98 protected:
99  //! The list of possible objects
100  QMap<QString, quint32> m_objects;
102 
103  void fillListItems(QComboBox *box, const QMap<QString, quint32> &list)const;
104  // No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other
105  //members by reimplementing the VPropertyPrivate class without touching this header file.
106 
107 private:
108  Q_DISABLE_COPY(VObjectProperty)
109 };
110 
111 }
112 
113 #endif // VOBJECTPROPERTY_H
QMap< QString, quint32 > m_objects
The list of possible objects.
virtual ~VObjectProperty() Q_DECL_OVERRIDE
Destructor.
VObjectProperty(const QString &name)
Constructor.
static int indexOfObject(const QMap< QString, quint32 > &objects, const QString &object)
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
virtual void setValue(const QVariant &value) Q_DECL_OVERRIDE
Sets the value of the property.
void currentIndexChanged(int index)
virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE
Gets the data from the widget.
QVector< QString > m_indexList
void setObjectsList(const QMap< QString, quint32 > &objects)
Sets the objects list.
void fillListItems(QComboBox *box, const QMap< QString, quint32 > &list) const
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate) Q_DECL_OVERRIDE
Returns an editor widget, or NULL if it doesn't supply one.
virtual QMap< QString, quint32 > getObjects() const
Get the settings. This function has to be implemented in a subclass in order to have an effect.