forked from qt-creator/qt-creator
Layouting: Introduce a 'bindTo' LayoutItem
... to 'export' the widget being operated on. The 'Tab' related changes are related, as they affect the order of execution. Change-Id: I7aa079f12e49a1dab7c6a49acfae9dc684cfb479 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -418,16 +418,22 @@ Tab::Tab(const QString &tabName, const LayoutBuilder &item)
|
||||
text = tabName;
|
||||
widget = new QWidget;
|
||||
item.attachTo(widget);
|
||||
specialType = LayoutItem::SpecialType::Tab;
|
||||
}
|
||||
|
||||
// "Widgets"
|
||||
|
||||
static void applyItems(QWidget *widget, const QList<LayoutItem> &items)
|
||||
static void applyItems(LayoutItem *owner, QWidget *widget, const QList<LayoutItem> &items)
|
||||
{
|
||||
owner->widget = widget;
|
||||
bool hadLayout = false;
|
||||
for (const LayoutItem &item : items) {
|
||||
if (item.setter) {
|
||||
item.setter(widget);
|
||||
} else if (item.specialType == LayoutItem::SpecialType::Tab) {
|
||||
auto tabWidget = qobject_cast<QTabWidget *>(widget);
|
||||
QTC_ASSERT(tabWidget, continue);
|
||||
tabWidget->addTab(item.widget, item.text);
|
||||
} else if (item.layout && !hadLayout) {
|
||||
hadLayout = true;
|
||||
widget->setLayout(item.layout);
|
||||
@@ -439,70 +445,65 @@ static void applyItems(QWidget *widget, const QList<LayoutItem> &items)
|
||||
|
||||
Group::Group(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
widget = new QGroupBox;
|
||||
applyItems(widget, items);
|
||||
applyItems(this, new QGroupBox, items);
|
||||
}
|
||||
|
||||
PushButton::PushButton(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
widget = new QPushButton;
|
||||
applyItems(widget, items);
|
||||
applyItems(this, new QPushButton, items);
|
||||
}
|
||||
|
||||
TextEdit::TextEdit(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
widget = new QTextEdit;
|
||||
applyItems(widget, items);
|
||||
applyItems(this, new QTextEdit, items);
|
||||
}
|
||||
|
||||
Splitter::Splitter(std::initializer_list<LayoutItem> items)
|
||||
: Splitter(new QSplitter(Qt::Vertical), items) {}
|
||||
|
||||
Splitter::Splitter(QSplitter *splitter, std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
widget = splitter;
|
||||
for (const LayoutItem &item : items)
|
||||
splitter->addWidget(item.widget);
|
||||
}
|
||||
applyItems(this, new QSplitter(Qt::Vertical), items);
|
||||
}
|
||||
|
||||
TabWidget::TabWidget(std::initializer_list<Tab> tabs)
|
||||
: TabWidget(new QTabWidget, tabs) {}
|
||||
|
||||
TabWidget::TabWidget(QTabWidget *tabWidget, std::initializer_list<Tab> tabs)
|
||||
{
|
||||
widget = tabWidget;
|
||||
for (const Tab &tab : tabs)
|
||||
tabWidget->addTab(tab.widget, tab.text);
|
||||
TabWidget::TabWidget(std::initializer_list<LayoutItem> items)
|
||||
{
|
||||
applyItems(this, new QTabWidget, items);
|
||||
}
|
||||
|
||||
// "Properties"
|
||||
|
||||
LayoutItem::Setter title(const QString &title)
|
||||
static LayoutItem setter(const LayoutItem::Setter &setter)
|
||||
{
|
||||
return [title](QObject *target) {
|
||||
LayoutItem item;
|
||||
item.setter = setter;
|
||||
return item;
|
||||
}
|
||||
|
||||
LayoutItem title(const QString &title)
|
||||
{
|
||||
return setter([title](QObject *target) {
|
||||
if (auto groupBox = qobject_cast<QGroupBox *>(target)) {
|
||||
groupBox->setTitle(title);
|
||||
groupBox->setObjectName(title);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
LayoutItem::Setter onClicked(const std::function<void ()> &func, QObject *guard)
|
||||
LayoutItem onClicked(const std::function<void ()> &func, QObject *guard)
|
||||
{
|
||||
return [func, guard](QObject *target) {
|
||||
return setter([func, guard](QObject *target) {
|
||||
if (auto button = qobject_cast<QAbstractButton *>(target)) {
|
||||
QObject::connect(button, &QAbstractButton::clicked, guard ? guard : target, func);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
LayoutItem::Setter text(const QString &text)
|
||||
LayoutItem text(const QString &text)
|
||||
{
|
||||
return [text](QObject *target) {
|
||||
return setter([text](QObject *target) {
|
||||
if (auto button = qobject_cast<QAbstractButton *>(target)) {
|
||||
button->setText(text);
|
||||
} else if (auto textEdit = qobject_cast<QTextEdit *>(target)) {
|
||||
@@ -510,18 +511,32 @@ LayoutItem::Setter text(const QString &text)
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
LayoutItem::Setter tooltip(const QString &toolTip)
|
||||
LayoutItem tooltip(const QString &toolTip)
|
||||
{
|
||||
return [toolTip](QObject *target) {
|
||||
return setter([toolTip](QObject *target) {
|
||||
if (auto widget = qobject_cast<QWidget *>(target)) {
|
||||
widget->setToolTip(toolTip);
|
||||
} else {
|
||||
QTC_CHECK(false);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
LayoutItem bindTo(QSplitter **out)
|
||||
{
|
||||
return setter([out](QObject *target) {
|
||||
*out = qobject_cast<QSplitter *>(target);
|
||||
});
|
||||
}
|
||||
|
||||
LayoutItem bindTo(QTabWidget **out)
|
||||
{
|
||||
return setter([out](QObject *target) {
|
||||
*out = qobject_cast<QTabWidget *>(target);
|
||||
});
|
||||
}
|
||||
|
||||
QWidget *createHr(QWidget *parent)
|
||||
|
||||
@@ -87,6 +87,7 @@ public:
|
||||
Stretch,
|
||||
Break,
|
||||
HorizontalRule,
|
||||
Tab,
|
||||
};
|
||||
|
||||
using Setter = std::function<void(QObject *target)>;
|
||||
@@ -170,14 +171,12 @@ class QTCREATOR_UTILS_EXPORT Splitter : public LayoutItem
|
||||
{
|
||||
public:
|
||||
Splitter(std::initializer_list<LayoutItem> items);
|
||||
Splitter(QSplitter *splitter, std::initializer_list<LayoutItem> items);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT TabWidget : public LayoutItem
|
||||
{
|
||||
public:
|
||||
TabWidget(std::initializer_list<Tab> tabs);
|
||||
TabWidget(QTabWidget *tabWidget, std::initializer_list<Tab> tabs);
|
||||
TabWidget(std::initializer_list<LayoutItem> items);
|
||||
};
|
||||
|
||||
// Singleton items.
|
||||
@@ -189,10 +188,13 @@ QTCREATOR_UTILS_EXPORT extern HorizontalRule hr;
|
||||
|
||||
// "Properties"
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem::Setter title(const QString &title);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem::Setter text(const QString &text);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem::Setter tooltip(const QString &toolTip);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem::Setter onClicked(const std::function<void()> &func,
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem bindTo(QTabWidget **);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem bindTo(QSplitter **);
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem title(const QString &title);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem text(const QString &text);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem tooltip(const QString &toolTip);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onClicked(const std::function<void()> &func,
|
||||
QObject *guard = nullptr);
|
||||
|
||||
|
||||
|
||||
@@ -1429,7 +1429,9 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
m_workingCopyView->setModel(m_proxyWorkingCopyModel);
|
||||
|
||||
using namespace Layouting;
|
||||
m_projectPartTab = qobject_cast<QTabWidget*>(TabWidget{
|
||||
|
||||
TabWidget projectPart {
|
||||
bindTo(&m_projectPartTab),
|
||||
Tab("&General",
|
||||
Row {
|
||||
m_partGeneralView,
|
||||
@@ -1454,10 +1456,10 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
),
|
||||
Tab("&Header Paths", Column{ projectHeaderPathsView }),
|
||||
Tab("Pre&compiled Headers", Column{ m_partPrecompiledHeadersEdit }),
|
||||
}.widget);
|
||||
QTC_CHECK(m_projectPartTab);
|
||||
};
|
||||
|
||||
m_docTab = qobject_cast<QTabWidget*>(TabWidget{
|
||||
TabWidget docTab {
|
||||
bindTo(&m_docTab),
|
||||
Tab("&General", Column { m_docGeneralView }),
|
||||
Tab("&Includes", Column { m_docIncludesView }),
|
||||
Tab("&Diagnostic Messages", Column { m_docDiagnosticMessagesView }),
|
||||
@@ -1465,8 +1467,7 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
Tab("P&reprocessed Source", Column { m_docPreprocessedSourceEdit }),
|
||||
Tab("&Symbols", Column { m_docSymbolsView }),
|
||||
Tab("&Tokens", Column { m_docTokensView }),
|
||||
}.widget);
|
||||
QTC_CHECK(m_docTab);
|
||||
};
|
||||
|
||||
Column {
|
||||
TabWidget {
|
||||
@@ -1474,7 +1475,7 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
Column {
|
||||
Splitter {
|
||||
m_projectPartsView,
|
||||
m_projectPartTab,
|
||||
projectPart,
|
||||
},
|
||||
}
|
||||
),
|
||||
@@ -1485,7 +1486,7 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
Form { QString("Sn&apshot:"), m_snapshotSelector },
|
||||
m_snapshotView,
|
||||
}.emerge(Layouting::WithoutMargins),
|
||||
m_docTab,
|
||||
docTab,
|
||||
},
|
||||
}
|
||||
),
|
||||
@@ -1506,6 +1507,7 @@ CppCodeModelInspectorDialog::CppCodeModelInspectorDialog(QWidget *parent)
|
||||
}
|
||||
}.attachTo(this);
|
||||
|
||||
QTC_CHECK(m_projectPartTab);
|
||||
m_projectPartTab->setCurrentIndex(3);
|
||||
|
||||
connect(m_snapshotView->selectionModel(),
|
||||
|
||||
@@ -162,11 +162,8 @@ public:
|
||||
, m_bindStarToLeftSpecifier(createCheckBox(Tr::tr("Left const/volatile")))
|
||||
, m_bindStarToRightSpecifier(createCheckBox(Tr::tr("Right const/volatile"),
|
||||
Tr::tr("This does not apply to references.")))
|
||||
, m_categoryTab(new QTabWidget)
|
||||
, m_tabSettingsWidget(new TabSettingsWidget)
|
||||
{
|
||||
m_categoryTab->setProperty("_q_custom_style_disabled", true);
|
||||
|
||||
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
@@ -234,7 +231,8 @@ public:
|
||||
};
|
||||
|
||||
Row {
|
||||
TabWidget { m_categoryTab, {
|
||||
TabWidget {
|
||||
bindTo(&m_categoryTab),
|
||||
Tab { Tr::tr("General"),
|
||||
Row { Column { m_tabSettingsWidget, st }, createPreview(0) }
|
||||
},
|
||||
@@ -243,9 +241,11 @@ public:
|
||||
Tab { Tr::tr("\"switch\""), Row { switchGroup, createPreview(3) } },
|
||||
Tab { Tr::tr("Alignment"), Row { alignmentGroup, createPreview(4) } },
|
||||
Tab { Tr::tr("Pointers and References"), Row { typesGroup, createPreview(5) } }
|
||||
} }
|
||||
}
|
||||
}.attachTo(q);
|
||||
|
||||
m_categoryTab->setProperty("_q_custom_style_disabled", true);
|
||||
|
||||
m_controllers.append(m_tabSettingsWidget);
|
||||
m_controllers.append(contentGroup.widget);
|
||||
m_controllers.append(bracesGroup.widget);
|
||||
|
||||
Reference in New Issue
Block a user