fixed crash that occurs when reloading the card database while deck editor or game is running
This commit is contained in:
parent
b0656ffcea
commit
7a7b686e67
8 changed files with 31 additions and 3 deletions
|
@ -13,14 +13,15 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphicsItem *parent)
|
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);
|
setCursor(Qt::OpenHandCursor);
|
||||||
setFlag(ItemIsSelectable);
|
setFlag(ItemIsSelectable);
|
||||||
setCacheMode(DeviceCoordinateCache);
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
|
||||||
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
|
||||||
|
cardInfoUpdated();
|
||||||
|
|
||||||
animationTimer = new QTimer(this);
|
animationTimer = new QTimer(this);
|
||||||
animationTimer->setSingleShot(false);
|
animationTimer->setSingleShot(false);
|
||||||
|
@ -42,6 +43,12 @@ void AbstractCardItem::pixmapUpdated()
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::cardInfoUpdated()
|
||||||
|
{
|
||||||
|
info = db->getCard(name);
|
||||||
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||||
|
}
|
||||||
|
|
||||||
void AbstractCardItem::setRealZValue(qreal _zValue)
|
void AbstractCardItem::setRealZValue(qreal _zValue)
|
||||||
{
|
{
|
||||||
realZValue = _zValue;
|
realZValue = _zValue;
|
||||||
|
|
|
@ -27,6 +27,7 @@ private:
|
||||||
private slots:
|
private slots:
|
||||||
void animationEvent();
|
void animationEvent();
|
||||||
void pixmapUpdated();
|
void pixmapUpdated();
|
||||||
|
void cardInfoUpdated();
|
||||||
void callUpdate() { update(); }
|
void callUpdate() { update(); }
|
||||||
signals:
|
signals:
|
||||||
void hovered(AbstractCardItem *card);
|
void hovered(AbstractCardItem *card);
|
||||||
|
|
|
@ -659,6 +659,8 @@ bool CardDatabase::loadCardDatabase(const QString &path)
|
||||||
allSets.sortByKey();
|
allSets.sortByKey();
|
||||||
for (int i = 0; i < allSets.size(); ++i)
|
for (int i = 0; i < allSets.size(); ++i)
|
||||||
allSets[i]->setSortKey(i);
|
allSets[i]->setSortKey(i);
|
||||||
|
|
||||||
|
emit cardListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadSuccess;
|
return loadSuccess;
|
||||||
|
|
|
@ -201,6 +201,8 @@ private slots:
|
||||||
void imageLoaded(CardInfo *card, QImage image);
|
void imageLoaded(CardInfo *card, QImage image);
|
||||||
void picDownloadChanged();
|
void picDownloadChanged();
|
||||||
void picsPathChanged();
|
void picsPathChanged();
|
||||||
|
signals:
|
||||||
|
void cardListChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, QObject *parent)
|
||||||
: QAbstractListModel(parent), db(_db)
|
: QAbstractListModel(parent), db(_db)
|
||||||
{
|
{
|
||||||
|
connect(db, SIGNAL(cardListChanged()), this, SLOT(updateCardList()));
|
||||||
cardList = db->getCardList();
|
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)
|
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
private:
|
private:
|
||||||
QList<CardInfo *> cardList;
|
QList<CardInfo *> cardList;
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
|
private slots:
|
||||||
|
void updateCardList();
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
class CardDatabaseDisplayModel : public QSortFilterProxyModel {
|
||||||
|
|
|
@ -115,6 +115,7 @@ void CardInfoWidget::setCard(CardInfo *card)
|
||||||
disconnect(info, 0, this, 0);
|
disconnect(info, 0, this, 0);
|
||||||
info = card;
|
info = card;
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(updatePixmap()));
|
||||||
|
connect(info, SIGNAL(destroyed()), this, SLOT(clear()));
|
||||||
|
|
||||||
updatePixmap();
|
updatePixmap();
|
||||||
nameLabel2->setText(card->getName());
|
nameLabel2->setText(card->getName());
|
||||||
|
@ -134,6 +135,11 @@ void CardInfoWidget::setCard(AbstractCardItem *card)
|
||||||
setCard(card->getInfo());
|
setCard(card->getInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardInfoWidget::clear()
|
||||||
|
{
|
||||||
|
setCard(db->getCard());
|
||||||
|
}
|
||||||
|
|
||||||
void CardInfoWidget::updatePixmap()
|
void CardInfoWidget::updatePixmap()
|
||||||
{
|
{
|
||||||
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
QPixmap *resizedPixmap = info->getPixmap(QSize(pixmapWidth, pixmapWidth * aspectRatio));
|
||||||
|
|
|
@ -39,6 +39,7 @@ public slots:
|
||||||
void setCard(const QString &cardName);
|
void setCard(const QString &cardName);
|
||||||
void setCard(AbstractCardItem *card);
|
void setCard(AbstractCardItem *card);
|
||||||
private slots:
|
private slots:
|
||||||
|
void clear();
|
||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
void minimizeClicked();
|
void minimizeClicked();
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in a new issue