Go to the documentation of this file.
33 #include <QStringList>
43 : QAbstractItemModel(parent), root_property_(root_property)
73 return property->getViewFlags(
index.column());
78 if (parent_index.isValid() && parent_index.column() != 0)
87 return createIndex(row, column, child);
97 if (!child_index.isValid())
109 return QModelIndex();
122 if (!
index.isValid())
141 if (property->getValue().type() == QVariant::Bool && role == Qt::CheckStateRole)
143 if (property->setValue(value.toInt() != Qt::Unchecked))
149 if (role != Qt::EditRole)
154 if (
index.column() != 0)
155 return property->setValue(value);
156 else if (value.type() == QVariant::String)
158 property->setName(value.toString());
172 if (indexes.count() <= 0)
181 QMimeData*
data =
new QMimeData();
182 const QString& format = types.at(0);
184 QDataStream stream(&encoded, QIODevice::WriteOnly);
186 QModelIndexList::ConstIterator it = indexes.begin();
187 for (; it != indexes.end(); ++it)
189 if ((*it).column() == 0)
191 void* pointer = (*it).internalPointer();
192 stream.writeRawData((
char*)&pointer,
sizeof(
void*));
196 data->setData(format, encoded);
208 Qt::DropAction action,
211 const QModelIndex& dest_parent)
213 if (!
data || action != Qt::MoveAction)
222 const QString& format = types.at(0);
223 if (!
data->hasFormat(format))
227 QByteArray encoded =
data->data(format);
228 QDataStream stream(&encoded, QIODevice::ReadOnly);
232 QList<Property*> source_properties;
235 while (!stream.atEnd())
238 if (
sizeof(
void*) != stream.readRawData((
char*)&pointer,
sizeof(
void*)))
240 printf(
"ERROR: dropped mime data has invalid pointer data.\n");
244 if (prop == dest_parent_property || prop->
isAncestorOf(dest_parent_property))
249 source_properties.append(prop);
256 for (
int i = 0; i < source_properties.size(); i++)
258 Property* prop = source_properties.at(i);
266 if (dest_parent_property == prop->
getParent() && dest_row > source_row)
271 dest_parent_property->
addChild(prop, dest_row);
289 return QModelIndex();
300 QModelIndex left_index =
indexOf(property);
301 QModelIndex right_index = createIndex(left_index.row(), 1, left_index.internalPointer());
302 Q_EMIT dataChanged(left_index, right_index);
311 beginInsertRows(
indexOf(parent_property), row_within_parent, row_within_parent + count - 1);
326 beginRemoveRows(
indexOf(parent_property), row_within_parent, row_within_parent + count - 1);
347 QModelIndexList indexes = persistentIndexList();
348 QModelIndexList::ConstIterator it = indexes.begin();
349 for (; it != indexes.end(); ++it)
351 if (!(*it).isValid())
353 printf(
" invalid index\n");
360 printf(
" null property\n");
364 printf(
" prop name '%s'\n", qPrintable(prop->
getName()));
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void expand(const QModelIndex &index)
Emitted when a Property wants to expand (display its children).
void collapse(const QModelIndex &index)
Emitted when a Property wants to collapse (hide its children).
void expandProperty(Property *property)
Expand (show the children of) the given Property.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int destination_row, int destination_column, const QModelIndex &destination_parent) override
Override from QAbstractItemModel. Takes a (non-standard) mime-encoded version of an index list and dr...
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this Property.
~PropertyTreeModel() override
Destructor. Deletes the root property (and thus the entire property tree).
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
virtual void addChild(Property *child, int index=-1)
Add a child property.
bool shouldBeSaved() const
Returns true if the property has data worth saving.
virtual int numChildren() const
Return the number of child objects (Property or otherwise).
QModelIndex parentIndex(const Property *child) const
Same as parent() but taking a Property pointer instead of an index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Return the number of rows under the given parent index.
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
A single element of a property tree, with a name, value, description, and possibly children.
void emitDataChanged(Property *property, bool emit_config_changed=true)
void configChanged()
Emitted when a Property which should be saved changes.
virtual Property * takeChildAt(int index)
Take a child out of the child list, but don't destroy it.
QModelIndex parent(const QModelIndex &index) const override
QModelIndex indexOf(Property *property) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Property * getParent() const
Return the parent Property.
void printPersistentIndices()
For debugging only. Uses printf() to print the property names of current persistent indices.
void beginInsert(Property *parent_property, int row_within_parent, int count=1)
Property * root_property_
int rowNumberInParent() const
Return the row number of this property within its parent, or -1 if it has no parent.
void beginRemove(Property *parent_property, int row_within_parent, int count=1)
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
QStringList mimeTypes() const override
Returns a list with just "application/x-rviz-" plus drag_drop_class_.
virtual QString getName() const
Return the name of this Property as a QString.
bool isAncestorOf(Property *possible_child) const
Returns true if this is an ancestor of possible_child, meaning is the parent or parent of parent etc.
Qt::ItemFlags flags(const QModelIndex &index) const override
QMimeData * mimeData(const QModelIndexList &indexes) const override
Override from QAbstractItemModel. Returns a (non-standard) mime-encoded version of the given indexes.
QVariant data(const QModelIndex &index, int role) const override
PropertyTreeModel(Property *root_property, QObject *parent=nullptr)
Constructor.
void setModel(PropertyTreeModel *model)
Set the model managing this Property and all its child properties, recursively.
virtual bool getReadOnly() const
Return the read-only-ness of this property.
rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10