From 08040a630b6aed8b88246f3ba3ee85d5f7bd3afb Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 10 Sep 2008 00:43:08 +0000 Subject: [FIX] Players now have money [FIX] Some more things added to Arena stuff [FIX] Can now delete objects in the tree in Sigmodr [FIX] Setting Sigmods as dirty is better now git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@258 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- sigmodr/SigmodTreeModel.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'sigmodr/SigmodTreeModel.cpp') diff --git a/sigmodr/SigmodTreeModel.cpp b/sigmodr/SigmodTreeModel.cpp index a2d8f5a0..1e01db61 100644 --- a/sigmodr/SigmodTreeModel.cpp +++ b/sigmodr/SigmodTreeModel.cpp @@ -21,6 +21,9 @@ // Model includes #include "models/RootModel.h" +// Sigmod includes +#include "../sigmod/Sigmod.h" + // Qt includes #include #include @@ -30,6 +33,7 @@ Sigmodr::SigmodTreeModel::SigmodTreeModel(QObject* parent) : QAbstractItemModel(parent), m_root(new RootModel) { + connect(m_root, SIGNAL(rowsChanged(QList)), this, SLOT(rowsChanged(QList))); } Sigmodr::SigmodTreeModel::~SigmodTreeModel() @@ -99,8 +103,12 @@ bool Sigmodr::SigmodTreeModel::setData(const QModelIndex& index, const QVariant& BaseModel* object = static_cast(index.internalPointer()); emit(layoutAboutToBeChanged()); bool success = object->setData(value, role); - emit(dataChanged(index, index)); emit(layoutChanged()); + if (success) + { + emit(dataChanged(index, index)); + emit(dirty(findSigmod(index), true)); + } return success; } @@ -143,17 +151,45 @@ bool Sigmodr::SigmodTreeModel::dropMimeData(const QMimeData* data, Qt::DropActio emit(layoutAboutToBeChanged()); bool success = m_root->setData(data->data("application/x-sigmod+xml"), Sigmodr::BaseModel::XmlRole); emit(layoutChanged()); + if (success) + emit(dirty(findSigmod(parent), true)); return success; } void Sigmodr::SigmodTreeModel::addSigmod(Sigmod::Sigmod* sigmod) { m_root->addSigmod(sigmod); - emit(reset()); + reset(); } void Sigmodr::SigmodTreeModel::deleteSigmod(const Sigmod::Sigmod* sigmod) { m_root->deleteSigmod(sigmod); - emit(reset()); + reset(); +} + +const Sigmod::Sigmod* Sigmodr::SigmodTreeModel::findSigmod(const QModelIndex& index) const +{ + QModelIndex curIndex = index; + QModelIndex parIndex = parent(curIndex); + while (parIndex.isValid()) + { + curIndex = parIndex; + parIndex = parent(curIndex); + } + return qobject_cast(getItem(curIndex)->object()); +} + +void Sigmodr::SigmodTreeModel::rowsChanged(const QList& rows) +{ + QModelIndex curIndex; + foreach (int row, rows) + curIndex = index(row, 0, curIndex); + if (curIndex.isValid()) + { + emit(dataChanged(curIndex, curIndex)); + emit(dirty(findSigmod(curIndex), true)); + } + else + reset(); } -- cgit