31 : QAbstractItemModel(parent), d_ptr(d)
43 delete d_ptr->Properties;
55 if (!d_ptr->Properties)
62 VProperty* tmpParent = getProperty(parentid);
63 int tmpRow = tmpParent !=
nullptr ? tmpParent->
getRowCount() : d_ptr->Properties->getRootPropertyCount();
64 beginInsertRows((tmpParent !=
nullptr ? getIndexFromProperty(tmpParent) : QModelIndex()), tmpRow, tmpRow);
67 d_ptr->Properties->addProperty(property,
id, parentid);
84 if (addProperty(tmpProp,
id, parentid))
95 return d_ptr->Properties !=
nullptr ? d_ptr->Properties->getProperty(
id) :
nullptr;
101 if (d_ptr->Properties ==
nullptr || (parent.isValid() && parent.column() > 1))
103 return QModelIndex();
106 if (parent.isValid())
109 VProperty* parentItem = getProperty(parent);
115 return createIndex(row, column, childItem);
119 else if (row >= 0 && row < d_ptr->
Properties->count())
121 return createIndex(row, column, d_ptr->Properties->getRootProperty(row));
124 return QModelIndex();
130 if (!index.isValid())
132 return QModelIndex();
135 VProperty* childItem = getProperty(index);
142 int parents_row = grandParentItem !=
nullptr ? grandParentItem->
getChildRow(parentItem)
143 : d_ptr->Properties->getRootProperties().indexOf(parentItem);
145 if (parents_row >= 0)
147 return createIndex(parents_row, 0, parentItem);
152 return QModelIndex();
158 VProperty* tmpProperty = getProperty(index);
161 return Qt::NoItemFlags;
164 return tmpProperty->
flags(index.column());
170 VProperty* tmpProperty = getProperty(index);
171 if (index.column() == 1 && tmpProperty)
173 bool tmpHasChanged = tmpProperty->
setData(value, role);
176 QModelIndex tmpParentIndex = parent(index);
177 emit dataChanged(tmpParentIndex, tmpParentIndex);
182 emit onDataChangedByEditor(tmpProperty);
194 VProperty* tmpProperty = getProperty(index);
200 return tmpProperty->
data(index.column(), role);
206 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
211 return d_ptr->HeadlineProperty;
213 else if (section == 1)
215 return d_ptr->HeadlineValue;
218 else if (role == Qt::DisplayRole)
220 return QVariant(section);
230 if (parent.isValid())
232 VProperty* tmpParent = getProperty(parent);
240 if (d_ptr->Properties)
242 return d_ptr->Properties->getRootPropertyCount();
274 return d_ptr->Properties !=
nullptr ? d_ptr->Properties->getPropertyID(prop) : QString();
279 if (!property || column > columnCount() || column < 0)
281 return QModelIndex();
292 return createIndex(row, column, property);
298 QModelIndex tmpIndex = getIndexFromProperty(property, 1);
299 if (tmpIndex.isValid())
301 emit dataChanged(tmpIndex, tmpIndex);
302 emit onDataChangedByEditor(property);
308 return d_ptr->Properties;
313 setPropertySet(
nullptr, emit_signals);
322 emit beginResetModel();
324 d_ptr->Properties = new_property_set;
327 emit endResetModel();
330 return tmpOldPropertySet;
335 VPropertySet* tmpOldPropertySet = takePropertySet(property_set, emit_signals);
336 delete tmpOldPropertySet;
341 QModelIndex tmpIndex = getIndexFromProperty(getProperty(
id));
342 if (d_ptr->Properties && tmpIndex.isValid())
344 beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row());
345 VProperty* tmpProp = d_ptr->Properties->takeProperty(
id);
355 QModelIndex tmpIndex = getIndexFromProperty(getProperty(
id));
356 if (d_ptr->Properties && tmpIndex.isValid())
358 beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row());
359 d_ptr->Properties->removeProperty(
id);
virtual QModelIndex getIndexFromProperty(VProperty *property, int column=0) const
Gets a property by its ModelIndex.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Returns the number of columns.
virtual Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE
Returns the item flags for the given index.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Returns the data of an model index.
void onDataChangedByModel(VProperty *property)
This function causes the views to update the property.
virtual ~VPropertyModel() Q_DECL_OVERRIDE
VPropertyModel(QObject *parent=nullptr)
virtual VProperty * createProperty(const QString &id, const QString &name, const QString &parentid=QString(), const QVariant &data=QVariant())
Creates a property and adds it to the model.
virtual QString getPropertyID(const VProperty *prop) const
Returns the ID of the property within the model The concept of property IDs is, that the object that ...
virtual void removeProperty(const QString &id)
Removes a property from the model and deletes it.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Returns the data for the given role and section in the header with the specified orientation.
virtual VPropertySet * takePropertySet(VPropertySet *new_property_set=nullptr, bool emit_signals=true)
Removes the current property set and returns it. If new_property_set is set, the old one will be repl...
virtual void setPropertySet(VPropertySet *property_set, bool emit_signals=true)
Sets a new property set. The model will take ownership of the property set. The old property set will...
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Returns the number of rows.
virtual bool addProperty(VProperty *property, const QString &id, const QString &parentid=QString(), bool emitsignals=true)
Adds the property to the model and attaches it to the parentid.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Returns the model index at row/column.
virtual VProperty * takeProperty(const QString &id)
Removes a property from the model and returns it.
virtual VProperty * getProperty(const QString &id)
Gets a property by it's ID.
virtual void clear(bool emit_signals=true)
Clears the model, deletes the property set managed by this model.
virtual QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE
Returns the parent of one model index.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) Q_DECL_OVERRIDE
Sets the role data for the item at index to value.
virtual const VPropertySet * getPropertySet() const
Returns a const pointer to the property set managed by this model. If you want to manipulate the prop...
VPropertySet is a simple class for managing a set of properties. If you don't need all the Model-func...
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 int getRowCount() const
Gets the number of children.
virtual void setValue(const QVariant &value)
Sets the value of the property.
virtual VProperty * getParent() const
Gets the parent of this property.
virtual int getChildRow(VProperty *child) const
Returns the row the child has.
virtual VProperty * getChild(int row) const
Returns the child at a certain row.