Files
qt-creator/tests/manual/layoutbuilder/v2/main.cpp
hjk acf1ecb47f LayoutBuilder: Complete experimental implementation
This adds support for inheritance to the existing experimental
implementation in tests/manual/layoutbuilder/experimental
and gets rid of the tight coupling and qobject_casts in the
setter implementations. Plan is to use this (minus "bindings"
via *::Id / id()) for utils/layoutbuilder.{h,cpp} later.

The "binding" support via id() is still experimental, and in
its current version not really useful. A possible idea would
be to re-use the Tasking::Storage idea, but it's not quite
clear how to expose that "long distance" (i.e. across multiple,
unrelated top-level builders). However, this is not used in
in current uses of the "old" layoutbuilder, so this is not
blocking anything.

Some notes:

The *Interface hierarchy is not strictly needed, it could directly
act on things in the QObject hierarchy but would then need #includes
of all "buildable" classes, which can be avoided in the current
implementation. Besides, the indirection allows us to tweak and/or
add functionailty to the Qt classes in the indirecting code, that
does not necessarily have to match 1:1 to the underlyings Qt classes.

The std::function based callbacks are quite fat and not functionally
needed and could be dropped  by "inlining" the relevant bits from
typical std::function implementations. However, these invariably seem
to end up calling functions through pointers to (ABI-compatible, but)
different types, which is for /user/ code formally undefined behavior
according to C++11 §5.2.10/6. To avoid a discussion whether doing
the same ourselves is tolerable or not, this uses std::function
and pays the price of the overhead.

Change-Id: I6d40c1bd48cf065fcf211eaff8d9a2298bca20eb
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
2024-05-16 12:06:06 +00:00

80 lines
2.0 KiB
C++

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "lb.h"
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QGroupBox>
#include <QTextEdit>
using namespace Layouting;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TextEdit::Id textId;
QWidget *w = nullptr;
QGroupBox *g = nullptr;
QLabel *l = nullptr;
Group {
bindTo(&w), // Works, as GroupInterface derives from WidgetInterface
// bindTo(&l), // Does (intentionally) not work, GroupInterface does not derive from LabelInterface
bindTo(&g),
size(300, 200),
title("HHHHHHH"),
Form {
"Hallo",
Group {
title("Title"),
Column {
Label {
text("World")
},
TextEdit {
id(&textId),
text("Och noe")
}
}
},
br,
"Col",
Column {
Row { "1", "2", "3" },
Row { "3", "4", "6" }
},
br,
"Grid",
Grid {
Span { 2, QString("1111111") }, "3", br,
"3", "4", "6", br,
"4", empty, "6", br,
hr, "4", "6"
},
br,
Column {
Label {
text("Hi"),
size(30, 20)
},
Row {
SpinBox {
onTextChanged([&](const QString &text) { textId->setText(text); })
},
st,
PushButton {
text("Quit"),
onClicked(QApplication::quit)
}
}
}
}
}.show();
return app.exec();
}