From 7a688fd7a990331cd8505b7249f0126d80f5f5a4 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Mon, 20 Jan 2025 00:40:43 -0800 Subject: [PATCH] fix view zone close --- cockatrice/src/game/player/player.cpp | 2 +- cockatrice/src/game/zones/view_zone.cpp | 11 ++++++++++- cockatrice/src/game/zones/view_zone.h | 3 ++- cockatrice/src/game/zones/view_zone_widget.cpp | 9 +++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index da70c5e49..71a9a0a3f 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -2083,7 +2083,7 @@ void Player::eventShuffle(const Event_Shuffle &event) int length = view->getCards().length(); // we want to close empty views as well if (length == 0 || length > absStart) { // note this assumes views always start at the top of the library - view->deleteLater(); + view->close(); break; } } else { diff --git a/cockatrice/src/game/zones/view_zone.cpp b/cockatrice/src/game/zones/view_zone.cpp index 9da4ecc39..9cc6bdf67 100644 --- a/cockatrice/src/game/zones/view_zone.cpp +++ b/cockatrice/src/game/zones/view_zone.cpp @@ -42,11 +42,20 @@ ZoneViewZone::ZoneViewZone(Player *_p, ZoneViewZone::~ZoneViewZone() { - emit beingDeleted(); qDebug("ZoneViewZone destructor"); +} + +/** + * Deletes this ZoneView and removes it from the origZone's views. + * You should normally call this method instead of deleteLater() + */ +void ZoneViewZone::close() +{ + emit closed(); if (!(revealZone && !writeableRevealZone)) { origZone->getViews().removeOne(this); } + deleteLater(); } QRectF ZoneViewZone::boundingRect() const diff --git a/cockatrice/src/game/zones/view_zone.h b/cockatrice/src/game/zones/view_zone.h index 6eda0fd23..65bcc4018 100644 --- a/cockatrice/src/game/zones/view_zone.h +++ b/cockatrice/src/game/zones/view_zone.h @@ -94,13 +94,14 @@ public: return isReversed; } public slots: + void close(); void setGroupBy(CardList::SortOption _groupBy); void setSortBy(CardList::SortOption _sortBy); void setPileView(int _pileView); private slots: void zoneDumpReceived(const Response &r); signals: - void beingDeleted(); + void closed(); void optimumRectChanged(); void wheelEventReceived(QGraphicsSceneWheelEvent *event); diff --git a/cockatrice/src/game/zones/view_zone_widget.cpp b/cockatrice/src/game/zones/view_zone_widget.cpp index 4bc596531..531ca06df 100644 --- a/cockatrice/src/game/zones/view_zone_widget.cpp +++ b/cockatrice/src/game/zones/view_zone_widget.cpp @@ -133,7 +133,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player, setLayout(vbox); connect(zone, &ZoneViewZone::optimumRectChanged, this, &ZoneViewWidget::resizeToZoneContents); - connect(zone, &ZoneViewZone::beingDeleted, this, &ZoneViewWidget::zoneDeleted); + connect(zone, &ZoneViewZone::closed, this, &ZoneViewWidget::zoneDeleted); zone->initializeCards(cardList); // QLabel sizes aren't taken into account until the widget is rendered. @@ -314,11 +314,12 @@ void ZoneViewWidget::handleScrollBarChange(int value) void ZoneViewWidget::closeEvent(QCloseEvent *event) { - disconnect(zone, &ZoneViewZone::beingDeleted, this, 0); + disconnect(zone, &ZoneViewZone::closed, this, 0); + // manually call zone->close in order to remove it from the origZones views + zone->close(); if (shuffleCheckBox.isChecked()) player->sendGameCommand(Command_Shuffle()); - emit closePressed(this); - deleteLater(); + zoneDeleted(); event->accept(); }