mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 08:52:15 -07:00
support multiselect in deck editor
This commit is contained in:
parent
6e1047032d
commit
4603bf7767
1 changed files with 29 additions and 11 deletions
|
|
@ -64,6 +64,7 @@ void TabDeckEditor::createDeckDock()
|
||||||
deckView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
deckView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
deckView->installEventFilter(&deckViewKeySignals);
|
deckView->installEventFilter(&deckViewKeySignals);
|
||||||
deckView->setContextMenuPolicy(Qt::CustomContextMenu);
|
deckView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
deckView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this,
|
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this,
|
||||||
SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
|
SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
|
||||||
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this,
|
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this,
|
||||||
|
|
@ -1299,14 +1300,23 @@ void TabDeckEditor::actAddCardToSideboard()
|
||||||
|
|
||||||
void TabDeckEditor::actRemoveCard()
|
void TabDeckEditor::actRemoveCard()
|
||||||
{
|
{
|
||||||
const QModelIndex ¤tIndex = deckView->selectionModel()->currentIndex();
|
auto selectedRows = deckView->selectionModel()->selectedRows();
|
||||||
if (!currentIndex.isValid() || deckModel->hasChildren(currentIndex))
|
std::reverse(selectedRows.begin(), selectedRows.end());
|
||||||
return;
|
|
||||||
deckModel->removeRow(currentIndex.row(), currentIndex.parent());
|
|
||||||
|
|
||||||
|
bool modified = false;
|
||||||
|
for (const auto &index : selectedRows) {
|
||||||
|
if (!index.isValid() || deckModel->hasChildren(index)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
deckModel->removeRow(index.row(), index.parent());
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
DeckLoader *const deck = deckModel->getDeckList();
|
DeckLoader *const deck = deckModel->getDeckList();
|
||||||
setSaveStatus(!deck->isEmpty());
|
setSaveStatus(!deck->isEmpty());
|
||||||
setModified(true);
|
setModified(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::offsetCountAtIndex(const QModelIndex &idx, int offset)
|
void TabDeckEditor::offsetCountAtIndex(const QModelIndex &idx, int offset)
|
||||||
|
|
@ -1357,14 +1367,22 @@ void TabDeckEditor::copyDatabaseCellContents()
|
||||||
|
|
||||||
void TabDeckEditor::actIncrement()
|
void TabDeckEditor::actIncrement()
|
||||||
{
|
{
|
||||||
const QModelIndex ¤tIndex = deckView->selectionModel()->currentIndex();
|
auto selectedRows = deckView->selectionModel()->selectedRows();
|
||||||
offsetCountAtIndex(currentIndex, 1);
|
|
||||||
|
for (const auto &index : selectedRows) {
|
||||||
|
offsetCountAtIndex(index, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actDecrement()
|
void TabDeckEditor::actDecrement()
|
||||||
{
|
{
|
||||||
const QModelIndex ¤tIndex = deckView->selectionModel()->currentIndex();
|
auto selectedRows = deckView->selectionModel()->selectedRows();
|
||||||
offsetCountAtIndex(currentIndex, -1);
|
// we need to iterate the rows in reverse order since there may be row deletions
|
||||||
|
std::reverse(selectedRows.begin(), selectedRows.end());
|
||||||
|
|
||||||
|
for (const auto &index : selectedRows) {
|
||||||
|
offsetCountAtIndex(index, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::setDeck(DeckLoader *_deck)
|
void TabDeckEditor::setDeck(DeckLoader *_deck)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue