summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-26 09:23:24 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-26 09:23:24 (GMT)
commit158596debe424d451cf85aa0cbd6c33d9fd5fe20 (patch)
tree14e0de4dfd9083ca44dff6310e35497fdd8acd92
parent272bc3c63ea31e4e5b3c9d8c06f123bc04d90d5a (diff)
parent206fc25d734f01d2812653d78eaa625cd20b34e3 (diff)
downloadQt-158596debe424d451cf85aa0cbd6c33d9fd5fe20.zip
Qt-158596debe424d451cf85aa0cbd6c33d9fd5fe20.tar.gz
Qt-158596debe424d451cf85aa0cbd6c33d9fd5fe20.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h76
-rw-r--r--tests/auto/qboxlayout/tst_qboxlayout.cpp79
-rw-r--r--tests/auto/qsharedpointer/tst_qsharedpointer.cpp13
3 files changed, 107 insertions, 61 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 0471a1b..2797622 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -87,9 +87,8 @@ namespace QtSharedPointer {
template <class T> class InternalRefCount;
template <class T> class ExternalRefCount;
- template <class X, class T> QSharedPointer<X> qStrongRefFromWeakHelper(const QWeakPointer<T> &, X*);
- template <class X, class T> QSharedPointer<X> qSharedPointerCastHelper(const QSharedPointer<T> &src, X *);
- template <class X, class T> QSharedPointer<X> qSharedPointerConstCastHelper(const QSharedPointer<T> &src, X *);
+ template <class X, class T> QSharedPointer<X> strongRefFromWeakHelper(const QWeakPointer<T> &, X*);
+ template <class X, class Y> QSharedPointer<X> copyAndSetPointer(X * ptr, const QSharedPointer<Y> &src);
// used in debug mode to verify the reuse of pointers
Q_CORE_EXPORT void internalSafetyCheckAdd(const volatile void *);
@@ -239,10 +238,8 @@ namespace QtSharedPointer {
#else
template <class X> friend class ExternalRefCount;
template <class X> friend class QWeakPointer;
- template <class X, class Y> friend QSharedPointer<X> qSharedPointerCastHelper(const QSharedPointer<Y> &src, X *);
- template <class X, class Y> friend QSharedPointer<X> qSharedPointerDynamicCastHelper(const QSharedPointer<Y> &src, X *);
- template <class X, class Y> friend QSharedPointer<X> qSharedPointerConstCastHelper(const QSharedPointer<Y> &src, X *);
- template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::qStrongRefFromWeakHelper(const QWeakPointer<Y> &src, X *);
+ template <class X, class Y> friend QSharedPointer<X> copyAndSetPointer(X * ptr, const QSharedPointer<Y> &src);
+ template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::strongRefFromWeakHelper(const QWeakPointer<Y> &src, X *);
#endif
inline void internalSet(Data *o, T *actual)
@@ -292,9 +289,9 @@ public:
}
inline QSharedPointer(const QWeakPointer<T> &other)
- { *this = QtSharedPointer::qStrongRefFromWeakHelper(other, static_cast<T*>(0)); }
+ { *this = QtSharedPointer::strongRefFromWeakHelper(other, static_cast<T*>(0)); }
inline QSharedPointer<T> &operator=(const QWeakPointer<T> &other)
- { *this = QtSharedPointer::qStrongRefFromWeakHelper(other, static_cast<T*>(0)); return *this; }
+ { *this = QtSharedPointer::strongRefFromWeakHelper(other, static_cast<T*>(0)); return *this; }
template <class X>
inline QSharedPointer(const QSharedPointer<X> &other) { *this = other; }
@@ -309,11 +306,11 @@ public:
template <class X>
inline QSharedPointer(const QWeakPointer<X> &other)
- { *this = QtSharedPointer::qStrongRefFromWeakHelper(other, static_cast<T *>(0)); }
+ { *this = QtSharedPointer::strongRefFromWeakHelper(other, static_cast<T *>(0)); }
template <class X>
inline QSharedPointer<T> &operator=(const QWeakPointer<X> &other)
- { *this = qStrongRefFromWeakHelper(other, static_cast<T *>(0)); return *this; }
+ { *this = strongRefFromWeakHelper(other, static_cast<T *>(0)); return *this; }
template <class X>
QSharedPointer<X> staticCast() const
@@ -417,7 +414,7 @@ private:
#if defined(Q_NO_TEMPLATE_FRIENDS)
public:
#else
- template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::qStrongRefFromWeakHelper(const QWeakPointer<Y> &src, X *);
+ template <class X, class Y> friend QSharedPointer<X> QtSharedPointer::strongRefFromWeakHelper(const QWeakPointer<Y> &src, X *);
#endif
inline void internalSet(Data *o, T *actual)
@@ -488,47 +485,14 @@ Q_INLINE_TEMPLATE QWeakPointer<T> QSharedPointer<T>::toWeakRef() const
namespace QtSharedPointer {
// helper functions:
template <class X, class T>
- Q_INLINE_TEMPLATE X *qVerifyStaticCast(T *src, X *)
- {
- return static_cast<X *>(src); // if you get an error in this line, the cast is invalid
- }
- template <class X, class T>
- Q_INLINE_TEMPLATE X *qVerifyDynamicCast(T *src, X *)
- {
- return dynamic_cast<X *>(src); // if you get an error in this line, the cast is invalid
- }
- template <class X, class T>
- Q_INLINE_TEMPLATE X *qVerifyConstCast(T *src, X *)
- {
- return const_cast<X *>(src); // if you get an error in this line, the cast is invalid
- }
-
- template <class X, class T>
- Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCastHelper(const QSharedPointer<T> &src, X *)
- {
- QSharedPointer<X> result;
- register T *ptr = src.data();
- result.internalSet(src.d, static_cast<X *>(ptr));
- return result;
- }
- template <class X, class T>
- Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCastHelper(const QSharedPointer<T> &src, X *)
- {
- QSharedPointer<X> result;
- register T *ptr = src.data();
- result.internalSet(src.d, dynamic_cast<X *>(ptr));
- return result;
- }
- template <class X, class T>
- Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerConstCastHelper(const QSharedPointer<T> &src, X *)
+ Q_INLINE_TEMPLATE QSharedPointer<X> copyAndSetPointer(X *ptr, const QSharedPointer<T> &src)
{
QSharedPointer<X> result;
- register T *ptr = src.data();
- result.internalSet(src.d, const_cast<X *>(ptr));
+ result.internalSet(src.d, ptr);
return result;
}
template <class X, class T>
- Q_INLINE_TEMPLATE QSharedPointer<X> qStrongRefFromWeakHelper
+ Q_INLINE_TEMPLATE QSharedPointer<X> strongRefFromWeakHelper
(const QT_PREPEND_NAMESPACE(QWeakPointer<T>) &src, X *)
{
QSharedPointer<X> result;
@@ -541,9 +505,8 @@ namespace QtSharedPointer {
template <class X, class T>
Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &src)
{
- X *x = 0;
- QtSharedPointer::qVerifyStaticCast(src.data(), x);
- return QtSharedPointer::qSharedPointerCastHelper(src, x);
+ register X *ptr = static_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid
+ return QtSharedPointer::copyAndSetPointer(ptr, src);
}
template <class X, class T>
Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &src)
@@ -554,8 +517,8 @@ Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerCast(const QWeakPointer<T> &sr
template <class X, class T>
Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src)
{
- X *x = 0;
- return QtSharedPointer::qSharedPointerDynamicCastHelper(src, x);
+ register X *ptr = dynamic_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid
+ return QtSharedPointer::copyAndSetPointer(ptr, src);
}
template <class X, class T>
Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer<T> &src)
@@ -566,14 +529,13 @@ Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QWeakPointer
template <class X, class T>
Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerConstCast(const QSharedPointer<T> &src)
{
- X *x = 0;
- return QtSharedPointer::qSharedPointerConstCastHelper(src, x);
+ register X *ptr = const_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid
+ return QtSharedPointer::copyAndSetPointer(ptr, src);
}
template <class X, class T>
Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerConstCast(const QWeakPointer<T> &src)
{
- X *x = 0;
- return QtSharedPointer::qSharedPointerConstCastHelper(src, x);
+ return qSharedPointerConstCast<X, T>(src.toStrongRef());
}
template <class X, class T>
diff --git a/tests/auto/qboxlayout/tst_qboxlayout.cpp b/tests/auto/qboxlayout/tst_qboxlayout.cpp
index f34fc00..be6f3dd 100644
--- a/tests/auto/qboxlayout/tst_qboxlayout.cpp
+++ b/tests/auto/qboxlayout/tst_qboxlayout.cpp
@@ -65,8 +65,53 @@ private slots:
void sizeHint();
void sizeConstraints();
void setGeometry();
+ void setStyleShouldChangeSpacing();
};
+class CustomLayoutStyle : public QWindowsStyle
+{
+ Q_OBJECT
+public:
+ CustomLayoutStyle() : QWindowsStyle()
+ {
+ hspacing = 5;
+ vspacing = 10;
+ }
+
+ virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
+ const QWidget * widget = 0 ) const;
+
+ int hspacing;
+ int vspacing;
+};
+
+int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/,
+ const QWidget * widget /*= 0*/ ) const
+{
+ switch (metric) {
+ case PM_LayoutLeftMargin:
+ return 0;
+ break;
+ case PM_LayoutTopMargin:
+ return 3;
+ break;
+ case PM_LayoutRightMargin:
+ return 6;
+ break;
+ case PM_LayoutBottomMargin:
+ return 9;
+ break;
+ case PM_LayoutHorizontalSpacing:
+ return hspacing;
+ case PM_LayoutVerticalSpacing:
+ return vspacing;
+ break;
+ default:
+ break;
+ }
+ return QWindowsStyle::pixelMetric(metric, option, widget);
+}
+
tst_QBoxLayout::tst_QBoxLayout()
{
@@ -163,12 +208,44 @@ void tst_QBoxLayout::setGeometry()
lay->addLayout(lay2);
w.setLayout(lay);
w.show();
-
+
QRect newGeom(0, 0, 70, 70);
lay2->setGeometry(newGeom);
QApplication::processEvents();
QVERIFY2(newGeom.contains(dial->geometry()), "dial->geometry() should be smaller and within newGeom");
}
+void tst_QBoxLayout::setStyleShouldChangeSpacing()
+{
+
+ QWidget *window = new QWidget;
+ QHBoxLayout *hbox = new QHBoxLayout(window);
+ QPushButton *pb1 = new QPushButton(tr("The spacing between this"));
+ QPushButton *pb2 = new QPushButton(tr("and this button should depend on the style of the parent widget"));;
+ hbox->addWidget(pb1);
+ hbox->addWidget(pb2);
+ CustomLayoutStyle *style1 = new CustomLayoutStyle;
+ style1->hspacing = 6;
+ window->setStyle(style1);
+ window->show();
+
+ QTest::qWait(100);
+ int spacing = pb2->geometry().left() - pb1->geometry().right() - 1;
+ QCOMPARE(spacing, 6);
+
+ CustomLayoutStyle *style2 = new CustomLayoutStyle();
+ style2->hspacing = 10;
+ window->setStyle(style2);
+ QTest::qWait(100);
+ spacing = pb2->geometry().left() - pb1->geometry().right() - 1;
+ QEXPECT_FAIL("", "Fix for next minor release", Continue);
+ QCOMPARE(spacing, 10);
+
+ delete window;
+ delete style1;
+ delete style2;
+}
+
+
QTEST_MAIN(tst_QBoxLayout)
#include "tst_qboxlayout.moc"
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
index a11164f..db93fc9 100644
--- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
@@ -908,7 +908,7 @@ void tst_QSharedPointer::invalidConstructs_data()
QTest::newRow("implicit-initialization3")
<< &QTest::QExternalTest::tryCompileFail
<< "QWeakPointer<Data> ptr = new Data;";
- QTest::newRow("implicit-initialization1")
+ QTest::newRow("implicit-initialization4")
<< &QTest::QExternalTest::tryCompileFail
<< "QWeakPointer<Data> ptr;"
"ptr = new Data;";
@@ -972,11 +972,13 @@ void tst_QSharedPointer::invalidConstructs_data()
<< &QTest::QExternalTest::tryCompileFail
<< "QSharedPointer<Data> ptr1;\n"
"QSharedPointer<int> ptr2 = qSharedPointerCast<int>(ptr1);";
+#ifndef QTEST_NO_RTTI
QTest::newRow("invalid-cast2")
<< &QTest::QExternalTest::tryCompileFail
<< "QSharedPointer<Data> ptr1;\n"
"QSharedPointer<int> ptr2 = qSharedPointerDynamicCast<int>(ptr1);";
- QTest::newRow("implicit-initialization1")
+#endif
+ QTest::newRow("invalid-cast3")
<< &QTest::QExternalTest::tryCompileFail
<< "QSharedPointer<Data> ptr1;\n"
"QSharedPointer<int> ptr2 = qSharedPointerConstCast<int>(ptr1);";
@@ -1024,7 +1026,12 @@ void tst_QSharedPointer::invalidConstructs()
QByteArray body = code.toLatin1();
- if (!(test.*testFunction)(body)) {
+ bool result = (test.*testFunction)(body);
+ if (qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) {
+ qDebug("External test output:");
+ printf("%s\n", test.standardError().constData());
+ }
+ if (!result) {
qWarning("External code testing failed\nCode:\n%s\n", body.constData());
QFAIL("Fail");
}