diff --git a/api/logic/minecraft/ModList.cpp b/api/logic/minecraft/ModList.cpp index ad588f163..b9c7d9ba8 100644 --- a/api/logic/minecraft/ModList.cpp +++ b/api/logic/minecraft/ModList.cpp @@ -175,35 +175,14 @@ bool ModList::installMod(const QString &filename) return false; } -bool ModList::deleteMod(int index) +bool ModList::deleteMods(const QModelIndexList& indexes) { - if (index >= mods.size() || index < 0) - return false; - Mod &m = mods[index]; - if (m.destroy()) - { - emit changed(); + if(indexes.isEmpty()) return true; - } - return false; -} -bool ModList::deleteMods(int first, int last) -{ - for (int i = first; i <= last; i++) - { - Mod &m = mods[i]; - m.destroy(); - } - emit changed(); - return true; -} - -bool ModList::deleteMods(const QVector &indexes) -{ for (auto i: indexes) { - Mod &m = mods[i]; + Mod &m = mods[i.row()]; m.destroy(); } emit changed(); diff --git a/api/logic/minecraft/ModList.h b/api/logic/minecraft/ModList.h index 24dcdaa43..14b102e16 100644 --- a/api/logic/minecraft/ModList.h +++ b/api/logic/minecraft/ModList.h @@ -83,14 +83,8 @@ public: */ bool installMod(const QString& filename); - /// Deletes the mod at the given index. - virtual bool deleteMod(int index); - /// Deletes all the selected mods - virtual bool deleteMods(int first, int last); - - /// Deletes all the selected mods - virtual bool deleteMods(const QVector &indexes); + virtual bool deleteMods(const QModelIndexList &indexes); void startWatching(); void stopWatching(); diff --git a/application/pages/ModFolderPage.cpp b/application/pages/ModFolderPage.cpp index 3926fc462..a1d02ccf7 100644 --- a/application/pages/ModFolderPage.cpp +++ b/application/pages/ModFolderPage.cpp @@ -167,19 +167,8 @@ void ModFolderPage::on_addModBtn_clicked() void ModFolderPage::on_rmModBtn_clicked() { - int first, last; - auto list = ui->modTreeView->selectionModel()->selectedRows(); - - if (!lastfirst(list, first, last)) - return; - - QVector toDelete; - for(int i = first; i <= last; i++) - { - auto index = m_filterModel->mapToSource(m_filterModel->index(i,0,QModelIndex())); - toDelete.append(index.row()); - } - m_mods->deleteMods(toDelete); + auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection()); + m_mods->deleteMods(selection.indexes()); } void ModFolderPage::on_viewModBtn_clicked() diff --git a/application/widgets/ModListView.cpp b/application/widgets/ModListView.cpp index 51b4a4756..90c6f798b 100644 --- a/application/widgets/ModListView.cpp +++ b/application/widgets/ModListView.cpp @@ -28,7 +28,7 @@ ModListView::ModListView ( QWidget* parent ) setRootIsDecorated ( false ); setSortingEnabled ( false ); setAlternatingRowColors ( true ); - setSelectionMode ( QAbstractItemView::ContiguousSelection ); + setSelectionMode ( QAbstractItemView::ExtendedSelection ); setHeaderHidden ( false ); setSelectionBehavior(QAbstractItemView::SelectRows); setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );