From 7bfa5c29faf7f593b81e6917f81364da1837a73a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 1 May 2009 22:27:01 -0400 Subject: Basic model for the new tree --- sigmodr/tree/TreeModel.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 sigmodr/tree/TreeModel.cpp (limited to 'sigmodr/tree/TreeModel.cpp') diff --git a/sigmodr/tree/TreeModel.cpp b/sigmodr/tree/TreeModel.cpp new file mode 100644 index 00000000..801fbdb7 --- /dev/null +++ b/sigmodr/tree/TreeModel.cpp @@ -0,0 +1,99 @@ +/* + * Copyright 2009 Ben Boeckel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "TreeModel.h" + +// Sigmodr tree includes +#include "RootTreeItem.h" + +using namespace Sigmodr::Tree; + +TreeModel::TreeModel(QObject* parent) : + QAbstractItemModel(parent) +{ +} + +TreeModel::~TreeModel() +{ + delete m_root; +} + +QVariant TreeModel::data(const QModelIndex& index, const int role) const +{ +} + +QModelIndex TreeModel::index(const int row, const int column, const QModelIndex& parent) const +{ + if (!parent.isValid()) + return QModelIndex(); + TreeItem* item = static_cast(parent.internalPointer()); + if (column || (row < 0) || (item->childCount() <= row)) + return QModelIndex(); + return createIndex(row, 0, item->childAt(row)); +} + +QModelIndex TreeModel::parent(const QModelIndex& child) const +{ + if (!child.isValid()) + return QModelIndex(); + TreeItem* item = static_cast(child.internalPointer()); + return createIndex(item->row(), 0, item->parent()); +} + +bool TreeModel::hasChildren(const QModelIndex& parent) const +{ + if (!parent.isValid()) + return false; + TreeItem* item = static_cast(parent.internalPointer()); + return item->childCount(); +} + +int TreeModel::rowCount(const QModelIndex& parent) const +{ + if (!parent.isValid()) + return 0; + return static_cast(parent.internalPointer())->childCount(); +} + +int TreeModel::columnCount(const QModelIndex& parent) const +{ + return 1; +} + +Qt::ItemFlags TreeModel::flags(const QModelIndex& index) const +{ + if (!index.isValid()) + return Qt::ItemFlags(); + return static_cast(index.internalPointer())->flags(); +} + +QStringList TreeModel::mimeTypes() const +{ +} + +QMimeData* TreeModel::mimeData(const QModelIndexList& indexes) const +{ +} + +bool TreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, const int row, const int column, const QModelIndex& parent) +{ +} + +Qt::DropActions TreeModel::supportedDropActions() const +{ +} -- cgit