Skip to content

Commit a838651

Browse files
committed
No need to refresh model if the model sets the data to the index
1 parent 96c2fb5 commit a838651

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/ui/DiffTreeModel.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ namespace {
2121

2222
const QString kLinkFmt = "<a href='%1'>%2</a>";
2323

24+
class Lock {
25+
public:
26+
Lock(bool &var) : mVar(var) { var = true; }
27+
~Lock() { mVar = false; }
28+
29+
private:
30+
bool &mVar;
31+
};
32+
2433
} // namespace
2534

2635
DiffTreeModel::DiffTreeModel(const git::Repository &repo, QObject *parent)
@@ -51,6 +60,8 @@ void DiffTreeModel::setDiff(const git::Diff &diff) {
5160
}
5261

5362
void DiffTreeModel::refresh(const QStringList &paths) {
63+
if (suppressRefresh)
64+
return;
5465
for (auto path : paths) {
5566
auto index = this->index(path);
5667
emit dataChanged(index, index, {Qt::CheckStateRole});
@@ -288,6 +299,8 @@ bool DiffTreeModel::discard(const QModelIndex &index) {
288299

289300
bool DiffTreeModel::setData(const QModelIndex &index, const QVariant &value,
290301
int role, bool ignoreIndexChanges) {
302+
303+
Lock l(suppressRefresh);
291304
switch (role) {
292305
case Qt::CheckStateRole: {
293306
QStringList files;

src/ui/DiffTreeModel.h

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class DiffTreeModel : public QAbstractItemModel {
160160
git::Repository mRepo;
161161

162162
bool mListView = false;
163+
bool suppressRefresh{false};
163164
};
164165

165166
#endif /* DIFFTREEMODEL */

0 commit comments

Comments
 (0)