本文整理汇总了C++中InnerDecklistNode类的典型用法代码示例。如果您正苦于以下问题:C++ InnerDecklistNode类的具体用法?C++ InnerDecklistNode怎么用?C++ InnerDecklistNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InnerDecklistNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clearContents
void DeckViewScene::rebuildTree()
{
clearContents();
if (!deck)
return;
InnerDecklistNode *listRoot = deck->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
if (!container) {
container = new DeckViewCardContainer(currentZone->getName());
cardContainers.insert(currentZone->getName(), container);
addItem(container);
}
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
for (int k = 0; k < currentCard->getNumber(); ++k) {
DeckViewCard *newCard = new DeckViewCard(currentCard->getName(), currentZone->getName(), container);
container->addCard(newCard);
emit newCardAdded(newCard);
}
}
}
}
示例2: createNodeIfNeeded
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;
}
}
示例3: rowCount
int DeckListModel::rowCount(const QModelIndex &parent) const
{
// debugIndexInfo("rowCount", parent);
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
if (node)
return node->size();
else
return 0;
}
示例4: beginResetModel
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();
}
示例5: QModelIndex
QModelIndex DeckListModel::index(int row, int column, const QModelIndex &parent) const
{
// debugIndexInfo("index", parent);
if (!hasIndex(row, column, parent))
return QModelIndex();
InnerDecklistNode *parentNode = getNode<InnerDecklistNode *>(parent);
if (row >= parentNode->size())
return QModelIndex();
return createIndex(row, column, parentNode->at(row));
}
示例6: saveToStream_Plain
bool DeckList::saveToStream_Plain(QTextStream &out)
{
// Support for this is only possible if the internal structure doesn't get more complicated.
for (int i = 0; i < root->size(); i++) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
for (int j = 0; j < node->size(); j++) {
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
out << QString("%1%2 %3\n").arg(node->getName() == "side" ? "SB: " : "").arg(card->getNumber()).arg(card->getName());
}
}
return true;
}
示例7: recursivePrice
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;
}
示例8: QVariant
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();
}
}
}
示例9: while
bool InnerDecklistNode::readElement(QXmlStreamReader *xml)
{
while (!xml->atEnd()) {
xml->readNext();
const QString childName = xml->name().toString();
if (xml->isStartElement()) {
if (childName == "zone") {
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), this);
newZone->readElement(xml);
} else if (childName == "card") {
float price = (xml->attributes().value("price") != NULL) ? xml->attributes().value("price").toString().toFloat() : 0;
DecklistCardNode *newCard = new DecklistCardNode(xml->attributes().value("name").toString(), xml->attributes().value("number").toString().toInt(), price, this);
newCard->readElement(xml);
}
} else if (xml->isEndElement() && (childName == "zone"))
return false;
}
return true;
}
示例10: updateDeckHash
void DeckList::updateDeckHash()
{
QStringList cardList;
for (int i = 0; i < root->size(); i++) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
for (int j = 0; j < node->size(); j++) {
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
for (int k = 0; k < card->getNumber(); ++k)
cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower());
}
}
cardList.sort();
QByteArray deckHashArray = QCryptographicHash::hash(cardList.join(";").toUtf8(), QCryptographicHash::Sha1);
quint64 number = (((quint64) (unsigned char) deckHashArray[0]) << 32)
+ (((quint64) (unsigned char) deckHashArray[1]) << 24)
+ (((quint64) (unsigned char) deckHashArray[2] << 16))
+ (((quint64) (unsigned char) deckHashArray[3]) << 8)
+ (quint64) (unsigned char) deckHashArray[4];
deckHash = QString::number(number, 32).rightJustified(8, '0');
emit deckHashChanged();
}
示例11: if
bool DeckList::readElement(QXmlStreamReader *xml)
{
const QString childName = xml->name().toString();
if (xml->isStartElement()) {
if (childName == "deckname")
name = xml->readElementText();
else if (childName == "comments")
comments = xml->readElementText();
else if (childName == "zone") {
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root);
newZone->readElement(xml);
} else if (childName == "sideboard_plan") {
SideboardPlan *newSideboardPlan = new SideboardPlan;
if (newSideboardPlan->readElement(xml))
sideboardPlans.insert(newSideboardPlan->getName(), newSideboardPlan);
else
delete newSideboardPlan;
}
} else if (xml->isEndElement() && (childName == "cockatrice_deck"))
return false;
return true;
}
示例12: removeRows
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent)
{
InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent);
if (!node)
return false;
if (row + count > node->size())
return false;
beginRemoveRows(parent, row, row + count - 1);
for (int i = 0; i < count; i++) {
AbstractDecklistNode *toDelete = node->takeAt(row);
if (DecklistModelCardNode *temp = dynamic_cast<DecklistModelCardNode *>(toDelete))
deckList->deleteNode(temp->getDataNode());
delete toDelete;
}
endRemoveRows();
if (!node->size() && (node != root))
removeRows(parent.row(), 1, parent.parent());
else
emitRecursiveUpdates(parent);
return true;
}
示例13: deleteLater
/**
* Called when the download of the json file with the prices is finished.
*/
void PriceUpdater::downloadFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
bool ok;
QVariantMap resultMap = QtJson::Json::parse(QString(reply->readAll()), ok).toMap();
if (!ok) {
reply->deleteLater();
deleteLater();
return;
}
QMap<QString, float> cardsPrice;
QListIterator<QVariant> it(resultMap.value("cards").toList());
while (it.hasNext()) {
QVariantMap map = it.next().toMap();
QString name = map.value("name").toString().toLower();
float price = map.value("price").toString().toFloat();
QString set = map.value("set_code").toString();
/**
* Make sure Masters Edition (MED) isn't the set, as it doesn't
* physically exist. Also check the price to see that the cheapest set
* ends up as the final price.
*/
if (set != "MED" && (!cardsPrice.contains(name) || cardsPrice.value(name) > price))
cardsPrice.insert(name, price);
}
InnerDecklistNode *listRoot = deck->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
currentCard->setPrice(cardsPrice[currentCard->getName().toLower()]);
}
}
reply->deleteLater();
deleteLater();
emit finishedUpdate();
}
示例14: deleteLater
/**
* Called when the download of the json file with the prices is finished.
*/
void PriceUpdater::downloadFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
bool ok;
QVariantMap resultMap = QtJson::Json::parse(QString(reply->readAll()), ok).toMap();
if (!ok) {
reply->deleteLater();
deleteLater();
return;
}
QMap<QString, float> cardsPrice;
QListIterator<QVariant> it(resultMap.value("cards").toList());
while (it.hasNext()) {
QVariantMap map = it.next().toMap();
QString name = map.value("name").toString().toLower();
float price = map.value("average").toString().toFloat();
if ((cardsPrice.find(name) == cardsPrice.end()) || (price < cardsPrice[name])) {
cardsPrice.insert(name, price);
}
}
InnerDecklistNode *listRoot = deck->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
currentCard->setPrice(cardsPrice[currentCard->getName().toLower()]);
}
}
reply->deleteLater();
deleteLater();
emit finishedUpdate();
}
示例15: Server_CardZone
void Server_Player::setupZones()
{
// This may need to be customized according to the game rules.
// ------------------------------------------------------------------
// Create zones
Server_CardZone *deckZone = new Server_CardZone(this, "deck", false, HiddenZone);
addZone(deckZone);
Server_CardZone *sbZone = new Server_CardZone(this, "sb", false, HiddenZone);
addZone(sbZone);
addZone(new Server_CardZone(this, "table", true, PublicZone));
addZone(new Server_CardZone(this, "hand", false, PrivateZone));
addZone(new Server_CardZone(this, "stack", false, PublicZone));
addZone(new Server_CardZone(this, "grave", false, PublicZone));
addZone(new Server_CardZone(this, "rfg", false, PublicZone));
addCounter(new Server_Counter(0, "life", Color(255, 255, 255), 25, 20));
addCounter(new Server_Counter(1, "w", Color(255, 255, 150), 20, 0));
addCounter(new Server_Counter(2, "u", Color(150, 150, 255), 20, 0));
addCounter(new Server_Counter(3, "b", Color(150, 150, 150), 20, 0));
addCounter(new Server_Counter(4, "r", Color(250, 150, 150), 20, 0));
addCounter(new Server_Counter(5, "g", Color(150, 255, 150), 20, 0));
addCounter(new Server_Counter(6, "x", Color(255, 255, 255), 20, 0));
addCounter(new Server_Counter(7, "storm", Color(255, 255, 255), 20, 0));
initialCards = 7;
// ------------------------------------------------------------------
// Assign card ids and create deck from decklist
InnerDecklistNode *listRoot = deck->getRoot();
nextCardId = 0;
for (int i = 0; i < listRoot->size(); ++i) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
Server_CardZone *z;
if (currentZone->getName() == "main")
z = deckZone;
else if (currentZone->getName() == "side")
z = sbZone;
else
continue;
for (int j = 0; j < currentZone->size(); ++j) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
for (int k = 0; k < currentCard->getNumber(); ++k)
z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0));
}
}
const QList<MoveCardToZone *> &sideboardPlan = deck->getCurrentSideboardPlan();
for (int i = 0; i < sideboardPlan.size(); ++i) {
MoveCardToZone *m = sideboardPlan[i];
Server_CardZone *start, *target;
if (m->getStartZone() == "main")
start = deckZone;
else if (m->getStartZone() == "side")
start = sbZone;
else
continue;
if (m->getTargetZone() == "main")
target = deckZone;
else if (m->getTargetZone() == "side")
target = sbZone;
else
continue;
for (int j = 0; j < start->cards.size(); ++j)
if (start->cards[j]->getName() == m->getCardName()) {
Server_Card *card = start->cards[j];
start->cards.removeAt(j);
target->cards.append(card);
break;
}
}
deckZone->shuffle();
}