Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need to refresh model if the model sets the data to the index #185

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ui/DiffTreeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class DiffTreeModel : public QAbstractItemModel {
git::Repository mRepo;

bool mListView = false;
bool suppressRefresh{false};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment to indicate that this is just a workaround?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I will do. We can let this mr at the moment aside, because it is not that important

};

#endif /* DIFFTREEMODEL */