diff --git a/src/lrcinstance.cpp b/src/lrcinstance.cpp index f68c85237ab823554b3b816fa9b480f97ab37113..3b07d3308bd71a133db970f62605aee7c96b2f4d 100644 --- a/src/lrcinstance.cpp +++ b/src/lrcinstance.cpp @@ -402,6 +402,12 @@ LRCInstance::setContentDraft(const QString& convUid, const QString& content) { auto draftKey = accountId + "_" + convUid; + + // prevent a senseless dataChanged signal from the + // model if nothing has changed + if (contentDrafts_[draftKey] == content) + return; + contentDrafts_[draftKey] = content; // this signal is only needed to update the current smartlist Q_EMIT draftSaved(convUid); diff --git a/src/mainview/components/SmartListItemDelegate.qml b/src/mainview/components/SmartListItemDelegate.qml index 28ac45cb802982df74de731587615920fd6ed0e5..ab24f1beb7f67417363b9eb67ad697680850b611 100644 --- a/src/mainview/components/SmartListItemDelegate.qml +++ b/src/mainview/components/SmartListItemDelegate.qml @@ -54,14 +54,13 @@ ItemDelegate { Connections { target: root.ListView.view.model - function onDataChanged(index) { - var model = root.ListView.view.model - avatar.updateImage(URI === undefined ? - model.data(index, ConversationList.URI): - URI, - PictureUid === undefined ? - model.data(index, ConversationList.PictureUid): - PictureUid) + function onDataChanged(idx) { + // TODO: currently the avatar dispaly mechanism requires + // that each dataChanged signal is caught by and induces an + // updateImage call per smartlist item. Once this is fixed + // we can filter for the current delegate's index like: + // if (idx.row !== index) return + avatar.updateImage(URI, PictureUid) } } diff --git a/src/selectablelistproxymodel.cpp b/src/selectablelistproxymodel.cpp index 5c7f0199a4f1f332da9cb3a8e5723342d8f3255a..fc2b34a6948de8b59f6ba89052d375b37f9d6287 100644 --- a/src/selectablelistproxymodel.cpp +++ b/src/selectablelistproxymodel.cpp @@ -30,24 +30,21 @@ void SelectableListProxyModel::bindSourceModel(QAbstractListModel* model) { setSourceModel(model); - connect( - sourceModel(), - &QAbstractListModel::dataChanged, - this, - [this] { updateSelection(); }, - Qt::UniqueConnection); - connect( - model, - &QAbstractListModel::rowsInserted, - this, - [this] { updateSelection(); }, - Qt::UniqueConnection); - connect( - model, - &QAbstractListModel::rowsRemoved, - this, - [this] { updateSelection(true); }, - Qt::UniqueConnection); + connect(sourceModel(), + &QAbstractListModel::dataChanged, + this, + &SelectableListProxyModel::onModelUpdated, + Qt::UniqueConnection); + connect(model, + &QAbstractListModel::rowsInserted, + this, + &SelectableListProxyModel::onModelUpdated, + Qt::UniqueConnection); + connect(model, + &QAbstractListModel::rowsRemoved, + this, + &SelectableListProxyModel::onModelTrimmed, + Qt::UniqueConnection); connect(sourceModel(), &QAbstractListModel::modelReset, this, @@ -152,6 +149,18 @@ SelectableListProxyModel::updateSelection(bool rowsRemoved) } } +void +SelectableListProxyModel::onModelUpdated() +{ + updateSelection(); +} + +void +SelectableListProxyModel::onModelTrimmed() +{ + updateSelection(true); +} + SelectableListProxyGroupModel::SelectableListProxyGroupModel(QList<SelectableListProxyModel*> models, QObject* parent) : QObject(parent) diff --git a/src/selectablelistproxymodel.h b/src/selectablelistproxymodel.h index ae252bf1167d7c7f01eaa0108fd37df8804cdfeb..a8e775dd7a4ac8c780c499de387429ce1eda03bc 100644 --- a/src/selectablelistproxymodel.h +++ b/src/selectablelistproxymodel.h @@ -52,6 +52,10 @@ public Q_SLOTS: Q_SIGNALS: void validSelectionChanged(); +private Q_SLOTS: + void onModelUpdated(); + void onModelTrimmed(); + private: QPersistentModelIndex selectedSourceIndex_; };