diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-04-19 01:09:45 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-04-19 01:09:45 -0400 |
| commit | c00fb11482ec7c103f05eb9ac8a210242064024a (patch) | |
| tree | 7705b3635210c5f0fb09f80abf4f520ba06a208c | |
| parent | afef610298a2803877e79fc1f781f224ca90b832 (diff) | |
Add how the model changed in signals and slots for notification of changes
| -rw-r--r-- | sigmodr/tree/BaseModel.cpp | 8 | ||||
| -rw-r--r-- | sigmodr/tree/BaseModel.h | 14 | ||||
| -rw-r--r-- | sigmodr/tree/GroupModel.cpp | 6 | ||||
| -rw-r--r-- | sigmodr/tree/GroupObjectModel.cpp | 6 | ||||
| -rw-r--r-- | sigmodr/tree/SigmodrTreeModel.cpp | 13 | ||||
| -rw-r--r-- | sigmodr/tree/SigmodrTreeModel.h | 2 |
6 files changed, 32 insertions, 17 deletions
diff --git a/sigmodr/tree/BaseModel.cpp b/sigmodr/tree/BaseModel.cpp index 3981e923..0dceeaa4 100644 --- a/sigmodr/tree/BaseModel.cpp +++ b/sigmodr/tree/BaseModel.cpp @@ -128,16 +128,16 @@ bool BaseModel::loadFromData(const QString& data, QDomDocument* xml) const return loaded; } -void BaseModel::childRowChanged(const int row) +void BaseModel::childRowChanged(const int row, const Change change) { QList<int> indexes; indexes << indexNumber() << row; - emit(rowsChanged(indexes)); + emit(rowsChanged(indexes, change)); } -void BaseModel::childRowsChanged(const QList<int>& rows) +void BaseModel::childRowsChanged(const QList<int>& rows, const Change change) { QList<int> indexes; indexes << indexNumber() << rows; - emit(rowsChanged(indexes)); + emit(rowsChanged(indexes, change)); } diff --git a/sigmodr/tree/BaseModel.h b/sigmodr/tree/BaseModel.h index e17c8696..a37bddb2 100644 --- a/sigmodr/tree/BaseModel.h +++ b/sigmodr/tree/BaseModel.h @@ -43,6 +43,12 @@ class SIGMODRTREE_NO_EXPORT BaseModel : public QObject Q_OBJECT public: + enum Change + { + Addition = 0, + Removal = 1 + }; + BaseModel(BaseModel* parent, Sigmod::Object* object, const QString& name = ""); virtual ~BaseModel(); @@ -73,8 +79,8 @@ class SIGMODRTREE_NO_EXPORT BaseModel : public QObject static const int WidgetRole; static const int ContextMenuRole; signals: - void rowChanged(const int row); - void rowsChanged(const QList<int>& rows); + void rowChanged(const int row, const Sigmodr::Tree::BaseModel::Change change); + void rowsChanged(const QList<int>& rows, const Sigmodr::Tree::BaseModel::Change change); protected: virtual int findChild(BaseModel* model) const = 0; @@ -82,8 +88,8 @@ class SIGMODRTREE_NO_EXPORT BaseModel : public QObject Sigmod::Object* m_object; QString m_name; protected slots: - void childRowChanged(const int row); - void childRowsChanged(const QList<int>& rows); + void childRowChanged(const int row, const Sigmodr::Tree::BaseModel::Change change); + void childRowsChanged(const QList<int>& rows, const Sigmodr::Tree::BaseModel::Change change); }; } } diff --git a/sigmodr/tree/GroupModel.cpp b/sigmodr/tree/GroupModel.cpp index c339f9c7..9d14aaef 100644 --- a/sigmodr/tree/GroupModel.cpp +++ b/sigmodr/tree/GroupModel.cpp @@ -71,10 +71,10 @@ Qt::DropActions GroupModel::supportedDropActions() const void GroupModel::addChild(BaseModel* model) { - connect(model, SIGNAL(rowChanged(int)), this, SLOT(childRowChanged(int))); - connect(model, SIGNAL(rowsChanged(QList<int>)), this, SLOT(childRowsChanged(QList<int>))); + connect(model, SIGNAL(rowChanged(int, Sigmodr::Tree::BaseModel::Change)), this, SLOT(childRowChanged(int, Sigmodr::Tree::BaseModel::Change))); + connect(model, SIGNAL(rowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change)), this, SLOT(childRowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change))); m_objects.append(model); - emit(rowChanged(m_objects.size() - 1)); + emit(rowChanged(m_objects.size() - 1, Addition)); } int GroupModel::findChild(BaseModel* model) const diff --git a/sigmodr/tree/GroupObjectModel.cpp b/sigmodr/tree/GroupObjectModel.cpp index 982a4885..50bde62c 100644 --- a/sigmodr/tree/GroupObjectModel.cpp +++ b/sigmodr/tree/GroupObjectModel.cpp @@ -50,10 +50,10 @@ BaseModel* GroupObjectModel::childItem(const int row) void GroupObjectModel::addChild(BaseModel* model) { - connect(model, SIGNAL(rowChanged(int)), this, SLOT(childRowChanged(int))); - connect(model, SIGNAL(rowsChanged(QList<int>)), this, SLOT(childRowsChanged(QList<int>))); + connect(model, SIGNAL(rowChanged(int, Sigmodr::Tree::BaseModel::Change)), this, SLOT(childRowChanged(int, Sigmodr::Tree::BaseModel::Change))); + connect(model, SIGNAL(rowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change)), this, SLOT(childRowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change))); m_objects.append(model); - emit(rowChanged(m_objects.size() - 1)); + emit(rowChanged(m_objects.size() - 1, Addition)); } int GroupObjectModel::findChild(BaseModel* model) const diff --git a/sigmodr/tree/SigmodrTreeModel.cpp b/sigmodr/tree/SigmodrTreeModel.cpp index 6dd42fb0..dcfd04f3 100644 --- a/sigmodr/tree/SigmodrTreeModel.cpp +++ b/sigmodr/tree/SigmodrTreeModel.cpp @@ -37,7 +37,7 @@ SigmodrTreeModel::SigmodrTreeModel(QObject* parent) : QAbstractItemModel(parent), m_root(new RootModel) { - connect(m_root, SIGNAL(rowsChanged(QList<int>)), this, SLOT(rowsChanged(QList<int>))); + connect(m_root, SIGNAL(rowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change)), this, SLOT(rowsChanged(QList<int>, Sigmodr::Tree::BaseModel::Change))); } SigmodrTreeModel::~SigmodrTreeModel() @@ -186,13 +186,22 @@ const Game* SigmodrTreeModel::findGame(const QModelIndex& index) const return qobject_cast<const Game*>(getItem(curIndex)->object()); } -void SigmodrTreeModel::rowsChanged(const QList<int>& rows) +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(dataChanged(curIndex, curIndex)); emit(dirty(findGame(curIndex), true)); } diff --git a/sigmodr/tree/SigmodrTreeModel.h b/sigmodr/tree/SigmodrTreeModel.h index c3131261..f97fe1fd 100644 --- a/sigmodr/tree/SigmodrTreeModel.h +++ b/sigmodr/tree/SigmodrTreeModel.h @@ -62,7 +62,7 @@ class SIGMODRTREE_NO_EXPORT SigmodrTreeModel : public QAbstractItemModel signals: void dirty(const Sigmod::Game* game, const bool dirty); protected slots: - void rowsChanged(const QList<int>& rows); + void rowsChanged(const QList<int>& rows, const Sigmodr::Tree::BaseModel::Change change); private: BaseModel* getItem(const QModelIndex& index) const; |
