Add Ui::WrapAsQObject.
This commit is contained in:
parent
663e2cc133
commit
8a70d4b6c5
1 changed files with 11 additions and 18 deletions
|
|
@ -24,23 +24,11 @@ class object_ptr;
|
|||
namespace Ui {
|
||||
namespace details {
|
||||
|
||||
struct ForwardTag {
|
||||
};
|
||||
|
||||
struct InPlaceTag {
|
||||
};
|
||||
|
||||
template <typename Value>
|
||||
class AttachmentOwner : public QObject {
|
||||
public:
|
||||
template <typename OtherValue>
|
||||
AttachmentOwner(QObject *parent, const ForwardTag&, OtherValue &&value)
|
||||
: QObject(parent)
|
||||
, _value(std::forward<OtherValue>(value)) {
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
AttachmentOwner(QObject *parent, const InPlaceTag&, Args &&...args)
|
||||
AttachmentOwner(QObject *parent, Args &&...args)
|
||||
: QObject(parent)
|
||||
, _value(std::forward<Args>(args)...) {
|
||||
}
|
||||
|
|
@ -56,6 +44,15 @@ private:
|
|||
|
||||
} // namespace details
|
||||
|
||||
template <typename Value>
|
||||
inline not_null<details::AttachmentOwner<std::decay_t<Value>>*> WrapAsQObject(
|
||||
not_null<QObject*> parent,
|
||||
Value &&value) {
|
||||
return CreateChild<details::AttachmentOwner<std::decay_t<Value>>>(
|
||||
parent.get(),
|
||||
std::forward<Value>(value));
|
||||
}
|
||||
|
||||
template <typename Widget, typename ...Args>
|
||||
inline base::unique_qptr<Widget> CreateObject(Args &&...args) {
|
||||
return base::make_unique_q<Widget>(
|
||||
|
|
@ -74,7 +71,6 @@ inline Value *CreateChild(
|
|||
} else {
|
||||
return CreateChild<details::AttachmentOwner<Value>>(
|
||||
parent,
|
||||
details::InPlaceTag{},
|
||||
std::forward<Args>(args)...)->value();
|
||||
}
|
||||
}
|
||||
|
|
@ -92,10 +88,7 @@ template <typename Value>
|
|||
inline not_null<std::decay_t<Value>*> AttachAsChild(
|
||||
not_null<QObject*> parent,
|
||||
Value &&value) {
|
||||
return CreateChild<details::AttachmentOwner<std::decay_t<Value>>>(
|
||||
parent.get(),
|
||||
details::ForwardTag{},
|
||||
std::forward<Value>(value))->value();
|
||||
return WrapAsQObject(parent, std::forward<Value>(value))->value();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool AppInFocus();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue