Commit a8ece5e9 authored by hjk's avatar hjk

TreeModel: Make root item configurable

This is mainly used to communicate the number of columns and
header contents.

Change-Id: Ic3163265338d71f1fa8250e4765bb764e5784197
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent e822d570
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment