mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
[DeckDockWidget] Correctly handle auto-expanding tree (#6446)
* move method * remove expandAll calls * update recursiveExpand * Refactor DeckModel access * [DeckDockWidget] Correctly handle auto-expand
This commit is contained in:
parent
e7af1bbec9
commit
421d6b334a
6 changed files with 131 additions and 86 deletions
|
|
@ -175,7 +175,6 @@ void CardAmountWidget::addPrinting(const QString &zone)
|
|||
|
||||
// Add the card and expand the list UI
|
||||
auto newCardIndex = deckModel->addCard(rootCard, zone);
|
||||
recursiveExpand(newCardIndex);
|
||||
|
||||
// Check if a card without a providerId already exists in the deckModel and replace it, if so.
|
||||
QString foundProviderId =
|
||||
|
|
@ -229,46 +228,6 @@ void CardAmountWidget::removePrintingSideboard()
|
|||
decrementCardHelper(DECK_ZONE_SIDE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Recursively expands the card in the deck view starting from the given index.
|
||||
*
|
||||
* @param index The model index of the card to expand.
|
||||
*/
|
||||
void CardAmountWidget::recursiveExpand(const QModelIndex &index)
|
||||
{
|
||||
if (index.parent().isValid()) {
|
||||
recursiveExpand(index.parent());
|
||||
}
|
||||
deckView->expand(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Offsets the card count at the specified index by the given amount.
|
||||
*
|
||||
* @param idx The model index of the card.
|
||||
* @param offset The amount to add or subtract from the card count.
|
||||
*/
|
||||
void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
|
||||
{
|
||||
if (!idx.isValid() || offset == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QModelIndex numberIndex = idx.siblingAtColumn(DeckListModelColumns::CARD_AMOUNT);
|
||||
const int count = numberIndex.data(Qt::EditRole).toInt();
|
||||
const int new_count = count + offset;
|
||||
|
||||
deckView->setCurrentIndex(numberIndex);
|
||||
|
||||
if (new_count <= 0) {
|
||||
deckModel->removeRow(idx.row(), idx.parent());
|
||||
} else {
|
||||
deckModel->setData(numberIndex, new_count, Qt::EditRole);
|
||||
}
|
||||
|
||||
deckEditor->setModified(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to decrement the card count for a given zone.
|
||||
*
|
||||
|
|
@ -288,7 +247,7 @@ void CardAmountWidget::decrementCardHelper(const QString &zone)
|
|||
QModelIndex idx = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(),
|
||||
rootCard.getPrinting().getProperty("num"));
|
||||
|
||||
offsetCountAtIndex(idx, -1);
|
||||
deckModel->decrementAmountAtIndex(idx);
|
||||
deckEditor->setModified(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,9 +57,7 @@ private:
|
|||
|
||||
bool hovered;
|
||||
|
||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||
void decrementCardHelper(const QString &zoneName);
|
||||
void recursiveExpand(const QModelIndex &index);
|
||||
|
||||
private slots:
|
||||
void addPrintingMainboard();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue