forked from qt-creator/qt-creator
Layouting: Introduce Ids for Items
Intenally just wrapping a 'bindTo' result, but less trigger potential for pointer related peladophobia Change-Id: I25171a2675fb0474ce97c04552ac1cf5ffd6ee56 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -694,6 +694,19 @@ LayoutItem columnStretch(int column, int stretch)
|
||||
};
|
||||
}
|
||||
|
||||
// Id based setters
|
||||
|
||||
LayoutItem id(Id &out)
|
||||
{
|
||||
return [&out](QObject *target) { out.ob = target; };
|
||||
}
|
||||
|
||||
void setText(Id id, const QString &text)
|
||||
{
|
||||
if (auto textEdit = qobject_cast<QTextEdit *>(id.ob))
|
||||
textEdit->setText(text);
|
||||
}
|
||||
|
||||
// Signals
|
||||
|
||||
LayoutItem onClicked(const std::function<void ()> &func, QObject *guard)
|
||||
|
||||
@@ -190,7 +190,7 @@ QTCREATOR_UTILS_EXPORT LayoutItem noMargin();
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem normalMargin();
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem withFormAlignment();
|
||||
|
||||
// "Properties"
|
||||
// "Setters"
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem title(const QString &title);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem text(const QString &text);
|
||||
@@ -200,6 +200,19 @@ QTCREATOR_UTILS_EXPORT LayoutItem columnStretch(int column, int stretch);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem spacing(int);
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem windowTitle(const QString &windowTitle);
|
||||
|
||||
// "Getters"
|
||||
|
||||
class Id
|
||||
{
|
||||
public:
|
||||
QObject *ob = nullptr;
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem id(Id &out);
|
||||
|
||||
QTCREATOR_UTILS_EXPORT void setText(Id id, const QString &text);
|
||||
|
||||
|
||||
// "Signals"
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onClicked(const std::function<void()> &,
|
||||
@@ -209,6 +222,8 @@ QTCREATOR_UTILS_EXPORT LayoutItem onTextChanged(const std::function<void(const Q
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onValueChanged(const std::function<void(int)> &,
|
||||
QObject *guard = nullptr);
|
||||
|
||||
QTCREATOR_UTILS_EXPORT LayoutItem onTextChanged(Id &id, QVariant(*sig)(QObject *));
|
||||
|
||||
// Convenience
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QWidget *createHr(QWidget *parent = nullptr);
|
||||
@@ -219,4 +234,5 @@ LayoutItem bindTo(T **out)
|
||||
return [out](QObject *target) { *out = qobject_cast<T *>(target); };
|
||||
}
|
||||
|
||||
|
||||
} // Layouting
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
using namespace Layouting;
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
|
||||
@@ -104,7 +103,7 @@ private:
|
||||
// KitAspectWidget interface
|
||||
void makeReadOnly() override { m_comboBox->setEnabled(false); }
|
||||
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_comboBox);
|
||||
builder.addItem(m_comboBox);
|
||||
@@ -349,7 +348,7 @@ private:
|
||||
// KitAspectWidget interface
|
||||
void makeReadOnly() override { m_changeButton->setEnabled(false); }
|
||||
|
||||
void addToLayout(LayoutItem &parent) override
|
||||
void addToLayout(Layouting::LayoutItem &parent) override
|
||||
{
|
||||
addMutableAction(m_label);
|
||||
parent.addItem(m_label);
|
||||
@@ -890,7 +889,7 @@ public:
|
||||
|
||||
private:
|
||||
// KitAspectWidget interface
|
||||
void addToLayout(LayoutItem &parent) override
|
||||
void addToLayout(Layouting::LayoutItem &parent) override
|
||||
{
|
||||
addMutableAction(m_summaryLabel);
|
||||
parent.addItem(m_summaryLabel);
|
||||
|
||||
@@ -341,12 +341,13 @@ public:
|
||||
|
||||
auto addMenu = new QMenu(addButton);
|
||||
addMenu->addAction(Tr::tr("Files in Directories"), this, [this] {
|
||||
addCustomFilter(new DirectoryFilter(Id(Constants::CUSTOM_DIRECTORY_FILTER_BASEID)
|
||||
addCustomFilter(new DirectoryFilter(Utils::Id(Constants::CUSTOM_DIRECTORY_FILTER_BASEID)
|
||||
.withSuffix(m_customFilters.size() + 1)));
|
||||
});
|
||||
addMenu->addAction(Tr::tr("URL Template"), this, [this] {
|
||||
auto filter = new UrlLocatorFilter(
|
||||
Id(Constants::CUSTOM_URL_FILTER_BASEID).withSuffix(m_customFilters.size() + 1));
|
||||
Utils::Id(Constants::CUSTOM_URL_FILTER_BASEID)
|
||||
.withSuffix(m_customFilters.size() + 1));
|
||||
filter->setIsCustomFilter(true);
|
||||
addCustomFilter(filter);
|
||||
});
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Utils;
|
||||
using namespace Layouting;
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
@@ -65,7 +64,7 @@ public:
|
||||
private:
|
||||
void makeReadOnly() override { m_chooser->setReadOnly(true); }
|
||||
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_chooser);
|
||||
builder.addItem(Layouting::Span(2, m_chooser));
|
||||
@@ -142,7 +141,7 @@ void SysRootKitAspect::addToMacroExpander(Kit *kit, MacroExpander *expander) con
|
||||
});
|
||||
}
|
||||
|
||||
Id SysRootKitAspect::id()
|
||||
Utils::Id SysRootKitAspect::id()
|
||||
{
|
||||
return "PE.Profile.SysRoot";
|
||||
}
|
||||
@@ -231,7 +230,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_mainWidget);
|
||||
builder.addItem(m_mainWidget);
|
||||
@@ -760,7 +759,7 @@ public:
|
||||
~DeviceTypeKitAspectWidget() override { delete m_comboBox; }
|
||||
|
||||
private:
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_comboBox);
|
||||
builder.addItem(m_comboBox);
|
||||
@@ -896,7 +895,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_comboBox);
|
||||
builder.addItem(m_comboBox);
|
||||
@@ -1156,7 +1155,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_comboBox);
|
||||
builder.addItem(m_comboBox);
|
||||
@@ -1387,7 +1386,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void addToLayout(LayoutItem &builder) override
|
||||
void addToLayout(Layouting::LayoutItem &builder) override
|
||||
{
|
||||
addMutableAction(m_mainWidget);
|
||||
builder.addItem(m_mainWidget);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "layoutbuilder.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Layouting;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Id textId;
|
||||
|
||||
Application app
|
||||
{
|
||||
resize(600, 400),
|
||||
@@ -14,19 +18,23 @@ int main(int argc, char *argv[])
|
||||
|
||||
Column {
|
||||
TextEdit {
|
||||
id(textId),
|
||||
text("Hallo")
|
||||
},
|
||||
|
||||
Row {
|
||||
SpinBox {
|
||||
text("Quit"),
|
||||
onTextChanged([](const QString &text) { qDebug() << text; })
|
||||
onTextChanged([&](const QString &text) { setText(textId, text); })
|
||||
},
|
||||
|
||||
Stretch(),
|
||||
|
||||
PushButton {
|
||||
text("Quit"),
|
||||
onClicked([] { QApplication::quit(); })
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return app.exec(argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user