summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/ChattablesModel.cpp19
-rw-r--r--Swift/QtUI/ChattablesModel.h6
2 files changed, 21 insertions, 4 deletions
diff --git a/Swift/QtUI/ChattablesModel.cpp b/Swift/QtUI/ChattablesModel.cpp
index d1257b9..67d0579 100644
--- a/Swift/QtUI/ChattablesModel.cpp
+++ b/Swift/QtUI/ChattablesModel.cpp
@@ -15,10 +15,21 @@
namespace Swift {
ChattablesModel::ChattablesModel(Chattables& chattables, QObject* parent) : QAbstractListModel(parent), chattables_(chattables) {
- //FIXME: scoped connections, do it properly not reset.
- chattables_.onAdded.connect([this](const JID& /*jid*/) {beginResetModel(); endResetModel();});
- chattables_.onRemoved.connect([this](const JID& /*jid*/) {beginResetModel(); endResetModel();});
- chattables_.onChanged.connect([this](const JID& /*jid*/) {beginResetModel(); endResetModel();});
+ using scoped_connection = boost::signals2::scoped_connection;
+ connectionList_.emplace_back(std::make_unique<scoped_connection>(
+ chattables_.onBeginAdd.connect([this](int index) {beginInsertRows(QModelIndex(), index, index);})
+ ));
+ connectionList_.emplace_back(std::make_unique<scoped_connection>(
+ chattables_.onAdded.connect([this]() {endInsertRows();})
+ ));
+ connectionList_.emplace_back(std::make_unique<scoped_connection>(
+ chattables_.onChanged.connect(
+ [this](const JID& jid, int index) {
+ auto modelIndex = createIndex(index, 0, const_cast<JID*>(&jid));
+ dataChanged(modelIndex, modelIndex, {});
+ }
+ )
+ ));
}
int ChattablesModel::rowCount(const QModelIndex& /*parent*/) const {
diff --git a/Swift/QtUI/ChattablesModel.h b/Swift/QtUI/ChattablesModel.h
index 57073aa..6617d97 100644
--- a/Swift/QtUI/ChattablesModel.h
+++ b/Swift/QtUI/ChattablesModel.h
@@ -6,6 +6,11 @@
#pragma once
+#include <memory>
+#include <vector>
+
+#include <boost/signals2/connection.hpp>
+
#include <QAbstractListModel>
namespace Swift {
@@ -23,6 +28,7 @@ class ChattablesModel : public QAbstractListModel {
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
private:
Chattables& chattables_;
+ std::vector<std::unique_ptr<boost::signals2::scoped_connection>> connectionList_;
};
}