diff options
Diffstat (limited to 'sigmodr/SigmodTreeModel.cpp')
| -rw-r--r-- | sigmodr/SigmodTreeModel.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
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 <QtCore/QMimeData> #include <QtCore/QStringList> @@ -30,6 +33,7 @@ Sigmodr::SigmodTreeModel::SigmodTreeModel(QObject* parent) : QAbstractItemModel(parent), m_root(new RootModel) { + connect(m_root, SIGNAL(rowsChanged(QList<int>)), this, SLOT(rowsChanged(QList<int>))); } Sigmodr::SigmodTreeModel::~SigmodTreeModel() @@ -99,8 +103,12 @@ bool Sigmodr::SigmodTreeModel::setData(const QModelIndex& index, const QVariant& BaseModel* object = static_cast<BaseModel*>(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<const Sigmod::Sigmod*>(getItem(curIndex)->object()); +} + +void Sigmodr::SigmodTreeModel::rowsChanged(const QList<int>& 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(); } |
