GH-1273 allow extended selection in mod lists

This commit is contained in:
Petr Mrázek 2016-08-04 22:57:16 +02:00
parent eec87db86a
commit 6ec2652b45
4 changed files with 7 additions and 45 deletions

View File

@ -175,35 +175,14 @@ bool ModList::installMod(const QString &filename)
return false; return false;
} }
bool ModList::deleteMod(int index) bool ModList::deleteMods(const QModelIndexList& indexes)
{ {
if (index >= mods.size() || index < 0) if(indexes.isEmpty())
return false;
Mod &m = mods[index];
if (m.destroy())
{
emit changed();
return true; 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<int> &indexes)
{
for (auto i: indexes) for (auto i: indexes)
{ {
Mod &m = mods[i]; Mod &m = mods[i.row()];
m.destroy(); m.destroy();
} }
emit changed(); emit changed();

View File

@ -83,14 +83,8 @@ public:
*/ */
bool installMod(const QString& filename); bool installMod(const QString& filename);
/// Deletes the mod at the given index.
virtual bool deleteMod(int index);
/// Deletes all the selected mods /// Deletes all the selected mods
virtual bool deleteMods(int first, int last); virtual bool deleteMods(const QModelIndexList &indexes);
/// Deletes all the selected mods
virtual bool deleteMods(const QVector<int> &indexes);
void startWatching(); void startWatching();
void stopWatching(); void stopWatching();

View File

@ -167,19 +167,8 @@ void ModFolderPage::on_addModBtn_clicked()
void ModFolderPage::on_rmModBtn_clicked() void ModFolderPage::on_rmModBtn_clicked()
{ {
int first, last; auto selection = m_filterModel->mapSelectionToSource(ui->modTreeView->selectionModel()->selection());
auto list = ui->modTreeView->selectionModel()->selectedRows(); m_mods->deleteMods(selection.indexes());
if (!lastfirst(list, first, last))
return;
QVector<int> 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);
} }
void ModFolderPage::on_viewModBtn_clicked() void ModFolderPage::on_viewModBtn_clicked()

View File

@ -28,7 +28,7 @@ ModListView::ModListView ( QWidget* parent )
setRootIsDecorated ( false ); setRootIsDecorated ( false );
setSortingEnabled ( false ); setSortingEnabled ( false );
setAlternatingRowColors ( true ); setAlternatingRowColors ( true );
setSelectionMode ( QAbstractItemView::ContiguousSelection ); setSelectionMode ( QAbstractItemView::ExtendedSelection );
setHeaderHidden ( false ); setHeaderHidden ( false );
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn ); setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOn );