Merge remote-tracking branch 'origin/5.11' into dev

Change-Id: Ia2441257c23169f8ca6a3933b2371255e1ba64e6
This commit is contained in:
Qt Forward Merge Bot 2018-03-10 09:22:38 +01:00
commit ffdacff6b0
12 changed files with 100 additions and 16 deletions

View File

@ -1381,7 +1381,7 @@ namespace QtPrivate
};
template<typename T, typename Enable = void>
struct IsGadgetHelper { enum { Value = false }; };
struct IsGadgetHelper { enum { IsRealGadget = false, IsGadgetOrDerivedFrom = false }; };
template<typename T>
struct IsGadgetHelper<T, typename T::QtGadgetHelper>
@ -1389,11 +1389,14 @@ namespace QtPrivate
template <typename X>
static char checkType(void (X::*)());
static void *checkType(void (T::*)());
enum { Value = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *) };
enum {
IsRealGadget = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *),
IsGadgetOrDerivedFrom = true
};
};
template<typename T, typename Enable = void>
struct IsPointerToGadgetHelper { enum { Value = false }; };
struct IsPointerToGadgetHelper { enum { IsRealGadget = false, IsGadgetOrDerivedFrom = false }; };
template<typename T>
struct IsPointerToGadgetHelper<T*, typename T::QtGadgetHelper>
@ -1402,7 +1405,10 @@ namespace QtPrivate
template <typename X>
static char checkType(void (X::*)());
static void *checkType(void (T::*)());
enum { Value = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *) };
enum {
IsRealGadget = sizeof(checkType(&T::qt_check_for_QGADGET_macro)) == sizeof(void *),
IsGadgetOrDerivedFrom = true
};
};
@ -1435,12 +1441,12 @@ namespace QtPrivate
static inline const QMetaObject *value() { return &T::staticMetaObject; }
};
template<typename T>
struct MetaObjectForType<T, typename std::enable_if<IsGadgetHelper<T>::Value>::type>
struct MetaObjectForType<T, typename std::enable_if<IsGadgetHelper<T>::IsGadgetOrDerivedFrom>::type>
{
static inline const QMetaObject *value() { return &T::staticMetaObject; }
};
template<typename T>
struct MetaObjectForType<T, typename QEnableIf<IsPointerToGadgetHelper<T>::Value>::Type>
struct MetaObjectForType<T, typename std::enable_if<IsPointerToGadgetHelper<T>::IsGadgetOrDerivedFrom>::type>
{
static inline const QMetaObject *value() { return &IsPointerToGadgetHelper<T>::BaseType::staticMetaObject; }
};
@ -1599,8 +1605,8 @@ namespace QtPrivate
template <typename T, int =
QtPrivate::IsPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::PointerToQObject :
QtPrivate::IsGadgetHelper<T>::Value ? QMetaType::IsGadget :
QtPrivate::IsPointerToGadgetHelper<T>::Value ? QMetaType::PointerToGadget :
QtPrivate::IsGadgetHelper<T>::IsRealGadget ? QMetaType::IsGadget :
QtPrivate::IsPointerToGadgetHelper<T>::IsRealGadget ? QMetaType::PointerToGadget :
QtPrivate::IsQEnumHelper<T>::Value ? QMetaType::IsEnumeration : 0>
struct QMetaTypeIdQObject
{
@ -1653,8 +1659,8 @@ namespace QtPrivate {
| (IsWeakPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::WeakPointerToQObject : 0)
| (IsTrackingPointerToTypeDerivedFromQObject<T>::Value ? QMetaType::TrackingPointerToQObject : 0)
| (std::is_enum<T>::value ? QMetaType::IsEnumeration : 0)
| (IsGadgetHelper<T>::Value ? QMetaType::IsGadget : 0)
| (IsPointerToGadgetHelper<T>::Value ? QMetaType::PointerToGadget : 0)
| (IsGadgetHelper<T>::IsGadgetOrDerivedFrom ? QMetaType::IsGadget : 0)
| (IsPointerToGadgetHelper<T>::IsGadgetOrDerivedFrom ? QMetaType::PointerToGadget : 0)
};
};

View File

@ -250,9 +250,12 @@ QT_BEGIN_NAMESPACE
/*!
\fn template <typename T, typename Cleanup> void QScopedPointer<T, Cleanup>::reset(T *other = 0)
Deletes the existing object it is pointing to if any, and sets its pointer to
Deletes the existing object it is pointing to (if any), and sets its pointer to
\a other. QScopedPointer now owns \a other and will delete it in its
destructor.
To clear the pointer held without deleting the object it points to (and hence take ownership
of the object), use \l take() instead.
*/
/*!

View File

@ -956,7 +956,7 @@ void QXcbConnection::xi2UpdateScrollingDevice(ScrollingDevice &scrollingDevice)
return;
}
QPointF lastScrollPosition;
if (lcQpaXInput().isDebugEnabled())
if (lcQpaXInputEvents().isDebugEnabled())
lastScrollPosition = scrollingDevice.lastScrollPosition;
for (int c = 0; c < deviceInfo->num_classes; ++c) {
XIAnyClassInfo *classInfo = deviceInfo->classes[c];

View File

@ -2333,7 +2333,7 @@ void QXcbWindow::handleMotionNotifyEvent(const xcb_motion_notify_event_t *event)
#if QT_CONFIG(xinput2)
static inline int fixed1616ToInt(FP1616 val)
{
return int((qreal(val >> 16)) + (val & 0xFFFF) / (qreal)0xFFFF);
return int(qreal(val) / 0x10000);
}
void QXcbWindow::handleXIMouseEvent(xcb_ge_event_t *event, Qt::MouseEventSource source)

View File

@ -963,7 +963,9 @@ bool QLabel::event(QEvent *e)
if (type == QEvent::Shortcut) {
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
if (se->shortcutId() == d->shortcutId) {
QWidget * w = d->buddy;
QWidget *w = d->buddy;
if (!w)
return QFrame::event(e);
if (w->focusPolicy() != Qt::NoFocus)
w->setFocus(Qt::ShortcutFocusReason);
#if QT_CONFIG(abstractbutton)
@ -1162,7 +1164,15 @@ void QLabelPrivate::updateLabel()
void QLabel::setBuddy(QWidget *buddy)
{
Q_D(QLabel);
if (d->buddy)
disconnect(d->buddy, SIGNAL(destroyed()), this, SLOT(_q_buddyDeleted()));
d->buddy = buddy;
if (buddy)
connect(buddy, SIGNAL(destroyed()), this, SLOT(_q_buddyDeleted()));
if (d->isTextLabel) {
if (d->shortcutId)
releaseShortcut(d->shortcutId);
@ -1203,6 +1213,13 @@ void QLabelPrivate::updateShortcut()
shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
}
void QLabelPrivate::_q_buddyDeleted()
{
Q_Q(QLabel);
q->setBuddy(nullptr);
}
#endif // QT_NO_SHORTCUT
#if QT_CONFIG(movie)

View File

@ -158,6 +158,9 @@ private:
#endif
Q_PRIVATE_SLOT(d_func(), void _q_linkHovered(const QString &))
#ifndef QT_NO_SHORTCUT
Q_PRIVATE_SLOT(d_func(), void _q_buddyDeleted())
#endif
friend class QTipLabel;
friend class QMessageBoxPrivate;
friend class QBalloonTip;

View File

@ -89,6 +89,7 @@ public:
#endif
#ifndef QT_NO_SHORTCUT
void updateShortcut();
void _q_buddyDeleted();
#endif
inline bool needTextControl() const {
return isTextLabel

View File

@ -141,6 +141,14 @@ public:
class CustomNonQObject {};
class GadgetDerived : public CustomGadget {};
// cannot use Q_GADGET due to moc limitations but wants to behave like
// a Q_GADGET in Qml land
template<typename T>
class GadgetDerivedAndTyped : public CustomGadget {};
Q_DECLARE_METATYPE(GadgetDerivedAndTyped<int>)
Q_DECLARE_METATYPE(GadgetDerivedAndTyped<int>*)
void tst_QMetaType::defined()
{
QCOMPARE(int(QMetaTypeId2<QString>::Defined), 1);
@ -157,6 +165,10 @@ void tst_QMetaType::defined()
QVERIFY(!QMetaTypeId2<CustomNonQObject>::Defined);
QVERIFY(!QMetaTypeId2<CustomNonQObject*>::Defined);
QVERIFY(!QMetaTypeId2<CustomGadget_NonDefaultConstructible>::Defined);
// registered with Q_DECLARE_METATYPE
QVERIFY(QMetaTypeId2<GadgetDerivedAndTyped<int>>::Defined);
QVERIFY(QMetaTypeId2<GadgetDerivedAndTyped<int>*>::Defined);
}
struct Bar
@ -396,6 +408,10 @@ void tst_QMetaType::typeName_data()
QTest::newRow("CustomGadget*") << ::qMetaTypeId<CustomGadget*>() << QString::fromLatin1("CustomGadget*");
QTest::newRow("CustomQObject::CustomQEnum") << ::qMetaTypeId<CustomQObject::CustomQEnum>() << QString::fromLatin1("CustomQObject::CustomQEnum");
QTest::newRow("Qt::ArrowType") << ::qMetaTypeId<Qt::ArrowType>() << QString::fromLatin1("Qt::ArrowType");
// template instance class derived from Q_GADGET enabled class
QTest::newRow("GadgetDerivedAndTyped<int>") << ::qMetaTypeId<GadgetDerivedAndTyped<int>>() << QString::fromLatin1("GadgetDerivedAndTyped<int>");
QTest::newRow("GadgetDerivedAndTyped<int>*") << ::qMetaTypeId<GadgetDerivedAndTyped<int>*>() << QString::fromLatin1("GadgetDerivedAndTyped<int>*");
}
void tst_QMetaType::typeName()
@ -1703,6 +1719,9 @@ void tst_QMetaType::metaObject_data()
QTest::newRow("MyGadget*") << ::qMetaTypeId<MyGadget*>() << &MyGadget::staticMetaObject << false << true << false;
QTest::newRow("MyEnum") << ::qMetaTypeId<MyGadget::MyEnum>() << &MyGadget::staticMetaObject << false << false << false;
QTest::newRow("Qt::ScrollBarPolicy") << ::qMetaTypeId<Qt::ScrollBarPolicy>() << &QObject::staticQtMetaObject << false << false << false;
QTest::newRow("GadgetDerivedAndTyped<int>") << ::qMetaTypeId<GadgetDerivedAndTyped<int>>() << &GadgetDerivedAndTyped<int>::staticMetaObject << true << false << false;
QTest::newRow("GadgetDerivedAndTyped<int>*") << ::qMetaTypeId<GadgetDerivedAndTyped<int>*>() << &GadgetDerivedAndTyped<int>::staticMetaObject << false << true << false;
}

View File

@ -966,12 +966,14 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::liveCount, 4);
vec.append(std::move(m3));
QVERIFY(m3.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
QCOMPARE(MyBase::errorCount, 0);
QCOMPARE(MyBase::liveCount, 4);
QCOMPARE(MyBase::movedCount, 1);
vec.push_back(std::move(m4));
QVERIFY(m4.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
QVERIFY(vec.at(1).wasConstructedAt(&m4));
QCOMPARE(MyBase::errorCount, 0);
@ -979,6 +981,7 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::movedCount, 2);
vec.prepend(std::move(m1));
QVERIFY(m1.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m3));
QVERIFY(vec.at(2).wasConstructedAt(&m4));
@ -987,9 +990,11 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::movedCount, 3);
vec.insert(1, std::move(m2));
QVERIFY(m2.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m2));
QVERIFY(vec.at(2).wasConstructedAt(&m3));
QVERIFY(vec.at(3).wasConstructedAt(&m4));
QCOMPARE(MyBase::copyCount, 0);
QCOMPARE(MyBase::liveCount, 4);
@ -1014,15 +1019,19 @@ void tst_QVarLengthArray::nonCopyable()
int *const ptr4 = val4.get();
vec.append(std::move(val3));
QVERIFY(!val3);
QVERIFY(ptr3 == vec.at(0).get());
vec.append(std::move(val4));
QVERIFY(!val4);
QVERIFY(ptr3 == vec.at(0).get());
QVERIFY(ptr4 == vec.at(1).get());
vec.prepend(std::move(val1));
QVERIFY(!val1);
QVERIFY(ptr1 == vec.at(0).get());
QVERIFY(ptr3 == vec.at(1).get());
QVERIFY(ptr4 == vec.at(2).get());
vec.insert(1, std::move(val2));
QVERIFY(!val2);
QVERIFY(ptr1 == vec.at(0).get());
QVERIFY(ptr2 == vec.at(1).get());
QVERIFY(ptr3 == vec.at(2).get());

View File

@ -2895,26 +2895,40 @@ void tst_QVector::insertMove() const
const int instancesCount = Movable::counter.loadAcquire();
{
QVector<Movable> vec;
vec.reserve(5);
Movable m0;
Movable m1;
Movable m2;
Movable m3;
Movable m4;
vec.append(std::move(m3));
QVERIFY(m3.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
vec.push_back(std::move(m4));
QVERIFY(m4.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
QVERIFY(vec.at(1).wasConstructedAt(&m4));
vec.prepend(std::move(m1));
QVERIFY(m1.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m3));
QVERIFY(vec.at(2).wasConstructedAt(&m4));
vec.insert(1, std::move(m2));
QVERIFY(m2.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m2));
QVERIFY(vec.at(2).wasConstructedAt(&m3));
QVERIFY(vec.at(3).wasConstructedAt(&m4));
vec.push_front(std::move(m0));
QVERIFY(m0.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m0));
QVERIFY(vec.at(1).wasConstructedAt(&m1));
QVERIFY(vec.at(2).wasConstructedAt(&m2));
QVERIFY(vec.at(3).wasConstructedAt(&m3));
QVERIFY(vec.at(4).wasConstructedAt(&m4));
QCOMPARE(Movable::counter.loadAcquire(), instancesCount + 8);
QCOMPARE(Movable::counter.loadAcquire(), instancesCount + 10);
}
QCOMPARE(Movable::counter.loadAcquire(), instancesCount);
}

View File

@ -693,7 +693,7 @@ QT_WARNING_DISABLE_GCC("-Wunused-local-typedefs")
[[noreturn]] void attribute_f1();
void attribute_f2 [[noreturn]] ();
# if (defined(__cpp_namespace_attributes) && __cpp_namespace_attributes >= 201411) && __has_cpp_attribute(deprecated)
namespace NS [[deprecated]] { }
namespace [[deprecated]] NS { }
# endif
#endif

View File

@ -178,9 +178,11 @@ void tst_QLabel::setBuddy()
test_label= new QLabel( test_box );
test_label->setText( "&Test with a buddy" );
QWidget *test_edit = new QLineEdit( test_box );
QWidget *test_edit2 = new QLineEdit( test_box );
QVBoxLayout *layout = new QVBoxLayout(test_box);
layout->addWidget(test_label);
layout->addWidget(test_edit);
layout->addWidget(test_edit2);
test_box->show();
qApp->setActiveWindow(test_box);
QVERIFY(test_box->isActiveWindow());
@ -190,6 +192,16 @@ void tst_QLabel::setBuddy()
QVERIFY( !test_edit->hasFocus() );
QTest::keyClick( test_box, 't', Qt::AltModifier );
QVERIFY( test_edit->hasFocus() );
// Setting a new buddy should disconnect the old one's destroyed() signal
test_label->setBuddy(test_edit2);
delete test_edit;
QCOMPARE(test_label->buddy(), test_edit2);
// And deleting our own buddy should disconnect and not crash
delete test_edit2;
QTest::keyClick(test_box, 't', Qt::AltModifier );
delete test_box;
}
#endif