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; }
QVariant DeckListModel::data(const QModelIndex &index, int role) const { // debugIndexInfo("data", index); if (!index.isValid()) return QVariant(); if (index.column() >= columnCount()) return QVariant(); AbstractDecklistNode *temp = static_cast<AbstractDecklistNode *>(index.internalPointer()); DecklistModelCardNode *card = dynamic_cast<DecklistModelCardNode *>(temp); if (!card) { InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(temp); switch (role) { case Qt::FontRole: { QFont f; f.setBold(true); return f; } case Qt::DisplayRole: case Qt::EditRole: switch (index.column()) { case 0: return node->recursiveCount(true); case 1: return node->getVisibleName(); case 2: return QString().sprintf("$%.2f", node->recursivePrice(true)); default: return QVariant(); } case Qt::BackgroundRole: { int color = 90 + 60 * node->depth(); return QBrush(QColor(color, 255, color)); } default: return QVariant(); } } else { switch (role) { case Qt::DisplayRole: case Qt::EditRole: { switch (index.column()) { case 0: return card->getNumber(); case 1: return card->getName(); case 2: return QString().sprintf("$%.2f", card->getTotalPrice()); default: return QVariant(); } } case Qt::BackgroundRole: { int color = 255 - (index.row() % 2) * 30; return QBrush(QColor(color, color, color)); } default: return QVariant(); } } }