Skip to content

Commit

Permalink
No need to refresh model if the model sets the data to the index
Browse files Browse the repository at this point in the history
  • Loading branch information
Murmele committed Jun 2, 2022
1 parent 96c2fb5 commit a838651
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ui/DiffTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace {

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

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)
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -288,6 +299,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;
Expand Down
1 change: 1 addition & 0 deletions src/ui/DiffTreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class DiffTreeModel : public QAbstractItemModel {
git::Repository mRepo;

bool mListView = false;
bool suppressRefresh{false};
};

#endif /* DIFFTREEMODEL */

0 comments on commit a838651

Please sign in to comment.