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