summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-09-28 17:22:21 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-10 08:45:22 +0200
commit43325a23f35bce7eddfb2e74d2a65d381b1c6aa0 (patch)
tree6e8916c1cc062b54f7883679e03ab6fd52648ea5
parent05541111ae1cf46ef934a287e89cebe08f175b99 (diff)
Delete the QVariant ctors taking global Qt enum values.
They have unexpected results in Qt 5 (the Qt::GlobalColor one works as expected in Qt 4, but was removed in Qt 5): QVariant v = QVariant(Qt::red); qDebug() << v; // QVariant(int, 7) v = Qt::red; qDebug() << v; // QVariant(int, 7) The correct way is to use: QVariant v = QVariant::fromValue(QColor(Qt::red)); The deleted constructors are the ones for which there is a class with an implicit constructor taking the enum, and that class is a built-in metatype. QLocale::Language and QKeySequence::StandardKey would also fit the description, but I can't include the header for QKeySequence as it is in QtGui, and I don't want to include the qlocale header in qvariant.h. Putting a QLocale::Language is probably very uncommon anyway. The QTextFormat test is doing the wrong thing, but the result isn't being tested. Added new tests which fail before the patch. Change-Id: Ia38a0784990f4d40ff7457a86daf58aabd4964eb Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r--dist/changes-5.0.04
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp12
-rw-r--r--examples/widgets/painting/basicdrawing/window.cpp50
-rw-r--r--src/corelib/kernel/qvariant.h10
-rw-r--r--tests/auto/gui/text/qtextformat/tst_qtextformat.cpp4
5 files changed, 48 insertions, 32 deletions
diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0
index c6c7f9292d..a56325d40a 100644
--- a/dist/changes-5.0.0
+++ b/dist/changes-5.0.0
@@ -92,6 +92,10 @@ information about a particular change.
instance was removed. Code constructing such variants can be migrated by
explicitly calling QColor constructor. For example from "QVariant(Qt::red)"
to "QVariant(QColor(Qt::red))"
+ * Similarly, implicit creation of QVariants from enum values Qt::BrushStyle,
+ Qt::PenStyle, and Qt::CursorShape have been removed. Create objects explicitly
+ or use static_cast<int>(Qt::SolidLine) to create a QVariant of type int with
+ the same value as the enum.
- QTestLib:
* The plain-text, xml and lightxml test output formats have been changed to
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
index d09d110118..09dec07dfe 100644
--- a/examples/widgets/animation/stickman/lifecycle.cpp
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -114,9 +114,9 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Make it blink when lightning strikes before entering dead animation
QState *lightningBlink = new QState(m_machine);
- lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white);
- lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black);
- lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white);
+ lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", QColor(Qt::white));
+ lightningBlink->assignProperty(m_stickMan, "penColor", QColor(Qt::black));
+ lightningBlink->assignProperty(m_stickMan, "fillColor", QColor(Qt::white));
lightningBlink->assignProperty(m_stickMan, "isDead", true);
//! [5]
@@ -128,9 +128,9 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
//! [5]
m_dead = new QState(m_machine);
- m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black);
- m_dead->assignProperty(m_stickMan, "penColor", Qt::white);
- m_dead->assignProperty(m_stickMan, "fillColor", Qt::black);
+ m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", QColor(Qt::black));
+ m_dead->assignProperty(m_stickMan, "penColor", QColor(Qt::white));
+ m_dead->assignProperty(m_stickMan, "fillColor", QColor(Qt::black));
m_dead->setObjectName("dead");
// Idle state (sets no properties)
diff --git a/examples/widgets/painting/basicdrawing/window.cpp b/examples/widgets/painting/basicdrawing/window.cpp
index 9136c36f93..bf01e57b7f 100644
--- a/examples/widgets/painting/basicdrawing/window.cpp
+++ b/examples/widgets/painting/basicdrawing/window.cpp
@@ -82,12 +82,12 @@ Window::Window()
//! [3]
penStyleComboBox = new QComboBox;
- penStyleComboBox->addItem(tr("Solid"), Qt::SolidLine);
- penStyleComboBox->addItem(tr("Dash"), Qt::DashLine);
- penStyleComboBox->addItem(tr("Dot"), Qt::DotLine);
- penStyleComboBox->addItem(tr("Dash Dot"), Qt::DashDotLine);
- penStyleComboBox->addItem(tr("Dash Dot Dot"), Qt::DashDotDotLine);
- penStyleComboBox->addItem(tr("None"), Qt::NoPen);
+ penStyleComboBox->addItem(tr("Solid"), static_cast<int>(Qt::SolidLine));
+ penStyleComboBox->addItem(tr("Dash"), static_cast<int>(Qt::DashLine));
+ penStyleComboBox->addItem(tr("Dot"), static_cast<int>(Qt::DotLine));
+ penStyleComboBox->addItem(tr("Dash Dot"), static_cast<int>(Qt::DashDotLine));
+ penStyleComboBox->addItem(tr("Dash Dot Dot"), static_cast<int>(Qt::DashDotDotLine));
+ penStyleComboBox->addItem(tr("None"), static_cast<int>(Qt::NoPen));
penStyleLabel = new QLabel(tr("&Pen Style:"));
penStyleLabel->setBuddy(penStyleComboBox);
@@ -112,27 +112,27 @@ Window::Window()
//! [4]
brushStyleComboBox = new QComboBox;
brushStyleComboBox->addItem(tr("Linear Gradient"),
- Qt::LinearGradientPattern);
+ static_cast<int>(Qt::LinearGradientPattern));
brushStyleComboBox->addItem(tr("Radial Gradient"),
- Qt::RadialGradientPattern);
+ static_cast<int>(Qt::RadialGradientPattern));
brushStyleComboBox->addItem(tr("Conical Gradient"),
- Qt::ConicalGradientPattern);
- brushStyleComboBox->addItem(tr("Texture"), Qt::TexturePattern);
- brushStyleComboBox->addItem(tr("Solid"), Qt::SolidPattern);
- brushStyleComboBox->addItem(tr("Horizontal"), Qt::HorPattern);
- brushStyleComboBox->addItem(tr("Vertical"), Qt::VerPattern);
- brushStyleComboBox->addItem(tr("Cross"), Qt::CrossPattern);
- brushStyleComboBox->addItem(tr("Backward Diagonal"), Qt::BDiagPattern);
- brushStyleComboBox->addItem(tr("Forward Diagonal"), Qt::FDiagPattern);
- brushStyleComboBox->addItem(tr("Diagonal Cross"), Qt::DiagCrossPattern);
- brushStyleComboBox->addItem(tr("Dense 1"), Qt::Dense1Pattern);
- brushStyleComboBox->addItem(tr("Dense 2"), Qt::Dense2Pattern);
- brushStyleComboBox->addItem(tr("Dense 3"), Qt::Dense3Pattern);
- brushStyleComboBox->addItem(tr("Dense 4"), Qt::Dense4Pattern);
- brushStyleComboBox->addItem(tr("Dense 5"), Qt::Dense5Pattern);
- brushStyleComboBox->addItem(tr("Dense 6"), Qt::Dense6Pattern);
- brushStyleComboBox->addItem(tr("Dense 7"), Qt::Dense7Pattern);
- brushStyleComboBox->addItem(tr("None"), Qt::NoBrush);
+ static_cast<int>(Qt::ConicalGradientPattern));
+ brushStyleComboBox->addItem(tr("Texture"), static_cast<int>(Qt::TexturePattern));
+ brushStyleComboBox->addItem(tr("Solid"), static_cast<int>(Qt::SolidPattern));
+ brushStyleComboBox->addItem(tr("Horizontal"), static_cast<int>(Qt::HorPattern));
+ brushStyleComboBox->addItem(tr("Vertical"), static_cast<int>(Qt::VerPattern));
+ brushStyleComboBox->addItem(tr("Cross"), static_cast<int>(Qt::CrossPattern));
+ brushStyleComboBox->addItem(tr("Backward Diagonal"), static_cast<int>(Qt::BDiagPattern));
+ brushStyleComboBox->addItem(tr("Forward Diagonal"), static_cast<int>(Qt::FDiagPattern));
+ brushStyleComboBox->addItem(tr("Diagonal Cross"), static_cast<int>(Qt::DiagCrossPattern));
+ brushStyleComboBox->addItem(tr("Dense 1"), static_cast<int>(Qt::Dense1Pattern));
+ brushStyleComboBox->addItem(tr("Dense 2"), static_cast<int>(Qt::Dense2Pattern));
+ brushStyleComboBox->addItem(tr("Dense 3"), static_cast<int>(Qt::Dense3Pattern));
+ brushStyleComboBox->addItem(tr("Dense 4"), static_cast<int>(Qt::Dense4Pattern));
+ brushStyleComboBox->addItem(tr("Dense 5"), static_cast<int>(Qt::Dense5Pattern));
+ brushStyleComboBox->addItem(tr("Dense 6"), static_cast<int>(Qt::Dense6Pattern));
+ brushStyleComboBox->addItem(tr("Dense 7"), static_cast<int>(Qt::Dense7Pattern));
+ brushStyleComboBox->addItem(tr("None"), static_cast<int>(Qt::NoBrush));
brushStyleLabel = new QLabel(tr("&Brush:"));
brushStyleLabel->setBuddy(brushStyleComboBox);
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 9e6de43823..86b43cf69a 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -461,6 +461,16 @@ private:
// want QVariant(QMetaType::String) to compile and falsely be an
// int variant, so delete this constructor:
QVariant(QMetaType::Type) Q_DECL_EQ_DELETE;
+
+ // These constructors don't create QVariants of the type associcated
+ // with the enum, as expected, but they would create a QVariant of
+ // type int with the value of the enum value.
+ // Use QVariant v = QColor(Qt::red) instead of QVariant v = Qt::red for
+ // example.
+ QVariant(Qt::GlobalColor) Q_DECL_EQ_DELETE;
+ QVariant(Qt::BrushStyle) Q_DECL_EQ_DELETE;
+ QVariant(Qt::PenStyle) Q_DECL_EQ_DELETE;
+ QVariant(Qt::CursorShape) Q_DECL_EQ_DELETE;
#ifdef QT_NO_CAST_FROM_ASCII
// force compile error when implicit conversion is not wanted
inline QVariant(const char *) Q_DECL_EQ_DELETE;
diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
index 5cf2efab1a..04d6694256 100644
--- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
+++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
@@ -203,7 +203,9 @@ void tst_QTextFormat::resolveFont()
QTextDocument doc;
QTextCharFormat fmt;
- fmt.setProperty(QTextFormat::ForegroundBrush, Qt::blue);
+ fmt.setProperty(QTextFormat::ForegroundBrush, QColor(Qt::blue));
+ QCOMPARE(fmt.property(QTextFormat::ForegroundBrush).userType(), qMetaTypeId<QColor>());
+ QCOMPARE(fmt.property(QTextFormat::ForegroundBrush).value<QColor>(), QColor(Qt::blue));
fmt.setProperty(QTextFormat::FontItalic, true);
QTextCursor(&doc).insertText("Test", fmt);