diff --git a/cockatrice/src/abstractcarditem.cpp b/cockatrice/src/abstractcarditem.cpp index a1ae0df1..d8e1adb1 100644 --- a/cockatrice/src/abstractcarditem.cpp +++ b/cockatrice/src/abstractcarditem.cpp @@ -13,14 +13,15 @@ #include AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphicsItem *parent) - : ArrowTarget(_owner, parent), info(db->getCard(_name)), infoWidget(0), name(_name), tapped(false), tapAngle(0), isHovered(false), realZValue(0) + : ArrowTarget(_owner, parent), infoWidget(0), name(_name), tapped(false), tapAngle(0), isHovered(false), realZValue(0) { setCursor(Qt::OpenHandCursor); setFlag(ItemIsSelectable); setCacheMode(DeviceCoordinateCache); - - connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); + + connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated())); connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate())); + cardInfoUpdated(); animationTimer = new QTimer(this); animationTimer->setSingleShot(false); @@ -42,6 +43,12 @@ void AbstractCardItem::pixmapUpdated() update(); } +void AbstractCardItem::cardInfoUpdated() +{ + info = db->getCard(name); + connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); +} + void AbstractCardItem::setRealZValue(qreal _zValue) { realZValue = _zValue; diff --git a/cockatrice/src/abstractcarditem.h b/cockatrice/src/abstractcarditem.h index caf13407..34074ece 100644 --- a/cockatrice/src/abstractcarditem.h +++ b/cockatrice/src/abstractcarditem.h @@ -27,6 +27,7 @@ private: private slots: void animationEvent(); void pixmapUpdated(); + void cardInfoUpdated(); void callUpdate() { update(); } signals: void hovered(AbstractCardItem *card); diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 180f2808..ff8e4474 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -659,6 +659,8 @@ bool CardDatabase::loadCardDatabase(const QString &path) allSets.sortByKey(); for (int i = 0; i < allSets.size(); ++i) allSets[i]->setSortKey(i); + + emit cardListChanged(); } return loadSuccess; diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 696bd3b1..04a92f0f 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -201,6 +201,8 @@ private slots: void imageLoaded(CardInfo *card, QImage image); void picDownloadChanged(); void picsPathChanged(); +signals: + void cardListChanged(); }; #endif diff --git a/cockatrice/src/carddatabasemodel.cpp b/cockatrice/src/carddatabasemodel.cpp index b5b09152..8e2a556b 100644 --- a/cockatrice/src/carddatabasemodel.cpp +++ b/cockatrice/src/carddatabasemodel.cpp @@ -3,6 +3,7 @@ CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent) : QAbstractListModel(parent), db(_db) { + connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList())); cardList = db->getCardList(); } @@ -63,6 +64,12 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, } } +void CardDatabaseModel::updateCardList() +{ + cardList = db->getCardList(); + reset(); +} + CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent) : QSortFilterProxyModel(parent) { diff --git a/cockatrice/src/carddatabasemodel.h b/cockatrice/src/carddatabasemodel.h index 6d651d4c..45378257 100644 --- a/cockatrice/src/carddatabasemodel.h +++ b/cockatrice/src/carddatabasemodel.h @@ -20,6 +20,8 @@ public: private: QList cardList; CardDatabase *db; +private slots: + void updateCardList(); }; class CardDatabaseDisplayModel : public QSortFilterProxyModel { diff --git a/cockatrice/src/cardinfowidget.cpp b/cockatrice/src/cardinfowidget.cpp index 9869d382..10bf1548 100644 --- a/cockatrice/src/cardinfowidget.cpp +++ b/cockatrice/src/cardinfowidget.cpp @@ -115,6 +115,7 @@ void CardInfoWidget::setCard(CardInfo *card) disconnect(info, 0, this, 0); info = card; connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap())); + connect(info, SIGNAL(destroyed()), this, SLOT(clear())); updatePixmap(); nameLabel2->setText(card->getName()); @@ -134,6 +135,11 @@ void CardInfoWidget::setCard(AbstractCardItem *card) setCard(card->getInfo()); } +void CardInfoWidget::clear() +{ + setCard(db->getCard()); +} + void CardInfoWidget::updatePixmap() { QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio)); diff --git a/cockatrice/src/cardinfowidget.h b/cockatrice/src/cardinfowidget.h index 617acd56..d140009e 100644 --- a/cockatrice/src/cardinfowidget.h +++ b/cockatrice/src/cardinfowidget.h @@ -39,6 +39,7 @@ public slots: void setCard(const QString &cardName); void setCard(AbstractCardItem *card); private slots: + void clear(); void updatePixmap(); void minimizeClicked(); signals: