Register parent QObjects properly

This commit is contained in:
ItsDrike 2024-12-07 13:30:02 +01:00
parent aa446e9c43
commit 36167edc78
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
3 changed files with 10 additions and 10 deletions

View file

@ -21,7 +21,7 @@ void GameState::dealCards() {
qDebug() << "Dealing cards";
cleanupBoard(false);
QList<PlayingCard*> deck = PlayingCard::createDeck();
QList<PlayingCard*> deck = PlayingCard::createDeck(this);
// Randomly shuffle the deck
std::random_device rd;
@ -36,7 +36,7 @@ void GameState::dealCards() {
// Deal exactly i+1 cards to the i-th column
for (int j = 0; j <= i; j++) {
bool revealed = (j == i);
ColumnSlot* col = new ColumnSlot(deck[index], revealed);
ColumnSlot* col = new ColumnSlot(deck[index], revealed, this);
column.append(col);
index++;
}
@ -59,7 +59,7 @@ void GameState::setupWinningDeck() {
cleanupBoard(false);
// Create a sorted deck of cards (4 suits, ordered)
QList<PlayingCard*> deck = PlayingCard::createDeck();
QList<PlayingCard*> deck = PlayingCard::createDeck(this);
// Setup the foundation with all cards except one per suit
for (int suit = 0; suit < 4; ++suit) {
@ -74,7 +74,7 @@ void GameState::setupWinningDeck() {
for (int i = 0; i < 4; ++i) {
QList<ColumnSlot*> column;
PlayingCard* kingCard = deck[i * 13 + 12]; // King of each suit
ColumnSlot* slot = new ColumnSlot(kingCard, true); // Revealed
ColumnSlot* slot = new ColumnSlot(kingCard, true, this); // Revealed
column.append(slot);
m_columns[i] = column;
}
@ -127,7 +127,7 @@ bool GameState::moveThrownCardToColumn(int columnId) {
}
// Success, perform the move
ColumnSlot* col = new ColumnSlot(cardToMove, true);
ColumnSlot* col = new ColumnSlot(cardToMove, true, this);
columnStack.append(col);
m_throwawayPile.removeLast();
qDebug() << "> Moving complete";
@ -494,7 +494,7 @@ bool GameState::tryAutoMoveSingleCard(PlayingCard& cardToMove, int skipColumnId)
continue;
if (isColumnMoveValid(cardToMove, columnId)) {
ColumnSlot* col = new ColumnSlot(&cardToMove, true);
ColumnSlot* col = new ColumnSlot(&cardToMove, true, this);
m_columns[columnId].append(col);
qDebug() << "* Auto-moved card " << cardToMove.toString() << " to column " << columnId;
return true;
@ -522,7 +522,7 @@ bool GameState::tryAutoMoveMultipleCards(const QList<PlayingCard*>& cards, int s
if (isColumnMoveValid(*firstCard, columnId)) {
for (auto card : cards) {
ColumnSlot* col = new ColumnSlot(card, true);
ColumnSlot* col = new ColumnSlot(card, true, this);
m_columns[columnId].append(col);
qDebug() << "* Auto-moved card " << card->toString() << " to column " << columnId;
}

View file

@ -59,12 +59,12 @@ QString PlayingCard::toString() const {
return valueString() + " of " + suitString();
}
QList<PlayingCard*> PlayingCard::createDeck() {
QList<PlayingCard*> PlayingCard::createDeck(QObject* parent) {
QList<PlayingCard*> deck;
for (int suitIndex = PlayingCard::Suit::Clubs; suitIndex <= PlayingCard::Suit::Spades; ++suitIndex) {
for (int valueIndex = PlayingCard::Value::Ace; valueIndex <= PlayingCard::Value::King; ++valueIndex) {
PlayingCard* card = new PlayingCard();
PlayingCard* card = new PlayingCard(parent);
card->setSuit(static_cast<PlayingCard::Suit>(suitIndex));
card->setValue(static_cast<PlayingCard::Value>(valueIndex));
deck.append(card);

View file

@ -54,7 +54,7 @@ class PlayingCard : public QObject {
QString toString() const;
static QList<PlayingCard*> createDeck();
static QList<PlayingCard*> createDeck(QObject* parent = nullptr);
static bool areOppositeColors(const PlayingCard& card1, const PlayingCard& card2);
signals: