Add ability to select all updates and reset action from menu
This commit is contained in:
parent
576d9d5662
commit
69819dee7f
@ -335,25 +335,38 @@ void Model::initView(QTreeView *view)
|
|||||||
view->hideColumn(int(update::Model::Column::Files));
|
view->hideColumn(int(update::Model::Column::Files));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto menu = new QMenu(view);
|
|
||||||
menu->addAction(toString(Action::NoAction));
|
|
||||||
menu->addAction(toString(Action::Remove));
|
|
||||||
menu->addAction(toString(Action::Install));
|
|
||||||
|
|
||||||
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(view, &QAbstractItemView::customContextMenuRequested, //
|
connect(view, &QAbstractItemView::customContextMenuRequested, //
|
||||||
menu, [this, menu, view, proxy] {
|
this, [this, view, proxy] {
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction(toString(Action::NoAction));
|
||||||
|
menu.addAction(toString(Action::Remove));
|
||||||
|
menu.addAction(toString(Action::Install));
|
||||||
|
menu.addSeparator();
|
||||||
|
auto updateAll = menu.addAction(tr("Select all updates"));
|
||||||
|
auto reset = menu.addAction(tr("Reset actions"));
|
||||||
|
|
||||||
|
const auto menuItem = menu.exec(QCursor::pos());
|
||||||
|
if (!menuItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (menuItem == updateAll) {
|
||||||
|
selectAllUpdates();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menuItem == reset) {
|
||||||
|
resetActions();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto selection = view->selectionModel();
|
const auto selection = view->selectionModel();
|
||||||
SOFT_ASSERT(selection, return );
|
SOFT_ASSERT(selection, return );
|
||||||
const auto indexes = selection->selectedRows(int(Column::Action));
|
const auto indexes = selection->selectedRows(int(Column::Action));
|
||||||
if (indexes.isEmpty())
|
if (indexes.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto menuItem = menu->exec(QCursor::pos());
|
const auto action = menu.actions().indexOf(menuItem);
|
||||||
if (!menuItem)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto action = menu->actions().indexOf(menuItem);
|
|
||||||
|
|
||||||
for (const auto &proxyIndex : indexes) {
|
for (const auto &proxyIndex : indexes) {
|
||||||
auto modelIndex = proxy->mapToSource(proxyIndex);
|
auto modelIndex = proxy->mapToSource(proxyIndex);
|
||||||
@ -561,6 +574,46 @@ void Model::resetProgress()
|
|||||||
updateProgress(*root_, {}, 0);
|
updateProgress(*root_, {}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::selectAllUpdates()
|
||||||
|
{
|
||||||
|
if (!root_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto visitor = [this](Component &component, auto v) -> void {
|
||||||
|
if (component.state == State::UpdateAvailable) {
|
||||||
|
component.action = Action::Install;
|
||||||
|
const auto index = toIndex(component, int(Column::Action));
|
||||||
|
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!component.children.empty()) {
|
||||||
|
for (auto &child : component.children) v(*child, v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
visitor(*root_, visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::resetActions()
|
||||||
|
{
|
||||||
|
if (!root_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto visitor = [this](Component &component, auto v) -> void {
|
||||||
|
if (component.action != Action::NoAction) {
|
||||||
|
component.action = Action::NoAction;
|
||||||
|
const auto index = toIndex(component, int(Column::Action));
|
||||||
|
emit dataChanged(index, index, {Qt::DisplayRole, Qt::EditRole});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!component.children.empty()) {
|
||||||
|
for (auto &child : component.children) v(*child, v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
visitor(*root_, visitor);
|
||||||
|
}
|
||||||
|
|
||||||
bool Model::hasUpdates(const Model::Component &component) const
|
bool Model::hasUpdates(const Model::Component &component) const
|
||||||
{
|
{
|
||||||
for (const auto &i : component.children) {
|
for (const auto &i : component.children) {
|
||||||
|
@ -65,6 +65,8 @@ public:
|
|||||||
bool hasUpdates() const;
|
bool hasUpdates() const;
|
||||||
void updateProgress(const QUrl& url, int progress);
|
void updateProgress(const QUrl& url, int progress);
|
||||||
void resetProgress();
|
void resetProgress();
|
||||||
|
void selectAllUpdates();
|
||||||
|
void resetActions();
|
||||||
|
|
||||||
QModelIndex index(int row, int column,
|
QModelIndex index(int row, int column,
|
||||||
const QModelIndex& parent) const override;
|
const QModelIndex& parent) const override;
|
||||||
|
Loading…
Reference in New Issue
Block a user