diff options
| author | Al <26797547+Al12rs@users.noreply.github.com> | 2020-01-22 23:09:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-22 23:09:57 +0100 |
| commit | 6305f6e2e93ec9c0e6fdef996713eb5be7bdd46e (patch) | |
| tree | 21ca3638d1f58ebdb194e00c2bf0d62800fa12ab /src | |
| parent | eacbe101f180b48bb48bf36d84125ed8cfd4901a (diff) | |
| parent | 5af018d18a279aee1fbfedf372b40d8fc5a97d7a (diff) | |
Merge pull request #980 from Al12rs/context-menu-fix
Fixed missing context menu on general conflicts tab.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modinfodialogconflicts.cpp | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index baa5a33c..63d89a1a 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -362,23 +362,29 @@ std::size_t smallSelectionSize(const QTreeView* tree) } template <class F> -void for_each_in_selection(QTreeView* tree, F&& f) +void forEachInSelection(QTreeView* tree, F&& f) { const auto* sel = tree->selectionModel(); - const auto* model = dynamic_cast<ConflictListModel*>(tree->model()); + + const auto* proxy = dynamic_cast<QAbstractProxyModel*>(tree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast<ConflictListModel*>(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<std::size_t>(row))) { - if (!f(item)) { - return; - } + for (const auto& rowIndex : sel->selectedRows()) { + auto modelRow = proxy->mapToSource(rowIndex).row(); + if (auto* item = model->getItem(static_cast<std::size_t>(modelRow))) { + if (!f(item)) { + return; } } } @@ -461,13 +467,21 @@ void ConflictsTab::changeItemsVisibility(QTreeView* tree, bool visible) FileRenamer renamer(parentWidget(), flags); - auto* model = dynamic_cast<ConflictListModel*>(tree->model()); + const auto* proxy = dynamic_cast<QAbstractProxyModel*>(tree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast<ConflictListModel*>(proxy->sourceModel()); + if (!model) { - log::error("list doesn't have a ConflictListModel"); + log::error("tree doesn't have a ConflictListModel"); return; } - for_each_in_selection(tree, [&](const ConflictItem* item) { + forEachInSelection(tree, [&](const ConflictItem* item) { if (stop) { return false; } @@ -532,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)) { @@ -549,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; }); @@ -568,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; }); @@ -583,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; }); @@ -707,16 +721,27 @@ ConflictsTab::Actions ConflictsTab::createMenuActions(QTreeView* tree) const auto n = smallSelectionSize(tree); - const auto* model = dynamic_cast<ConflictListModel*>(tree->model()); + const auto* proxy = dynamic_cast<QAbstractProxyModel*>(tree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return {}; + } + + const auto* model = dynamic_cast<ConflictListModel*>(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<std::size_t>( - tree->selectionModel()->selectedRows()[0].row())); + modelSel.indexes()[0].row())); if (!item) { return {}; @@ -749,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; } @@ -797,7 +822,7 @@ ConflictsTab::Actions ConflictsTab::createMenuActions(QTreeView* tree) if (enableGoto && n == 1) { const auto* item = model->getItem(static_cast<std::size_t>( - tree->selectionModel()->selectedRows()[0].row())); + modelSel.indexes()[0].row())); actions.gotoActions = createGotoActions(item); } @@ -1027,12 +1052,23 @@ ConflictItem GeneralConflictsTab::createOverwrittenItem( void GeneralConflictsTab::onOverwriteActivated(const QModelIndex& index) { - auto* model = dynamic_cast<ConflictListModel*>(ui->overwriteTree->model()); + const auto* proxy = dynamic_cast<QAbstractProxyModel*>(ui->overwriteTree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast<ConflictListModel*>(proxy->sourceModel()); + if (!model) { + log::error("tree doesn't have a ConflictListModel"); return; } - auto* item = model->getItem(static_cast<std::size_t>(index.row())); + auto modelIndex = proxy->mapToSource(index); + + auto* item = model->getItem(static_cast<std::size_t>(modelIndex.row())); if (!item) { return; } @@ -1045,12 +1081,25 @@ void GeneralConflictsTab::onOverwriteActivated(const QModelIndex& index) void GeneralConflictsTab::onOverwrittenActivated(const QModelIndex& index) { - auto* model = dynamic_cast<ConflictListModel*>(ui->overwrittenTree->model()); + const auto* proxy = dynamic_cast<QAbstractProxyModel*>(ui->overwrittenTree->model()); + + if (!proxy) { + log::error("tree doesn't have a SortProxyModel"); + return; + } + + const auto* model = dynamic_cast<ConflictListModel*>(proxy->sourceModel()); + if (!model) { + log::error("tree doesn't have a ConflictListModel"); return; } - auto* item = model->getItem(static_cast<std::size_t>(index.row())); + proxy->mapSelectionToSource(ui->overwrittenTree->selectionModel()->selection()); + + auto modelIndex = proxy->mapToSource(index); + + auto* item = model->getItem(static_cast<std::size_t>(modelIndex.row())); if (!item) { return; } @@ -1067,6 +1116,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 +1149,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 +1306,6 @@ std::optional<ConflictItem> 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); |
