mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-01-18 15:56:34 -08:00
fixed crash that occurs when reloading the card database while deck editor or game is running
This commit is contained in:
@@ -13,14 +13,15 @@
|
||||
#include <QTimer>
|
||||
|
||||
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;
|
||||
|
||||
@@ -27,6 +27,7 @@ private:
|
||||
private slots:
|
||||
void animationEvent();
|
||||
void pixmapUpdated();
|
||||
void cardInfoUpdated();
|
||||
void callUpdate() { update(); }
|
||||
signals:
|
||||
void hovered(AbstractCardItem *card);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -201,6 +201,8 @@ private slots:
|
||||
void imageLoaded(CardInfo *card, QImage image);
|
||||
void picDownloadChanged();
|
||||
void picsPathChanged();
|
||||
signals:
|
||||
void cardListChanged();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
private:
|
||||
QList<CardInfo *> cardList;
|
||||
CardDatabase *db;
|
||||
private slots:
|
||||
void updateCardList();
|
||||
};
|
||||
|
||||
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -39,6 +39,7 @@ public slots:
|
||||
void setCard(const QString &cardName);
|
||||
void setCard(AbstractCardItem *card);
|
||||
private slots:
|
||||
void clear();
|
||||
void updatePixmap();
|
||||
void minimizeClicked();
|
||||
signals:
|
||||
|
||||
Reference in New Issue
Block a user