+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();
+
+ connect(child, SIGNAL(dataChanged(int)),
+ this, SLOT(itemDataChanged(int)));
+
+ connect(child, SIGNAL(newChild(AbstractTreeItem *)),
+ this, SLOT(newChild(AbstractTreeItem *)));
+
+ connect(child, SIGNAL(beginRemoveChilds(int, int)),
+ this, SLOT(beginRemoveChilds(int, int)));
+
+ connect(child, SIGNAL(endRemoveChilds()),
+ this, SLOT(endRemoveChilds()));
+}
+
+void TreeModel::newChild(AbstractTreeItem *child) {
+ appendChild(static_cast<AbstractTreeItem *>(sender()), child);
+}
+
+void TreeModel::beginRemoveChilds(int firstRow, int lastRow) {
+ QModelIndex parent = indexByItem(static_cast<AbstractTreeItem *>(sender()));
+ beginRemoveRows(parent, firstRow, lastRow);
+}
+
+void TreeModel::endRemoveChilds() {
+ endRemoveRows();
+}
+