price tag feature by Marcio Ribeiro

This commit is contained in:
Max-Wilhelm Bruker 2011-06-16 16:43:01 +02:00
parent 9f85074ca3
commit 6226e381de
12 changed files with 184 additions and 23 deletions

View file

@ -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());
}

View file

@ -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