diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2022-05-17 11:47:01 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2023-07-09 17:20:40 +0200 |
| commit | d13f6bb870cdda71257f665367be8ef9fca86255 (patch) | |
| tree | 52e214718478f1e52856572f5aa1a2ac58537f9f /src/modlistview.cpp | |
| parent | 86bb01ba9eac879d3685c439ac9da0028bc4bc80 (diff) | |
Apply clang-format.
Diffstat (limited to 'src/modlistview.cpp')
| -rw-r--r-- | src/modlistview.cpp | 727 |
1 files changed, 404 insertions, 323 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 7eb06f98..73bbd33d 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -1,7 +1,7 @@ #include "modlistview.h" -#include <QUrl> #include <QMimeData> #include <QProxyStyle> +#include <QUrl> #include <widgetutility.h> @@ -10,26 +10,26 @@ #include "ui_mainwindow.h" +#include "copyeventfilter.h" #include "filterlist.h" -#include "organizercore.h" -#include "modlist.h" -#include "modlistsortproxy.h" -#include "modlistbypriorityproxy.h" +#include "genericicondelegate.h" #include "log.h" -#include "modflagicondelegate.h" +#include "mainwindow.h" #include "modconflicticondelegate.h" #include "modcontenticondelegate.h" +#include "modelutils.h" +#include "modflagicondelegate.h" +#include "modlist.h" +#include "modlistbypriorityproxy.h" +#include "modlistcontextmenu.h" +#include "modlistdropinfo.h" +#include "modlistsortproxy.h" #include "modlistversiondelegate.h" #include "modlistviewactions.h" -#include "modlistdropinfo.h" -#include "modlistcontextmenu.h" -#include "genericicondelegate.h" -#include "copyeventfilter.h" -#include "shared/fileentry.h" +#include "organizercore.h" #include "shared/directoryentry.h" +#include "shared/fileentry.h" #include "shared/filesorigin.h" -#include "mainwindow.h" -#include "modelutils.h" using namespace MOBase; using namespace MOShared; @@ -47,11 +47,11 @@ class ModListStyledItemDelegate : public QStyledItemDelegate ModListView* m_view; public: + ModListStyledItemDelegate(ModListView* view) : QStyledItemDelegate(view), m_view(view) + {} - ModListStyledItemDelegate(ModListView* view) : - QStyledItemDelegate(view), m_view(view) { } - - void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const override + void initStyleOption(QStyleOptionViewItem* option, + const QModelIndex& index) const override { // the parent version always overwrite the background brush, so // we need to save it and restore it @@ -63,7 +63,8 @@ public: } } - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override + void paint(QPainter* painter, const QStyleOptionViewItem& option, + const QModelIndex& index) const override { QStyleOptionViewItem opt(option); @@ -95,16 +96,19 @@ public: // compute ideal foreground color for some rows if (color.isValid()) { - if (((index.column() == ModList::COL_NAME || index.column() == ModList::COL_PRIORITY) - && ModInfo::getByIndex(index.data(ModList::IndexRole).toInt())->isSeparator()) - || index.column() == ModList::COL_NOTES) { + if (((index.column() == ModList::COL_NAME || + index.column() == ModList::COL_PRIORITY) && + ModInfo::getByIndex(index.data(ModList::IndexRole).toInt()) + ->isSeparator()) || + index.column() == ModList::COL_NOTES) { // combine the color with the background and then find the "ideal" text color const auto a = color.alpha() / 255.; - int r = (1 - a) * bg.red() + a * color.red(), - g = (1 - a) * bg.green() + a * color.green(), - b = (1 - a) * bg.blue() + a * color.blue(); - opt.palette.setBrush(QPalette::Text, ColorSettings::idealTextColor(QColor(r, g, b))); + int r = (1 - a) * bg.red() + a * color.red(), + g = (1 - a) * bg.green() + a * color.green(), + b = (1 - a) * bg.blue() + a * color.blue(); + opt.palette.setBrush(QPalette::Text, + ColorSettings::idealTextColor(QColor(r, g, b))); } } @@ -112,12 +116,14 @@ public: } }; -class ModListViewMarkingScrollBar : public ViewMarkingScrollBar { +class ModListViewMarkingScrollBar : public ViewMarkingScrollBar +{ ModListView* m_view; -public: - ModListViewMarkingScrollBar(ModListView* view) : - ViewMarkingScrollBar(view, ModList::ScrollMarkRole), m_view(view) { } +public: + ModListViewMarkingScrollBar(ModListView* view) + : ViewMarkingScrollBar(view, ModList::ScrollMarkRole), m_view(view) + {} QColor color(const QModelIndex& index) const override { @@ -127,18 +133,13 @@ public: } return color; } - }; ModListView::ModListView(QWidget* parent) - : QTreeView(parent) - , m_core(nullptr) - , m_sortProxy(nullptr) - , m_byPriorityProxy(nullptr) - , m_byCategoryProxy(nullptr) - , m_byNexusIdProxy(nullptr) - , m_markers{ {}, {}, {}, {}, {}, {} } - , m_scrollbar(new ModListViewMarkingScrollBar(this)) + : QTreeView(parent), m_core(nullptr), m_sortProxy(nullptr), + m_byPriorityProxy(nullptr), m_byCategoryProxy(nullptr), + m_byNexusIdProxy(nullptr), m_markers{{}, {}, {}, {}, {}, {}}, + m_scrollbar(new ModListViewMarkingScrollBar(this)) { setVerticalScrollBar(m_scrollbar); MOBase::setCustomizableColumns(this); @@ -147,7 +148,8 @@ ModListView::ModListView(QWidget* parent) setItemDelegate(new ModListStyledItemDelegate(this)); connect(this, &ModListView::doubleClicked, this, &ModListView::onDoubleClicked); - connect(this, &ModListView::customContextMenuRequested, this, &ModListView::onCustomContextMenuRequested); + connect(this, &ModListView::customContextMenuRequested, this, + &ModListView::onCustomContextMenuRequested); // the timeout is pretty small because its main purpose is to avoid // refreshing multiple times when calling expandAll() or collapseAll() @@ -155,18 +157,19 @@ ModListView::ModListView(QWidget* parent) // time window m_refreshMarkersTimer.setInterval(50); m_refreshMarkersTimer.setSingleShot(true); - connect(&m_refreshMarkersTimer, &QTimer::timeout, [=] { refreshMarkersAndPlugins(); }); + connect(&m_refreshMarkersTimer, &QTimer::timeout, [=] { + refreshMarkersAndPlugins(); + }); installEventFilter(new CopyEventFilter(this, [=](auto& index) { QVariant mIndex = index.data(ModList::IndexRole); - QString name = index.data(Qt::DisplayRole).toString(); + QString name = index.data(Qt::DisplayRole).toString(); if (mIndex.isValid() && hasCollapsibleSeparators()) { ModInfo::Ptr info = ModInfo::getByIndex(mIndex.toInt()); if (info->isSeparator()) { name = "[" + name + "]"; } - } - else if (model()->hasChildren(index)) { + } else if (model()->hasChildren(index)) { name = "[" + name + "]"; } return name; @@ -181,20 +184,23 @@ void ModListView::refresh() void ModListView::onProfileChanged(Profile* oldProfile, Profile* newProfile) { const auto perProfileSeparators = - m_core->settings().interface().collapsibleSeparatorsPerProfile(); + m_core->settings().interface().collapsibleSeparatorsPerProfile(); // save expanded/collapsed state of separators if (oldProfile && perProfileSeparators) { auto& collapsed = m_collapsed[m_byPriorityProxy]; - oldProfile->storeSetting("UserInterface", "collapsed_separators", QStringList(collapsed.begin(), collapsed.end())); + oldProfile->storeSetting("UserInterface", "collapsed_separators", + QStringList(collapsed.begin(), collapsed.end())); } m_sortProxy->setProfile(newProfile); m_byPriorityProxy->setProfile(newProfile); if (newProfile && perProfileSeparators) { - auto collapsed = newProfile->setting("UserInterface", "collapsed_separators", QStringList()).toStringList(); - m_collapsed[m_byPriorityProxy] = { collapsed.begin(), collapsed.end() }; + auto collapsed = + newProfile->setting("UserInterface", "collapsed_separators", QStringList()) + .toStringList(); + m_collapsed[m_byPriorityProxy] = {collapsed.begin(), collapsed.end()}; } } @@ -222,17 +228,13 @@ ModListView::GroupByMode ModListView::groupByMode() const { if (m_sortProxy == nullptr) { return GroupByMode::NONE; - } - else if (m_sortProxy->sourceModel() == m_byPriorityProxy) { + } else if (m_sortProxy->sourceModel() == m_byPriorityProxy) { return GroupByMode::SEPARATOR; - } - else if (m_sortProxy->sourceModel() == m_byCategoryProxy) { + } else if (m_sortProxy->sourceModel() == m_byCategoryProxy) { return GroupByMode::CATEGORY; - } - else if (m_sortProxy->sourceModel() == m_byNexusIdProxy) { + } else if (m_sortProxy->sourceModel() == m_byNexusIdProxy) { return GroupByMode::NEXUS_ID; - } - else { + } else { return GroupByMode::NONE; } } @@ -271,7 +273,7 @@ std::optional<unsigned int> ModListView::nextMod(unsigned int modIndex) const return {}; } -std::optional<unsigned int> ModListView::prevMod(unsigned int modIndex) const +std::optional<unsigned int> ModListView::prevMod(unsigned int modIndex) const { const QModelIndex start = indexModelToView(m_core->modList()->index(modIndex, 0)); @@ -304,24 +306,28 @@ void ModListView::invalidateFilter() m_sortProxy->invalidate(); } -void ModListView::setFilterCriteria(const std::vector<ModListSortProxy::Criteria>& criteria) +void ModListView::setFilterCriteria( + const std::vector<ModListSortProxy::Criteria>& criteria) { m_sortProxy->setCriteria(criteria); } -void ModListView::setFilterOptions(ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep) +void ModListView::setFilterOptions(ModListSortProxy::FilterMode mode, + ModListSortProxy::SeparatorsMode sep) { m_sortProxy->setOptions(mode, sep); } bool ModListView::isModVisible(unsigned int index) const { - return m_sortProxy->filterMatchesMod(ModInfo::getByIndex(index), m_core->currentProfile()->modEnabled(index)); + return m_sortProxy->filterMatchesMod(ModInfo::getByIndex(index), + m_core->currentProfile()->modEnabled(index)); } bool ModListView::isModVisible(ModInfo::Ptr mod) const { - return m_sortProxy->filterMatchesMod(mod, m_core->currentProfile()->modEnabled(ModInfo::getIndex(mod->name()))); + return m_sortProxy->filterMatchesMod( + mod, m_core->currentProfile()->modEnabled(ModInfo::getIndex(mod->name()))); } QModelIndex ModListView::indexModelToView(const QModelIndex& index) const @@ -358,13 +364,15 @@ QModelIndex ModListView::nextIndex(const QModelIndex& index) const if (index.parent().isValid()) { if (index.row() + 1 < model->rowCount(index.parent())) { return index.model()->index(index.row() + 1, index.column(), index.parent()); + } else { + return index.model()->index((index.parent().row() + 1) % + model->rowCount(index.parent().parent()), + index.column(), index.parent().parent()); + ; } - else { - return index.model()->index((index.parent().row() + 1) % model->rowCount(index.parent().parent()), index.column(), index.parent().parent());; - } - } - else { - return index.model()->index((index.row() + 1) % model->rowCount(index.parent()), index.column(), index.parent()); + } else { + return index.model()->index((index.row() + 1) % model->rowCount(index.parent()), + index.column(), index.parent()); } } @@ -379,7 +387,8 @@ QModelIndex ModListView::prevIndex(const QModelIndex& index) const return {}; } - auto prev = model->index((index.row() - 1) % model->rowCount(index.parent()), index.column(), index.parent()); + auto prev = model->index((index.row() - 1) % model->rowCount(index.parent()), + index.column(), index.parent()); if (model->rowCount(prev) > 0) { return model->index(model->rowCount(prev) - 1, index.column(), prev); @@ -390,14 +399,17 @@ QModelIndex ModListView::prevIndex(const QModelIndex& index) const std::pair<QModelIndex, QModelIndexList> ModListView::selected() const { - return { indexViewToModel(currentIndex()), indexViewToModel(selectionModel()->selectedRows()) }; + return {indexViewToModel(currentIndex()), + indexViewToModel(selectionModel()->selectedRows())}; } -void ModListView::setSelected(const QModelIndex& current, const QModelIndexList& selected) +void ModListView::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); } } @@ -406,7 +418,8 @@ void ModListView::scrollToAndSelect(const QModelIndex& index) scrollToAndSelect(QModelIndexList{index}); } -void ModListView::scrollToAndSelect(const QModelIndexList& indexes, const QModelIndex& current) +void ModListView::scrollToAndSelect(const QModelIndexList& indexes, + const QModelIndex& current) { // focus, scroll to and select if (!current.isValid() && indexes.isEmpty()) { @@ -418,8 +431,11 @@ void ModListView::scrollToAndSelect(const QModelIndexList& indexes, const QModel for (auto& idx : indexes) { selection.select(idx, idx); } - selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows); - QTimer::singleShot(50, [=] { setFocus(); }); + selectionModel()->select(selection, + QItemSelectionModel::Select | QItemSelectionModel::Rows); + QTimer::singleShot(50, [=] { + setFocus(); + }); } void ModListView::refreshExpandedItems() @@ -472,12 +488,10 @@ void ModListView::onModFilterActive(bool filterActive) if (filterActive) { setStyleSheet("QTreeView { border: 2px ridge #f00; }"); ui.counter->setStyleSheet("QLCDNumber { border: 2px ridge #f00; }"); - } - else if (ui.groupBy->currentIndex() != GroupBy::NONE) { + } else if (ui.groupBy->currentIndex() != GroupBy::NONE) { setStyleSheet("QTreeView { border: 2px ridge #337733; }"); ui.counter->setStyleSheet(""); - } - else { + } else { setStyleSheet(""); ui.counter->setStyleSheet(""); } @@ -491,9 +505,8 @@ ModListView::ModCounters ModListView::counters() const return std::find(flags.begin(), flags.end(), filter) != flags.end(); }; - for (unsigned int index = 0; index < ModInfo::getNumMods(); ++index) { - auto info = ModInfo::getByIndex(index); + auto info = ModInfo::getByIndex(index); const auto flags = info->getFlags(); const bool enabled = m_core->currentProfile()->modEnabled(index); @@ -501,22 +514,24 @@ ModListView::ModCounters ModListView::counters() const if (info->isBackup()) { c.backup++; - if (visible) c.visible.backup++; - } - else if (info->isForeign()) { + if (visible) + c.visible.backup++; + } else if (info->isForeign()) { c.foreign++; - if (visible) c.visible.foreign++; - } - else if (info->isSeparator()) { + if (visible) + c.visible.foreign++; + } else if (info->isSeparator()) { c.separator++; - if (visible) c.visible.separator++; - } - else if (!info->isOverwrite()) { + if (visible) + c.visible.separator++; + } else if (!info->isOverwrite()) { c.regular++; - if (visible) c.visible.regular++; + if (visible) + c.visible.regular++; if (enabled) { c.active++; - if (visible) c.visible.active++; + if (visible) + c.visible.active++; } } } @@ -530,23 +545,26 @@ void ModListView::updateModCount() ui.counter->display(c.visible.active); ui.counter->setToolTip(tr("<table cellspacing=\"5\">" - "<tr><th>Type</th><th>All</th><th>Visible</th>" - "<tr><td>Enabled mods: </td><td align=right>%1 / %2</td><td align=right>%3 / %4</td></tr>" - "<tr><td>Unmanaged/DLCs: </td><td align=right>%5</td><td align=right>%6</td></tr>" - "<tr><td>Mod backups: </td><td align=right>%7</td><td align=right>%8</td></tr>" - "<tr><td>Separators: </td><td align=right>%9</td><td align=right>%10</td></tr>" - "</table>") - .arg(c.active) - .arg(c.regular) - .arg(c.visible.active) - .arg(c.visible.regular) - .arg(c.foreign) - .arg(c.visible.foreign) - .arg(c.backup) - .arg(c.visible.backup) - .arg(c.separator) - .arg(c.visible.separator) - ); + "<tr><th>Type</th><th>All</th><th>Visible</th>" + "<tr><td>Enabled mods: </td><td align=right>%1 / " + "%2</td><td align=right>%3 / %4</td></tr>" + "<tr><td>Unmanaged/DLCs: </td><td " + "align=right>%5</td><td align=right>%6</td></tr>" + "<tr><td>Mod backups: </td><td align=right>%7</td><td " + "align=right>%8</td></tr>" + "<tr><td>Separators: </td><td align=right>%9</td><td " + "align=right>%10</td></tr>" + "</table>") + .arg(c.active) + .arg(c.regular) + .arg(c.visible.active) + .arg(c.visible.regular) + .arg(c.foreign) + .arg(c.visible.foreign) + .arg(c.backup) + .arg(c.visible.backup) + .arg(c.separator) + .arg(c.visible.separator)); } void ModListView::refreshFilters() @@ -571,10 +589,13 @@ void ModListView::onExternalFolderDropped(const QUrl& url, int priority) do { bool ok; - name.update(QInputDialog::getText(this, tr("Copy Folder..."), - tr("This will copy the content of %1 to a new mod.\n" - "Please enter the name:").arg(fileInfo.fileName()), QLineEdit::Normal, name, &ok), - GUESS_USER); + name.update( + QInputDialog::getText(this, tr("Copy Folder..."), + tr("This will copy the content of %1 to a new mod.\n" + "Please enter the name:") + .arg(fileInfo.fileName()), + QLineEdit::Normal, name, &ok), + GUESS_USER); if (!ok) { return; } @@ -634,23 +655,23 @@ bool ModListView::toggleSelectionState() if (!selectionModel()->hasSelection()) { return true; } - return m_core->modList()->toggleState(indexViewToModel(selectionModel()->selectedRows())); + return m_core->modList()->toggleState( + indexViewToModel(selectionModel()->selectedRows())); } void ModListView::updateGroupByProxy() { - int groupIndex = ui.groupBy->currentIndex(); + int groupIndex = ui.groupBy->currentIndex(); auto* previousModel = m_sortProxy->sourceModel(); QAbstractItemModel* nextModel = m_core->modList(); if (groupIndex == GroupBy::CATEGORY) { nextModel = m_byCategoryProxy; - } - else if (groupIndex == GroupBy::NEXUS_ID) { + } else if (groupIndex == GroupBy::NEXUS_ID) { nextModel = m_byNexusIdProxy; - } - else if (m_core->settings().interface().collapsibleSeparators(m_sortProxy->sortOrder()) - && m_sortProxy->sortColumn() == ModList::COL_PRIORITY) { + } else if (m_core->settings().interface().collapsibleSeparators( + m_sortProxy->sortOrder()) && + m_sortProxy->sortColumn() == ModList::COL_PRIORITY) { m_byPriorityProxy->setSortOrder(m_sortProxy->sortOrder()); nextModel = m_byPriorityProxy; } @@ -675,98 +696,127 @@ void ModListView::updateGroupByProxy() if (hasCollapsibleSeparators()) { ui.filterSeparators->setCurrentIndex(ModListSortProxy::SeparatorFilter); ui.filterSeparators->setEnabled(false); - } - else { + } else { ui.filterSeparators->setEnabled(true); } - } } -void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindow* mw, Ui::MainWindow* mwui) +void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindow* mw, + Ui::MainWindow* mwui) { // attributes m_core = &core; m_filters.reset(new FilterList(mwui, core, factory)); m_categories = &factory; - m_actions = new ModListViewActions(core, *m_filters, factory, this, mwui->espList, mw); - ui = { - mwui->groupCombo, mwui->activeModsCounter, mwui->modFilterEdit, - mwui->currentCategoryLabel, mwui->clearFiltersButton, mwui->filtersSeparators, - mwui->espList - }; - + m_actions = + new ModListViewActions(core, *m_filters, factory, this, mwui->espList, mw); + ui = {mwui->groupCombo, + mwui->activeModsCounter, + mwui->modFilterEdit, + mwui->currentCategoryLabel, + mwui->clearFiltersButton, + mwui->filtersSeparators, + mwui->espList}; - connect(m_core, &OrganizerCore::modInstalled, [=](auto&& name) { onModInstalled(name); }); + connect(m_core, &OrganizerCore::modInstalled, [=](auto&& name) { + onModInstalled(name); + }); connect(m_core, &OrganizerCore::profileChanged, this, &ModListView::onProfileChanged); - connect(core.modList(), &ModList::modPrioritiesChanged, [=](auto&& indices) { onModPrioritiesChanged(indices); }); - connect(core.modList(), &ModList::clearOverwrite, [=] { m_actions->clearOverwrite(); }); + connect(core.modList(), &ModList::modPrioritiesChanged, [=](auto&& indices) { + onModPrioritiesChanged(indices); + }); + connect(core.modList(), &ModList::clearOverwrite, [=] { + m_actions->clearOverwrite(); + }); connect(core.modList(), &ModList::modStatesChanged, [=] { updateModCount(); setOverwriteMarkers(selectionModel()->selectedRows()); }); - connect(core.modList(), &ModList::modelReset, [=] { clearOverwriteMarkers(); }); + connect(core.modList(), &ModList::modelReset, [=] { + clearOverwriteMarkers(); + }); // proxy for various group by m_byPriorityProxy = new ModListByPriorityProxy(core.currentProfile(), core, this); - m_byCategoryProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_CATEGORY, ModList::GroupingRole, 0, ModList::AggrRole); - m_byNexusIdProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_MODID, ModList::GroupingRole, - QtGroupingProxy::FLAG_NOGROUPNAME | QtGroupingProxy::FLAG_NOSINGLE, ModList::AggrRole); + m_byCategoryProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_CATEGORY, + ModList::GroupingRole, 0, ModList::AggrRole); + m_byNexusIdProxy = new QtGroupingProxy( + QModelIndex(), ModList::COL_MODID, ModList::GroupingRole, + QtGroupingProxy::FLAG_NOGROUPNAME | QtGroupingProxy::FLAG_NOSINGLE, + ModList::AggrRole); // we need to store the expanded/collapsed state of all items and restore them 1) when // switching proxies, 2) when filtering and 3) when reseting the mod list. connect(this, &QTreeView::expanded, [=](const QModelIndex& index) { - auto it = m_collapsed[m_sortProxy->sourceModel()].find(index.data(Qt::DisplayRole).toString()); + auto it = m_collapsed[m_sortProxy->sourceModel()].find( + index.data(Qt::DisplayRole).toString()); if (it != m_collapsed[m_sortProxy->sourceModel()].end()) { m_collapsed[m_sortProxy->sourceModel()].erase(it); } }); connect(this, &QTreeView::collapsed, [=](const QModelIndex& index) { - m_collapsed[m_sortProxy->sourceModel()].insert(index.data(Qt::DisplayRole).toString()); + m_collapsed[m_sortProxy->sourceModel()].insert( + index.data(Qt::DisplayRole).toString()); }); // the top-level proxy m_sortProxy = new ModListSortProxy(core.currentProfile(), &core); setModel(m_sortProxy); - connect(m_sortProxy, &ModList::modelReset, [=] { refreshExpandedItems(); }); + connect(m_sortProxy, &ModList::modelReset, [=] { + refreshExpandedItems(); + }); // update the proxy when changing the sort column/direction and the group - connect(m_sortProxy, &QAbstractItemModel::layoutAboutToBeChanged, [this](auto&& parents, auto&& hint) { - if (hint == QAbstractItemModel::VerticalSortHint) { - updateGroupByProxy(); - } - }); - connect(ui.groupBy, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index) { - updateGroupByProxy(); - onModFilterActive(m_sortProxy->isFilterActive()); - }); + connect(m_sortProxy, &QAbstractItemModel::layoutAboutToBeChanged, + [this](auto&& parents, auto&& hint) { + if (hint == QAbstractItemModel::VerticalSortHint) { + updateGroupByProxy(); + } + }); + connect(ui.groupBy, QOverload<int>::of(&QComboBox::currentIndexChanged), + [=](int index) { + updateGroupByProxy(); + onModFilterActive(m_sortProxy->isFilterActive()); + }); sortByColumn(ModList::COL_PRIORITY, Qt::AscendingOrder); // inform the mod list about the type of item being dropped at the beginning of a drag // and the position of the drop indicator at the end (only for by-priority) connect(this, &ModListView::dragEntered, core.modList(), &ModList::onDragEnter); - connect(this, &ModListView::dropEntered, m_byPriorityProxy, &ModListByPriorityProxy::onDropEnter); + connect(this, &ModListView::dropEntered, m_byPriorityProxy, + &ModListByPriorityProxy::onDropEnter); - connect(m_sortProxy, &ModListSortProxy::filterInvalidated, this, &ModListView::updateModCount); + connect(m_sortProxy, &ModListSortProxy::filterInvalidated, this, + &ModListView::updateModCount); - connect(header(), &QHeaderView::sortIndicatorChanged, [=](int, Qt::SortOrder) { verticalScrollBar()->repaint(); }); - connect(header(), &QHeaderView::sectionResized, [=](int logicalIndex, int oldSize, int newSize) { - m_sortProxy->setColumnVisible(logicalIndex, newSize != 0); }); + connect(header(), &QHeaderView::sortIndicatorChanged, [=](int, Qt::SortOrder) { + verticalScrollBar()->repaint(); + }); + connect(header(), &QHeaderView::sectionResized, + [=](int logicalIndex, int oldSize, int newSize) { + m_sortProxy->setColumnVisible(logicalIndex, newSize != 0); + }); - setItemDelegateForColumn(ModList::COL_FLAGS, new ModFlagIconDelegate(this, ModList::COL_FLAGS, 120)); - setItemDelegateForColumn(ModList::COL_CONFLICTFLAGS, new ModConflictIconDelegate(this, ModList::COL_CONFLICTFLAGS, 80)); - setItemDelegateForColumn(ModList::COL_CONTENT, new ModContentIconDelegate(this, ModList::COL_CONTENT, 150)); - setItemDelegateForColumn(ModList::COL_VERSION, new ModListVersionDelegate(this, core.settings())); + setItemDelegateForColumn(ModList::COL_FLAGS, + new ModFlagIconDelegate(this, ModList::COL_FLAGS, 120)); + setItemDelegateForColumn( + ModList::COL_CONFLICTFLAGS, + new ModConflictIconDelegate(this, ModList::COL_CONFLICTFLAGS, 80)); + setItemDelegateForColumn(ModList::COL_CONTENT, + new ModContentIconDelegate(this, ModList::COL_CONTENT, 150)); + setItemDelegateForColumn(ModList::COL_VERSION, + new ModListVersionDelegate(this, core.settings())); if (m_core->settings().geometry().restoreState(header())) { - // hack: force the resize-signal to be triggered because restoreState doesn't seem to do that + // hack: force the resize-signal to be triggered because restoreState doesn't seem + // to do that for (int column = 0; column <= ModList::COL_LASTCOLUMN; ++column) { int sectionSize = header()->sectionSize(column); header()->resizeSection(column, sectionSize + 1); header()->resizeSection(column, sectionSize); } - } - else { + } else { // hide these columns by default header()->setSectionHidden(ModList::COL_CONTENT, true); header()->setSectionHidden(ModList::COL_MODID, true); @@ -788,28 +838,47 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo // we need QueuedConnection for the download/archive dropped otherwise the // installation starts within the drop-event and it's not possible to drag&drop // in the manual installer - connect(m_core->modList(), &ModList::downloadArchiveDropped, this, [=](int row, int priority) { - m_core->installDownload(row, priority); - }, Qt::QueuedConnection); - connect(m_core->modList(), &ModList::externalArchiveDropped, this, [=](const QUrl& url, int priority) { - setWindowState(Qt::WindowActive); - m_core->installArchive(url.toLocalFile(), priority, false, nullptr); - }, Qt::QueuedConnection); - connect(m_core->modList(), &ModList::externalFolderDropped, this, &ModListView::onExternalFolderDropped); + connect( + m_core->modList(), &ModList::downloadArchiveDropped, this, + [=](int row, int priority) { + m_core->installDownload(row, priority); + }, + Qt::QueuedConnection); + connect( + m_core->modList(), &ModList::externalArchiveDropped, this, + [=](const QUrl& url, int priority) { + setWindowState(Qt::WindowActive); + m_core->installArchive(url.toLocalFile(), priority, false, nullptr); + }, + Qt::QueuedConnection); + connect(m_core->modList(), &ModList::externalFolderDropped, this, + &ModListView::onExternalFolderDropped); - connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=] { m_refreshMarkersTimer.start(); }); - connect(this, &QTreeView::collapsed, [=] { m_refreshMarkersTimer.start(); }); - connect(this, &QTreeView::expanded, [=] { m_refreshMarkersTimer.start(); }); + connect(selectionModel(), &QItemSelectionModel::selectionChanged, [=] { + m_refreshMarkersTimer.start(); + }); + connect(this, &QTreeView::collapsed, [=] { + m_refreshMarkersTimer.start(); + }); + connect(this, &QTreeView::expanded, [=] { + m_refreshMarkersTimer.start(); + }); // filters - connect(m_sortProxy, &ModListSortProxy::filterActive, this, &ModListView::onModFilterActive); - connect(m_filters.get(), &FilterList::criteriaChanged, [=](auto&& v) { onFiltersCriteria(v); }); - connect(m_filters.get(), &FilterList::optionsChanged, [=](auto&& mode, auto&& sep) { setFilterOptions(mode, sep); }); - connect(ui.filter, &QLineEdit::textChanged, m_sortProxy, &ModListSortProxy::updateFilter); + connect(m_sortProxy, &ModListSortProxy::filterActive, this, + &ModListView::onModFilterActive); + connect(m_filters.get(), &FilterList::criteriaChanged, [=](auto&& v) { + onFiltersCriteria(v); + }); + connect(m_filters.get(), &FilterList::optionsChanged, [=](auto&& mode, auto&& sep) { + setFilterOptions(mode, sep); + }); + connect(ui.filter, &QLineEdit::textChanged, m_sortProxy, + &ModListSortProxy::updateFilter); connect(ui.clearFilters, &QPushButton::clicked, [=]() { - ui.filter->clear(); - m_filters->clearSelection(); - }); + ui.filter->clear(); + m_filters->clearSelection(); + }); connect(m_sortProxy, &ModListSortProxy::filterInvalidated, [=]() { if (hasCollapsibleSeparators()) { refreshExpandedItems(); @@ -842,25 +911,26 @@ QRect ModListView::visualRect(const QModelIndex& index) const // this shift the visualRect() from QTreeView to match the new actual // zone after removing indentation (see the ModListStyledItemDelegate) QRect rect = QTreeView::visualRect(index); - if (hasCollapsibleSeparators() - && index.column() == 0 && index.isValid() - && index.parent().isValid()) { + if (hasCollapsibleSeparators() && index.column() == 0 && index.isValid() && + index.parent().isValid()) { rect.adjust(-indentation(), 0, 0, 0); } return rect; } -void ModListView::drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const +void ModListView::drawBranches(QPainter* painter, const QRect& rect, + const QModelIndex& index) const { - // the branches are the small indicator left to the row (there are none in the default style, and - // the VS dark style only has background for these) + // the branches are the small indicator left to the row (there are none in the default + // style, and the VS dark style only has background for these) // - // the branches are not shifted left with the visualRect() change and since MO2 uses stylesheet, - // it is not possible to shift those in the proxy style so we have to shift it here. + // the branches are not shifted left with the visualRect() change and since MO2 uses + // stylesheet, it is not possible to shift those in the proxy style so we have to + // shift it here. // QRect r(rect); if (hasCollapsibleSeparators() && index.parent().isValid()) { - r.adjust(-indentation(), 0, 0 -indentation(), 0); + r.adjust(-indentation(), 0, 0 - indentation(), 0); } QTreeView::drawBranches(painter, r, index); } @@ -872,8 +942,7 @@ void ModListView::commitData(QWidget* editor) auto [current, selected] = this->selected(); QTreeView::commitData(editor); setSelected(current, selected); - } - else { + } else { QTreeView::commitData(editor); } } @@ -900,15 +969,13 @@ void ModListView::onCustomContextMenuRequested(const QPoint& pos) if (!contextIdx.isValid()) { // no selection ModListGlobalContextMenu(*m_core, this).exec(viewport()->mapToGlobal(pos)); + } else { + ModListContextMenu(contextIdx, *m_core, *m_categories, this) + .exec(viewport()->mapToGlobal(pos)); } - else { - ModListContextMenu(contextIdx, *m_core, *m_categories, this).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")); } } @@ -919,7 +986,8 @@ void ModListView::onDoubleClicked(const QModelIndex& index) return; } - if (m_core->modList()->timeElapsedSinceLastChecked() <= QApplication::doubleClickInterval()) { + if (m_core->modList()->timeElapsedSinceLastChecked() <= + QApplication::doubleClickInterval()) { // don't interpret double click if we only just checked a mod return; } @@ -937,38 +1005,44 @@ void ModListView::onDoubleClicked(const QModelIndex& index) if (modifiers.testFlag(Qt::ControlModifier)) { try { shell::Explore(modInfo->absolutePath()); - } - catch (const std::exception& e) { + } catch (const std::exception& e) { reportError(e.what()); } - } - else if (modifiers.testFlag(Qt::ShiftModifier)) { + } else if (modifiers.testFlag(Qt::ShiftModifier)) { try { - actions().visitNexusOrWebPage({ indexViewToModel(index) }); - } - catch (const std::exception& e) { + actions().visitNexusOrWebPage({indexViewToModel(index)}); + } catch (const std::exception& e) { reportError(e.what()); } - } - else if (hasCollapsibleSeparators() && modInfo->isSeparator()) { + } else if (hasCollapsibleSeparators() && modInfo->isSeparator()) { setExpanded(index, !isExpanded(index)); - } - else { + } else { try { auto tab = ModInfoTabIDs::None; switch (index.column()) { - case ModList::COL_NOTES: tab = ModInfoTabIDs::Notes; break; - case ModList::COL_VERSION: tab = ModInfoTabIDs::Nexus; break; - case ModList::COL_MODID: tab = ModInfoTabIDs::Nexus; break; - case ModList::COL_GAME: tab = ModInfoTabIDs::Nexus; break; - case ModList::COL_CATEGORY: tab = ModInfoTabIDs::Categories; break; - case ModList::COL_CONFLICTFLAGS: tab = ModInfoTabIDs::Conflicts; break; + case ModList::COL_NOTES: + tab = ModInfoTabIDs::Notes; + break; + case ModList::COL_VERSION: + tab = ModInfoTabIDs::Nexus; + break; + case ModList::COL_MODID: + tab = ModInfoTabIDs::Nexus; + break; + case ModList::COL_GAME: + tab = ModInfoTabIDs::Nexus; + break; + case ModList::COL_CATEGORY: + tab = ModInfoTabIDs::Categories; + break; + case ModList::COL_CONFLICTFLAGS: + tab = ModInfoTabIDs::Conflicts; + break; } actions().displayModInformation(modIndex, tab); - } - catch (const std::exception& e) { + } catch (const std::exception& e) { reportError(e.what()); } } @@ -1006,7 +1080,8 @@ void ModListView::setOverwriteMarkers(const QModelIndexList& indexes) insert(m_markers.archiveLooseOverwritten, info->getModArchiveLooseOverwritten()); } } - dataChanged(model()->index(0, 0), model()->index(model()->rowCount(), model()->columnCount())); + dataChanged(model()->index(0, 0), + model()->index(model()->rowCount(), model()->columnCount())); verticalScrollBar()->repaint(); } @@ -1016,9 +1091,7 @@ void ModListView::refreshMarkersAndPlugins() if (m_core->settings().interface().collapsibleSeparatorsHighlightFrom()) { for (auto& idx : selectionModel()->selectedRows()) { - if (hasCollapsibleSeparators() - && model()->hasChildren(idx) - && !isExpanded(idx)) { + if (hasCollapsibleSeparators() && model()->hasChildren(idx) && !isExpanded(idx)) { for (int i = 0; i < model()->rowCount(idx); ++i) { indexes.append(model()->index(i, idx.column(), idx)); } @@ -1037,7 +1110,6 @@ void ModListView::refreshMarkersAndPlugins() ui.pluginList->verticalScrollBar()->repaint(); } - void ModListView::setHighlightedMods(const std::vector<unsigned int>& pluginIndices) { m_markers.highlight.clear(); @@ -1045,16 +1117,19 @@ void ModListView::setHighlightedMods(const std::vector<unsigned int>& pluginIndi for (auto idx : pluginIndices) { QString pluginName = m_core->pluginList()->getName(idx); - const MOShared::FileEntryPtr fileEntry = directoryEntry.findFile(pluginName.toStdWString()); + const MOShared::FileEntryPtr fileEntry = + directoryEntry.findFile(pluginName.toStdWString()); if (fileEntry.get() != nullptr) { - QString originName = QString::fromStdWString(directoryEntry.getOriginByID(fileEntry->getOrigin()).getName()); + QString originName = QString::fromStdWString( + directoryEntry.getOriginByID(fileEntry->getOrigin()).getName()); const auto index = ModInfo::getIndex(originName); if (index != UINT_MAX) { m_markers.highlight.insert(index); } } } - dataChanged(model()->index(0, 0), model()->index(model()->rowCount(), model()->columnCount())); + dataChanged(model()->index(0, 0), + model()->index(model()->rowCount(), model()->columnCount())); verticalScrollBar()->repaint(); } @@ -1063,33 +1138,34 @@ QColor ModListView::markerColor(const QModelIndex& index) const unsigned int modIndex = index.data(ModList::IndexRole).toInt(); bool highligth = m_markers.highlight.find(modIndex) != m_markers.highlight.end(); bool overwrite = m_markers.overwrite.find(modIndex) != m_markers.overwrite.end(); - bool archiveOverwrite = m_markers.archiveOverwrite.find(modIndex) != m_markers.archiveOverwrite.end(); - bool archiveLooseOverwrite = m_markers.archiveLooseOverwrite.find(modIndex) != m_markers.archiveLooseOverwrite.end(); - bool overwritten = m_markers.overwritten.find(modIndex) != m_markers.overwritten.end(); - bool archiveOverwritten = m_markers.archiveOverwritten.find(modIndex) != m_markers.archiveOverwritten.end(); - bool archiveLooseOverwritten = m_markers.archiveLooseOverwritten.find(modIndex) != m_markers.archiveLooseOverwritten.end(); + bool archiveOverwrite = + m_markers.archiveOverwrite.find(modIndex) != m_markers.archiveOverwrite.end(); + bool archiveLooseOverwrite = m_markers.archiveLooseOverwrite.find(modIndex) != + m_markers.archiveLooseOverwrite.end(); + bool overwritten = + m_markers.overwritten.find(modIndex) != m_markers.overwritten.end(); + bool archiveOverwritten = + m_markers.archiveOverwritten.find(modIndex) != m_markers.archiveOverwritten.end(); + bool archiveLooseOverwritten = m_markers.archiveLooseOverwritten.find(modIndex) != + m_markers.archiveLooseOverwritten.end(); if (highligth) { return Settings::instance().colors().modlistContainsPlugin(); - } - else if (overwritten || archiveLooseOverwritten) { + } else if (overwritten || archiveLooseOverwritten) { return Settings::instance().colors().modlistOverwritingLoose(); - } - else if (overwrite || archiveLooseOverwrite) { + } else if (overwrite || archiveLooseOverwrite) { return Settings::instance().colors().modlistOverwrittenLoose(); - } - else if (archiveOverwritten) { + } else if (archiveOverwritten) { return Settings::instance().colors().modlistOverwritingArchive(); - } - else if (archiveOverwrite) { + } else if (archiveOverwrite) { return Settings::instance().colors().modlistOverwrittenArchive(); } // collapsed separator auto rowIndex = index.sibling(index.row(), 0); - if (hasCollapsibleSeparators() - && m_core->settings().interface().collapsibleSeparatorsHighlightTo() - && model()->hasChildren(rowIndex) && !isExpanded(rowIndex)) { + if (hasCollapsibleSeparators() && + m_core->settings().interface().collapsibleSeparatorsHighlightTo() && + model()->hasChildren(rowIndex) && !isExpanded(rowIndex)) { std::vector<QColor> colors; for (int i = 0; i < model()->rowCount(rowIndex); ++i) { @@ -1111,31 +1187,33 @@ QColor ModListView::markerColor(const QModelIndex& index) const a += color.alpha(); } - return QColor(r / colors.size(), g / colors.size(), b / colors.size(), a / colors.size()); + return QColor(r / colors.size(), g / colors.size(), b / colors.size(), + a / colors.size()); } return QColor(); } -std::vector<ModInfo::EFlag> ModListView::modFlags(const QModelIndex& index, bool* forceCompact) const +std::vector<ModInfo::EFlag> ModListView::modFlags(const QModelIndex& index, + bool* forceCompact) const { ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt()); - auto flags = info->getFlags(); + auto flags = info->getFlags(); bool compact = false; - if (info->isSeparator() - && hasCollapsibleSeparators() - && m_core->settings().interface().collapsibleSeparatorsIcons(ModList::COL_FLAGS) - && !isExpanded(index.sibling(index.row(), 0))) { + if (info->isSeparator() && hasCollapsibleSeparators() && + m_core->settings().interface().collapsibleSeparatorsIcons(ModList::COL_FLAGS) && + !isExpanded(index.sibling(index.row(), 0))) { // combine the child conflicts std::set eFlags(flags.begin(), flags.end()); for (int i = 0; i < model()->rowCount(index); ++i) { - auto cIndex = model()->index(i, index.column(), index).data(ModList::IndexRole).toInt(); + auto cIndex = + model()->index(i, index.column(), index).data(ModList::IndexRole).toInt(); auto cFlags = ModInfo::getByIndex(cIndex)->getFlags(); eFlags.insert(cFlags.begin(), cFlags.end()); } - flags = { eFlags.begin(), eFlags.end() }; + flags = {eFlags.begin(), eFlags.end()}; // force compact because there can be a lots of flags here compact = true; @@ -1148,25 +1226,27 @@ std::vector<ModInfo::EFlag> ModListView::modFlags(const QModelIndex& index, bool return flags; } -std::vector<ModInfo::EConflictFlag> ModListView::conflictFlags(const QModelIndex& index, bool* forceCompact) const +std::vector<ModInfo::EConflictFlag> ModListView::conflictFlags(const QModelIndex& index, + bool* forceCompact) const { ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt()); - auto flags = info->getConflictFlags(); + auto flags = info->getConflictFlags(); bool compact = false; - if (info->isSeparator() - && hasCollapsibleSeparators() - && m_core->settings().interface().collapsibleSeparatorsIcons(ModList::COL_CONFLICTFLAGS) - && !isExpanded(index.sibling(index.row(), 0))) { + if (info->isSeparator() && hasCollapsibleSeparators() && + m_core->settings().interface().collapsibleSeparatorsIcons( + ModList::COL_CONFLICTFLAGS) && + !isExpanded(index.sibling(index.row(), 0))) { // combine the child conflicts std::set<ModInfo::EConflictFlag> eFlags(flags.begin(), flags.end()); for (int i = 0; i < model()->rowCount(index); ++i) { - auto cIndex = model()->index(i, index.column(), index).data(ModList::IndexRole).toInt(); + auto cIndex = + model()->index(i, index.column(), index).data(ModList::IndexRole).toInt(); auto cFlags = ModInfo::getByIndex(cIndex)->getConflictFlags(); eFlags.insert(cFlags.begin(), cFlags.end()); } - flags = { eFlags.begin(), eFlags.end() }; + flags = {eFlags.begin(), eFlags.end()}; // force compact because there can be a lots of flags here compact = true; @@ -1179,29 +1259,30 @@ std::vector<ModInfo::EConflictFlag> ModListView::conflictFlags(const QModelIndex return flags; } -std::set<int> ModListView::contents(const QModelIndex& index, bool* includeChildren) const +std::set<int> ModListView::contents(const QModelIndex& index, + bool* includeChildren) const { auto modIndex = index.data(ModList::IndexRole); if (!modIndex.isValid()) { return {}; } ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt()); - auto contents = info->getContents(); - bool children = false; + auto contents = info->getContents(); + bool children = false; - if (info->isSeparator() - && hasCollapsibleSeparators() - && m_core->settings().interface().collapsibleSeparatorsIcons(ModList::COL_CONTENT) - && !isExpanded(index.sibling(index.row(), 0))) { + if (info->isSeparator() && hasCollapsibleSeparators() && + m_core->settings().interface().collapsibleSeparatorsIcons(ModList::COL_CONTENT) && + !isExpanded(index.sibling(index.row(), 0))) { // combine the child contents std::set eContents(contents.begin(), contents.end()); for (int i = 0; i < model()->rowCount(index); ++i) { - auto cIndex = model()->index(i, index.column(), index).data(ModList::IndexRole).toInt(); + auto cIndex = + model()->index(i, index.column(), index).data(ModList::IndexRole).toInt(); auto cContents = ModInfo::getByIndex(cIndex)->getContents(); eContents.insert(cContents.begin(), cContents.end()); } - contents = { eContents.begin(), eContents.end() }; + contents = {eContents.begin(), eContents.end()}; children = true; } @@ -1212,14 +1293,19 @@ std::set<int> ModListView::contents(const QModelIndex& index, bool* includeChild return contents; } -QList<QString> ModListView::contentsIcons(const QModelIndex& index, bool* forceCompact) const +QList<QString> ModListView::contentsIcons(const QModelIndex& index, + bool* forceCompact) const { auto contents = this->contents(index, forceCompact); QList<QString> result; m_core->modDataContents().forEachContentInOrOut( - contents, - [&result](auto const& content) { result.append(content.icon()); }, - [&result](auto const&) { result.append(QString()); }); + contents, + [&result](auto const& content) { + result.append(content.icon()); + }, + [&result](auto const&) { + result.append(QString()); + }); return result; } @@ -1232,14 +1318,16 @@ QString ModListView::contentsTooltip(const QModelIndex& index) const QString result("<table cellspacing=7>"); m_core->modDataContents().forEachContentIn(contents, [&result](auto const& content) { result.append(QString("<tr><td><img src=\"%1\" width=32/></td>" - "<td valign=\"middle\">%2</td></tr>") - .arg(content.icon()).arg(content.name())); - }); + "<td valign=\"middle\">%2</td></tr>") + .arg(content.icon()) + .arg(content.name())); + }); result.append("</table>"); return result; } -void ModListView::onFiltersCriteria(const std::vector<ModListSortProxy::Criteria>& criteria) +void ModListView::onFiltersCriteria( + const std::vector<ModListSortProxy::Criteria>& criteria) { setFilterCriteria(criteria); @@ -1247,23 +1335,20 @@ void ModListView::onFiltersCriteria(const std::vector<ModListSortProxy::Criteria if (criteria.empty()) { label = ""; - } - else if (criteria.size() == 1) { + } else if (criteria.size() == 1) { const auto& c = criteria[0]; if (c.type == ModListSortProxy::TypeContent) { const auto* content = m_core->modDataContents().findById(c.id); - label = content ? content->name() : QString(); - } - else { + label = content ? content->name() : QString(); + } else { label = m_categories->getCategoryNameByID(c.id); } if (label.isEmpty()) { log::error("category {}:{} not found", c.type, c.id); } - } - else { + } else { label = tr("<Multiple>"); } @@ -1282,8 +1367,8 @@ void ModListView::dragEnterEvent(QDragEnterEvent* event) // returns false, so we notify user on drag enter ModListDropInfo dropInfo(event->mimeData(), *m_core); - if (dropInfo.isValid() && !dropInfo.isLocalFileDrop() - && sortColumn() != ModList::COL_PRIORITY) { + if (dropInfo.isValid() && !dropInfo.isLocalFileDrop() && + sortColumn() != ModList::COL_PRIORITY) { log::warn("Drag&Drop is only supported when sorting by priority."); } } @@ -1315,7 +1400,8 @@ void ModListView::dropEvent(QDropEvent* event) // this event is used by the byPriorityProxy to know if allow // dropping mod between a separator and its first mod (there // is no way to deduce this except using dropIndicatorPosition()) - emit dropEntered(event->mimeData(), isExpanded(index), static_cast<DropPosition>(dropIndicatorPosition())); + emit dropEntered(event->mimeData(), isExpanded(index), + static_cast<DropPosition>(dropIndicatorPosition())); // see selectedIndexes() m_inDragMoveEvent = true; @@ -1328,14 +1414,14 @@ void ModListView::timerEvent(QTimerEvent* event) // prevent auto-collapse, see dragMoveEvent() if (event->timerId() == m_openTimer.timerId()) { QPoint pos = viewport()->mapFromGlobal(QCursor::pos()); - if (state() == QAbstractItemView::DraggingState - && viewport()->rect().contains(pos)) { + if (state() == QAbstractItemView::DraggingState && + viewport()->rect().contains(pos)) { QModelIndex index = indexAt(pos); - setExpanded(index, !m_core->settings().interface().autoCollapseOnHover() || !isExpanded(index)); + setExpanded(index, !m_core->settings().interface().autoCollapseOnHover() || + !isExpanded(index)); } m_openTimer.stop(); - } - else { + } else { QTreeView::timerEvent(event); } } @@ -1363,16 +1449,16 @@ void ModListView::mousePressEvent(QMouseEvent* event) const auto index = indexAt(event->pos()); - if (event->isAccepted() - && hasCollapsibleSeparators() - && index.isValid() && model()->hasChildren(indexAt(event->pos())) - && (event->modifiers() & Qt::AltModifier)) { + if (event->isAccepted() && hasCollapsibleSeparators() && index.isValid() && + model()->hasChildren(indexAt(event->pos())) && + (event->modifiers() & Qt::AltModifier)) { - const auto flag = selectionModel()->isSelected(index) ? - QItemSelectionModel::Select : QItemSelectionModel::Deselect; + const auto flag = selectionModel()->isSelected(index) + ? QItemSelectionModel::Select + : QItemSelectionModel::Deselect; const QItemSelection selection( - model()->index(0, index.column(), index), - model()->index(model()->rowCount(index) - 1, index.column(), index)); + model()->index(0, index.column(), index), + model()->index(model()->rowCount(index) - 1, index.column(), index)); selectionModel()->select(selection, flag | QItemSelectionModel::Rows); } } @@ -1399,25 +1485,24 @@ void ModListView::mouseReleaseEvent(QMouseEvent* event) // restore triggers setEditTriggers(triggers); - if (event->isAccepted() - && hasCollapsibleSeparators() - && index.isValid() && model()->hasChildren(indexAt(event->pos())) - && (event->modifiers() & Qt::AltModifier)) { + if (event->isAccepted() && hasCollapsibleSeparators() && index.isValid() && + model()->hasChildren(indexAt(event->pos())) && + (event->modifiers() & Qt::AltModifier)) { - const auto flag = selectionModel()->isSelected(index) ? - QItemSelectionModel::Select : QItemSelectionModel::Deselect; + const auto flag = selectionModel()->isSelected(index) + ? QItemSelectionModel::Select + : QItemSelectionModel::Deselect; const QItemSelection selection( - model()->index(0, index.column(), index), - model()->index(model()->rowCount(index) - 1, index.column(), index)); + model()->index(0, index.column(), index), + model()->index(model()->rowCount(index) - 1, index.column(), index)); selectionModel()->select(selection, flag | QItemSelectionModel::Rows); } } bool ModListView::event(QEvent* event) { - if (event->type() == QEvent::KeyPress - && m_core->currentProfile() - && selectionModel()->hasSelection()) { + if (event->type() == QEvent::KeyPress && m_core->currentProfile() && + selectionModel()->hasSelection()) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); auto index = selectionModel()->currentIndex(); @@ -1426,36 +1511,32 @@ bool ModListView::event(QEvent* event) // ctrl+enter open explorer if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) { if (selectionModel()->selectedRows().count() == 1) { - m_actions->openExplorer({ indexViewToModel(index) }); + m_actions->openExplorer({indexViewToModel(index)}); return true; } } // ctrl+up/down move selection - else if (sortColumn() == ModList::COL_PRIORITY - && (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down)) { + else if (sortColumn() == ModList::COL_PRIORITY && + (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down)) { return moveSelection(keyEvent->key()); } - } - else if (keyEvent->modifiers() == Qt::ShiftModifier) { + } else if (keyEvent->modifiers() == Qt::ShiftModifier) { // shift+enter expand - if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) - && selectionModel()->selectedRows().count() == 1) { + if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) && + selectionModel()->selectedRows().count() == 1) { if (model()->hasChildren(index)) { setExpanded(index, !isExpanded(index)); - } - else if (index.parent().isValid()) { + } else if (index.parent().isValid()) { setExpanded(index.parent(), false); - selectionModel()->select(index.parent(), - QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + selectionModel()->select(index.parent(), QItemSelectionModel::SelectCurrent | + QItemSelectionModel::Rows); setCurrentIndex(index.parent()); } } - } - else { + } else { if (keyEvent->key() == Qt::Key_Delete) { return removeSelection(); - } - else if (keyEvent->key() == Qt::Key_Space) { + } else if (keyEvent->key() == Qt::Key_Space) { return toggleSelectionState(); } } |
