mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Determine where we will insert the card before actually inserting it in the model.
This commit is contained in:
parent
249f4d9d01
commit
dcd63e4a7f
14 changed files with 122 additions and 63 deletions
|
|
@ -71,10 +71,15 @@ void SideboardPlan::write(QXmlStreamWriter *xml)
|
|||
xml->writeEndElement();
|
||||
}
|
||||
|
||||
AbstractDecklistNode::AbstractDecklistNode(InnerDecklistNode *_parent) : parent(_parent), sortMethod(Default)
|
||||
AbstractDecklistNode::AbstractDecklistNode(InnerDecklistNode *_parent, int position)
|
||||
: parent(_parent), sortMethod(Default)
|
||||
{
|
||||
if (parent) {
|
||||
parent->append(this);
|
||||
if (position == -1) {
|
||||
parent->append(this);
|
||||
} else {
|
||||
parent->insert(position, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +279,7 @@ bool InnerDecklistNode::readElement(QXmlStreamReader *xml)
|
|||
} else if (childName == "card") {
|
||||
DecklistCardNode *newCard = new DecklistCardNode(
|
||||
xml->attributes().value("name").toString(), xml->attributes().value("number").toString().toInt(),
|
||||
this, xml->attributes().value("setShortName").toString(),
|
||||
this, -1, xml->attributes().value("setShortName").toString(),
|
||||
xml->attributes().value("collectorNumber").toString(), xml->attributes().value("uuid").toString());
|
||||
newCard->readElement(xml);
|
||||
}
|
||||
|
|
@ -725,7 +730,7 @@ bool DeckList::loadFromStream_Plain(QTextStream &in, bool preserveMetadata)
|
|||
QString zoneName = getCardZoneFromName(cardName, sideboard ? DECK_ZONE_SIDE : DECK_ZONE_MAIN);
|
||||
|
||||
// make new entry in decklist
|
||||
new DecklistCardNode(cardName, amount, getZoneObjFromName(zoneName), setCode, collectorNumber);
|
||||
new DecklistCardNode(cardName, amount, getZoneObjFromName(zoneName), -1, setCode, collectorNumber);
|
||||
}
|
||||
|
||||
refreshDeckHash();
|
||||
|
|
@ -856,6 +861,7 @@ int DeckList::getSideboardSize() const
|
|||
|
||||
DecklistCardNode *DeckList::addCard(const QString &cardName,
|
||||
const QString &zoneName,
|
||||
const int position,
|
||||
const QString &cardSetName,
|
||||
const QString &cardSetCollectorNumber,
|
||||
const QString &cardProviderId)
|
||||
|
|
@ -865,7 +871,8 @@ DecklistCardNode *DeckList::addCard(const QString &cardName,
|
|||
zoneNode = new InnerDecklistNode(zoneName, root);
|
||||
}
|
||||
|
||||
auto *node = new DecklistCardNode(cardName, 1, zoneNode, cardSetName, cardSetCollectorNumber, cardProviderId);
|
||||
auto *node =
|
||||
new DecklistCardNode(cardName, 1, zoneNode, position, cardSetName, cardSetCollectorNumber, cardProviderId);
|
||||
refreshDeckHash();
|
||||
|
||||
return node;
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ protected:
|
|||
DeckSortMethod sortMethod;
|
||||
|
||||
public:
|
||||
explicit AbstractDecklistNode(InnerDecklistNode *_parent = nullptr);
|
||||
explicit AbstractDecklistNode(InnerDecklistNode *_parent = nullptr, int position = -1);
|
||||
virtual ~AbstractDecklistNode() = default;
|
||||
virtual void setSortMethod(DeckSortMethod method)
|
||||
{
|
||||
|
|
@ -88,8 +88,8 @@ class InnerDecklistNode : public AbstractDecklistNode, public QList<AbstractDeck
|
|||
class compareFunctor;
|
||||
|
||||
public:
|
||||
explicit InnerDecklistNode(QString _name = QString(), InnerDecklistNode *_parent = nullptr)
|
||||
: AbstractDecklistNode(_parent), name(std::move(_name))
|
||||
explicit InnerDecklistNode(QString _name = QString(), InnerDecklistNode *_parent = nullptr, int position = -1)
|
||||
: AbstractDecklistNode(_parent, position), name(std::move(_name))
|
||||
{
|
||||
}
|
||||
explicit InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = nullptr);
|
||||
|
|
@ -153,7 +153,7 @@ public:
|
|||
class AbstractDecklistCardNode : public AbstractDecklistNode
|
||||
{
|
||||
public:
|
||||
explicit AbstractDecklistCardNode(InnerDecklistNode *_parent = nullptr) : AbstractDecklistNode(_parent)
|
||||
explicit AbstractDecklistCardNode(InnerDecklistNode *_parent = nullptr, int position = -1) : AbstractDecklistNode(_parent, position)
|
||||
{
|
||||
}
|
||||
virtual int getNumber() const = 0;
|
||||
|
|
@ -190,10 +190,11 @@ public:
|
|||
explicit DecklistCardNode(QString _name = QString(),
|
||||
int _number = 1,
|
||||
InnerDecklistNode *_parent = nullptr,
|
||||
int position = -1,
|
||||
QString _cardSetShortName = QString(),
|
||||
QString _cardSetNumber = QString(),
|
||||
QString _cardProviderId = QString())
|
||||
: AbstractDecklistCardNode(_parent), name(std::move(_name)), number(_number),
|
||||
: AbstractDecklistCardNode(_parent, position), name(std::move(_name)), number(_number),
|
||||
cardSetShortName(std::move(_cardSetShortName)), cardSetNumber(std::move(_cardSetNumber)),
|
||||
cardProviderId(std::move(_cardProviderId))
|
||||
{
|
||||
|
|
@ -373,6 +374,7 @@ public:
|
|||
}
|
||||
DecklistCardNode *addCard(const QString &cardName,
|
||||
const QString &zoneName,
|
||||
int position,
|
||||
const QString &cardSetName = QString(),
|
||||
const QString &cardSetCollectorNumber = QString(),
|
||||
const QString &cardProviderId = QString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue