mirror of
https://github.com/tnodir/fort
synced 2024-11-15 11:15:08 +00:00
UI: ProgramsWindow: Multi selection.
This commit is contained in:
parent
0db519bf3e
commit
310397b193
@ -5,6 +5,18 @@ TableView::TableView(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<int> TableView::selectedRows() const
|
||||||
|
{
|
||||||
|
QSet<int> rowsSet;
|
||||||
|
for (const auto index : selectedIndexes()) {
|
||||||
|
rowsSet.insert(index.row());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto rows = rowsSet.values();
|
||||||
|
std::sort(rows.begin(), rows.end());
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
void TableView::currentChanged(const QModelIndex ¤t,
|
void TableView::currentChanged(const QModelIndex ¤t,
|
||||||
const QModelIndex &previous)
|
const QModelIndex &previous)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,8 @@ class TableView : public QTableView
|
|||||||
public:
|
public:
|
||||||
explicit TableView(QWidget *parent = nullptr);
|
explicit TableView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
QVector<int> selectedRows() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentIndexChanged(const QModelIndex &index);
|
void currentIndexChanged(const QModelIndex &index);
|
||||||
|
|
||||||
|
@ -209,8 +209,8 @@ QLayout *ProgramsWindow::setupHeader()
|
|||||||
updateAppEditForm(true);
|
updateAppEditForm(true);
|
||||||
});
|
});
|
||||||
connect(m_actRemoveApp, &QAction::triggered, [&] {
|
connect(m_actRemoveApp, &QAction::triggered, [&] {
|
||||||
if (fortManager()->showQuestionBox(tr("Are you sure to remove the selected program?"))) {
|
if (fortManager()->showQuestionBox(tr("Are you sure to remove selected program(s)?"))) {
|
||||||
deleteCurrentApp();
|
deleteSelectedApps();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -222,10 +222,10 @@ QLayout *ProgramsWindow::setupHeader()
|
|||||||
m_btBlockApp = ControlUtil::createLinkButton(":/images/stop.png");
|
m_btBlockApp = ControlUtil::createLinkButton(":/images/stop.png");
|
||||||
|
|
||||||
connect(m_btAllowApp, &QAbstractButton::clicked, [&] {
|
connect(m_btAllowApp, &QAbstractButton::clicked, [&] {
|
||||||
updateCurrentApp(false);
|
updateSelectedApps(false);
|
||||||
});
|
});
|
||||||
connect(m_btBlockApp, &QAbstractButton::clicked, [&] {
|
connect(m_btBlockApp, &QAbstractButton::clicked, [&] {
|
||||||
updateCurrentApp(true);
|
updateSelectedApps(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log Blocked
|
// Log Blocked
|
||||||
@ -408,7 +408,7 @@ void ProgramsWindow::setupTableApps()
|
|||||||
m_appListView = new TableView();
|
m_appListView = new TableView();
|
||||||
m_appListView->setIconSize(QSize(24, 24));
|
m_appListView->setIconSize(QSize(24, 24));
|
||||||
m_appListView->setAlternatingRowColors(true);
|
m_appListView->setAlternatingRowColors(true);
|
||||||
m_appListView->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_appListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
m_appListView->setSelectionBehavior(QAbstractItemView::SelectItems);
|
m_appListView->setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||||
|
|
||||||
m_appListView->setSortingEnabled(true);
|
m_appListView->setSortingEnabled(true);
|
||||||
@ -536,23 +536,33 @@ void ProgramsWindow::updateAppEditForm(bool editCurrentApp)
|
|||||||
m_formAppEdit->show();
|
m_formAppEdit->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramsWindow::updateCurrentApp(bool blocked)
|
void ProgramsWindow::updateApp(int row, bool blocked)
|
||||||
{
|
{
|
||||||
const int appIndex = appListCurrentIndex();
|
const auto appRow = appListModel()->appRowAt(row);
|
||||||
if (appIndex >= 0) {
|
appListModel()->updateApp(appRow.appId, appRow.appPath, appRow.appName,
|
||||||
const auto appRow = appListModel()->appRowAt(appIndex);
|
QDateTime(), appRow.groupIndex,
|
||||||
appListModel()->updateApp(appRow.appId, appRow.appPath, appRow.appName,
|
appRow.useGroupPerm, blocked);
|
||||||
QDateTime(), appRow.groupIndex,
|
}
|
||||||
appRow.useGroupPerm, blocked);
|
|
||||||
|
void ProgramsWindow::deleteApp(int row)
|
||||||
|
{
|
||||||
|
const auto appRow = appListModel()->appRowAt(row);
|
||||||
|
appListModel()->deleteApp(appRow.appId, appRow.appPath, row);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgramsWindow::updateSelectedApps(bool blocked)
|
||||||
|
{
|
||||||
|
const auto rows = m_appListView->selectedRows();
|
||||||
|
for (int i = rows.size(); --i >= 0; ) {
|
||||||
|
updateApp(rows.at(i), blocked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramsWindow::deleteCurrentApp()
|
void ProgramsWindow::deleteSelectedApps()
|
||||||
{
|
{
|
||||||
const int appIndex = appListCurrentIndex();
|
const auto rows = m_appListView->selectedRows();
|
||||||
if (appIndex >= 0) {
|
for (int i = rows.size(); --i >= 0; ) {
|
||||||
const auto appRow = appListModel()->appRowAt(appIndex);
|
deleteApp(rows.at(i));
|
||||||
appListModel()->deleteApp(appRow.appId, appRow.appPath, appIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +60,11 @@ private:
|
|||||||
void setupTableAppsChanged();
|
void setupTableAppsChanged();
|
||||||
|
|
||||||
void updateAppEditForm(bool editCurrentApp);
|
void updateAppEditForm(bool editCurrentApp);
|
||||||
void updateCurrentApp(bool blocked);
|
void updateApp(int row, bool blocked);
|
||||||
void deleteCurrentApp();
|
void deleteApp(int row);
|
||||||
|
|
||||||
|
void updateSelectedApps(bool blocked);
|
||||||
|
void deleteSelectedApps();
|
||||||
|
|
||||||
int appListCurrentIndex() const;
|
int appListCurrentIndex() const;
|
||||||
QString appListCurrentPath() const;
|
QString appListCurrentPath() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user