diff options
| -rw-r--r-- | smtreemodel.cpp | 14 | ||||
| -rw-r--r-- | smtreemodel.h | 3 | 
2 files changed, 16 insertions, 1 deletions
| diff --git a/smtreemodel.cpp b/smtreemodel.cpp index 2c7a2d6..fe5482c 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -39,6 +39,20 @@ QModelIndex SmTreeModel::index(int row, int column, const QModelIndex &parent) c  	return QModelIndex();  } +QModelIndex SmTreeModel::parent(const QModelIndex &child) const{ +	if(!child.isValid()){ +		return QModelIndex(); +	} + +	SmTreeItem *childItem = itemAt(child); +	SmTreeItem *parentItem = childItem->parent(); + +	if(parentItem == mRootItem){ +		return QModelIndex(); +	} +	return createIndex(parentItem->row(), 0, parentItem); +} +  Qt::ItemFlags SmTreeModel::flags(const QModelIndex &index) const{  	if(!index.isValid()){  		return 0; diff --git a/smtreemodel.h b/smtreemodel.h index 46f852f..698a2ce 100644 --- a/smtreemodel.h +++ b/smtreemodel.h @@ -23,8 +23,9 @@ class SmTreeModel : public QAbstractItemModel {  		int rowCount(const QModelIndex &parent) const;  		int columnCount(const QModelIndex &parent) const; -		// index and flags +		// index, parent and flags  		QModelIndex index(int row, int column, const QModelIndex &parent) const; +		QModelIndex parent(const QModelIndex &child) const;  		Qt::ItemFlags flags(const QModelIndex &index) const;  		// headers + data | 
