Add ability to select updates via context menu
This commit is contained in:
parent
0ef82187d6
commit
ee899c1b23
@ -1,15 +1,19 @@
|
|||||||
#include "updates.h"
|
#include "updates.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
#include <QAbstractItemView>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QMenu>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
@ -280,6 +284,46 @@ Model::Model(QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::initView(QTreeView *view)
|
||||||
|
{
|
||||||
|
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
auto proxy = new QSortFilterProxyModel(view);
|
||||||
|
proxy->setSourceModel(this);
|
||||||
|
view->setModel(proxy);
|
||||||
|
view->setItemDelegate(new update::UpdateDelegate(view));
|
||||||
|
#ifndef DEVELOP
|
||||||
|
view->hideColumn(int(update::Model::Column::Files));
|
||||||
|
#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);
|
||||||
|
connect(view, &QAbstractItemView::customContextMenuRequested, //
|
||||||
|
menu, [this, menu, view, proxy] {
|
||||||
|
const auto selection = view->selectionModel();
|
||||||
|
SOFT_ASSERT(selection, return );
|
||||||
|
const auto indexes = selection->selectedRows(int(Column::Action));
|
||||||
|
if (indexes.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto menuItem = menu->exec(QCursor::pos());
|
||||||
|
if (!menuItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto action = menu->actions().indexOf(menuItem);
|
||||||
|
|
||||||
|
for (const auto &proxyIndex : indexes) {
|
||||||
|
auto modelIndex = proxy->mapToSource(proxyIndex);
|
||||||
|
if (!modelIndex.isValid() || rowCount(modelIndex) > 0)
|
||||||
|
continue;
|
||||||
|
setData(modelIndex, action, Qt::EditRole);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Model::parse(const QByteArray &data)
|
void Model::parse(const QByteArray &data)
|
||||||
{
|
{
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
class QNetworkAccessManager;
|
class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class QTreeView;
|
||||||
|
|
||||||
namespace update
|
namespace update
|
||||||
{
|
{
|
||||||
@ -55,6 +56,8 @@ public:
|
|||||||
|
|
||||||
explicit Model(QObject* parent = nullptr);
|
explicit Model(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
void initView(QTreeView* view);
|
||||||
|
|
||||||
void parse(const QByteArray& data);
|
void parse(const QByteArray& data);
|
||||||
void setExpansions(const std::map<QString, QString>& expansions);
|
void setExpansions(const std::map<QString, QString>& expansions);
|
||||||
UserActions userActions() const;
|
UserActions userActions() const;
|
||||||
|
@ -2,16 +2,12 @@
|
|||||||
#include "languagecodes.h"
|
#include "languagecodes.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "runatsystemstart.h"
|
#include "runatsystemstart.h"
|
||||||
#include "tesseract.h"
|
|
||||||
#include "translator.h"
|
#include "translator.h"
|
||||||
#include "ui_settingseditor.h"
|
#include "ui_settingseditor.h"
|
||||||
#include "updates.h"
|
#include "updates.h"
|
||||||
#include "widgetstate.h"
|
#include "widgetstate.h"
|
||||||
|
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
#include <QStringListModel>
|
|
||||||
|
|
||||||
SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater)
|
SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater)
|
||||||
: ui(new Ui::SettingsEditor)
|
: ui(new Ui::SettingsEditor)
|
||||||
@ -84,13 +80,7 @@ SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater)
|
|||||||
this, [this] { pickColor(ColorContext::Bagkround); });
|
this, [this] { pickColor(ColorContext::Bagkround); });
|
||||||
|
|
||||||
// updates
|
// updates
|
||||||
auto updatesProxy = new QSortFilterProxyModel(this);
|
updater.model()->initView(ui->updatesView);
|
||||||
updatesProxy->setSourceModel(updater_.model());
|
|
||||||
ui->updatesView->setModel(updatesProxy);
|
|
||||||
ui->updatesView->setItemDelegate(new update::UpdateDelegate(this));
|
|
||||||
#ifndef DEVELOP
|
|
||||||
ui->updatesView->hideColumn(int(update::Model::Column::Files));
|
|
||||||
#endif
|
|
||||||
adjustUpdatesView();
|
adjustUpdatesView();
|
||||||
connect(updater_.model(), &QAbstractItemModel::modelReset, //
|
connect(updater_.model(), &QAbstractItemModel::modelReset, //
|
||||||
this, &SettingsEditor::adjustUpdatesView);
|
this, &SettingsEditor::adjustUpdatesView);
|
||||||
|
Loading…
Reference in New Issue
Block a user