diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-05-23 01:07:11 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-05-23 01:07:11 -0400 |
commit | b81b2ae4d0c96b37e442b5c8d2a82d518c50cfff (patch) | |
tree | 4ead6e424bef729cfc1ec97f7f4d3b0496dc3643 /sigmodr/tree/SigmodrTreeModel.cpp | |
parent | 2cc02d1c40fbc340951aa66a2dd1d53409952db3 (diff) | |
download | sigen-b81b2ae4d0c96b37e442b5c8d2a82d518c50cfff.tar.gz sigen-b81b2ae4d0c96b37e442b5c8d2a82d518c50cfff.tar.xz sigen-b81b2ae4d0c96b37e442b5c8d2a82d518c50cfff.zip |
Delete old tree widget files
Diffstat (limited to 'sigmodr/tree/SigmodrTreeModel.cpp')
-rw-r--r-- | sigmodr/tree/SigmodrTreeModel.cpp | 212 |
1 files changed, 0 insertions, 212 deletions
diff --git a/sigmodr/tree/SigmodrTreeModel.cpp b/sigmodr/tree/SigmodrTreeModel.cpp deleted file mode 100644 index 509605d7..00000000 --- a/sigmodr/tree/SigmodrTreeModel.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com> - * - * 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 <http://www.gnu.org/licenses/>. - */ - -// Header include -#include "SigmodrTreeModel.h" - -// Sigmodr tree includes -#include "RootModel.h" - -// Sigmod includes -#include <sigmod/Game.h> - -// Qt includes -#include <QtCore/QMimeData> -#include <QtCore/QStringList> -#include <QtCore/QUrl> -#include <QtXml/QDomDocument> - -using namespace Sigmod; -using namespace Sigmodr::Tree; - -SigmodrTreeModel::SigmodrTreeModel(QObject* parent) : - QAbstractItemModel(parent), - m_root(new RootModel) -{ - connect(m_root, SIGNAL(rowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change)), this, SLOT(rowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change))); -} - -SigmodrTreeModel::~SigmodrTreeModel() -{ - delete m_root; -} - -QVariant SigmodrTreeModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - return QVariant(); - return static_cast<BaseModel*>(index.internalPointer())->data(role); -} - -QModelIndex SigmodrTreeModel::index(int row, int column, const QModelIndex& parent) const -{ - if ((row < -1) || (column < -1)) - return QModelIndex(); - if (row == -1) - return createIndex(row, 0, m_root); - BaseModel* model = getItem(parent); - if ((model->rowCount() <= row) || (1 <= column)) - return QModelIndex(); - return createIndex(row, 0, model->childItem(row)); -} - -QModelIndex SigmodrTreeModel::parent(const QModelIndex& index) const -{ - if (!index.isValid()) - return QModelIndex(); - BaseModel* parent = static_cast<BaseModel*>(index.internalPointer())->parent(); - if (!parent || (parent == m_root)) - return QModelIndex(); - return createIndex(parent->indexNumber(), 0, parent); -} - -int SigmodrTreeModel::rowCount(const QModelIndex& parent) const -{ - return getItem(parent)->rowCount(); -} - -int SigmodrTreeModel::columnCount(const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return 1; -} - -Qt::ItemFlags SigmodrTreeModel::flags(const QModelIndex& index) const -{ - Qt::ItemFlags flags = QAbstractItemModel::flags(index); - if (index.isValid()) - flags |= static_cast<BaseModel*>(index.internalPointer())->flags(); - return flags; -} - -bool SigmodrTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid()) - return false; - emit(layoutAboutToBeChanged()); - bool success = static_cast<BaseModel*>(index.internalPointer())->setData(value, role); - emit(layoutChanged()); - if (success) - { - emit(dataChanged(index, index)); - emit(dirty(findGame(index), true)); - } - return success; -} - -BaseModel* SigmodrTreeModel::getItem(const QModelIndex& index) const -{ - if (index.isValid()) - return static_cast<BaseModel*>(index.internalPointer()); - return m_root; -} - -QStringList SigmodrTreeModel::mimeTypes() const -{ - return QStringList() << "application/x-sigmod+xml" << "text/uri-list"; -} - -QMimeData* SigmodrTreeModel::mimeData(const QModelIndexList& indexes) const -{ - QMimeData *mimeData = new QMimeData; - if ((indexes.size() == 1) && indexes[0].isValid()) - { - QDomDocument xml; - xml.setContent(data(indexes[0], BaseModel::XmlRole).toString()); - mimeData->setData("application/x-sigmod+xml", xml.toByteArray()); - } - return mimeData; -} - -bool SigmodrTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) -{ - Q_UNUSED(row) - Q_UNUSED(column) - if (action == Qt::IgnoreAction) - return true; - QString format; - bool success = false; - if (data->hasFormat("application/x-sigmod+xml")) - { - QByteArray mimeData = data->data("application/x-sigmod+xml"); - emit(layoutAboutToBeChanged()); - success = parent.isValid() ? setData(parent, mimeData, BaseModel::XmlRole) : m_root->setData(mimeData, BaseModel::XmlRole); - emit(layoutChanged()); - } - else if (data->hasFormat("text/uri-list")) - { - QList<QUrl> urls = data->urls(); - foreach (const QUrl& url, urls) - { - emit(layoutAboutToBeChanged()); - success = parent.isValid() ? setData(parent, url.toEncoded(), BaseModel::XmlRole) : m_root->setData(url.toEncoded(), BaseModel::XmlRole); - emit(layoutChanged()); - } - } - if (success) - emit(dirty(findGame(parent), true)); - return success; -} - -void SigmodrTreeModel::addGame(Game* game) -{ - m_root->addGame(game); - reset(); -} - -void SigmodrTreeModel::deleteGame(const Game* game) -{ - m_root->deleteGame(game); - reset(); -} - -const Game* SigmodrTreeModel::findGame(const QModelIndex& index) const -{ - QModelIndex curIndex = index; - QModelIndex parIndex = parent(curIndex); - while (parIndex.isValid()) - { - curIndex = parIndex; - parIndex = parent(curIndex); - } - return qobject_cast<const Game*>(getItem(curIndex)->object()); -} - -void SigmodrTreeModel::rowsChanged(const QList<int>& rows, const BaseModel::Change change) -{ - QModelIndex curIndex; - foreach (int row, rows) - curIndex = index(row, 0, curIndex); - if (curIndex.isValid()) - { - switch (change) - { - case BaseModel::Addition: - insertRow(rows.back(), parent(curIndex)); - break; - case BaseModel::Removal: - removeRow(rows.back(), parent(curIndex)); - break; - } - emit(layoutAboutToBeChanged()); - emit(layoutChanged()); - emit(dataChanged(curIndex, curIndex)); - emit(dirty(findGame(curIndex), true)); - } - else - reset(); -} |