diff options
| author | Mikaƫl Capelle <capelle.mikael@gmail.com> | 2023-07-09 17:36:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-09 17:36:03 +0200 |
| commit | ef94aee28464039672b277243a0181ae93550d6c (patch) | |
| tree | 0575a68af5f154e9d6d0738edbaefb16a11d6f5c /src/pluginlistview.cpp | |
| parent | 7d6cb8528d20e36a4cee822263865ee2f7f32481 (diff) | |
| parent | 3de050e9c03e553f7ae3f780f6bd080a30ae123e (diff) | |
Merge pull request #1839 from Holt59/ci/initial-gh-action-for-build
Clang-Format + Github Workflow
Diffstat (limited to 'src/pluginlistview.cpp')
| -rw-r--r-- | src/pluginlistview.cpp | 216 |
1 files changed, 117 insertions, 99 deletions
diff --git a/src/pluginlistview.cpp b/src/pluginlistview.cpp index c7183d0b..a0a0162f 100644 --- a/src/pluginlistview.cpp +++ b/src/pluginlistview.cpp @@ -1,29 +1,28 @@ #include "pluginlistview.h" -#include <QUrl> #include <QMimeData> +#include <QUrl> #include <report.h> #include <widgetutility.h> -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "organizercore.h" -#include "pluginlistsortproxy.h" -#include "pluginlistcontextmenu.h" -#include "modlistview.h" #include "copyeventfilter.h" -#include "modlistviewactions.h" #include "genericicondelegate.h" +#include "mainwindow.h" #include "modelutils.h" +#include "modlistview.h" +#include "modlistviewactions.h" +#include "organizercore.h" +#include "pluginlistcontextmenu.h" +#include "pluginlistsortproxy.h" +#include "ui_mainwindow.h" using namespace MOBase; -PluginListView::PluginListView(QWidget *parent) - : QTreeView(parent) - , m_sortProxy(nullptr) - , m_Scrollbar(new ViewMarkingScrollBar(this, Qt::BackgroundRole)) - , m_didUpdateMasterList(false) +PluginListView::PluginListView(QWidget* parent) + : QTreeView(parent), m_sortProxy(nullptr), + m_Scrollbar(new ViewMarkingScrollBar(this, Qt::BackgroundRole)), + m_didUpdateMasterList(false) { setVerticalScrollBar(m_Scrollbar); MOBase::setCustomizableColumns(this); @@ -57,31 +56,29 @@ QModelIndexList PluginListView::indexViewToModel(const QModelIndexList& index) c void PluginListView::updatePluginCount() { - int activeMasterCount = 0; + int activeMasterCount = 0; int activeLightMasterCount = 0; - int activeRegularCount = 0; - int masterCount = 0; - int lightMasterCount = 0; - int regularCount = 0; - int activeVisibleCount = 0; + int activeRegularCount = 0; + int masterCount = 0; + int lightMasterCount = 0; + int regularCount = 0; + int activeVisibleCount = 0; PluginList* list = m_core->pluginList(); - QString filter = ui.filter->text(); + QString filter = ui.filter->text(); for (QString plugin : list->pluginNames()) { - bool active = list->isEnabled(plugin); + bool active = list->isEnabled(plugin); bool visible = m_sortProxy->filterMatchesPlugin(plugin); if (list->hasLightExtension(plugin) || list->isLightFlagged(plugin)) { lightMasterCount++; activeLightMasterCount += active; activeVisibleCount += visible && active; - } - else if (list->hasMasterExtension(plugin) || list->isMasterFlagged(plugin)) { + } else if (list->hasMasterExtension(plugin) || list->isMasterFlagged(plugin)) { masterCount++; activeMasterCount += active; activeVisibleCount += visible && active; - } - else { + } else { regularCount++; activeRegularCount += active; activeVisibleCount += visible && active; @@ -89,23 +86,30 @@ void PluginListView::updatePluginCount() } int activeCount = activeMasterCount + activeLightMasterCount + activeRegularCount; - int totalCount = masterCount + lightMasterCount + regularCount; + int totalCount = masterCount + lightMasterCount + regularCount; ui.counter->display(activeVisibleCount); - ui.counter->setToolTip(tr("<table cellspacing=\"6\">" - "<tr><th>Type</th><th>Active </th><th>Total</th></tr>" - "<tr><td>All plugins:</td><td align=right>%1 </td><td align=right>%2</td></tr>" - "<tr><td>ESMs:</td><td align=right>%3 </td><td align=right>%4</td></tr>" - "<tr><td>ESPs:</td><td align=right>%7 </td><td align=right>%8</td></tr>" - "<tr><td>ESMs+ESPs:</td><td align=right>%9 </td><td align=right>%10</td></tr>" - "<tr><td>ESLs:</td><td align=right>%5 </td><td align=right>%6</td></tr>" - "</table>") - .arg(activeCount).arg(totalCount) - .arg(activeMasterCount).arg(masterCount) - .arg(activeLightMasterCount).arg(lightMasterCount) - .arg(activeRegularCount).arg(regularCount) - .arg(activeMasterCount + activeRegularCount).arg(masterCount + regularCount) - ); + ui.counter->setToolTip( + tr("<table cellspacing=\"6\">" + "<tr><th>Type</th><th>Active </th><th>Total</th></tr>" + "<tr><td>All plugins:</td><td align=right>%1 </td><td " + "align=right>%2</td></tr>" + "<tr><td>ESMs:</td><td align=right>%3 </td><td align=right>%4</td></tr>" + "<tr><td>ESPs:</td><td align=right>%7 </td><td align=right>%8</td></tr>" + "<tr><td>ESMs+ESPs:</td><td align=right>%9 </td><td " + "align=right>%10</td></tr>" + "<tr><td>ESLs:</td><td align=right>%5 </td><td align=right>%6</td></tr>" + "</table>") + .arg(activeCount) + .arg(totalCount) + .arg(activeMasterCount) + .arg(masterCount) + .arg(activeLightMasterCount) + .arg(lightMasterCount) + .arg(activeRegularCount) + .arg(regularCount) + .arg(activeMasterCount + activeRegularCount) + .arg(masterCount + regularCount)); } void PluginListView::onFilterChanged(const QString& filter) @@ -113,8 +117,7 @@ void PluginListView::onFilterChanged(const QString& filter) if (!filter.isEmpty()) { setStyleSheet("QTreeView { border: 2px ridge #f00; }"); ui.counter->setStyleSheet("QLCDNumber { border: 2px ridge #f00; }"); - } - else { + } else { setStyleSheet(""); ui.counter->setStyleSheet(""); } @@ -128,17 +131,16 @@ void PluginListView::onSortButtonClicked() auto r = QMessageBox::No; if (offline) { - r = QMessageBox::question( - topLevelWidget(), tr("Sorting plugins"), - tr("Are you sure you want to sort your plugins list?") + "\r\n\r\n" + - tr("Note: You are currently in offline mode and LOOT will not update the master list."), - QMessageBox::Yes | QMessageBox::No); - } - else { - r = QMessageBox::question( - topLevelWidget(), tr("Sorting plugins"), - tr("Are you sure you want to sort your plugins list?"), - QMessageBox::Yes | QMessageBox::No); + r = QMessageBox::question(topLevelWidget(), tr("Sorting plugins"), + tr("Are you sure you want to sort your plugins list?") + + "\r\n\r\n" + + tr("Note: You are currently in offline mode and LOOT " + "will not update the master list."), + QMessageBox::Yes | QMessageBox::No); + } else { + r = QMessageBox::question(topLevelWidget(), tr("Sorting plugins"), + tr("Are you sure you want to sort your plugins list?"), + QMessageBox::Yes | QMessageBox::No); } if (r != QMessageBox::Yes) { @@ -148,7 +150,9 @@ void PluginListView::onSortButtonClicked() m_core->savePluginList(); topLevelWidget()->setEnabled(false); - Guard g([=]() { topLevelWidget()->setEnabled(true); }); + Guard g([=]() { + topLevelWidget()->setEnabled(true); + }); // don't try to update the master list in offline mode const bool didUpdateMasterList = offline ? true : m_didUpdateMasterList; @@ -166,22 +170,24 @@ void PluginListView::onSortButtonClicked() std::pair<QModelIndex, QModelIndexList> PluginListView::selected() const { - return { indexViewToModel(currentIndex()), indexViewToModel(selectionModel()->selectedRows()) }; + return {indexViewToModel(currentIndex()), + indexViewToModel(selectionModel()->selectedRows())}; } -void PluginListView::setSelected(const QModelIndex& current, const QModelIndexList& selected) +void PluginListView::setSelected(const QModelIndex& current, + const QModelIndexList& selected) { setCurrentIndex(indexModelToView(current)); for (auto idx : selected) { - selectionModel()->select(indexModelToView(idx), QItemSelectionModel::Select | QItemSelectionModel::Rows); + selectionModel()->select(indexModelToView(idx), + QItemSelectionModel::Select | QItemSelectionModel::Rows); } } - void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow* mwui) { - m_core = &core; - ui = { mwui->activePluginsCounter, mwui->espFilterEdit }; + m_core = &core; + ui = {mwui->activePluginsCounter, mwui->espFilterEdit}; m_modActions = &mwui->modList->actions(); m_sortProxy = new PluginListSortProxy(&core); @@ -192,28 +198,40 @@ void PluginListView::setup(OrganizerCore& core, MainWindow* mw, Ui::MainWindow* setItemDelegateForColumn(PluginList::COL_FLAGS, new GenericIconDelegate(this)); // counter - connect(core.pluginList(), &PluginList::writePluginsList, [=]{ updatePluginCount(); }); - connect(core.pluginList(), &PluginList::esplist_changed, [=]{ updatePluginCount(); }); + connect(core.pluginList(), &PluginList::writePluginsList, [=] { + updatePluginCount(); + }); + connect(core.pluginList(), &PluginList::esplist_changed, [=] { + updatePluginCount(); + }); // sort - connect(mwui->bossButton, &QPushButton::clicked, [=]{ onSortButtonClicked(); }); + connect(mwui->bossButton, &QPushButton::clicked, [=] { + onSortButtonClicked(); + }); // filter - connect(ui.filter, &QLineEdit::textChanged, m_sortProxy, &PluginListSortProxy::updateFilter); + connect(ui.filter, &QLineEdit::textChanged, m_sortProxy, + &PluginListSortProxy::updateFilter); connect(ui.filter, &QLineEdit::textChanged, this, &PluginListView::onFilterChanged); // highligth mod list when selected - connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=](auto&& selected) { - std::vector<unsigned int> pluginIndices; - for (auto& idx : indexViewToModel(selectionModel()->selectedRows())) { - pluginIndices.push_back(idx.row()); - } - mwui->modList->setHighlightedMods(pluginIndices); - }); + connect(selectionModel(), &QItemSelectionModel::selectionChanged, + [=](auto&& selected) { + std::vector<unsigned int> pluginIndices; + for (auto& idx : indexViewToModel(selectionModel()->selectedRows())) { + pluginIndices.push_back(idx.row()); + } + mwui->modList->setHighlightedMods(pluginIndices); + }); // using a lambda here to avoid storing the mod list actions - connect(this, &QTreeView::customContextMenuRequested, [=](auto&& pos) { onCustomContextMenuRequested(pos); }); - connect(this, &QTreeView::doubleClicked, [=](auto&& index) { onDoubleClicked(index); }); + connect(this, &QTreeView::customContextMenuRequested, [=](auto&& pos) { + onCustomContextMenuRequested(pos); + }); + connect(this, &QTreeView::doubleClicked, [=](auto&& index) { + onDoubleClicked(index); + }); } void PluginListView::onCustomContextMenuRequested(const QPoint& pos) @@ -221,13 +239,12 @@ void PluginListView::onCustomContextMenuRequested(const QPoint& pos) try { PluginListContextMenu menu(indexViewToModel(indexAt(pos)), *m_core, this); connect(&menu, &PluginListContextMenu::openModInformation, [=](auto&& modIndex) { - m_modActions->displayModInformation(modIndex); }); + m_modActions->displayModInformation(modIndex); + }); menu.exec(viewport()->mapToGlobal(pos)); - } - catch (const std::exception& e) { + } catch (const std::exception& e) { reportError(tr("Exception: ").arg(e.what())); - } - catch (...) { + } catch (...) { reportError(tr("Unknown exception")); } } @@ -238,32 +255,34 @@ void PluginListView::onDoubleClicked(const QModelIndex& index) return; } - if (m_core->pluginList()->timeElapsedSinceLastChecked() <= QApplication::doubleClickInterval()) { + if (m_core->pluginList()->timeElapsedSinceLastChecked() <= + QApplication::doubleClickInterval()) { // don't interpret double click if we only just checked a plugin return; } try { - if (selectionModel()->hasSelection() && selectionModel()->selectedRows().count() == 1) { + if (selectionModel()->hasSelection() && + selectionModel()->selectedRows().count() == 1) { - QModelIndex idx = selectionModel()->currentIndex(); + QModelIndex idx = selectionModel()->currentIndex(); QString fileName = idx.data().toString(); if (ModInfo::getIndex(m_core->pluginList()->origin(fileName)) == UINT_MAX) { return; } - auto modIndex = ModInfo::getIndex(m_core->pluginList()->origin(fileName)); + auto modIndex = ModInfo::getIndex(m_core->pluginList()->origin(fileName)); ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex); if (modInfo->isRegular() || modInfo->isOverwrite()) { Qt::KeyboardModifiers modifiers = QApplication::queryKeyboardModifiers(); if (modifiers.testFlag(Qt::ControlModifier)) { - m_modActions->openExplorer({ m_core->modList()->index(modIndex, 0) }); - } - else { - m_modActions->displayModInformation(ModInfo::getIndex(m_core->pluginList()->origin(fileName))); + m_modActions->openExplorer({m_core->modList()->index(modIndex, 0)}); + } else { + m_modActions->displayModInformation( + ModInfo::getIndex(m_core->pluginList()->origin(fileName))); } // workaround to cancel the editor that might have opened because of @@ -271,8 +290,7 @@ void PluginListView::onDoubleClicked(const QModelIndex& index) closePersistentEditor(index); } } - } - catch (const std::exception& e) { + } catch (const std::exception& e) { reportError(e.what()); } } @@ -308,10 +326,11 @@ bool PluginListView::event(QEvent* event) if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); - if (keyEvent->modifiers() == Qt::ControlModifier - && (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)) { - if (selectionModel()->hasSelection() && selectionModel()->selectedRows().count() == 1) { - QModelIndex idx = selectionModel()->currentIndex(); + if (keyEvent->modifiers() == Qt::ControlModifier && + (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)) { + if (selectionModel()->hasSelection() && + selectionModel()->selectedRows().count() == 1) { + QModelIndex idx = selectionModel()->currentIndex(); QString fileName = idx.data().toString(); if (ModInfo::getIndex(m_core->pluginList()->origin(fileName)) == UINT_MAX) { @@ -319,16 +338,15 @@ bool PluginListView::event(QEvent* event) } auto modIndex = ModInfo::getIndex(m_core->pluginList()->origin(fileName)); - m_modActions->openExplorer({ m_core->modList()->index(modIndex, 0) }); + m_modActions->openExplorer({m_core->modList()->index(modIndex, 0)}); return true; } - } - else if (keyEvent->modifiers() == Qt::ControlModifier - && (sortColumn() == PluginList::COL_PRIORITY || sortColumn() == PluginList::COL_MODINDEX) - && (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down)) { + } else if (keyEvent->modifiers() == Qt::ControlModifier && + (sortColumn() == PluginList::COL_PRIORITY || + sortColumn() == PluginList::COL_MODINDEX) && + (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down)) { return moveSelection(keyEvent->key()); - } - else if (keyEvent->key() == Qt::Key_Space) { + } else if (keyEvent->key() == Qt::Key_Space) { return toggleSelectionState(); } return QTreeView::event(event); |
