Skip to content
Snippets Groups Projects
Commit e18c3297 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

smartlist: prevent excessive updates to items during reselection

Only save the draft if it changes and filter for index on data
changed signals before updating the avatar.

Change-Id: Ia23a35b512249e4b7953e3a2cef2cedbda386e65
parent e165855e
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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)
}
}
......
......@@ -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)
......
......@@ -52,6 +52,10 @@ public Q_SLOTS:
Q_SIGNALS:
void validSelectionChanged();
private Q_SLOTS:
void onModelUpdated();
void onModelTrimmed();
private:
QPersistentModelIndex selectedSourceIndex_;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment