diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/modlistbypriorityproxy.cpp | 12 | ||||
| -rw-r--r-- | src/modlistsortproxy.cpp | 11 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index addefb6f..a5f8667f 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -43,6 +43,7 @@ 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()) { ModInfo::Ptr modInfo = ModInfo::getByIndex(index); @@ -58,6 +59,10 @@ void ModListByPriorityProxy::buildTree() overwrite = std::make_unique<TreeItem>(modInfo, index, &m_Root); item = overwrite.get(); } + else if (modInfo->isBackup()) { + backups.push_back(std::make_unique<TreeItem>(modInfo, index, &m_Root)); + item = backups.back().get(); + } else { root->children.push_back(std::make_unique<TreeItem>(modInfo, index, root)); item = root->children.back().get(); @@ -66,6 +71,8 @@ void ModListByPriorityProxy::buildTree() m_IndexToItem[index] = item; } + 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)); endResetModel(); @@ -101,6 +108,7 @@ QModelIndex ModListByPriorityProxy::mapToSource(const QModelIndex& proxyIndex) c return QModelIndex(); } auto* item = static_cast<TreeItem*>(proxyIndex.internalPointer()); + return sourceModel()->index(item->index, proxyIndex.column()); } @@ -124,7 +132,6 @@ int ModListByPriorityProxy::columnCount(const QModelIndex& index) const return sourceModel()->columnCount(mapToSource(index)); } - QModelIndex ModListByPriorityProxy::parent(const QModelIndex& child) const { if (!child.isValid()) { @@ -137,7 +144,7 @@ QModelIndex ModListByPriorityProxy::parent(const QModelIndex& child) const return QModelIndex(); } - return createIndex(item->parent->parent->childIndex(item->parent), 0, item->parent); + return createIndex(item->parent->parent->childIndex(item->parent), child.column(), item->parent); } bool ModListByPriorityProxy::hasChildren(const QModelIndex& parent) const @@ -270,6 +277,7 @@ QModelIndex ModListByPriorityProxy::index(int row, int column, const QModelIndex else { parentItem = static_cast<TreeItem*>(parent.internalPointer()); } + return createIndex(row, column, parentItem->children[row].get()); } diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index cf82ca74..422fa044 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -133,12 +133,17 @@ bool ModListSortProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
if (sourceModel()->hasChildren(left) || sourceModel()->hasChildren(right)) {
- return QSortFilterProxyModel::lessThan(left, right);
+ // when sorting by priority, we do not want to use the parent lessThan because
+ // it uses the display role which can be inconsistent (e.g. for backups)
+ if (sortColumn() != ModList::COL_PRIORITY) {
+ return QSortFilterProxyModel::lessThan(left, right);
+ }
}
bool lOk, rOk;
- int leftIndex = left.data(Qt::UserRole + 1).toInt(&lOk);
- int rightIndex = right.data(Qt::UserRole + 1).toInt(&rOk);
+ int leftIndex = left.data(ModList::IndexRole).toInt(&lOk);
+ int rightIndex = right.data(ModList::IndexRole).toInt(&rOk);
+
if (!lOk || !rOk) {
return false;
}
|
