Commit 31cf3b20 authored by unknown's avatar unknown
Browse files
parents 1bc05562 87addd12
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -127,6 +127,19 @@ int InnerDecklistNode::recursiveCount(bool countTotalCards) const
return result;
}
float InnerDecklistNode::recursivePrice(bool countTotalCards) const
{
float result = 0;
for (int i = 0; i < size(); i++) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(at(i));
if (node)
result += node->recursivePrice(countTotalCards);
else if (countTotalCards)
result += dynamic_cast<AbstractDecklistCardNode *>(at(i))->getTotalPrice();
}
return result;
}
bool InnerDecklistNode::compare(AbstractDecklistNode *other) const
{
InnerDecklistNode *other2 = dynamic_cast<InnerDecklistNode *>(other);
......@@ -165,11 +178,12 @@ bool InnerDecklistNode::readElement(QXmlStreamReader *xml)
}
if (xml->isStartElement() && (xml->name() == "zone"))
currentItem = new InnerDecklistNode(xml->attributes().value("name").toString(), this);
else if (xml->isStartElement() && (xml->name() == "card"))
currentItem = new DecklistCardNode(xml->attributes().value("name").toString(), xml->attributes().value("number").toString().toInt(), this);
else if (xml->isEndElement() && (xml->name() == "zone"))
else if (xml->isStartElement() && (xml->name() == "card")) {
float price = (xml->attributes().value("price") != NULL) ? xml->attributes().value("price").toString().toFloat() : 0;
currentItem = new DecklistCardNode(xml->attributes().value("name").toString(), xml->attributes().value("number").toString().toInt(), price, this);
} else if (xml->isEndElement() && (xml->name() == "zone"))
return true;
return false;
}
......@@ -194,6 +208,7 @@ void AbstractDecklistCardNode::writeElement(QXmlStreamWriter *xml)
{
xml->writeEmptyElement("card");
xml->writeAttribute("number", QString::number(getNumber()));
xml->writeAttribute("price", QString::number(getPrice()));
xml->writeAttribute("name", getName());
}
......
......@@ -69,6 +69,7 @@ public:
AbstractDecklistNode *findChild(const QString &name);
int height() const;
int recursiveCount(bool countTotalCards = false) const;
float recursivePrice(bool countTotalCards = false) const;
bool compare(AbstractDecklistNode *other) const;
QVector<QPair<int, int> > sort(Qt::SortOrder order = Qt::AscendingOrder);
......@@ -83,6 +84,9 @@ public:
virtual void setNumber(int _number) = 0;
virtual QString getName() const = 0;
virtual void setName(const QString &_name) = 0;
virtual float getPrice() const = 0;
virtual void setPrice(float _price) = 0;
float getTotalPrice() const { return getNumber() * getPrice(); }
int height() const { return 0; }
bool compare(AbstractDecklistNode *other) const;
......@@ -94,14 +98,18 @@ class DecklistCardNode : public AbstractDecklistCardNode {
private:
QString name;
int number;
float price;
public:
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number) { }
DecklistCardNode(const QString &_name = QString(), int _number = 1, float _price = 0, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(_price) { }
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(0) { }
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
int getNumber() const { return number; }
void setNumber(int _number) { number = _number; }
QString getName() const { return name; }
void setName(const QString &_name) { name = _name; }
};
float getPrice() const { return price; }
void setPrice(const float _price) { price = _price; }
};
class DeckList : public SerializableItem {
Q_OBJECT
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment