summaryrefslogtreecommitdiff
path: root/src/modlistview.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-07 20:33:01 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-10 10:27:30 +0100
commit80371ae2ccdb233f9aa92c8982bad6a136c54ae9 (patch)
tree4e602fe5c237cfa50db6e9b4ed9ac0517da74d3d /src/modlistview.cpp
parentf919e0917344d7396f03423ef4fcd4d41fe37b07 (diff)
Update markers and plugins highligths when separator is expanded/collapsed.
Diffstat (limited to 'src/modlistview.cpp')
-rw-r--r--src/modlistview.cpp81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index 2c9634bd..7b1b6f0c 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -138,6 +138,14 @@ ModListView::ModListView(QWidget* parent)
connect(this, &ModListView::doubleClicked, this, &ModListView::onDoubleClicked);
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()
+ // which emit a lots of expanded/collapsed signals in a very small
+ // time window
+ m_refreshMarkersTimer.setInterval(50);
+ m_refreshMarkersTimer.setSingleShot(true);
+ 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();
@@ -432,8 +440,8 @@ void ModListView::onModInstalled(const QString& modName)
QModelIndex qIndex = indexModelToView(m_core->modList()->index(index, 0));
- if (hasCollapsibleSeparators()) {
- setExpanded(qIndex, true);
+ if (hasCollapsibleSeparators() && qIndex.parent().isValid()) {
+ setExpanded(qIndex.parent(), true);
}
// focus, scroll to and select
@@ -777,7 +785,9 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo
});
connect(m_core->modList(), &ModList::externalFolderDropped, this, &ModListView::onExternalFolderDropped);
- connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &ModListView::onSelectionChanged);
+ 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);
@@ -975,6 +985,34 @@ void ModListView::setOverwriteMarkers(const QModelIndexList& indexes)
verticalScrollBar()->repaint();
}
+void ModListView::refreshMarkersAndPlugins()
+{
+ QModelIndexList indexes = selectionModel()->selectedRows();
+
+ if (m_core->settings().interface().collapsibleSeparatorsConflicts()) {
+ for (auto& idx : selectionModel()->selectedRows()) {
+ if (hasCollapsibleSeparators()
+ && model()->hasChildren(idx)
+ && !isExpanded(idx)) {
+ for (int i = 0; i < model()->rowCount(idx); ++i) {
+ indexes.append(model()->index(i, idx.column(), idx));
+ }
+ }
+ }
+ }
+
+ setOverwriteMarkers(indexes);
+
+ // highligth plugins
+ std::vector<unsigned int> modIndices;
+ for (auto& idx : indexes) {
+ modIndices.push_back(idx.data(ModList::IndexRole).toInt());
+ }
+ m_core->pluginList()->highlightPlugins(modIndices, *m_core->directoryStructure());
+ ui.pluginList->verticalScrollBar()->repaint();
+}
+
+
void ModListView::setHighlightedMods(const std::vector<unsigned int>& pluginIndices)
{
m_markers.highlight.clear();
@@ -1176,41 +1214,6 @@ QString ModListView::contentsTooltip(const QModelIndex& index) const
return result;
}
-void ModListView::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
-{
- if (hasCollapsibleSeparators()) {
- for (auto& idx : selected.indexes()) {
- if (idx.parent().isValid() && !isExpanded(idx.parent())) {
- setExpanded(idx.parent(), true);
- }
- }
- }
-
- QModelIndexList indexes = selectionModel()->selectedRows();
-
- if (m_core->settings().interface().collapsibleSeparatorsConflicts()) {
- for (auto& idx : selectionModel()->selectedRows()) {
- if (hasCollapsibleSeparators()
- && model()->hasChildren(idx)
- && !isExpanded(idx)) {
- for (int i = 0; i < model()->rowCount(idx); ++i) {
- indexes.append(model()->index(i, idx.column(), idx));
- }
- }
- }
- }
-
- setOverwriteMarkers(indexes);
-
- // highligth plugins
- std::vector<unsigned int> modIndices;
- for (auto& idx : indexes) {
- modIndices.push_back(idx.data(ModList::IndexRole).toInt());
- }
- m_core->pluginList()->highlightPlugins(modIndices, *m_core->directoryStructure());
- ui.pluginList->verticalScrollBar()->repaint();
-}
-
void ModListView::onFiltersCriteria(const std::vector<ModListSortProxy::Criteria>& criteria)
{
setFilterCriteria(criteria);
@@ -1319,12 +1322,10 @@ void ModListView::mousePressEvent(QMouseEvent* event)
const auto flag = selectionModel()->isSelected(index) ?
QItemSelectionModel::Select : QItemSelectionModel::Deselect;
- const bool expanded = isExpanded(index);
const QItemSelection selection(
model()->index(0, index.column(), index),
model()->index(model()->rowCount(index) - 1, index.column(), index));
selectionModel()->select(selection, flag | QItemSelectionModel::Rows);
- setExpanded(index, expanded);
}
}