aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@gmail.com>2017-04-03 09:53:19 +0200
committerJ-P Nurmi <jpnurmi@gmail.com>2017-04-03 09:53:19 +0200
commit4bd9acec8876e1c36168010758d0fea645a25ba2 (patch)
treea79345df4902efdf7827cc6c4ac6aafefdfaa39b /src/quicktemplates2
parentc3cc73e3087db62a8427ff569abff1a8289dae83 (diff)
parentf720bc8e38dfdc14c48ffe3178a704f5d130f932 (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: src/imports/controls/ComboBox.qml src/imports/controls/material/ComboBox.qml src/imports/controls/universal/ComboBox.qml Change-Id: Ib900bb6298c32245399f52980b44575b64b7409f
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r--src/quicktemplates2/qquickapplicationwindow.cpp14
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp4
-rw-r--r--src/quicktemplates2/qquickcontrol.cpp8
-rw-r--r--src/quicktemplates2/qquickdial.cpp2
-rw-r--r--src/quicktemplates2/qquickdialogbuttonbox.cpp2
-rw-r--r--src/quicktemplates2/qquickoverlay.cpp2
-rw-r--r--src/quicktemplates2/qquickstackelement.cpp25
-rw-r--r--src/quicktemplates2/qquickstackelement_p_p.h4
-rw-r--r--src/quicktemplates2/qquickstackview.cpp46
-rw-r--r--src/quicktemplates2/qquickstackview_p.cpp28
-rw-r--r--src/quicktemplates2/qquickstackview_p_p.h7
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp2
-rw-r--r--src/quicktemplates2/qquickswipeview.cpp1
13 files changed, 105 insertions, 40 deletions
diff --git a/src/quicktemplates2/qquickapplicationwindow.cpp b/src/quicktemplates2/qquickapplicationwindow.cpp
index d49c9b0e..9b220a2b 100644
--- a/src/quicktemplates2/qquickapplicationwindow.cpp
+++ b/src/quicktemplates2/qquickapplicationwindow.cpp
@@ -638,6 +638,20 @@ void QQuickApplicationWindow::resetFont()
}
+/*!
+ \qmlproperty Locale QtQuick.Controls::ApplicationWindow::locale
+
+ This property holds the locale of the window.
+
+ The default locale depends on the system environment. You can set the
+ default locale by calling QLocale::setDefault(), before loading any QML.
+
+ ApplicationWindow propagates the locale to child controls. If you change
+ the window's locale, that locale propagates to all child controls in the
+ window, overriding the system default locale.
+
+ \sa Control::locale, {LayoutMirroring}{LayoutMirroring}
+*/
QLocale QQuickApplicationWindow::locale() const
{
Q_D(const QQuickApplicationWindow);
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 29fa5e55..786db55b 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -633,9 +633,7 @@ QQuickComboBox::QQuickComboBox(QQuickItem *parent)
QQuickComboBox::~QQuickComboBox()
{
- Q_D(QQuickComboBox);
- delete d->popup;
- d->popup = nullptr;
+ setPopup(nullptr);
}
/*!
diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp
index c707aede..4adf80e0 100644
--- a/src/quicktemplates2/qquickcontrol.cpp
+++ b/src/quicktemplates2/qquickcontrol.cpp
@@ -802,14 +802,14 @@ void QQuickControl::resetSpacing()
\qmlproperty Locale QtQuick.Controls::Control::locale
This property holds the locale of the control.
+
It contains locale specific properties for formatting data and numbers.
Unless a special locale has been set, this is either the parent's locale
or the default locale.
- Control propagates explicit locale properties from parent to children.
- If you change a specific property on a control's locale, that property
- propagates to all of the control's children, overriding any system defaults
- for that property.
+ Control propagates the locale from parent to children. If you change the
+ control's locale, that locale propagates to all of the control's children,
+ overriding the system default locale.
\sa mirrored, {LayoutMirroring}{LayoutMirroring}
*/
diff --git a/src/quicktemplates2/qquickdial.cpp b/src/quicktemplates2/qquickdial.cpp
index 198bd631..24a8df01 100644
--- a/src/quicktemplates2/qquickdial.cpp
+++ b/src/quicktemplates2/qquickdial.cpp
@@ -521,7 +521,7 @@ void QQuickDial::setPressed(bool pressed)
The default value is \c true.
- \sa value, valueAt()
+ \sa value
*/
bool QQuickDial::live() const
{
diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp
index a912ba6a..f1971635 100644
--- a/src/quicktemplates2/qquickdialogbuttonbox.cpp
+++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp
@@ -312,7 +312,7 @@ QQuickAbstractButton *QQuickDialogButtonBoxPrivate::createStandardButton(QPlatfo
QQmlContext *creationContext = delegate->creationContext();
if (!creationContext)
creationContext = qmlContext(q);
- QQmlContext *context = new QQmlContext(creationContext);
+ QQmlContext *context = new QQmlContext(creationContext, q);
context->setContextObject(q);
QObject *object = delegate->beginCreate(context);
diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp
index e3910509..c72979ae 100644
--- a/src/quicktemplates2/qquickoverlay.cpp
+++ b/src/quicktemplates2/qquickoverlay.cpp
@@ -80,7 +80,7 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ
QQmlContext *creationContext = component->creationContext();
if (!creationContext)
creationContext = qmlContext(parent);
- QQmlContext *context = new QQmlContext(creationContext);
+ QQmlContext *context = new QQmlContext(creationContext, parent);
context->setContextObject(popup);
item = qobject_cast<QQuickItem*>(component->beginCreate(context));
}
diff --git a/src/quicktemplates2/qquickstackelement.cpp b/src/quicktemplates2/qquickstackelement.cpp
index 2744c3e9..a3bb840e 100644
--- a/src/quicktemplates2/qquickstackelement.cpp
+++ b/src/quicktemplates2/qquickstackelement.cpp
@@ -122,17 +122,30 @@ QQuickStackElement::~QQuickStackElement()
delete context;
}
-QQuickStackElement *QQuickStackElement::fromString(const QString &str, QQuickStackView *view)
+QQuickStackElement *QQuickStackElement::fromString(const QString &str, QQuickStackView *view, QString *error)
{
+ QUrl url(str);
+ if (!url.isValid()) {
+ *error = QStringLiteral("invalid url: ") + str;
+ return nullptr;
+ }
+
QQuickStackElement *element = new QQuickStackElement;
- element->component = new QQmlComponent(qmlEngine(view), QUrl(str), view);
+ element->component = new QQmlComponent(qmlEngine(view), url, view);
element->ownComponent = true;
return element;
}
-QQuickStackElement *QQuickStackElement::fromObject(QObject *object, QQuickStackView *view)
+QQuickStackElement *QQuickStackElement::fromObject(QObject *object, QQuickStackView *view, QString *error)
{
Q_UNUSED(view);
+ QQmlComponent *component = qobject_cast<QQmlComponent *>(object);
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (!component && !item) {
+ *error = QQmlMetaType::prettyTypeName(object) + QStringLiteral(" is not supported. Must be Item or Component.");
+ return nullptr;
+ }
+
QQuickStackElement *element = new QQuickStackElement;
element->component = qobject_cast<QQmlComponent *>(object);
element->item = qobject_cast<QQuickItem *>(object);
@@ -152,7 +165,7 @@ bool QQuickStackElement::load(QQuickStackView *parent)
if (status == QQmlComponent::Ready)
load(view);
else if (status == QQmlComponent::Error)
- qWarning() << qPrintable(component->errorString().trimmed());
+ QQuickStackViewPrivate::get(view)->warn(component->errorString().trimmed());
});
return true;
}
@@ -160,13 +173,13 @@ bool QQuickStackElement::load(QQuickStackView *parent)
QQmlContext *creationContext = component->creationContext();
if (!creationContext)
creationContext = qmlContext(parent);
- context = new QQmlContext(creationContext);
+ context = new QQmlContext(creationContext, parent);
context->setContextObject(parent);
QQuickStackIncubator incubator(this);
component->create(incubator, context);
if (component->isError())
- qWarning() << qPrintable(component->errorString().trimmed());
+ QQuickStackViewPrivate::get(parent)->warn(component->errorString().trimmed());
} else {
initialize();
}
diff --git a/src/quicktemplates2/qquickstackelement_p_p.h b/src/quicktemplates2/qquickstackelement_p_p.h
index 9cb11855..2308f47d 100644
--- a/src/quicktemplates2/qquickstackelement_p_p.h
+++ b/src/quicktemplates2/qquickstackelement_p_p.h
@@ -67,8 +67,8 @@ class QQuickStackElement : public QQuickItemViewTransitionableItem, public QQuic
public:
~QQuickStackElement();
- static QQuickStackElement *fromString(const QString &str, QQuickStackView *view);
- static QQuickStackElement *fromObject(QObject *object, QQuickStackView *view);
+ static QQuickStackElement *fromString(const QString &str, QQuickStackView *view, QString *error);
+ static QQuickStackElement *fromObject(QObject *object, QQuickStackView *view, QString *error);
bool load(QQuickStackView *parent);
void incubate(QObject *object);
diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp
index a9922704..155f5f4d 100644
--- a/src/quicktemplates2/qquickstackview.cpp
+++ b/src/quicktemplates2/qquickstackview.cpp
@@ -39,6 +39,7 @@
#include "qquickstackelement_p_p.h"
#include "qquickstacktransition_p_p.h"
+#include <QtCore/qscopedvaluerollback.h>
#include <QtQml/qjsvalue.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlinfo.h>
@@ -474,8 +475,9 @@ QQuickItem *QQuickStackView::find(const QJSValue &callback, LoadBehavior behavio
void QQuickStackView::push(QQmlV4Function *args)
{
Q_D(QQuickStackView);
+ QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("push"));
if (args->length() <= 0) {
- qmlWarning(this) << "push: missing arguments";
+ d->warn(QStringLiteral("missing arguments"));
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -488,7 +490,8 @@ void QQuickStackView::push(QQmlV4Function *args)
if (lastArg->isInt32())
operation = static_cast<Operation>(lastArg->toInt32());
- QList<QQuickStackElement *> elements = d->parseElements(args);
+ QStringList errors;
+ QList<QQuickStackElement *> elements = d->parseElements(0, args, &errors);
// Remove any items that are already in the stack, as they can't be in two places at once.
for (int i = 0; i < elements.size(); ) {
QQuickStackElement *element = elements.at(i);
@@ -498,8 +501,13 @@ void QQuickStackView::push(QQmlV4Function *args)
++i;
}
- if (elements.isEmpty()) {
- qmlWarning(this) << "push: nothing to push";
+ if (!errors.isEmpty() || elements.isEmpty()) {
+ if (!errors.isEmpty()) {
+ for (const QString &error : qAsConst(errors))
+ d->warn(error);
+ } else {
+ d->warn(QStringLiteral("nothing to push"));
+ }
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -557,10 +565,11 @@ void QQuickStackView::push(QQmlV4Function *args)
void QQuickStackView::pop(QQmlV4Function *args)
{
Q_D(QQuickStackView);
+ QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("pop"));
int argc = args->length();
if (d->elements.count() <= 1 || argc > 2) {
if (argc > 2)
- qmlWarning(this) << "pop: too many arguments";
+ d->warn(QStringLiteral("too many arguments"));
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -580,7 +589,7 @@ void QQuickStackView::pop(QQmlV4Function *args)
enter = d->findElement(item);
if (!enter) {
if (item != d->currentItem)
- qmlWarning(this) << "pop: unknown argument: " << value->toQString(); // TODO: safe?
+ d->warn(QStringLiteral("unknown argument: ") + value->toQString()); // TODO: safe?
args->setReturnValue(QV4::Encode::null());
d->elements.push(exit); // restore
return;
@@ -708,8 +717,9 @@ void QQuickStackView::pop(QQmlV4Function *args)
void QQuickStackView::replace(QQmlV4Function *args)
{
Q_D(QQuickStackView);
+ QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("replace"));
if (args->length() <= 0) {
- qmlWarning(this) << "replace: missing arguments";
+ d->warn(QStringLiteral("missing arguments"));
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -729,9 +739,15 @@ void QQuickStackView::replace(QQmlV4Function *args)
else if (!firstArg->isInt32())
target = d->findElement(firstArg);
- QList<QQuickStackElement *> elements = d->parseElements(args, target ? 1 : 0);
- if (elements.isEmpty()) {
- qmlWarning(this) << "replace: nothing to push";
+ QStringList errors;
+ QList<QQuickStackElement *> elements = d->parseElements(target ? 1 : 0, args, &errors);
+ if (!errors.isEmpty() || elements.isEmpty()) {
+ if (!errors.isEmpty()) {
+ for (const QString &error : qAsConst(errors))
+ d->warn(error);
+ } else {
+ d->warn(QStringLiteral("nothing to push"));
+ }
args->setReturnValue(QV4::Encode::null());
return;
}
@@ -968,12 +984,16 @@ void QQuickStackView::componentComplete()
QQuickControl::componentComplete();
Q_D(QQuickStackView);
+ QScopedValueRollback<QString> rollback(d->operation, QStringLiteral("initialItem"));
QQuickStackElement *element = nullptr;
+ QString error;
if (QObject *o = d->initialItem.value<QObject *>())
- element = QQuickStackElement::fromObject(o, this);
+ element = QQuickStackElement::fromObject(o, this, &error);
else if (d->initialItem.canConvert<QString>())
- element = QQuickStackElement::fromString(d->initialItem.toString(), this);
- if (d->pushElement(element)) {
+ element = QQuickStackElement::fromString(d->initialItem.toString(), this, &error);
+ if (!error.isEmpty()) {
+ d->warn(error);
+ } else if (d->pushElement(element)) {
emit depthChanged();
d->setCurrentItem(element);
element->setStatus(QQuickStackView::Active);
diff --git a/src/quicktemplates2/qquickstackview_p.cpp b/src/quicktemplates2/qquickstackview_p.cpp
index 89b3c6e3..c6f9291d 100644
--- a/src/quicktemplates2/qquickstackview_p.cpp
+++ b/src/quicktemplates2/qquickstackview_p.cpp
@@ -38,6 +38,7 @@
#include "qquickstackelement_p_p.h"
#include "qquickstacktransition_p_p.h"
+#include <QtQml/qqmlinfo.h>
#include <QtQml/qqmllist.h>
#include <QtQml/private/qv4qmlcontext_p.h>
#include <QtQml/private/qv4qobjectwrapper_p.h>
@@ -53,6 +54,15 @@ QQuickStackViewPrivate::QQuickStackViewPrivate()
{
}
+void QQuickStackViewPrivate::warn(const QString &error)
+{
+ Q_Q(QQuickStackView);
+ if (operation.isEmpty())
+ qmlWarning(q) << error;
+ else
+ qmlWarning(q) << operation << ": " << error;
+}
+
void QQuickStackViewPrivate::setCurrentItem(QQuickStackElement *element)
{
Q_Q(QQuickStackView);
@@ -80,7 +90,7 @@ static bool initProperties(QQuickStackElement *element, const QV4::Value &props,
return false;
}
-QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function *args, int from)
+QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(int from, QQmlV4Function *args, QStringList *errors)
{
QV4::ExecutionEngine *v4 = args->v4engine();
QV4::Scope scope(v4);
@@ -93,8 +103,9 @@ QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function
if (QV4::ArrayObject *array = arg->as<QV4::ArrayObject>()) {
int len = array->getLength();
for (int j = 0; j < len; ++j) {
+ QString error;
QV4::ScopedValue value(scope, array->getIndexed(j));
- QQuickStackElement *element = createElement(value);
+ QQuickStackElement *element = createElement(value, &error);
if (element) {
if (j < len - 1) {
QV4::ScopedValue props(scope, array->getIndexed(j + 1));
@@ -102,10 +113,13 @@ QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function
++j;
}
elements += element;
+ } else if (!error.isEmpty()) {
+ *errors += error;
}
}
} else {
- QQuickStackElement *element = createElement(arg);
+ QString error;
+ QQuickStackElement *element = createElement(arg, &error);
if (element) {
if (i < argc - 1) {
QV4::ScopedValue props(scope, (*args)[i + 1]);
@@ -113,6 +127,8 @@ QList<QQuickStackElement *> QQuickStackViewPrivate::parseElements(QQmlV4Function
++i;
}
elements += element;
+ } else if (!error.isEmpty()) {
+ *errors += error;
}
}
}
@@ -137,13 +153,13 @@ QQuickStackElement *QQuickStackViewPrivate::findElement(const QV4::Value &value)
return nullptr;
}
-QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &value)
+QQuickStackElement *QQuickStackViewPrivate::createElement(const QV4::Value &value, QString *error)
{
Q_Q(QQuickStackView);
if (const QV4::String *s = value.as<QV4::String>())
- return QQuickStackElement::fromString(s->toQString(), q);
+ return QQuickStackElement::fromString(s->toQString(), q, error);
if (const QV4::QObjectWrapper *o = value.as<QV4::QObjectWrapper>())
- return QQuickStackElement::fromObject(o->object(), q);
+ return QQuickStackElement::fromObject(o->object(), q, error);
return nullptr;
}
diff --git a/src/quicktemplates2/qquickstackview_p_p.h b/src/quicktemplates2/qquickstackview_p_p.h
index ca610153..26d741f8 100644
--- a/src/quicktemplates2/qquickstackview_p_p.h
+++ b/src/quicktemplates2/qquickstackview_p_p.h
@@ -72,12 +72,14 @@ public:
return view->d_func();
}
+ void warn(const QString &error);
+
void setCurrentItem(QQuickStackElement *element);
- QList<QQuickStackElement *> parseElements(QQmlV4Function *args, int from = 0);
+ QList<QQuickStackElement *> parseElements(int from, QQmlV4Function *args, QStringList *errors);
QQuickStackElement *findElement(QQuickItem *item) const;
QQuickStackElement *findElement(const QV4::Value &value) const;
- QQuickStackElement *createElement(const QV4::Value &value);
+ QQuickStackElement *createElement(const QV4::Value &value, QString *error);
bool pushElements(const QList<QQuickStackElement *> &elements);
bool pushElement(QQuickStackElement *element);
bool popElements(QQuickStackElement *element);
@@ -91,6 +93,7 @@ public:
void setBusy(bool busy);
bool busy;
+ QString operation;
QVariant initialItem;
QQuickItem *currentItem;
QSet<QQuickStackElement*> removing;
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 7824708a..97a784b6 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -237,7 +237,7 @@ QQuickItem *QQuickSwipePrivate::createDelegateItem(QQmlComponent *component)
// the creation context will be null and we have to create it ourselves.
if (!creationContext)
creationContext = qmlContext(control);
- QQmlContext *context = new QQmlContext(creationContext);
+ QQmlContext *context = new QQmlContext(creationContext, control);
context->setContextObject(control);
QQuickItem *item = qobject_cast<QQuickItem*>(component->beginCreate(context));
if (item) {
diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp
index 631869ef..d278beb7 100644
--- a/src/quicktemplates2/qquickswipeview.cpp
+++ b/src/quicktemplates2/qquickswipeview.cpp
@@ -182,6 +182,7 @@ void QQuickSwipeView::setInteractive(bool interactive)
}
/*!
+ \since QtQuick.Controls 2.2
\qmlproperty enumeration QtQuick.Controls::SwipeView::orientation
This property holds the orientation.