25 #include <QItemEditorFactory>
28 #include <QMetaProperty>
30 #include <QStandardItemEditorCreator>
53 while (!d_ptr->Children.isEmpty())
55 VProperty *tmpChild = d_ptr->Children.takeLast();
70 if (column == DPC_Name && Qt::DisplayRole == role)
72 return QVariant(d_ptr->Name);
74 else if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
76 return d_ptr->VariantValue;
78 else if (Qt::ToolTipRole == role)
80 return QVariant(d_ptr->Description);
88 bool tmpResult =
false;
89 if (Qt::EditRole == role)
91 tmpResult = (d_ptr->VariantValue != data);
99 const QAbstractItemDelegate *)
const
106 const QAbstractItemDelegate *)
108 QItemEditorFactory *factory =
new QItemEditorFactory;
109 QItemEditorCreatorBase *lineCreator =
new QStandardItemEditorCreator<QLineEdit>();
110 factory->registerEditor(QVariant::String, lineCreator);
111 QItemEditorFactory::setDefaultFactory(factory);
113 d_ptr->editor = factory->createEditor(
static_cast<int>(d_ptr->PropertyVariantType), parent);
114 return d_ptr->editor;
124 QByteArray n = editor->metaObject()->userProperty().name();
128 editor->blockSignals(
true);
129 editor->setProperty(n, d_ptr->VariantValue);
130 editor->blockSignals(
false);
145 QByteArray n = editor->metaObject()->userProperty().name();
149 return editor->property(n);
158 if (column == DPC_Name)
160 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
162 else if (column == DPC_Data)
164 return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
167 return Qt::NoItemFlags;
173 d_ptr->VariantValue = value;
174 d_ptr->VariantValue.convert(
static_cast<int>(d_ptr->PropertyVariantType));
175 if (d_ptr->editor !=
nullptr)
177 setEditorData(d_ptr->editor);
183 return d_ptr->VariantValue;
189 return getValue().toString();
194 setValue(QVariant(value));
212 d_ptr->Description = desc;
218 return d_ptr->Description;
224 return d_ptr->Children;
230 return d_ptr->Children;
236 if (row >= 0 && row < getRowCount())
238 return d_ptr->Children.at(row);
247 return d_ptr->Children.count();
253 return d_ptr->Parent;
259 if (d_ptr->Parent == parent)
265 d_ptr->Parent = parent;
272 if (d_ptr->Parent && d_ptr->Parent->getChildRow(
this) == -1)
274 d_ptr->Parent->addChild(
this);
285 if (!d_ptr->Children.contains(child) && child !=
nullptr)
287 d_ptr->Children.push_back(child);
288 return d_ptr->Children.count()-1;
292 return d_ptr->Children.indexOf(child);
299 d_ptr->Children.removeAll(child);
310 return d_ptr->Children.indexOf(child);
316 return d_ptr->updateParent;
322 return d_ptr->UpdateChildren;
328 d_ptr->updateParent = update_parent;
329 d_ptr->UpdateChildren = update_children;
336 for (; tmpIterator != settings.constEnd(); ++tmpIterator)
338 setSetting(tmpIterator.key(), tmpIterator.value());
346 QStringList tmpKeyList = getSettingKeys();
347 foreach(
const QString &tmpKey, tmpKeyList)
348 tmpResult.insert(tmpKey, getSetting(tmpKey));
369 return QStringList();
376 container =
new VProperty(getName(), d_ptr->PropertyVariantType);
386 if (include_children)
388 foreach(
VProperty *tmpChild, d_ptr->Children)
413 Q_UNUSED(typeForParent)
virtual ~UserChangeEvent() Q_DECL_OVERRIDE
virtual ~VPropertyPrivate()
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
virtual void setUpdateBehaviour(bool update_parent, bool update_children)
Sets whether the views should update Parents or children after this property changes.
virtual Qt::ItemFlags flags(int column=DPC_Name) const
Returns item flags.
virtual bool setData(const QVariant &data, int role=Qt::EditRole)
This is used by the model to set the data.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const
Get the data how it should be displayed.
virtual bool getUpdateParent() const
Returns whether the views have to update the parent of this property if it changes.
virtual void setSetting(const QString &key, const QVariant &value)
Sets the settings. This function has to be implemented in a subclass in order to have an effect.
virtual QVariant getValue() const
Returns the value of the property as a QVariant.
virtual int getRowCount() const
Gets the number of children.
virtual QStringList getSettingKeys() const
Returns the list of keys of the property's settings.
virtual void removeChild(VProperty *child)
Removes a child from the children list, doesn't delete the child!
virtual QString getName() const
Gets the name of the property.
virtual void setDescription(const QString &desc)
Sets the name of the property.
virtual bool setEditorData(QWidget *editor)
Sets the property's data to the editor (returns false, if the standard delegate should do that)
virtual void setValue(const QVariant &value)
Sets the value of the property.
virtual QString getDescription() const
Gets the name of the property.
void setPropertyType(const Property &type)
virtual QString serialize() const
Serializes the value to a string.
virtual VProperty * getParent() const
Gets the parent of this property.
virtual QVariant getEditorData(const QWidget *editor) const
Gets the data from the widget.
virtual int addChild(VProperty *child)
Adds a child to this property.
virtual void childValueChanged(const QVariant &value, int typeForParent)
virtual int getChildRow(VProperty *child) const
Returns the row the child has.
virtual void updateParent(const QVariant &value)
virtual bool paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &, const QAbstractItemDelegate *) const
This is called by the delegate when the property value is being drawn. The standard implementation do...
virtual QMap< QString, QVariant > getSettings() const
Get the settings.
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.
Property propertyType() const
virtual void setSettings(const QMap< QString, QVariant > &settings)
Sets the settings by calling the overloaded setSetting(const QString &key, const QVariant &value) for...
virtual VProperty * getChild(int row) const
Returns the child at a certain row.
virtual bool getUpdateChildren() const
Returns whether the views have to update the children of this property if it changes.
VProperty(const QString &name, QVariant::Type type=QVariant::String)
Standard constructor, takes a name and a parent property as argument.
virtual ~VProperty() Q_DECL_OVERRIDE
Destructor.
virtual void setParent(VProperty *parent)
Sets the parent of this property.
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QAbstractItemDelegate *)
Returns an editor widget, or NULL if it doesn't supply one.
virtual void setName(const QString &name)
Sets the name of the property.
virtual QList< VProperty * > & getChildren()
Returns a reference to the list of children.
virtual QString type() const
Returns a string containing the type of the property.
virtual void deserialize(const QString &value)
Deserializes the value from a string.