diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-12-11 15:31:55 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-12-13 13:37:26 +0000 |
commit | 2567cb8e405b72a50cdba0cffd98aa2f4ede3c54 (patch) | |
tree | d0ca29e4bea29d610d71bb33d3eb887d7c4d45a8 /src/quicktemplates2 | |
parent | 0195d0b1b4a2d17aeb2dfd09e6ab62d953c5cdce (diff) |
TextArea: use deferred execution
Task-number: QTBUG-50992
Change-Id: I6d205f8ea0c90986b18b7e6cedbf347f1ce38eec
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquicktextarea.cpp | 25 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextarea_p.h | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktextarea_p_p.h | 5 |
3 files changed, 27 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 8c48bdf9..06867742 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -39,6 +39,7 @@ #include "qquickcontrol_p.h" #include "qquickcontrol_p_p.h" #include "qquickscrollview_p.h" +#include "qquickdeferredexecute_p_p.h" #include <QtQml/qqmlinfo.h> #include <QtQuick/private/qquickitem_p.h> @@ -391,6 +392,20 @@ QAccessible::Role QQuickTextAreaPrivate::accessibleRole() const } #endif +static inline QString backgroundName() { return QStringLiteral("background"); } + +void QQuickTextAreaPrivate::executeBackground(bool complete) +{ + Q_Q(QQuickTextArea); + if (background.wasExecuted()) + return; + + if (!background) + quickBeginDeferred(q, backgroundName(), background); + if (complete) + quickCompleteDeferred(q, backgroundName(), background); +} + QQuickTextArea::QQuickTextArea(QQuickItem *parent) : QQuickTextEdit(*(new QQuickTextAreaPrivate), parent) { @@ -444,7 +459,9 @@ void QQuickTextArea::setFont(const QFont &font) */ QQuickItem *QQuickTextArea::background() const { - Q_D(const QQuickTextArea); + QQuickTextAreaPrivate *d = const_cast<QQuickTextAreaPrivate *>(d_func()); + if (!d->background) + d->executeBackground(); return d->background; } @@ -454,7 +471,7 @@ void QQuickTextArea::setBackground(QQuickItem *background) if (d->background == background) return; - QQuickControlPrivate::destroyDelegate(d->background, this); + delete d->background; d->background = background; if (background) { background->setParentItem(this); @@ -463,7 +480,8 @@ void QQuickTextArea::setBackground(QQuickItem *background) if (isComponentComplete()) d->resizeBackground(); } - emit backgroundChanged(); + if (!d->background.isExecuting()) + emit backgroundChanged(); } /*! @@ -607,6 +625,7 @@ void QQuickTextArea::classBegin() void QQuickTextArea::componentComplete() { Q_D(QQuickTextArea); + d->executeBackground(true); QQuickTextEdit::componentComplete(); #if QT_CONFIG(quicktemplates2_hover) if (!d->explicitHoverEnabled) diff --git a/src/quicktemplates2/qquicktextarea_p.h b/src/quicktemplates2/qquicktextarea_p.h index 507f8b14..86d91346 100644 --- a/src/quicktemplates2/qquicktextarea_p.h +++ b/src/quicktemplates2/qquicktextarea_p.h @@ -70,6 +70,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTextArea : public QQuickTextEdit // 2.1 (Qt 5.8) Q_PROPERTY(bool hovered READ isHovered NOTIFY hoveredChanged FINAL REVISION 1) Q_PROPERTY(bool hoverEnabled READ isHoverEnabled WRITE setHoverEnabled RESET resetHoverEnabled NOTIFY hoverEnabledChanged FINAL REVISION 1) + Q_CLASSINFO("DeferredPropertyNames", "background") public: explicit QQuickTextArea(QQuickItem *parent = nullptr); diff --git a/src/quicktemplates2/qquicktextarea_p_p.h b/src/quicktemplates2/qquicktextarea_p_p.h index ef2c7237..ede9d97f 100644 --- a/src/quicktemplates2/qquicktextarea_p_p.h +++ b/src/quicktemplates2/qquicktextarea_p_p.h @@ -51,6 +51,7 @@ #include <QtQuick/private/qquicktextedit_p_p.h> #include <QtQuick/private/qquickitemchangelistener_p.h> #include <QtQuickTemplates2/private/qquickpresshandler_p_p.h> +#include <QtQuickTemplates2/private/qquickdeferredpointer_p_p.h> #include "qquicktextarea_p.h" @@ -108,12 +109,14 @@ public: QAccessible::Role accessibleRole() const override; #endif + void executeBackground(bool complete = false); + #if QT_CONFIG(quicktemplates2_hover) bool hovered; bool explicitHoverEnabled; #endif QFont font; - QQuickItem *background; + QQuickDeferredPointer<QQuickItem> background; QString placeholder; Qt::FocusReason focusReason; QQuickPressHandler pressHandler; |