mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-05 20:39:59 -08:00
[VDE] Proper parent lookup syncs group-by box again (#6396)
* [VDE] Proper parent lookup syncs group-by box again * [VDE] Proper lib inclusion. * [VDE] Lint.
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include "../tabs/visual_deck_editor/tab_deck_editor_visual.h"
|
#include "../tabs/visual_deck_editor/tab_deck_editor_visual.h"
|
||||||
|
|
||||||
VisualDeckDisplayOptionsWidget::VisualDeckDisplayOptionsWidget(QWidget *parent)
|
#include <libcockatrice/utility/qt_utils.h>
|
||||||
|
|
||||||
|
VisualDeckDisplayOptionsWidget::VisualDeckDisplayOptionsWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
groupAndSortLayout = new QHBoxLayout(this);
|
groupAndSortLayout = new QHBoxLayout(this);
|
||||||
groupAndSortLayout->setAlignment(Qt::AlignLeft);
|
groupAndSortLayout->setAlignment(Qt::AlignLeft);
|
||||||
@@ -11,23 +13,19 @@ VisualDeckDisplayOptionsWidget::VisualDeckDisplayOptionsWidget(QWidget *parent)
|
|||||||
groupByLabel = new QLabel(this);
|
groupByLabel = new QLabel(this);
|
||||||
|
|
||||||
groupByComboBox = new QComboBox(this);
|
groupByComboBox = new QComboBox(this);
|
||||||
if (auto visualDeckEditorWidget = qobject_cast<VisualDeckEditorWidget *>(parent)) {
|
|
||||||
if (auto tabWidget = qobject_cast<TabDeckEditorVisualTabWidget *>(visualDeckEditorWidget)) {
|
|
||||||
// Inside a central widget QWidget container inside TabDeckEditorVisual
|
|
||||||
if (auto tab = qobject_cast<TabDeckEditorVisual *>(tabWidget->parent()->parent())) {
|
|
||||||
auto originalBox = tab->getDeckDockWidget()->getGroupByComboBox();
|
|
||||||
groupByComboBox->setModel(originalBox->model());
|
|
||||||
groupByComboBox->setModelColumn(originalBox->modelColumn());
|
|
||||||
|
|
||||||
// Original -> clone
|
if (auto tab = QtUtils::findParentOfType<TabDeckEditorVisual>(this)) {
|
||||||
connect(originalBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
auto originalBox = tab->getDeckDockWidget()->getGroupByComboBox();
|
||||||
[this](int index) { groupByComboBox->setCurrentIndex(index); });
|
groupByComboBox->setModel(originalBox->model());
|
||||||
|
groupByComboBox->setModelColumn(originalBox->modelColumn());
|
||||||
|
|
||||||
// Clone -> original
|
// Original -> clone
|
||||||
connect(groupByComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
connect(originalBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
[originalBox](int index) { originalBox->setCurrentIndex(index); });
|
[this](int index) { groupByComboBox->setCurrentIndex(index); });
|
||||||
}
|
|
||||||
}
|
// Clone -> original
|
||||||
|
connect(groupByComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
|
[originalBox](int index) { originalBox->setCurrentIndex(index); });
|
||||||
} else {
|
} else {
|
||||||
groupByComboBox->addItem(
|
groupByComboBox->addItem(
|
||||||
tr(qPrintable(DeckListModelGroupCriteria::toString(DeckListModelGroupCriteria::MAIN_TYPE))),
|
tr(qPrintable(DeckListModelGroupCriteria::toString(DeckListModelGroupCriteria::MAIN_TYPE))),
|
||||||
|
|||||||
20
libcockatrice_utility/libcockatrice/utility/qt_utils.h
Normal file
20
libcockatrice_utility/libcockatrice/utility/qt_utils.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef COCKATRICE_QT_UTILS_H
|
||||||
|
#define COCKATRICE_QT_UTILS_H
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace QtUtils
|
||||||
|
{
|
||||||
|
template <typename T> T *findParentOfType(const QObject *obj)
|
||||||
|
{
|
||||||
|
const QObject *p = obj ? obj->parent() : nullptr;
|
||||||
|
while (p) {
|
||||||
|
if (auto casted = qobject_cast<T *>(const_cast<QObject *>(p))) {
|
||||||
|
return casted;
|
||||||
|
}
|
||||||
|
p = p->parent();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
} // namespace QtUtils
|
||||||
|
|
||||||
|
#endif // COCKATRICE_QT_UTILS_H
|
||||||
Reference in New Issue
Block a user