summaryrefslogtreecommitdiff
path: root/src/modlistview.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2020-12-30 14:39:57 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-02 15:38:16 +0100
commit8eb59316f9140a621bc4cf0d06d7b5b898b50972 (patch)
treefe5ce3479f28ae6ff58a05ed2ad975b4b686fec7 /src/modlistview.cpp
parent1efa793290a533b018271ca8442004e366da58db (diff)
Do not invalidate the sort proxy when not required (keep selection).
Diffstat (limited to 'src/modlistview.cpp')
-rw-r--r--src/modlistview.cpp92
1 files changed, 34 insertions, 58 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index 74f4b566..c4641934 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -171,64 +171,28 @@ int ModListView::prevMod(int modIndex) const
return -1;
}
-void ModListView::invalidate()
-{
- if (m_sortProxy) {
- m_sortProxy->invalidate();
- }
-}
-
void ModListView::enableAllVisible()
{
- Profile* profile = m_core->currentProfile();
-
- QList<unsigned int> modsToEnable;
- for (auto& index : allIndex(model())) {
- modsToEnable.append(index.data(ModList::IndexRole).toInt());
- }
- profile->setModsEnabled(modsToEnable, {});
- invalidate();
+ m_core->modList()->setActive(indexViewToModel(allIndex(model())), true);
}
void ModListView::disableAllVisible()
{
- MOBase::log::debug("disableAllVisible: {}", model()->rowCount());
- Profile* profile = m_core->currentProfile();
-
- QList<unsigned int> modsToDisable;
- for (auto& index : allIndex(model())) {
- modsToDisable.append(index.data(ModList::IndexRole).toInt());
- }
- profile->setModsEnabled({}, modsToDisable);
- invalidate();
+ m_core->modList()->setActive(indexViewToModel(allIndex(model())), false);
}
void ModListView::enableSelected()
{
- Profile* profile = m_core->currentProfile();
if (selectionModel()->hasSelection()) {
- QList<unsigned int> modsToEnable;
- for (auto row : selectionModel()->selectedRows(ModList::COL_PRIORITY)) {
- int modID = profile->modIndexByPriority(row.data().toInt());
- modsToEnable.append(modID);
- }
- profile->setModsEnabled(modsToEnable, {});
+ m_core->modList()->setActive(indexViewToModel(selectionModel()->selectedRows()), true);
}
- invalidate();
}
void ModListView::disableSelected()
{
- Profile* profile = m_core->currentProfile();
if (selectionModel()->hasSelection()) {
- QList<unsigned int> modsToDisable;
- for (auto row : selectionModel()->selectedRows(ModList::COL_PRIORITY)) {
- int modID = profile->modIndexByPriority(row.data().toInt());
- modsToDisable.append(modID);
- }
- profile->setModsEnabled({}, modsToDisable);
+ m_core->modList()->setActive(indexViewToModel(selectionModel()->selectedRows()), false);
}
- invalidate();
}
void ModListView::setFilterCriteria(const std::vector<ModListSortProxy::Criteria>& criteria)
@@ -279,6 +243,15 @@ QModelIndex ModListView::indexModelToView(const QModelIndex& index) const
return qindex;
}
+QModelIndexList ModListView::indexModelToView(const QModelIndexList& index) const
+{
+ QModelIndexList result;
+ for (auto& idx : index) {
+ result.append(indexModelToView(idx));
+ }
+ return result;
+}
+
QModelIndex ModListView::indexViewToModel(const QModelIndex& index) const
{
if (index.model() == m_core->modList()) {
@@ -292,6 +265,15 @@ QModelIndex ModListView::indexViewToModel(const QModelIndex& index) const
}
}
+QModelIndexList ModListView::indexViewToModel(const QModelIndexList& index) const
+{
+ QModelIndexList result;
+ for (auto& idx : index) {
+ result.append(indexViewToModel(idx));
+ }
+ return result;
+}
+
QModelIndex ModListView::nextIndex(const QModelIndex& index) const
{
auto* model = index.model();
@@ -329,15 +311,13 @@ QModelIndex ModListView::prevIndex(const QModelIndex& index) const
return prev;
}
-std::vector<QModelIndex> ModListView::allIndex(
+QModelIndexList ModListView::allIndex(
const QAbstractItemModel* model, int column, const QModelIndex& parent) const
{
- std::vector<QModelIndex> index;
+ QModelIndexList index;
for (std::size_t i = 0; i < model->rowCount(parent); ++i) {
- index.push_back(model->index(i, column, parent));
-
- auto cindex = allIndex(model, column, index.back());
- index.insert(index.end(), cindex.begin(), cindex.end());
+ index.append(model->index(i, column, parent));
+ index.append(allIndex(model, column, index.back()));
}
return index;
}
@@ -376,10 +356,6 @@ void ModListView::onModPrioritiesChanged(std::vector<int> const& indices)
m_core->currentProfile()->writeModlist();
m_core->directoryStructure()->getFileRegister()->sortOrigins();
- if (m_sortProxy) {
- m_sortProxy->invalidate();
- }
-
{ // refresh selection
QModelIndex current = currentIndex();
if (current.isValid()) {
@@ -431,7 +407,7 @@ void ModListView::onModInstalled(const QString& modName)
setFocus(Qt::OtherFocusReason);
scrollTo(qIndex);
setCurrentIndex(qIndex);
- selectionModel()->select(qIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ selectionModel()->select(qIndex, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
}
void ModListView::onModFilterActive(bool filterActive)
@@ -666,6 +642,12 @@ void ModListView::setup(OrganizerCore& core, Ui::MainWindow* mwui)
});
}
+void ModListView::setModel(QAbstractItemModel* model)
+{
+ QTreeView::setModel(model);
+ setVerticalScrollBar(new ViewMarkingScrollBar(model, this));
+}
+
QRect ModListView::visualRect(const QModelIndex& index) const
{
QRect rect = QTreeView::visualRect(index);
@@ -680,12 +662,6 @@ QRect ModListView::visualRect(const QModelIndex& index) const
return rect;
}
-void ModListView::setModel(QAbstractItemModel* model)
-{
- QTreeView::setModel(model);
- setVerticalScrollBar(new ViewMarkingScrollBar(model, this));
-}
-
QModelIndexList ModListView::selectedIndexes() const
{
return m_inDragMoveEvent ? QModelIndexList() : QTreeView::selectedIndexes();
@@ -747,7 +723,7 @@ bool ModListView::moveSelection(int key)
offset = -offset;
}
- m_core->modList()->moveMods(sourceRows, offset);
+ m_core->modList()->shiftMods(sourceRows, offset);
// reset the selection and the index
setCurrentIndex(indexModelToView(cindex));