Multi-select + context menu. (Fixes #2480)

Content selector, added multi-select + context menu to allow check/uncheck the multi-selected items.
pull/562/head
dteviot 10 years ago
parent 048d7be87c
commit b0c4be2316

@ -57,6 +57,17 @@ void ContentSelectorView::ContentSelector::buildAddonView()
connect(ui.addonView, SIGNAL(activated(const QModelIndex&)), this, SLOT(slotAddonTableItemActivated(const QModelIndex&)));
connect(mContentModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SIGNAL(signalAddonDataChanged(QModelIndex,QModelIndex)));
buildContextMenu();
}
void ContentSelectorView::ContentSelector::buildContextMenu()
{
ui.addonView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui.addonView, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(slotShowContextMenu(const QPoint&)));
mContextMenu = new QMenu(ui.addonView);
mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems()));
mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems()));
}
void ContentSelectorView::ContentSelector::setProfileContent(const QStringList &fileList)
@ -196,3 +207,32 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QMo
mContentModel->setData(sourceIndex, checkState, Qt::CheckStateRole);
}
void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos)
{
QPoint globalPos = ui.addonView->viewport()->mapToGlobal(pos);
mContextMenu->exec(globalPos);
}
void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked)
{
Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked;
foreach(const QModelIndex& index, ui.addonView->selectionModel()->selectedIndexes())
{
QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index);
if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState)
{
mContentModel->setData(sourceIndex, checkState, Qt::CheckStateRole);
}
}
}
void ContentSelectorView::ContentSelector::slotUncheckMultiSelectedItems()
{
setCheckStateForMultiSelectedItems(false);
}
void ContentSelectorView::ContentSelector::slotCheckMultiSelectedItems()
{
setCheckStateForMultiSelectedItems(true);
}

@ -14,6 +14,7 @@ namespace ContentSelectorView
{
Q_OBJECT
QMenu *mContextMenu;
QStringList mFilePaths;
protected:
@ -51,7 +52,9 @@ namespace ContentSelectorView
void buildContentModel();
void buildGameFileView();
void buildAddonView();
void buildContextMenu();
void setGameFileSelected(int index, bool selected);
void setCheckStateForMultiSelectedItems(bool checked);
signals:
void signalCurrentGamefileIndexChanged (int);
@ -62,6 +65,9 @@ namespace ContentSelectorView
void slotCurrentGameFileIndexChanged(int index);
void slotAddonTableItemActivated(const QModelIndex& index);
void slotShowContextMenu(const QPoint& pos);
void slotCheckMultiSelectedItems();
void slotUncheckMultiSelectedItems();
};
}

@ -72,7 +72,7 @@
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>

Loading…
Cancel
Save