diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-11 18:55:15 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-11 18:55:15 +0100 |
| commit | e53905329a7a204ad0ad41600a9fb3040b942991 (patch) | |
| tree | c92be116c2098dda59c85c402bae4cb8c923ab70 /src | |
| parent | 9e663691b0ad23faa979361facb416b7ea0fb08d (diff) | |
Allow collapsible separator in descending priority.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modlistbypriorityproxy.cpp | 59 | ||||
| -rw-r--r-- | src/modlistbypriorityproxy.h | 8 | ||||
| -rw-r--r-- | src/modlistsortproxy.cpp | 7 | ||||
| -rw-r--r-- | src/modlistview.cpp | 4 |
4 files changed, 66 insertions, 12 deletions
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index 480a4105..e6728942 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -43,6 +43,11 @@ void ModListByPriorityProxy::setProfile(Profile* profile) m_profile = profile; } +void ModListByPriorityProxy::setSortOrder(Qt::SortOrder order) +{ + m_sortOrder = order; +} + void ModListByPriorityProxy::buildTree() { if (!sourceModel()) return; @@ -56,7 +61,9 @@ void ModListByPriorityProxy::buildTree() TreeItem* root = &m_Root; std::unique_ptr<TreeItem> overwrite; std::vector<std::unique_ptr<TreeItem>> backups; - for (auto& [priority, index] : m_profile->getAllIndexesByPriority()) { + + auto fn = [&](const auto& p) { + auto& [priority, index] = p; ModInfo::Ptr modInfo = ModInfo::getByIndex(index); TreeItem* item; @@ -81,11 +88,24 @@ void ModListByPriorityProxy::buildTree() } m_IndexToItem[index] = item; + }; + + auto& ibp = m_profile->getAllIndexesByPriority(); + if (m_sortOrder == Qt::AscendingOrder) { + std::for_each(ibp.begin(), ibp.end(), fn); + m_Root.children.insert(m_Root.children.begin(), + std::make_move_iterator(backups.begin()), std::make_move_iterator(backups.end())); + m_Root.children.push_back(std::move(overwrite)); + } + else { + std::for_each(ibp.rbegin(), ibp.rend(), fn); + m_Root.children.insert(m_Root.children.begin(), std::move(overwrite)); + m_Root.children.insert(m_Root.children.end(), + std::make_move_iterator(backups.begin()), std::make_move_iterator(backups.end())); } - m_Root.children.insert(m_Root.children.begin(), - std::make_move_iterator(backups.begin()), std::make_move_iterator(backups.end())); - m_Root.children.push_back(std::move(overwrite)); + // we do not really care about their position in the root + // as long as those are not in a separator endResetModel(); } @@ -185,7 +205,8 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi int firstRowPriority = INT_MAX; for (auto sourceRow : dropInfo.rows()) { hasSeparator = hasSeparator || ModInfo::getByIndex(sourceRow)->isSeparator(); - if (m_profile->getModPriority(sourceRow) < firstRowPriority) { + if (m_sortOrder == Qt::AscendingOrder && m_profile->getModPriority(sourceRow) < firstRowPriority + || m_sortOrder == Qt::DescendingOrder && m_profile->getModPriority(sourceRow) > firstRowPriority) { firstRowIndex = sourceRow; firstRowPriority = m_profile->getModPriority(sourceRow); } @@ -193,7 +214,7 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi bool firstRowSeparator = firstRowIndex != -1 && ModInfo::getByIndex(firstRowIndex)->isSeparator(); - // row = -1 and invalid parent means we're dropping onto an item, we don't want to drop + // row = -1 and valid parent means we're dropping onto an item, we don't want to drop // separators onto items or items into their own separator if (row == -1 && parent.isValid()) { auto* parentItem = static_cast<TreeItem*>(parent.internalPointer()); @@ -216,8 +237,10 @@ bool ModListByPriorityProxy::canDropMimeData(const QMimeData* data, Qt::DropActi } // the row may be outside of the children list if we insert at the end - if (!parent.isValid() && row >= m_Root.children.size()) { - return false; + if (!parent.isValid()) { + if (row >= m_Root.children.size()) { + return false; + } } return QAbstractProxyModel::canDropMimeData(data, action, row, column, parent); @@ -237,15 +260,25 @@ bool ModListByPriorityProxy::dropMimeData(const QMimeData* data, Qt::DropAction else { if (row >= 0) { + MOBase::log::debug("row={}, name={}, expand={}, drop={}", row, m_Root.children[row]->mod->name(), m_dropExpanded, m_dropPosition); if (!parent.isValid()) { if (row < m_Root.children.size()) { sourceRow = m_Root.children[row]->index; if (row > 0 + && m_sortOrder == Qt::AscendingOrder && m_Root.children[row - 1]->mod->isSeparator() && !m_Root.children[row - 1]->children.empty() && m_dropExpanded && m_dropPosition == ModListView::DropPosition::BelowItem) { - sourceRow = m_Root.children[row - 1]->children[0]->index; + sourceRow = m_Root.children[row - 1]->children[0]->index; + } + else if (row > 0 + && m_sortOrder == Qt::DescendingOrder + && m_Root.children[row]->mod->isSeparator() + && !m_Root.children[row]->children.empty() + && (!m_dropExpanded + || m_dropPosition == ModListView::DropPosition::AboveItem)) { + sourceRow = m_Root.children[row]->children.back()->index; } } else { @@ -265,7 +298,13 @@ bool ModListByPriorityProxy::dropMimeData(const QMimeData* data, Qt::DropAction } else if (parent.isValid()) { // this is a drop in a separator - sourceRow = m_Root.children[parent.row() + 1]->index; + if (m_sortOrder == Qt::AscendingOrder) { + sourceRow = m_Root.children[parent.row() + 1]->index; + } + else { + auto* item = m_Root.children[parent.row()].get(); + sourceRow = item->children.empty() ? item->index : item->children.back()->index; + } } } diff --git a/src/modlistbypriorityproxy.h b/src/modlistbypriorityproxy.h index 74ecc942..380e257b 100644 --- a/src/modlistbypriorityproxy.h +++ b/src/modlistbypriorityproxy.h @@ -28,6 +28,13 @@ public: ~ModListByPriorityProxy(); void setProfile(Profile* profile); + + // set the sort order but does not refresh the proxy + // + void setSortOrder(Qt::SortOrder order); + + // refresh the proxy by rebuilding the inner structure + // void refresh(); void setSourceModel(QAbstractItemModel* sourceModel) override; @@ -83,6 +90,7 @@ private: OrganizerCore& m_core; Profile* m_profile; + Qt::SortOrder m_sortOrder = Qt::AscendingOrder; bool m_dropExpanded = false; ModListView::DropPosition m_dropPosition = ModListView::DropPosition::OnItem; }; diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 9ae37a43..0682b9c3 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -617,6 +617,13 @@ bool ModListSortProxy::canDropMimeData(const QMimeData* data, Qt::DropAction act }
}
+ // in the regular model, when dropping between rows, the row-value passed to
+ // the sourceModel is inconsistent between ascending and descending ordering.
+ // This should fix that
+ if (sortOrder() == Qt::DescendingOrder) {
+ --row;
+ }
+
return QSortFilterProxyModel::canDropMimeData(data, action, row, column, parent);
}
diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 8827733b..1926a3f4 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -683,8 +683,8 @@ void ModListView::updateGroupByProxy() nextProxy = m_byNexusIdProxy;
}
else if (m_core->settings().interface().collapsibleSeparators()
- && m_sortProxy->sortColumn() == ModList::COL_PRIORITY
- && m_sortProxy->sortOrder() == Qt::AscendingOrder) {
+ && m_sortProxy->sortColumn() == ModList::COL_PRIORITY) {
+ m_byPriorityProxy->setSortOrder(m_sortProxy->sortOrder());
nextProxy = m_byPriorityProxy;
}
|
