Remove QVariant constructor taking Qt::GlobalColor.
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>
Fri, 13 Apr 2012 12:52:34 +0000 (14:52 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 19 Apr 2012 08:09:39 +0000 (10:09 +0200)
The constructor is wrong, it creates instance of QVariant encapsulating
a QColor instance. QVariant should not implicitly convert data, never.

Change-Id: Idc794ecdecb42d8b53fee3f993bf51ddd43f595d
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
dist/changes-5.0.0
src/corelib/kernel/qvariant.cpp
src/corelib/kernel/qvariant.h
src/gui/kernel/qguivariant.cpp
tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp
tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp

index d3ea3fb..9cef238 100644 (file)
@@ -68,6 +68,12 @@ information about a particular change.
     method returns void is to compare the return value of QMetaMethod::returnType()
     to QMetaType::Void.
 
+- QVariant:
+  * Inconsistent constructor taking Qt::GlobalColor and producing QVariant(QColor)
+    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))"
+
 - QTestLib:
   * The plain-text, xml and lightxml test output formats have been changed to
     show a test result for every row of test data in data-driven tests.  In
index 179a33c..10b86bc 100644 (file)
@@ -1349,19 +1349,6 @@ QVariant::QVariant(const char *val)
   Constructs a new variant with the regular expression value \a re.
 */
 
-/*! \since 4.2
-  \fn QVariant::QVariant(Qt::GlobalColor color)
-
-  Constructs a new variant of type QVariant::Color and initializes
-  it with \a color.
-
-  This is a convenience constructor that allows \c{QVariant(Qt::blue);}
-  to create a valid QVariant storing a QColor.
-
-  Note: This constructor will assert if the application does not link
-  to the Qt GUI library.
- */
-
 QVariant::QVariant(Type type)
 { create(type, 0); }
 QVariant::QVariant(int typeId, const void *copy)
@@ -1443,7 +1430,6 @@ QVariant::QVariant(const QRegExp &regExp) { d.is_null = false; d.type = RegExp;
 QVariant::QVariant(const QRegularExpression &re) { d.is_null = false; d.type = QMetaType::QRegularExpression; v_construct<QRegularExpression>(&d, re); }
 #endif // QT_BOOTSTRAPPED
 #endif // QT_NO_REGEXP
-QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); }
 
 /*!
     Returns the storage type of the value stored in the variant.
index fb0e059..cd8ac98 100644 (file)
@@ -248,7 +248,6 @@ class Q_CORE_EXPORT QVariant
     QVariant(const QUrl &url);
     QVariant(const QEasingCurve &easing);
 #endif
-    QVariant(Qt::GlobalColor color);
 
     QVariant& operator=(const QVariant &other);
 #ifdef Q_COMPILER_RVALUE_REFS
index 44dc2d2..9d1294d 100644 (file)
@@ -108,15 +108,6 @@ struct GuiTypesFilter {
 static void construct(QVariant::Private *x, const void *copy)
 {
     const int type = x->type;
-    if (Q_UNLIKELY(type == 62)) {
-        // small 'trick' to let a QVariant(Qt::blue) create a variant
-        // of type QColor
-        // TODO Get rid of this hack.
-        x->type = QVariant::Color;
-        QColor color(*reinterpret_cast<const Qt::GlobalColor *>(copy));
-        v_construct<QColor>(x, &color);
-        return;
-    }
     QVariantConstructor<GuiTypesFilter> constructor(x, copy);
     QMetaTypeSwitcher::switcher<void>(constructor, type, 0);
 }
index f9a6bae..dc9fc19 100644 (file)
@@ -97,7 +97,7 @@ void tst_QMimeData::colorData() const
     QCOMPARE(qvariant_cast<QColor>(mimeData.colorData()), red);
 
     // change, verify
-    mimeData.setColorData(Qt::blue);
+    mimeData.setColorData(QColor(Qt::blue));
     QVERIFY(mimeData.hasColor());
     QCOMPARE(qvariant_cast<QColor>(mimeData.colorData()), blue);
 }
index 6a6460d..7d821f0 100644 (file)
@@ -235,8 +235,6 @@ private slots:
 
     void saveLoadCustomTypes();
 
-    void globalColor();
-
     void variantMap();
     void variantHash();
 
@@ -2447,13 +2445,6 @@ void tst_QVariant::url()
     QCOMPARE(v3.toString(), str);
 }
 
-void tst_QVariant::globalColor()
-{
-    QVariant variant(Qt::blue);
-    QVERIFY(variant.type() == QVariant::Color);
-    QVERIFY(qVariantValue<QColor>(variant) == QColor(Qt::blue));
-}
-
 void tst_QVariant::variantMap()
 {
     QMap<QString, QVariant> map;