diff --git a/cockatrice/src/dialogs/dlg_select_set_for_cards.cpp b/cockatrice/src/dialogs/dlg_select_set_for_cards.cpp index ea7378dbc..325d13cf0 100644 --- a/cockatrice/src/dialogs/dlg_select_set_for_cards.cpp +++ b/cockatrice/src/dialogs/dlg_select_set_for_cards.cpp @@ -109,8 +109,10 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode bottomSplitter->setStretchFactor(0, 1); // Left and right equally split bottomSplitter->setStretchFactor(1, 1); -} + connect(this, &DlgSelectSetForCards::orderChanged, this, &DlgSelectSetForCards::updateLayoutOrder); + connect(this, &DlgSelectSetForCards::widgetOrderChanged, this, &DlgSelectSetForCards::updateCardLists); +} void DlgSelectSetForCards::actOK() { @@ -194,7 +196,6 @@ QMap DlgSelectSetForCards::getSetsForCards() void DlgSelectSetForCards::updateCardLists() { - updateLayoutOrder(); for (SetEntryWidget *entryWidget : entry_widgets) { entryWidget->populateCardList(); if (entryWidget->expanded) { @@ -259,13 +260,12 @@ void DlgSelectSetForCards::updateCardLists() .getProperty("uuid")); CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(modifiedCardsFlowWidget); picture_widget->setCard(infoPtr); - modifiedCardsFlowWidget->addWidget(picture_widget);} + modifiedCardsFlowWidget->addWidget(picture_widget); + } } } } - - void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("application/x-setentrywidget")) { @@ -302,6 +302,9 @@ void DlgSelectSetForCards::dropEvent(QDropEvent *event) event->acceptProposedAction(); // Reset cursor after drop unsetCursor(); + + // We need to execute this AFTER the current event-cycle so we use a timer. + QTimer::singleShot(10, this, [this]() { emit orderChanged(); }); } QMap DlgSelectSetForCards::getCardsForSets() @@ -376,6 +379,8 @@ void DlgSelectSetForCards::updateLayoutOrder() entry_widgets.append(entry); } } + + emit widgetOrderChanged(); } SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_setName, int count) @@ -387,7 +392,7 @@ SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_se QHBoxLayout *headerLayout = new QHBoxLayout(); CardSetPtr set = CardDatabaseManager::getInstance()->getSet(setName); checkBox = new QCheckBox("(" + set->getShortName() + ") - " + set->getLongName(), this); - connect(checkBox, &QCheckBox::checkStateChanged, parent, &DlgSelectSetForCards::updateCardLists); + connect(checkBox, &QCheckBox::checkStateChanged, parent, &DlgSelectSetForCards::updateLayoutOrder); expandButton = new QPushButton("+", this); countLabel = new QLabel(QString::number(count), this); diff --git a/cockatrice/src/dialogs/dlg_select_set_for_cards.h b/cockatrice/src/dialogs/dlg_select_set_for_cards.h index 6c0c6d44b..3bfcf3599 100644 --- a/cockatrice/src/dialogs/dlg_select_set_for_cards.h +++ b/cockatrice/src/dialogs/dlg_select_set_for_cards.h @@ -23,13 +23,17 @@ public: void sortSetsByCount(); QMap getCardsForSets(); QMap getModifiedCards(); - void updateLayoutOrder(); QVBoxLayout *listLayout; QList entry_widgets; QMap cardsForSets; +signals: + void widgetOrderChanged(); + void orderChanged(); + public slots: void actOK(); + void updateLayoutOrder(); void updateCardLists(); void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override;