summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp50
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/modlist.cpp30
-rw-r--r--src/modlist.h5
-rw-r--r--src/modlistbypriorityproxy.cpp3
5 files changed, 37 insertions, 55 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 9ca7e534..1891e496 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2439,58 +2439,8 @@ void MainWindow::esplist_changed()
updatePluginCount();
}
-QModelIndex MainWindow::modViewIndexToModel(const QModelIndex& index) const
-{
- auto sindex = index;
-
- // remove the sort proxy.
- sindex = m_ModListSortProxy->mapToSource(index);
-
- // if there is another proxy
- if (auto* proxy = qobject_cast<QAbstractProxyModel*>(m_ModListSortProxy->sourceModel())) {
- sindex = proxy->mapToSource(sindex);
- }
-
- return sindex;
-}
-
-QModelIndex MainWindow::modModelIndexToView(const QModelIndex& index) const
-{
- auto dindex = index;
-
- // if there is another proxy than the sort
- if (auto* proxy = qobject_cast<QAbstractProxyModel*>(m_ModListSortProxy->sourceModel())) {
- dindex = proxy->mapFromSource(dindex);
- }
-
- // add the sort proxy
- dindex = m_ModListSortProxy->mapFromSource(dindex);
-
- return dindex;
-
-}
-
void MainWindow::onModPrioritiesChanged(std::vector<int> const& indices)
{
- // if we have collapsible separators, we need to refresh, expand if necessary,
- // and recreate the selection
- if (m_ModListSortProxy->sourceModel() == m_ModListByPriorityProxy) {
-
- // manually retain the selection and restore it after
- QModelIndex current = modViewIndexToModel(ui->modList->currentIndex());
- std::vector<QModelIndex> selected;
- for (const auto& idx : ui->modList->selectionModel()->selectedRows()) {
- selected.push_back(modViewIndexToModel(idx));
- }
-
- m_ModListByPriorityProxy->refresh();
-
- ui->modList->setCurrentIndex(modModelIndexToView(current));
- for (auto idx : selected) {
- ui->modList->selectionModel()->select(modModelIndexToView(idx), QItemSelectionModel::Select | QItemSelectionModel::Rows);
- }
- }
-
for (unsigned int i = 0; i < m_OrganizerCore.currentProfile()->numMods(); ++i) {
int priority = m_OrganizerCore.currentProfile()->getModPriority(i);
if (m_OrganizerCore.currentProfile()->modEnabled(i)) {
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 61a8b5e3..8dd72174 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -610,10 +610,6 @@ private slots: // ui slots
void setupModList();
void updateModListByPriorityProxy();
-
- // map index from the modlist view to the modlist model, handling proxy
- QModelIndex modViewIndexToModel(const QModelIndex& index) const;
- QModelIndex modModelIndexToView(const QModelIndex& index) const;
};
#endif // MAINWINDOW_H
diff --git a/src/modlist.cpp b/src/modlist.cpp
index 8c14d509..1f2f1171 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -1493,14 +1493,33 @@ QString ModList::getColumnToolTip(int column) const
}
}
+QModelIndex ModList::indexToProxy(QAbstractItemModel* proxyModel, const QModelIndex& index)
+{
+ if (!proxyModel) {
+ return QModelIndex();
+ }
+
+ if (proxyModel == this) {
+ return index;
+ }
+
+ if (auto* proxy = qobject_cast<QAbstractProxyModel*>(proxyModel)) {
+ return proxy->mapFromSource(indexToProxy(proxy->sourceModel(), index));
+ }
+
+ return QModelIndex();
+}
bool ModList::moveSelection(QAbstractItemView *itemView, int direction)
{
QItemSelectionModel *selectionModel = itemView->selectionModel();
+ int currentIndex = itemView->currentIndex().data(IndexRole).toInt();
const QAbstractProxyModel *proxyModel = qobject_cast<const QAbstractProxyModel*>(selectionModel->model());
const QSortFilterProxyModel *filterModel = nullptr;
+ emit layoutAboutToBeChanged();
+
while ((filterModel == nullptr) && (proxyModel != nullptr)) {
filterModel = qobject_cast<const QSortFilterProxyModel*>(proxyModel);
if (filterModel == nullptr) {
@@ -1534,7 +1553,18 @@ bool ModList::moveSelection(QAbstractItemView *itemView, int direction)
}
}
+ emit layoutChanged();
+
emit modPrioritiesChanged(allIndex);
+
+ // reset the selection and the index
+ itemView->setCurrentIndex(indexToProxy(itemView->model(), index(currentIndex, 0)));
+ for (auto idx : allIndex) {
+ itemView->selectionModel()->select(
+ indexToProxy(itemView->selectionModel()->model(), index(idx, 0)),
+ QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ }
+
return true;
}
diff --git a/src/modlist.h b/src/modlist.h
index 83e8ec9c..edf7d53a 100644
--- a/src/modlist.h
+++ b/src/modlist.h
@@ -371,6 +371,11 @@ private:
private:
+ // convert an index of the modlist to an index for the given model, assuming
+ // the given model is a proxy (of a proxy (of... )) the modlist
+ //
+ QModelIndex indexToProxy(QAbstractItemModel* proxyModel, const QModelIndex& index);
+
// retrieve the relative path of file and its origin given a URL from Mime data
// returns an empty optional if the URL is not a valid file for dropping
//
diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp
index a5f8667f..0b73ba78 100644
--- a/src/modlistbypriorityproxy.cpp
+++ b/src/modlistbypriorityproxy.cpp
@@ -20,8 +20,9 @@ void ModListByPriorityProxy::setSourceModel(QAbstractItemModel* model)
if (sourceModel()) {
m_CollapsedItems.clear();
+ connect(sourceModel(), &QAbstractItemModel::layoutChanged, this, [this]() { buildTree(); }, Qt::UniqueConnection);
connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, [this]() { buildTree(); }, Qt::UniqueConnection);
- // connect(sourceModel(), &QAbstractItemModel::modelReset, this, &ModListByPriorityProxy::buildTree, Qt::UniqueConnection);
+ connect(sourceModel(), &QAbstractItemModel::modelReset, this, &ModListByPriorityProxy::buildTree, Qt::UniqueConnection);
refresh();
}
}