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:
hjk
2023-05-05 15:19:58 +02:00
parent 7581dcd369
commit 62f3d29be4
6 changed files with 60 additions and 24 deletions

View File

@@ -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