32 #include <QStringList> 43 : QAbstractItemModel( parent )
44 , root_property_( root_property )
69 if( !index.isValid() )
74 return property->getViewFlags( index.column() );
79 if( parent_index.isValid() && parent_index.column() != 0 )
88 return createIndex( row, column, child );
98 if( !child_index.isValid() )
100 return QModelIndex();
110 return QModelIndex();
115 return QModelIndex();
127 if( !index.isValid() )
145 if( property->getValue().type() == QVariant::Bool && role == Qt::CheckStateRole )
147 if( property->setValue( value.toInt() != Qt::Unchecked ))
153 if( role != Qt::EditRole )
158 if( property->setValue( value ))
173 if( indexes.count() <= 0 )
178 if( types.isEmpty() )
182 QMimeData *
data =
new QMimeData();
183 QString format = types.at(0);
185 QDataStream stream( &encoded, QIODevice::WriteOnly );
187 QModelIndexList::ConstIterator it = indexes.begin();
188 for( ; it != indexes.end(); ++it )
190 if( (*it).column() == 0 )
192 void* pointer = (*it).internalPointer();
193 stream.writeRawData( (
char*)&pointer,
sizeof(
void* ));
197 data->setData( format, encoded );
209 Qt::DropAction action,
210 int dest_row,
int dest_column,
211 const QModelIndex& dest_parent )
213 if( !data || action != Qt::MoveAction )
218 if( types.isEmpty() )
222 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() ));
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Property * getParent() const
Return the parent Property.
virtual QModelIndex parent(const QModelIndex &index) const
PropertyTreeModel(Property *root_property, QObject *parent=0)
Constructor.
int rowNumberInParent() const
Return the row number of this property within its parent, or -1 if it has no parent.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual ~PropertyTreeModel()
Destructor. Deletes the root property (and thus the entire property tree).
QString drag_drop_class_
Identifier to add to mimeTypes() entry to keep drag/drops from crossing types.
A single element of a property tree, with a name, value, description, and possibly children...
void printPersistentIndices()
For debugging only. Uses printf() to print the property names of current persistent indices...
bool shouldBeSaved() const
Returns true if the property is not read-only AND has data worth saving.
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of rows under the given parent index.
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this Property. ...
void collapse(const QModelIndex &index)
Emitted when a Property wants to collapse (hide its children).
void expand(const QModelIndex &index)
Emitted when a Property wants to expand (display its children).
void beginRemove(Property *parent_property, int row_within_parent, int count=1)
virtual int numChildren() const
Return the number of child objects (Property or otherwise).
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...
QModelIndex parentIndex(const Property *child) const
Same as parent() but taking a Property pointer instead of an index.
virtual QStringList mimeTypes() const
Returns a list with just "application/x-rviz-" plus drag_drop_class_.
virtual QMimeData * mimeData(const QModelIndexList &indexes) const
Override from QAbstractItemModel. Returns a (non-standard) mime-encoded version of the given indexes...
void expandProperty(Property *property)
Expand (show the children of) the given Property.
Property * childAt(int index) const
Return the child Property with the given index, or NULL if the index is out of bounds or if the child...
QModelIndex indexOf(Property *property) const
virtual QVariant data(const QModelIndex &index, int role) const
void setModel(PropertyTreeModel *model)
Set the model managing this Property and all its child properties, recursively.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
void configChanged()
Emitted when a Property which should be saved changes.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual Property * takeChildAt(int index)
Take a child out of the child list, but don't destroy it.
virtual void addChild(Property *child, int index=-1)
Add a child property.
void collapseProperty(Property *property)
Collapse (hide the children of) the given Property.
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int destination_row, int destination_column, const QModelIndex &destination_parent)
Override from QAbstractItemModel. Takes a (non-standard) mime-encoded version of an index list and dr...
void emitDataChanged(Property *property)
void beginInsert(Property *parent_property, int row_within_parent, int count=1)
Property * getProp(const QModelIndex &index) const
return the Property at the given index, or the root property if the index is invalid.
virtual QString getName() const
Return the name of this Property as a QString.
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
Property * root_property_