forked from qt-creator/qt-creator
TreeModel: Make root item configurable
This is mainly used to communicate the number of columns and header contents. Change-Id: Ic3163265338d71f1fa8250e4765bb764e5784197 Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -198,6 +198,14 @@ QVariant TreeModel::data(const QModelIndex &idx, int role) const
|
||||
return item ? item->data(idx.column(), role) : QVariant();
|
||||
}
|
||||
|
||||
QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal)
|
||||
return m_root->data(section, role);
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const
|
||||
{
|
||||
TreeItem *item = itemFromIndex(idx);
|
||||
@@ -210,6 +218,12 @@ TreeItem *TreeModel::rootItem() const
|
||||
return m_root;
|
||||
}
|
||||
|
||||
void TreeModel::setRootItem(TreeItem *item)
|
||||
{
|
||||
delete m_root;
|
||||
m_root = item;
|
||||
}
|
||||
|
||||
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
checkIndex(parent);
|
||||
|
||||
@@ -87,8 +87,10 @@ public:
|
||||
QModelIndex index(int, int, const QModelIndex &idx) const;
|
||||
QModelIndex parent(const QModelIndex &idx) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &idx) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
TreeItem *rootItem() const;
|
||||
void setRootItem(TreeItem *item);
|
||||
TreeItem *itemFromIndex(const QModelIndex &) const;
|
||||
QModelIndex indexFromItem(const TreeItem *needle) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user