-TreeModel::TreeModel(const QList<QVariant> &data, QObject *parent) : QAbstractItemModel(parent) {
- rootItem = new TreeItem(data, 0);
-}
-
-TreeModel::~TreeModel() {
- delete rootItem;
-}
-
-QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const {
- if(!hasIndex(row, column, parent))
- return QModelIndex();
-
- TreeItem *parentItem;
-
- if(!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<TreeItem*>(parent.internalPointer());
-
- TreeItem *childItem = parentItem->child(row);
- if(childItem)
- return createIndex(row, column, childItem);
- else
- return QModelIndex();
-}
-
-QModelIndex TreeModel::parent(const QModelIndex &index) const {
- if(!index.isValid())
- return QModelIndex();
-
- TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
- TreeItem *parentItem = childItem->parent();
-
- if(parentItem == rootItem)
- return QModelIndex();
-
- return createIndex(parentItem->row(), 0, parentItem);
-}
-
-int TreeModel::rowCount(const QModelIndex &parent) const {
- TreeItem *parentItem;
- if(parent.column() > 0)
- return 0;
-
- if(!parent.isValid())
- parentItem = rootItem;
- else
- parentItem = static_cast<TreeItem*>(parent.internalPointer());
-
- return parentItem->childCount();
-}
-
-int TreeModel::columnCount(const QModelIndex &parent) const {
- if(parent.isValid())
- return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
- else
+TreeModel::TreeModel(const QList<QVariant> &data, QObject *parent)
+ : QAbstractItemModel(parent),
+ _childStatus(QModelIndex(), 0, 0, 0),
+ _aboutToRemoveOrInsert(false)
+{
+ rootItem = new SimpleTreeItem(data, 0);
+ connectItem(rootItem);
+
+ if (Quassel::isOptionSet("debugmodel")) {
+ connect(this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
+ this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int)));
+ connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
+ this, SLOT(debug_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
+ connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ 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 &)));
+ }
+}
+
+
+TreeModel::~TreeModel()
+{
+ delete rootItem;
+}
+
+
+QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const
+{
+ if (row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent))
+ return QModelIndex();
+
+ AbstractTreeItem *parentItem;
+
+ if (!parent.isValid())
+ parentItem = rootItem;
+ else
+ parentItem = static_cast<AbstractTreeItem *>(parent.internalPointer());
+
+ AbstractTreeItem *childItem = parentItem->child(row);
+
+ if (childItem)
+ return createIndex(row, column, childItem);
+ else
+ return QModelIndex();
+}
+
+
+QModelIndex TreeModel::indexByItem(AbstractTreeItem *item) const
+{
+ if (item == 0) {
+ qWarning() << "TreeModel::indexByItem(AbstractTreeItem *item) received NULL-Pointer";
+ return QModelIndex();
+ }
+
+ if (item == rootItem)
+ return QModelIndex();
+ else
+ return createIndex(item->row(), 0, item);
+}
+
+
+QModelIndex TreeModel::parent(const QModelIndex &index) const
+{
+ if (!index.isValid()) {
+ // ModelTest does this
+ // qWarning() << "TreeModel::parent(): has been asked for the rootItems Parent!";
+ return QModelIndex();
+ }
+
+ AbstractTreeItem *childItem = static_cast<AbstractTreeItem *>(index.internalPointer());
+ AbstractTreeItem *parentItem = childItem->parent();
+
+ Q_ASSERT(parentItem);
+ if (parentItem == rootItem)
+ return QModelIndex();
+
+ return createIndex(parentItem->row(), 0, parentItem);
+}
+
+
+int TreeModel::rowCount(const QModelIndex &parent) const
+{
+ AbstractTreeItem *parentItem;
+ if (!parent.isValid())
+ parentItem = rootItem;
+ else
+ parentItem = static_cast<AbstractTreeItem *>(parent.internalPointer());
+
+ return parentItem->childCount(parent.column());
+}
+
+
+int TreeModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent)