aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-01-16 10:21:58 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-01-21 07:27:30 +0100
commit15ea475b40f6ad28d46e5cbd65a1ccc8556a53df (patch)
tree8156cc4a122f06d49623352c2fc6fbaf4e02b402
parent9aceff567c859bb91fe7221d2265953437402b43 (diff)
Make FontLoader.name read-only
Being able to set the name of a FontLoader seems to have been made to allow for some alternative coding patterns, but it doesn't really provide any convenience over other ways of customizing font names, and it definitely adds confusion for users, as well as as a possible race condition if both the source and name of the same FontLoader is set at unpredictable times. [ChangeLog][QtQuick] FontLoader.name property has been made read-only to reduce confusion about its use and precedence over conflicting properties. Fixes: QTBUG-80031 Change-Id: I0dd0e76ff376402c0b458ed7e5c57ec017bbc92d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--examples/quick/text/doc/src/text.qdoc3
-rw-r--r--examples/quick/text/fonts/fonts.qml7
-rw-r--r--src/quick/util/qquickfontloader.cpp12
-rw-r--r--src/quick/util/qquickfontloader_p.h3
-rw-r--r--tests/auto/qmltest/fontloader/daniel.ttfbin0 -> 51984 bytes
-rw-r--r--tests/auto/qmltest/fontloader/tst_fontloader.qml9
-rw-r--r--tests/auto/quick/qquickfontloader/data/qtbug-20268.qml8
-rw-r--r--tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp24
8 files changed, 12 insertions, 54 deletions
diff --git a/examples/quick/text/doc/src/text.qdoc b/examples/quick/text/doc/src/text.qdoc
index d8bd8d349a..6378e3efe6 100644
--- a/examples/quick/text/doc/src/text.qdoc
+++ b/examples/quick/text/doc/src/text.qdoc
@@ -49,9 +49,6 @@
Simply by name, using the font.family property directly:
\snippet text/fonts/fonts.qml name
- or using a \l FontLoader type:
- \snippet text/fonts/fonts.qml fontloader
-
or using a FontLoader and specifying a local font file:
\snippet text/fonts/fonts.qml fontloaderlocal
diff --git a/examples/quick/text/fonts/fonts.qml b/examples/quick/text/fonts/fonts.qml
index d356e00417..f4e721b6c1 100644
--- a/examples/quick/text/fonts/fonts.qml
+++ b/examples/quick/text/fonts/fonts.qml
@@ -56,9 +56,6 @@ Rectangle {
width: 320; height: 480
color: "steelblue"
-//! [fontloader]
- FontLoader { id: fixedFont; name: "Courier" }
-//! [fontloader]
//! [fontloaderlocal]
FontLoader { id: localFont; source: "content/fonts/tarzeau_ocr_a.ttf" }
//! [fontloaderlocal]
@@ -94,14 +91,14 @@ Rectangle {
width: parent.width
horizontalAlignment: Text.AlignRight
wrapMode: Text.WordWrap
- font { family: fixedFont.name; pixelSize: 20; weight: Font.Bold; capitalization: Font.AllLowercase }
+ font { family: "Courier"; pixelSize: 20; weight: Font.Bold; capitalization: Font.AllLowercase }
}
Text {
text: myText
color: "lightsteelblue"
width: parent.width
wrapMode: Text.WordWrap
- font { family: fixedFont.name; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }
+ font { family: "Courier"; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }
}
Text {
text: myText
diff --git a/src/quick/util/qquickfontloader.cpp b/src/quick/util/qquickfontloader.cpp
index 505c70df7c..addf8b0c18 100644
--- a/src/quick/util/qquickfontloader.cpp
+++ b/src/quick/util/qquickfontloader.cpp
@@ -310,6 +310,7 @@ void QQuickFontLoader::updateFontInfo(const QString& name, QQuickFontLoader::Sta
/*!
\qmlproperty string QtQuick::FontLoader::name
+ \readonly
This property holds the name of the font family.
It is set automatically when a font is loaded using the \l source property.
@@ -338,17 +339,6 @@ QString QQuickFontLoader::name() const
return d->name;
}
-void QQuickFontLoader::setName(const QString &name)
-{
- Q_D(QQuickFontLoader);
- if (d->name == name)
- return;
- d->name = name;
- emit nameChanged();
- d->status = Ready;
- emit statusChanged();
-}
-
/*!
\qmlproperty enumeration QtQuick::FontLoader::status
diff --git a/src/quick/util/qquickfontloader_p.h b/src/quick/util/qquickfontloader_p.h
index e849c52a35..c0247cee3a 100644
--- a/src/quick/util/qquickfontloader_p.h
+++ b/src/quick/util/qquickfontloader_p.h
@@ -65,7 +65,7 @@ class Q_AUTOTEST_EXPORT QQuickFontLoader : public QObject
Q_DECLARE_PRIVATE(QQuickFontLoader)
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
QML_NAMED_ELEMENT(FontLoader)
@@ -80,7 +80,6 @@ public:
void setSource(const QUrl &url);
QString name() const;
- void setName(const QString &name);
Status status() const;
diff --git a/tests/auto/qmltest/fontloader/daniel.ttf b/tests/auto/qmltest/fontloader/daniel.ttf
new file mode 100644
index 0000000000..aae50d5035
--- /dev/null
+++ b/tests/auto/qmltest/fontloader/daniel.ttf
Binary files differ
diff --git a/tests/auto/qmltest/fontloader/tst_fontloader.qml b/tests/auto/qmltest/fontloader/tst_fontloader.qml
index 0d1831230e..48b92e02ba 100644
--- a/tests/auto/qmltest/fontloader/tst_fontloader.qml
+++ b/tests/auto/qmltest/fontloader/tst_fontloader.qml
@@ -81,10 +81,6 @@ Item {
fontloader.source = "dummy.ttf";
tryCompare(fontloader, 'status', FontLoader.Error)
compare(testinput.font.family, "")
- fontloader.source = "";
- fontloader.name = "Courier";
- tryCompare(fontloader, 'status', FontLoader.Ready)
- compare(testinput.font.family, "Courier")
}
function test_fontswitching() {
@@ -92,10 +88,9 @@ Item {
fontswitch.source = "tarzeau_ocr_a.ttf";
tryCompare(fontswitch, 'status', FontLoader.Ready)
compare(fontswitch.name, "OCRA")
- fontswitch.source = "";
- fontswitch.name = "Courier";
+ fontswitch.source = "daniel.ttf";
tryCompare(fontswitch, 'status', FontLoader.Ready)
- compare(fontswitch.name, "Courier")
+ compare(fontswitch.name, "Daniel")
fontswitch.source = "tarzeau_ocr_a.ttf";
tryCompare(fontswitch, 'status', FontLoader.Ready)
compare(fontswitch.name, "OCRA")
diff --git a/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml b/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml
index 0eafdfa17b..e9282bf2c7 100644
--- a/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml
+++ b/tests/auto/quick/qquickfontloader/data/qtbug-20268.qml
@@ -4,7 +4,7 @@ Rectangle {
id: test
property variant fontloader: fontloaderelement
height: 100; width: 100
- property bool usename: false
+ property bool useotherfont: false
property int statenum: 1
property alias name: fontloaderelement.name
property alias source: fontloaderelement.source
@@ -15,11 +15,11 @@ Rectangle {
}
states: [
- State { name: "start"; when: !usename
+ State { name: "start"; when: !useotherfont
PropertyChanges { target: fontloaderelement; source: "tarzeau_ocr_a.ttf" }
},
- State { name: "changefont"; when: usename
- PropertyChanges { target: fontloaderelement; name: "Tahoma" }
+ State { name: "changefont"; when: useotherfont
+ PropertyChanges { target: fontloaderelement; source: "daniel.ttf" }
}
]
diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp
index 87a5bd469a..8f6910bee4 100644
--- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp
+++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp
@@ -45,7 +45,6 @@ public:
private slots:
void initTestCase();
void noFont();
- void namedFont();
void localFont();
void failLocalFont();
void webFont();
@@ -85,19 +84,6 @@ void tst_qquickfontloader::noFont()
delete fontObject;
}
-void tst_qquickfontloader::namedFont()
-{
- QString componentStr = "import QtQuick 2.0\nFontLoader { name: \"Helvetica\" }";
- QQmlComponent component(&engine);
- component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
- QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create());
-
- QVERIFY(fontObject != nullptr);
- QCOMPARE(fontObject->source(), QUrl(""));
- QCOMPARE(fontObject->name(), QString("Helvetica"));
- QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready);
-}
-
void tst_qquickfontloader::localFont()
{
QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + testFileUrl("tarzeau_ocr_a.ttf").toString() + "\" }";
@@ -223,16 +209,10 @@ void tst_qquickfontloader::changeFontSourceViaState()
QVERIFY(fontObject->source() != QUrl(""));
QTRY_COMPARE(fontObject->name(), QString("OCRA"));
- window.rootObject()->setProperty("usename", true);
-
- // This warning should probably not be printed once QTBUG-20268 is fixed
- QString warning = QString(testFileUrl("qtbug-20268.qml").toString()) +
- QLatin1String(":13:5: QML FontLoader: Cannot load font: \"\"");
- QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+ window.rootObject()->setProperty("useotherfont", true);
- QEXPECT_FAIL("", "QTBUG-20268", Abort);
QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready);
- QCOMPARE(window.rootObject()->property("name").toString(), QString("Tahoma"));
+ QCOMPARE(window.rootObject()->property("name").toString(), QString("Daniel"));
}
QTEST_MAIN(tst_qquickfontloader)