+ connect(item, SIGNAL(beginAppendChilds(int, int)),
+ this, SLOT(beginAppendChilds(int, int)));
+ connect(item, SIGNAL(endAppendChilds()),
+ this, SLOT(endAppendChilds()));
+
+ connect(item, SIGNAL(beginRemoveChilds(int, int)),
+ this, SLOT(beginRemoveChilds(int, int)));
+ connect(item, SIGNAL(endRemoveChilds()),
+ this, SLOT(endRemoveChilds()));
+}
+
+void TreeModel::beginAppendChilds(int firstRow, int lastRow) {
+ AbstractTreeItem *parentItem = qobject_cast<AbstractTreeItem *>(sender());
+ if(!parentItem) {
+ qWarning() << "TreeModel::beginAppendChilds(): cannot append Childs to unknown parent";
+ return;
+ }
+
+ QModelIndex parent = indexByItem(parentItem);
+ Q_ASSERT(!_aboutToRemoveOrInsert);
+
+ _aboutToRemoveOrInsert = true;
+ _childStatus = ChildStatus(parent, rowCount(parent), firstRow, lastRow);
+ beginInsertRows(parent, firstRow, lastRow);
+}
+
+void TreeModel::endAppendChilds() {
+ AbstractTreeItem *parentItem = qobject_cast<AbstractTreeItem *>(sender());
+ if(!parentItem) {
+ qWarning() << "TreeModel::endAppendChilds(): cannot append Childs to unknown parent";
+ return;
+ }
+ 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;
+ for(int i = cs.start; i <= cs.end; i++) {
+ connectItem(parentItem->child(i));
+ }
+ endInsertRows();
+}
+
+void TreeModel::beginRemoveChilds(int firstRow, int lastRow) {
+ AbstractTreeItem *parentItem = qobject_cast<AbstractTreeItem *>(sender());
+ if(!parentItem) {
+ 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);