From 123f9f408b1845c5eb6878b0df2394eef4dbe3b8 Mon Sep 17 00:00:00 2001 From: Al <26797547+Al12rs@users.noreply.github.com> Date: Tue, 21 Jan 2020 01:16:41 +0100 Subject: Fixed missing context menu on general conflicts tab. Was due to the new FilterWidget adding a QSortProxy and the selection had to be translated to the underlying model. Normalized use of FilderWidget on the Advanced Conflicts tab. --- src/modinfodialogconflicts.cpp | 103 ++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 31 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index baa5a33c..6d040e3f 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -365,20 +365,28 @@ template void for_each_in_selection(QTreeView* tree, F&& f) { const auto* sel = tree->selectionModel(); - const auto* model = dynamic_cast(tree->model()); + + const auto* proxy = dynamic_cast(tree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast(proxy->sourceModel()); if (!model) { log::error("tree doesn't have a ConflictListModel"); return; } - for (const auto& range : sel->selection()) { - // ranges are inclusive - for (int row=range.top(); row<=range.bottom(); ++row) { - if (auto* item=model->getItem(static_cast(row))) { - if (!f(item)) { - return; - } + auto modelSel = proxy->mapSelectionToSource(sel->selection()); + + for (const auto& rowIndex : sel->selectedRows()) { + auto modelRow = proxy->mapToSource(rowIndex).row(); + if (auto* item = model->getItem(static_cast(modelRow))) { + if (!f(item)) { + return; } } } @@ -461,9 +469,17 @@ void ConflictsTab::changeItemsVisibility(QTreeView* tree, bool visible) FileRenamer renamer(parentWidget(), flags); - auto* model = dynamic_cast(tree->model()); + const auto* proxy = dynamic_cast(tree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast(proxy->sourceModel()); + if (!model) { - log::error("list doesn't have a ConflictListModel"); + log::error("tree doesn't have a ConflictListModel"); return; } @@ -707,16 +723,27 @@ ConflictsTab::Actions ConflictsTab::createMenuActions(QTreeView* tree) const auto n = smallSelectionSize(tree); - const auto* model = dynamic_cast(tree->model()); + const auto* proxy = dynamic_cast(tree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return {}; + } + + const auto* model = dynamic_cast(proxy->sourceModel()); + if (!model) { log::error("tree doesn't have a ConflictListModel"); return {}; } + auto modelSel = proxy->mapSelectionToSource(tree->selectionModel()->selection()); + + if (n == 1) { // this is a single selection const auto* item = model->getItem(static_cast( - tree->selectionModel()->selectedRows()[0].row())); + modelSel.indexes()[0].row())); if (!item) { return {}; @@ -797,7 +824,7 @@ ConflictsTab::Actions ConflictsTab::createMenuActions(QTreeView* tree) if (enableGoto && n == 1) { const auto* item = model->getItem(static_cast( - tree->selectionModel()->selectedRows()[0].row())); + modelSel.indexes()[0].row())); actions.gotoActions = createGotoActions(item); } @@ -1027,12 +1054,23 @@ ConflictItem GeneralConflictsTab::createOverwrittenItem( void GeneralConflictsTab::onOverwriteActivated(const QModelIndex& index) { - auto* model = dynamic_cast(ui->overwriteTree->model()); + const auto* proxy = dynamic_cast(ui->overwriteTree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast(proxy->sourceModel()); + if (!model) { + log::error("tree doesn't have a ConflictListModel"); return; } - auto* item = model->getItem(static_cast(index.row())); + auto modelIndex = proxy->mapToSource(index); + + auto* item = model->getItem(static_cast(modelIndex.row())); if (!item) { return; } @@ -1045,12 +1083,25 @@ void GeneralConflictsTab::onOverwriteActivated(const QModelIndex& index) void GeneralConflictsTab::onOverwrittenActivated(const QModelIndex& index) { - auto* model = dynamic_cast(ui->overwrittenTree->model()); + const auto* proxy = dynamic_cast(ui->overwrittenTree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast(proxy->sourceModel()); + if (!model) { + log::error("tree doesn't have a ConflictListModel"); return; } - auto* item = model->getItem(static_cast(index.row())); + proxy->mapSelectionToSource(ui->overwrittenTree->selectionModel()->selection()); + + auto modelIndex = proxy->mapToSource(index); + + auto* item = model->getItem(static_cast(modelIndex.row())); if (!item) { return; } @@ -1067,6 +1118,10 @@ AdvancedConflictsTab::AdvancedConflictsTab( m_tab(tab), ui(pui), m_core(oc), m_model(new AdvancedConflictListModel(ui->conflictsAdvancedList)) { + + m_filter.setEdit(ui->conflictsAdvancedFilter); + m_filter.setList(ui->conflictsAdvancedList); + // left-elide the overwrites column so that the nearest are visible ui->conflictsAdvancedList->setItemDelegateForColumn( 0, new ElideLeftDelegate(ui->conflictsAdvancedList)); @@ -1096,9 +1151,6 @@ AdvancedConflictsTab::AdvancedConflictsTab( QObject::connect( ui->conflictsAdvancedList, &QTreeView::customContextMenuRequested, [&](const QPoint& p){ m_tab->showContextMenu(p, ui->conflictsAdvancedList); }); - - m_filter.setEdit(ui->conflictsAdvancedFilter); - QObject::connect(&m_filter, &FilterWidget::changed, [&]{ update(); }); } void AdvancedConflictsTab::clear() @@ -1256,17 +1308,6 @@ std::optional AdvancedConflictsTab::createItem( auto beforeQS = QString::fromStdWString(before); auto afterQS = QString::fromStdWString(after); - const bool matched = m_filter.matches([&](auto&& what) { - return - beforeQS.contains(what, Qt::CaseInsensitive) || - relativeName.contains(what, Qt::CaseInsensitive) || - afterQS.contains(what, Qt::CaseInsensitive); - }); - - if (!matched) { - return {}; - } - return ConflictItem( std::move(beforeQS), std::move(relativeName), std::move(afterQS), index, std::move(fileName), hasAlts, QString(), archive); -- cgit v1.3.1 From 2217d9c57588c562134136a63f5e518410e7074c Mon Sep 17 00:00:00 2001 From: Al <26797547+Al12rs@users.noreply.github.com> Date: Tue, 21 Jan 2020 01:49:22 +0100 Subject: Removed missed line --- src/modinfodialogconflicts.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 6d040e3f..eb3debc5 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -380,8 +380,6 @@ void for_each_in_selection(QTreeView* tree, F&& f) return; } - auto modelSel = proxy->mapSelectionToSource(sel->selection()); - for (const auto& rowIndex : sel->selectedRows()) { auto modelRow = proxy->mapToSource(rowIndex).row(); if (auto* item = model->getItem(static_cast(modelRow))) { -- cgit v1.3.1 From 5af018d18a279aee1fbfedf372b40d8fc5a97d7a Mon Sep 17 00:00:00 2001 From: Al <26797547+Al12rs@users.noreply.github.com> Date: Tue, 21 Jan 2020 01:54:44 +0100 Subject: Renamed underscores function name to pascal case --- src/modinfodialogconflicts.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index eb3debc5..63d89a1a 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -362,7 +362,7 @@ std::size_t smallSelectionSize(const QTreeView* tree) } template -void for_each_in_selection(QTreeView* tree, F&& f) +void forEachInSelection(QTreeView* tree, F&& f) { const auto* sel = tree->selectionModel(); @@ -481,7 +481,7 @@ void ConflictsTab::changeItemsVisibility(QTreeView* tree, bool visible) return; } - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { if (stop) { return false; } @@ -546,7 +546,7 @@ void ConflictsTab::activateItems(QTreeView* tree) // the menu item is only shown for a single selection, but handle all of them // in case this changes - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { const auto path = item->fileName(); if (tryPreview && canPreviewFile(plugin(), item->isArchive(), path)) { @@ -563,7 +563,7 @@ void ConflictsTab::openItems(QTreeView* tree, bool hooked) { // the menu item is only shown for a single selection, but handle all of them // in case this changes - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { openItem(item, hooked); return true; }); @@ -582,7 +582,7 @@ void ConflictsTab::previewItems(QTreeView* tree) { // the menu item is only shown for a single selection, but handle all of them // in case this changes - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { previewItem(item); return true; }); @@ -597,7 +597,7 @@ void ConflictsTab::exploreItems(QTreeView* tree) { // the menu item is only shown for a single selection, but handle all of them // in case this changes - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { shell::Explore(item->fileName()); return true; }); @@ -774,7 +774,7 @@ ConflictsTab::Actions ConflictsTab::createMenuActions(QTreeView* tree) enableHide = false; enableUnhide = false; - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { if (item->canHide()) { enableHide = true; } -- cgit v1.3.1