QVariant CardModel::data(const QModelIndex &index, int role) const { QVariant res; if (!index.isValid()) { return res; } CardItem* item = (CardItem*)items.value(index.row()); if (role == Qt::DisplayRole) { if (item != NULL) { res = item->getName() + " (" + QString::number(item->getDiscont()) + ")"; } } else if (role == Qt::EditRole || role == SortRole || role == SearchRole) { if (item != NULL) { res = item->getName(); } } else if (role == KeyRole) { res = item->getId(); } else if (role == DiscontRole) { res = item->getDiscont(); } return res; }
CardItem *CardZone::getCard(int cardId, const QString &cardName) { CardItem *c = cards.findCard(cardId, false); if (!c) { qDebug() << "CardZone::getCard: card id=" << cardId << "not found"; return 0; } // If the card's id is -1, this zone is invisible, // so we need to give the card an id and a name as it comes out. // It can be assumed that in an invisible zone, all cards are equal. if ((c->getId() == -1) || (c->getName().isEmpty())) { c->setId(cardId); c->setName(cardName); } return c; }