Update DiffTreeModel.cpp and DiffTreeModel.h

This commit is contained in:
Martin Marmsoler 2022-06-02 15:46:52 +02:00
parent 627f73d9fd
commit 0e0b78c618
2 changed files with 14 additions and 0 deletions

View File

@ -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)
@ -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;

View File

@ -162,6 +162,7 @@ private:
git::Repository mRepo;
bool mListView = false;
bool suppressRefresh{false};
};
#endif /* DIFFTREEMODEL */