mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-03 03:53:56 -07:00
[DeckListModel] Refactor api for offset count (#6454)
This commit is contained in:
parent
96c82a0377
commit
296866a675
4 changed files with 9 additions and 30 deletions
|
|
@ -831,11 +831,8 @@ void DeckEditorDeckDockWidget::offsetCountAtIndex(const QModelIndex &idx, bool i
|
||||||
|
|
||||||
emit requestDeckHistorySave(reason);
|
emit requestDeckHistorySave(reason);
|
||||||
|
|
||||||
if (isIncrement) {
|
int offset = isIncrement ? 1 : -1;
|
||||||
deckModel->incrementAmountAtIndex(sourceIndex);
|
deckModel->offsetCountAtIndex(sourceIndex, offset);
|
||||||
} else {
|
|
||||||
deckModel->decrementAmountAtIndex(sourceIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit deckModified();
|
emit deckModified();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,7 @@ void CardAmountWidget::decrementCardHelper(const QString &zone)
|
||||||
QModelIndex idx = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(),
|
QModelIndex idx = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(),
|
||||||
rootCard.getPrinting().getProperty("num"));
|
rootCard.getPrinting().getProperty("num"));
|
||||||
|
|
||||||
deckModel->decrementAmountAtIndex(idx);
|
deckModel->offsetCountAtIndex(idx, -1);
|
||||||
deckEditor->setModified(true);
|
deckEditor->setModified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -443,17 +443,7 @@ QModelIndex DeckListModel::addCard(const ExactCard &card, const QString &zoneNam
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckListModel::incrementAmountAtIndex(const QModelIndex &idx)
|
bool DeckListModel::offsetCountAtIndex(const QModelIndex &idx, int offset)
|
||||||
{
|
|
||||||
return offsetAmountAtIndex(idx, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeckListModel::decrementAmountAtIndex(const QModelIndex &idx)
|
|
||||||
{
|
|
||||||
return offsetAmountAtIndex(idx, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeckListModel::offsetAmountAtIndex(const QModelIndex &idx, int offset)
|
|
||||||
{
|
{
|
||||||
if (!idx.isValid()) {
|
if (!idx.isValid()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -307,19 +307,13 @@ public:
|
||||||
QModelIndex addCard(const ExactCard &card, const QString &zoneName);
|
QModelIndex addCard(const ExactCard &card, const QString &zoneName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Increments the `amount` field of the card node at the index by 1.
|
* @brief Changes the `amount` field in the card node at the index by the amount.
|
||||||
* @param idx The index of a card node. No-ops if the index is invalid or not a card node
|
* Removes the node if it causes the amount to fall to 0 or below.
|
||||||
|
* @param idx The index of a card node. No-ops if the index is invalid or not a card node.
|
||||||
|
* @param offset The amount to change the amount field by.
|
||||||
* @return Whether the operation was successful
|
* @return Whether the operation was successful
|
||||||
*/
|
*/
|
||||||
bool incrementAmountAtIndex(const QModelIndex &idx);
|
bool offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Decrements the `amount` field of the card node at the index by 1.
|
|
||||||
* Removes the node if it causes the amount to fall to 0.
|
|
||||||
* @param idx The index of a card node. No-ops if the index is invalid or not a card node
|
|
||||||
* @return Whether the operation was successful
|
|
||||||
*/
|
|
||||||
bool decrementAmountAtIndex(const QModelIndex &idx);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Determines the sorted insertion row for a card.
|
* @brief Determines the sorted insertion row for a card.
|
||||||
|
|
@ -395,8 +389,6 @@ private:
|
||||||
const QString &providerId = "",
|
const QString &providerId = "",
|
||||||
const QString &cardNumber = "") const;
|
const QString &cardNumber = "") const;
|
||||||
|
|
||||||
bool offsetAmountAtIndex(const QModelIndex &idx, int offset);
|
|
||||||
|
|
||||||
void emitRecursiveUpdates(const QModelIndex &index);
|
void emitRecursiveUpdates(const QModelIndex &index);
|
||||||
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
void sortHelper(InnerDecklistNode *node, Qt::SortOrder order);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue