aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2014-11-14 08:08:32 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-12-13 08:42:12 +0100
commit172cab1a74bc15f10dac5bda2d47a3523bcc237a (patch)
tree9bc36a73905fe0c89344af10dc5cc103a23fceff
parent450883d16b51b326e5d517de1517e14bf906df69 (diff)
Simplify QFont value type wrapper in preparation for gadgets
The value type wrapper for QFont tries to keep track whether pixel or point sizes were set and warns the programmer accordingly if both were set. This is implemented using separate boolean variables, but this can also be done using QFont's resolve mask. This move is motivated by the ability of the value type wrappers to operate only on the type they wrap in the future, without requiring additional helper variables. Change-Id: Ia05093b5dcc950281ef89b2bb6fe96c18329cdfa Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Michael Brasser <michael.brasser@live.com>
-rw-r--r--src/quick/util/qquickvaluetypes.cpp20
-rw-r--r--src/quick/util/qquickvaluetypes_p.h4
-rw-r--r--tests/auto/qml/qqmlvaluetypes/testtypes.h1
3 files changed, 3 insertions, 22 deletions
diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp
index 862e5cee55..37a5ba307f 100644
--- a/src/quick/util/qquickvaluetypes.cpp
+++ b/src/quick/util/qquickvaluetypes.cpp
@@ -599,18 +599,10 @@ bool QQuickMatrix4x4ValueType::isEqual(const QVariant &other) const
}
QQuickFontValueType::QQuickFontValueType(QObject *parent)
- : QQmlValueTypeBase<QFont>(QMetaType::QFont, parent),
- pixelSizeSet(false),
- pointSizeSet(false)
+ : QQmlValueTypeBase<QFont>(QMetaType::QFont, parent)
{
}
-void QQuickFontValueType::onLoad()
-{
- pixelSizeSet = false;
- pointSizeSet = false;
-}
-
QString QQuickFontValueType::toString() const
{
return QString(QLatin1String("QFont(%1)")).arg(v.toString());
@@ -698,16 +690,13 @@ qreal QQuickFontValueType::pointSize() const
void QQuickFontValueType::setPointSize(qreal size)
{
- if (pixelSizeSet) {
+ if ((v.resolve() & QFont::SizeResolved) && v.pixelSize() != -1) {
qWarning() << "Both point size and pixel size set. Using pixel size.";
return;
}
if (size >= 0.0) {
- pointSizeSet = true;
v.setPointSizeF(size);
- } else {
- pointSizeSet = false;
}
}
@@ -724,12 +713,9 @@ int QQuickFontValueType::pixelSize() const
void QQuickFontValueType::setPixelSize(int size)
{
if (size >0) {
- if (pointSizeSet)
+ if ((v.resolve() & QFont::SizeResolved) && v.pointSizeF() != -1)
qWarning() << "Both point size and pixel size set. Using pixel size.";
v.setPixelSize(size);
- pixelSizeSet = true;
- } else {
- pixelSizeSet = false;
}
}
diff --git a/src/quick/util/qquickvaluetypes_p.h b/src/quick/util/qquickvaluetypes_p.h
index d6546fba36..7c1cdd1148 100644
--- a/src/quick/util/qquickvaluetypes_p.h
+++ b/src/quick/util/qquickvaluetypes_p.h
@@ -345,11 +345,7 @@ public:
qreal wordSpacing() const;
void setWordSpacing(qreal spacing);
- void onLoad();
-
private:
- bool pixelSizeSet;
- bool pointSizeSet;
mutable QQmlNullableValue<int> dpi;
};
diff --git a/tests/auto/qml/qqmlvaluetypes/testtypes.h b/tests/auto/qml/qqmlvaluetypes/testtypes.h
index 559b14a015..715401e87d 100644
--- a/tests/auto/qml/qqmlvaluetypes/testtypes.h
+++ b/tests/auto/qml/qqmlvaluetypes/testtypes.h
@@ -100,7 +100,6 @@ public:
m_font.setUnderline(true);
m_font.setOverline(true);
m_font.setStrikeOut(true);
- m_font.setPointSize(29);
m_font.setCapitalization(QFont::AllLowercase);
m_font.setLetterSpacing(QFont::AbsoluteSpacing, 10.2);
m_font.setWordSpacing(19.7);