示例#1
0
void DeckListModel::rebuildTree()
{
    beginResetModel();

    root->clearTree();
    InnerDecklistNode *listRoot = deckList->getRoot();
    for (int i = 0; i < listRoot->size(); i++) {
        InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
        InnerDecklistNode *node = new InnerDecklistNode(currentZone->getName(), root);
        for (int j = 0; j < currentZone->size(); j++) {
            DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
            // XXX better sanity checking
            if (!currentCard)
                continue;

            CardInfo *info = db->getCard(currentCard->getName());
            QString cardType;
            if (!info)
                cardType = "unknown";
            else
                cardType = info->getMainCardType();
            InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType));
            if (!cardTypeNode)
                cardTypeNode = new InnerDecklistNode(cardType, node);

            new DecklistModelCardNode(currentCard, cardTypeNode);
        }
    }

    endResetModel();
}
示例#2
0
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName)
{
	InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root);

	CardInfo *info = db->getCard(cardName);
	QString cardType = info->getMainCardType();
	InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode);

	DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName));
	if (!cardNode) {
		DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName);
		QModelIndex parentIndex = nodeToIndex(cardTypeNode);
		beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size());
		cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode);
		endInsertRows();
		sort(1);
		emitRecursiveUpdates(parentIndex);
		return nodeToIndex(cardNode);
	} else {
		cardNode->setNumber(cardNode->getNumber() + 1);
		QModelIndex ind = nodeToIndex(cardNode);
		emitRecursiveUpdates(ind);
		return ind;
	}
}