-int TreeModel::columnCount(const QModelIndex &parent) const {
- Q_UNUSED(parent)
- // since there the Qt Views don't draw more columns than the header has columns
- // we can be lazy and simply return the count of header columns
- // actually this gives us more freedom cause we don't have to ensure that a rows parent
- // has equal or more columns than that row
-
-// if(parent.isValid()) {
-// AbstractTreeItem *child;
-// if(child = static_cast<AbstractTreeItem *>(parent.internalPointer())->child(parent.column(), parent.row()))
-// return child->columnCount();
-// else
-// return static_cast<AbstractTreeItem*>(parent.internalPointer())->columnCount();
-// } else {
-// return rootItem->columnCount();
-// }
-
- return rootItem->columnCount();
-}
-
-QVariant TreeModel::data(const QModelIndex &index, int role) const {
- if(!index.isValid())
- return QVariant();
-
- AbstractTreeItem *item = static_cast<AbstractTreeItem*>(index.internalPointer());
- return item->data(index.column(), role);
-}
-
-Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const {
- AbstractTreeItem *item;
- if(!index.isValid())
- item = rootItem;
- else
- item = static_cast<AbstractTreeItem *>(index.internalPointer());
- return item->flags();
-}
-
-QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const {
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
- return rootItem->data(section, role);
- else
- return QVariant();
-}
-
-void TreeModel::itemDataChanged(int column) {
- AbstractTreeItem *item = qobject_cast<AbstractTreeItem *>(sender());
- QModelIndex leftIndex, rightIndex;
-
- if(item == rootItem)
- return;
-
- if(column == -1) {
- leftIndex = createIndex(item->row(), 0, item);
- rightIndex = createIndex(item->row(), item->columnCount()-1, item);
- } else {
- leftIndex = createIndex(item->row(), column, item);
- rightIndex = leftIndex;
- }
-
- emit dataChanged(leftIndex, rightIndex);
-}
-
-void TreeModel::appendChild(AbstractTreeItem *parent, AbstractTreeItem *child) {
- if(parent == 0 || child == 0) {
- qWarning() << "TreeModel::appendChild(parent, child) parent and child have to be valid pointers!" << parent << child;
- return;
- }
-
- int nextRow = parent->childCount();
- beginInsertRows(indexByItem(parent), nextRow, nextRow);
- parent->appendChild(child);
- endInsertRows();