From 0e0b78c618cfa7f4dfecd8b4ac6c86970a3e3e26 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 2 Jun 2022 15:46:52 +0200 Subject: [PATCH] Update DiffTreeModel.cpp and DiffTreeModel.h --- src/ui/DiffTreeModel.cpp | 13 +++++++++++++ src/ui/DiffTreeModel.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/ui/DiffTreeModel.cpp b/src/ui/DiffTreeModel.cpp index 8fe10965e..7c8e54a1f 100644 --- a/src/ui/DiffTreeModel.cpp +++ b/src/ui/DiffTreeModel.cpp @@ -21,6 +21,15 @@ namespace { const QString kLinkFmt = "%2"; +class Lock { +public: + Lock(bool &var) : mVar(var) { var = true; } + ~Lock() { mVar = false; } + +private: + bool &mVar; +}; + } // namespace DiffTreeModel::DiffTreeModel(const git::Repository &repo, QObject *parent) @@ -51,6 +60,8 @@ void DiffTreeModel::setDiff(const git::Diff &diff) { } void DiffTreeModel::refresh(const QStringList &paths) { + if (suppressRefresh) + return; for (auto path : paths) { auto index = this->index(path); emit dataChanged(index, index, {Qt::CheckStateRole}); @@ -305,6 +316,8 @@ bool DiffTreeModel::discard(const QModelIndex &index) { bool DiffTreeModel::setData(const QModelIndex &index, const QVariant &value, int role, bool ignoreIndexChanges) { + + Lock l(suppressRefresh); switch (role) { case Qt::CheckStateRole: { QStringList files; diff --git a/src/ui/DiffTreeModel.h b/src/ui/DiffTreeModel.h index 970a5db9e..71875e453 100644 --- a/src/ui/DiffTreeModel.h +++ b/src/ui/DiffTreeModel.h @@ -162,6 +162,7 @@ class DiffTreeModel : public QAbstractItemModel { git::Repository mRepo; bool mListView = false; + bool suppressRefresh{false}; }; #endif /* DIFFTREEMODEL */