From 1ba4f6be4d7b115a8414e51ef959097cda3c680d Mon Sep 17 00:00:00 2001 From: Gres Date: Wed, 8 Apr 2020 20:41:40 +0300 Subject: [PATCH] Check for supported actions in setter --- src/service/updates.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/service/updates.cpp b/src/service/updates.cpp index c35cff1..3eea563 100644 --- a/src/service/updates.cpp +++ b/src/service/updates.cpp @@ -809,6 +809,17 @@ bool Model::setData(const QModelIndex &index, const QVariant &value, int role) if (ptr->action == newAction) return false; + if (newAction != Action::NoAction) { + const QMap> supported{ + {State::NotAvailable, {}}, + {State::Actual, {Action::Remove}}, + {State::NotInstalled, {Action::Install}}, + {State::UpdateAvailable, {Action::Remove, Action::Install}}, + }; + if (!supported[ptr->state].contains(newAction)) + return false; + } + ptr->action = newAction; emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});