return 0;
}
-int AbstractTreeItem::childCount() const {
- return _childItems.count();
+int AbstractTreeItem::childCount(int column) const {
+ if(column > 0)
+ return 0;
+ else
+ return _childItems.count();
}
int AbstractTreeItem::row() const {
this, SLOT(debug_rowsInserted(const QModelIndex &, int, int)));
connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
this, SLOT(debug_rowsRemoved(const QModelIndex &, int, int)));
+ connect(this, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
+ this, SLOT(debug_dataChanged(const QModelIndex &, const QModelIndex &)));
}
}
else
parentItem = static_cast<AbstractTreeItem*>(parent.internalPointer());
- return parentItem->childCount();
+ return parentItem->childCount(parent.column());
}
int TreeModel::columnCount(const QModelIndex &parent) const {
Q_UNUSED(parent)
+ return rootItem->columnCount();
// 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();
+// AbstractTreeItem *parentItem;
+// if(!parent.isValid())
+// parentItem = rootItem;
+// else
+// parentItem = static_cast<AbstractTreeItem*>(parent.internalPointer());
+// return parentItem->columnCount();
}
QVariant TreeModel::data(const QModelIndex &index, int role) const {
}
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();
+ if(!index.isValid()) {
+ return rootItem->flags() & Qt::ItemIsDropEnabled;
+ } else {
+ AbstractTreeItem *item = static_cast<AbstractTreeItem *>(index.internalPointer());
+ return item->flags();
+ }
}
QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const {
qWarning() << "TreeModel::beginRemoveChilds(): cannot append Childs to unknown parent";
return;
}
+
+ for(int i = firstRow; i <= lastRow; i++) {
+ disconnect(parentItem->child(i), 0, this, 0);
+ }
+
+ // consitency checks
QModelIndex parent = indexByItem(parentItem);
Q_ASSERT(firstRow <= lastRow);
Q_ASSERT(parentItem->childCount() > lastRow);
Q_ASSERT(!_aboutToRemoveOrInsert);
-
_aboutToRemoveOrInsert = true;
_childStatus = ChildStatus(parent, rowCount(parent), firstRow, lastRow);
+
beginRemoveRows(parent, firstRow, lastRow);
}
void TreeModel::endRemoveChilds() {
AbstractTreeItem *parentItem = qobject_cast<AbstractTreeItem *>(sender());
if(!parentItem) {
- qWarning() << "TreeModel::endRemoveChilds(): cannot append Childs to unknown parent";
+ qWarning() << "TreeModel::endRemoveChilds(): cannot remove Childs from unknown parent";
return;
}
+
+ // concistency checks
Q_ASSERT(_aboutToRemoveOrInsert);
ChildStatus cs = _childStatus;
QModelIndex parent = indexByItem(parentItem);
Q_ASSERT(cs.parent == parent);
Q_ASSERT(rowCount(parent) == cs.childCount - cs.end + cs.start - 1);
-
_aboutToRemoveOrInsert = false;
+
endRemoveRows();
}
parentItem = static_cast<AbstractTreeItem *>(parent.internalPointer());
if(!parentItem)
parentItem = rootItem;
- qDebug() << "#" << parent << parentItem << parent.data().toString() << rowCount(parent) << start << end;
+ qDebug() << "debug_rowsAboutToBeRemoved" << parent << parentItem << parent.data().toString() << rowCount(parent) << start << end;
QModelIndex child;
AbstractTreeItem *childItem;
parentItem = static_cast<AbstractTreeItem *>(parent.internalPointer());
if(!parentItem)
parentItem = rootItem;
- qDebug() << "#" << parent << parentItem << parent.data().toString() << rowCount(parent) << start << end;
+ qDebug() << "debug_rowsInserted:" << parent << parentItem << parent.data().toString() << rowCount(parent) << start << end;
QModelIndex child;
AbstractTreeItem *childItem;
void TreeModel::debug_rowsRemoved(const QModelIndex &parent, int start, int end) {
qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
}
+
+void TreeModel::debug_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+ qDebug() << "debug_dataChanged" << topLeft << bottomRight;
+ QStringList displayData;
+ for(int row = topLeft.row(); row <= bottomRight.row(); row++) {
+ displayData = QStringList();
+ for(int column = topLeft.column(); column <= bottomRight.column(); column++) {
+ displayData << data(topLeft.sibling(row, column), Qt::DisplayRole).toString();
+ }
+ qDebug() << " row:" << row << displayData;
+ }
+}