New layout updating?

This commit is contained in:
Lukas Brübach 2025-02-10 08:27:40 +01:00
parent 3b3ba55bcb
commit 5a8dc3ec66
2 changed files with 16 additions and 7 deletions

View file

@ -109,8 +109,10 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
bottomSplitter->setStretchFactor(0, 1); // Left and right equally split bottomSplitter->setStretchFactor(0, 1); // Left and right equally split
bottomSplitter->setStretchFactor(1, 1); bottomSplitter->setStretchFactor(1, 1);
}
connect(this, &DlgSelectSetForCards::orderChanged, this, &DlgSelectSetForCards::updateLayoutOrder);
connect(this, &DlgSelectSetForCards::widgetOrderChanged, this, &DlgSelectSetForCards::updateCardLists);
}
void DlgSelectSetForCards::actOK() void DlgSelectSetForCards::actOK()
{ {
@ -194,7 +196,6 @@ QMap<QString, int> DlgSelectSetForCards::getSetsForCards()
void DlgSelectSetForCards::updateCardLists() void DlgSelectSetForCards::updateCardLists()
{ {
updateLayoutOrder();
for (SetEntryWidget *entryWidget : entry_widgets) { for (SetEntryWidget *entryWidget : entry_widgets) {
entryWidget->populateCardList(); entryWidget->populateCardList();
if (entryWidget->expanded) { if (entryWidget->expanded) {
@ -259,12 +260,11 @@ void DlgSelectSetForCards::updateCardLists()
.getProperty("uuid")); .getProperty("uuid"));
CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(modifiedCardsFlowWidget); CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(modifiedCardsFlowWidget);
picture_widget->setCard(infoPtr); picture_widget->setCard(infoPtr);
modifiedCardsFlowWidget->addWidget(picture_widget);} modifiedCardsFlowWidget->addWidget(picture_widget);
}
} }
} }
} }
void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event) void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event)
{ {
@ -302,6 +302,9 @@ void DlgSelectSetForCards::dropEvent(QDropEvent *event)
event->acceptProposedAction(); event->acceptProposedAction();
// Reset cursor after drop // Reset cursor after drop
unsetCursor(); unsetCursor();
// We need to execute this AFTER the current event-cycle so we use a timer.
QTimer::singleShot(10, this, [this]() { emit orderChanged(); });
} }
QMap<QString, QStringList> DlgSelectSetForCards::getCardsForSets() QMap<QString, QStringList> DlgSelectSetForCards::getCardsForSets()
@ -376,6 +379,8 @@ void DlgSelectSetForCards::updateLayoutOrder()
entry_widgets.append(entry); entry_widgets.append(entry);
} }
} }
emit widgetOrderChanged();
} }
SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_setName, int count) SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_setName, int count)
@ -387,7 +392,7 @@ SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_se
QHBoxLayout *headerLayout = new QHBoxLayout(); QHBoxLayout *headerLayout = new QHBoxLayout();
CardSetPtr set = CardDatabaseManager::getInstance()->getSet(setName); CardSetPtr set = CardDatabaseManager::getInstance()->getSet(setName);
checkBox = new QCheckBox("(" + set->getShortName() + ") - " + set->getLongName(), this); 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); expandButton = new QPushButton("+", this);
countLabel = new QLabel(QString::number(count), this); countLabel = new QLabel(QString::number(count), this);

View file

@ -23,13 +23,17 @@ public:
void sortSetsByCount(); void sortSetsByCount();
QMap<QString, QStringList> getCardsForSets(); QMap<QString, QStringList> getCardsForSets();
QMap<QString, QStringList> getModifiedCards(); QMap<QString, QStringList> getModifiedCards();
void updateLayoutOrder();
QVBoxLayout *listLayout; QVBoxLayout *listLayout;
QList<SetEntryWidget *> entry_widgets; QList<SetEntryWidget *> entry_widgets;
QMap<QString, QStringList> cardsForSets; QMap<QString, QStringList> cardsForSets;
signals:
void widgetOrderChanged();
void orderChanged();
public slots: public slots:
void actOK(); void actOK();
void updateLayoutOrder();
void updateCardLists(); void updateCardLists();
void dragEnterEvent(QDragEnterEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override; void dropEvent(QDropEvent *event) override;