Exemplo n.º 1
0
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
{
	if (!index.isValid())
		return QVariant();
	if ((index.row() >= cardList.size()) || (index.column() >= 5))
		return QVariant();
	if (role != Qt::DisplayRole)
		return QVariant();

	CardInfo *card = cardList.at(index.row());
	switch (index.column()){
		case 0: return card->getName();
		case 1: {
			QStringList setList;
			const QList<CardSet *> &sets = card->getSets();
			for (int i = 0; i < sets.size(); i++)
				setList << sets[i]->getShortName();
			return setList.join(", ");
		}
		case 2: return card->getManaCost();
		case 3: return card->getCardType();
		case 4: return card->getPowTough();
		default: return QVariant();
	}
}
Exemplo n.º 2
0
void DlgEditTokens::tokenSelectionChanged(const QModelIndex &current, const QModelIndex & /* previous */)
{
    const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
    CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : cardDatabaseModel->getDatabase()->getCard();
    if (!cardInfo->getName().isEmpty())
        currentCard = cardInfo;
    else
        currentCard = 0;
    
    nameEdit->setText(cardInfo->getName());
    const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first());
    colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
    ptEdit->setText(cardInfo->getPowTough());
    annotationEdit->setText(cardInfo->getText());
}