Seamly2D
Code documentation
vlabelproperty.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * @file vlabelproperty.cpp
3  ** @author DS Caskey
4  ** @date Feb 18, 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 /************************************************************************
29  **
30  ** @file vlabelproperty.cpp
31  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
32  ** @date 28 8, 2014
33  **
34  ** @brief
35  ** @copyright
36  ** This source code is part of the Valentina project, a pattern making
37  ** program, whose allow create and modeling patterns of clothing.
38  ** Copyright (C) 2014 Valentina project
39  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
40  **
41  ** Valentina is free software: you can redistribute it and/or modify
42  ** it under the terms of the GNU General Public License as published by
43  ** the Free Software Foundation, either version 3 of the License, or
44  ** (at your option) any later version.
45  **
46  ** Valentina is distributed in the hope that it will be useful,
47  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
48  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  ** GNU General Public License for more details.
50  **
51  ** You should have received a copy of the GNU General Public License
52  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
53  **
54  *************************************************************************/
55 
56 #include "vlabelproperty.h"
57 
58 #include <QKeyEvent>
59 #include <QLatin1String>
60 #include <QLabel>
61 #include <QSizePolicy>
62 #include <QStaticStringData>
63 #include <QStringData>
64 #include <QStringDataPtr>
65 
66 #include "../vproperty_p.h"
67 
68 VPE::VLabelProperty::VLabelProperty(const QString &name, const QMap<QString, QVariant> &settings)
69  : VProperty(name, QVariant::String)
70  , typeForParent(0)
71 {
72  VProperty::setSettings(settings);
73  d_ptr->VariantValue.setValue(QString());
74  d_ptr->VariantValue.convert(QVariant::String);
75 }
76 
78  : VProperty(name)
79  , typeForParent(0)
80 {
81  d_ptr->VariantValue.setValue(QString());
82  d_ptr->VariantValue.convert(QVariant::String);
83 }
84 
85 QWidget *VPE::VLabelProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options,
86  const QAbstractItemDelegate *delegate)
87 {
88  Q_UNUSED(options)
89  Q_UNUSED(delegate)
90 
91  QLabel *labelTextEditor = new QLabel(parent);
92  labelTextEditor->setAlignment(Qt::AlignLeft | Qt::AlignTop);
93  labelTextEditor->setLocale(parent->locale());
94  labelTextEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
95  labelTextEditor->setText(d_ptr->VariantValue.toString());
96 
97  d_ptr->editor = labelTextEditor;
98  return d_ptr->editor;
99 }
100 
101 QVariant VPE::VLabelProperty::getEditorData(const QWidget *editor) const
102 {
103  const QLabel *labelTextEditor = qobject_cast<const QLabel*>(editor);
104  if (labelTextEditor)
105  {
106  return labelTextEditor->text();
107  }
108 
109  return QVariant(QString());
110 }
111 
112 void VPE::VLabelProperty::setSetting(const QString &key, const QVariant &value)
113 {
114  if (key == QLatin1String("TypeForParent"))
115  {
116  setTypeForParent(value.toInt());
117  }
118 }
119 
120 QVariant VPE::VLabelProperty::getSetting(const QString &key) const
121 {
122  if (key == QLatin1String("TypeForParent"))
123  {
124  return typeForParent;
125  }
126  else
127  return VProperty::getSetting(key);
128 }
129 
131 {
132  QStringList settings;
133  settings << QStringLiteral("TypeForParent");
134  return settings;
135 }
136 
138 {
139  return QStringLiteral("label");
140 }
141 
142 VPE::VProperty *VPE::VLabelProperty::clone(bool include_children, VPE::VProperty *container) const
143 {
144  return VProperty::clone(include_children, container ? container : new VLabelProperty(getName(), getSettings()));
145 }
146 
147 void VPE::VLabelProperty::updateParent(const QVariant &value)
148 {
149  emit childChanged(value, typeForParent);
150 }
151 
153 {
154  return typeForParent;
155 }
156 
158 {
159  typeForParent = value;
160 }
Class for holding a string property.
virtual void updateParent(const QVariant &value) Q_DECL_OVERRIDE
int getTypeForParent() const
virtual void setSetting(const QString &key, const QVariant &value) Q_DECL_OVERRIDE
Sets the settings.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
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 QVariant getSetting(const QString &key) const Q_DECL_OVERRIDE
Get the settings. This function has to be implemented in a subclass in order to have an effect.
virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE
Gets the data from the widget.
virtual QStringList getSettingKeys() const Q_DECL_OVERRIDE
Returns the list of keys of the property's settings.
VLabelProperty(const QString &name, const QMap< QString, QVariant > &settings)
void setTypeForParent(int value)
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
QVariant VariantValue
The property's value. This does not have to be used by subclasses, but it makes sense in cases where ...
Definition: vproperty_p.h:40
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
Definition: vproperty.cpp:372
VPropertyPrivate * d_ptr
The protected structure holding the member variables (to assure binary compatibility)
Definition: vproperty.h:214
virtual QVariant getSetting(const QString &key) const
Get the settings. This function has to be implemented in a subclass in order to have an effect.
Definition: vproperty.cpp:360
virtual void setSettings(const QMap< QString, QVariant > &settings)
Sets the settings by calling the overloaded setSetting(const QString &key, const QVariant &value) for...
Definition: vproperty.cpp:333