From 0e888ae1a10750c7f5e644da8f774376f0c8da6a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 7 Oct 2016 10:49:18 +0200 Subject: [PATCH 01/21] tst_QGraphicsItem: plug remaining leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store QGraphicsItems that are either not added to a scene or removed from it again and that are also not children of other items - iow: those that were leaked, even on successful runs of the tests, in either a QScopedPointer, or, where that'd cause too much churn due to adding of .data() calls, back the pointer by a stack-allocated object. This fixes the remaining leaks reported by GCC 6.2.1's ASan on successful runs of tests/auto/widgets/graphicsview/qgraphicsitem. Change-Id: I61c3a1cd39b9e96e83c5d7b8cf392e0b26ecbaf0 Reviewed-by: Edward Welbourne Reviewed-by: Sérgio Martins --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 8ee9ffe2947..4a5a66dd052 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -848,14 +848,14 @@ void tst_QGraphicsItem::parentItem() void tst_QGraphicsItem::setParentItem() { QGraphicsScene scene; - QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10)); + const QScopedPointer item(scene.addRect(QRectF(0, 0, 10, 10))); QCOMPARE(item->scene(), &scene); - QGraphicsRectItem *child = new QGraphicsRectItem; + const QScopedPointer child(new QGraphicsRectItem); QCOMPARE(child->scene(), (QGraphicsScene *)0); // This implicitly adds the item to the parent's scene - child->setParentItem(item); + child->setParentItem(item.data()); QCOMPARE(child->scene(), &scene); // This just makes it a toplevel @@ -863,8 +863,8 @@ void tst_QGraphicsItem::setParentItem() QCOMPARE(child->scene(), &scene); // Add the child back to the parent, then remove the parent from the scene - child->setParentItem(item); - scene.removeItem(item); + child->setParentItem(item.data()); + scene.removeItem(item.data()); QCOMPARE(child->scene(), (QGraphicsScene *)0); } @@ -962,19 +962,19 @@ void tst_QGraphicsItem::flags() QCOMPARE(item->pos(), QPointF(10, 10)); } { - QGraphicsItem* clippingParent = new QGraphicsRectItem; + const QScopedPointer clippingParent(new QGraphicsRectItem); clippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); - QGraphicsItem* nonClippingParent = new QGraphicsRectItem; + const QScopedPointer nonClippingParent(new QGraphicsRectItem); nonClippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); - QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent); + QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent.data()); QVERIFY(!child->isClipped()); - child->setParentItem(clippingParent); + child->setParentItem(clippingParent.data()); QVERIFY(child->isClipped()); - child->setParentItem(nonClippingParent); + child->setParentItem(nonClippingParent.data()); QVERIFY(!child->isClipped()); } } @@ -3133,7 +3133,8 @@ void tst_QGraphicsItem::isAncestorOf() void tst_QGraphicsItem::commonAncestorItem() { - QGraphicsItem *ancestor = new QGraphicsRectItem; + QGraphicsRectItem ancestorItem; + QGraphicsItem *ancestor = &ancestorItem; QGraphicsItem *grandMa = new QGraphicsRectItem; QGraphicsItem *grandPa = new QGraphicsRectItem; QGraphicsItem *brotherInLaw = new QGraphicsRectItem; @@ -3633,7 +3634,7 @@ void tst_QGraphicsItem::setGroup() QGraphicsItemGroup group1; QGraphicsItemGroup group2; - QGraphicsRectItem *rect = new QGraphicsRectItem; + const QScopedPointer rect(new QGraphicsRectItem); QCOMPARE(rect->group(), (QGraphicsItemGroup *)0); QCOMPARE(rect->parentItem(), (QGraphicsItem *)0); rect->setGroup(&group1); @@ -6831,8 +6832,8 @@ void tst_QGraphicsItem::opacity() QFETCH(qreal, c2_effectiveOpacity); QFETCH(qreal, c3_effectiveOpacity); - QGraphicsRectItem *p = new QGraphicsRectItem; - QGraphicsRectItem *c1 = new QGraphicsRectItem(p); + const QScopedPointer p(new QGraphicsRectItem); + QGraphicsRectItem *c1 = new QGraphicsRectItem(p.data()); QGraphicsRectItem *c2 = new QGraphicsRectItem(c1); QGraphicsRectItem *c3 = new QGraphicsRectItem(c2); @@ -7219,11 +7220,12 @@ void tst_QGraphicsItem::sceneTransformCache() // Test that an item's scene transform is updated correctly when the // parent is transformed. QGraphicsScene scene; - QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); + + const QScopedPointer rect(scene.addRect(0, 0, 100, 100)); rect->setPen(QPen(Qt::black, 0)); QGraphicsRectItem *rect2 = scene.addRect(0, 0, 100, 100); rect2->setPen(QPen(Qt::black, 0)); - rect2->setParentItem(rect); + rect2->setParentItem(rect.data()); rect2->rotate(90); rect->translate(0, 50); QGraphicsView view(&scene); @@ -7235,7 +7237,7 @@ void tst_QGraphicsItem::sceneTransformCache() x.rotate(90); QCOMPARE(rect2->sceneTransform(), x); - scene.removeItem(rect); + scene.removeItem(rect.data()); //Crazy use case : rect4 child of rect3 so the transformation of rect4 will be cached.Good! //We remove rect4 from the scene, then the validTransform bit flag is set to 0 and the index of the cache @@ -10688,7 +10690,7 @@ void tst_QGraphicsItem::scenePosChange() { ScenePosChangeTester* root = new ScenePosChangeTester; ScenePosChangeTester* child1 = new ScenePosChangeTester(root); - ScenePosChangeTester* grandChild1 = new ScenePosChangeTester(child1); + const QScopedPointer grandChild1(new ScenePosChangeTester(child1)); ScenePosChangeTester* child2 = new ScenePosChangeTester(root); ScenePosChangeTester* grandChild2 = new ScenePosChangeTester(child2); @@ -10740,7 +10742,7 @@ void tst_QGraphicsItem::scenePosChange() QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 3); // remove - scene.removeItem(grandChild1); + scene.removeItem(grandChild1.data()); delete grandChild2; grandChild2 = 0; QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants() root->moveBy(1.0, 1.0); From 84dc7d5f5560d69a0d7973f591ce253605a458ac Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 10 Oct 2016 21:53:09 +0200 Subject: [PATCH 02/21] QComboBox: fix build with GCC 7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 7 warns about implicit fall-throughs now. Fix by adding the missing comments. Interestingly, Coverity only found one of them, even though all three still exist in dev, too. Change-Id: I9f2c5e2700d5ec5234fee3a532feffe01b7c4ce3 Coverity-Id: 11156 Reviewed-by: Edward Welbourne Reviewed-by: Sérgio Martins --- src/widgets/widgets/qcombobox.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 0ef76b95f00..22ba26b6a3a 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -3125,6 +3125,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) case Qt::Key_Up: if (e->modifiers() & Qt::ControlModifier) break; // pass to line edit for auto completion + // fall through case Qt::Key_PageUp: #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) @@ -3210,6 +3211,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) switch (move) { case MoveFirst: newIndex = -1; + // fall through case MoveDown: newIndex++; while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled)) @@ -3217,6 +3219,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) break; case MoveLast: newIndex = count(); + // fall through case MoveUp: newIndex--; while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled)) From e70e168abb4b75dc8d00e2cba12efa1a111d429d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 29 Sep 2016 09:06:12 +0200 Subject: [PATCH 03/21] Plug leaks in tst_QWizard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This completely over-engineered piece of code has a hierarchy of Operation subclasses encapsulating but three actual operations on a QWizard. Because these operations and their containers were all allocated on the heap, but never deleted, asan went crazy and reported over 50 leaks (not the record so far, but a (distant) second). Since these collections are passed through addColumn/QFETCH, too, it's nearly impossible to track their lifetimes. So instead of trying, delegate that to the runtime, ie. pack the Operation objects into QSharedPointer and pass around those instead. Change-Id: I8a0fe7a60cd30aed618667affaa030e80cf2b1ac Reviewed-by: Edward Welbourne Reviewed-by: Sérgio Martins --- .../widgets/dialogs/qwizard/tst_qwizard.cpp | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index b2bdbac79a3..5789f0ca42e 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -1626,28 +1626,44 @@ class SetPage : public Operation wizard->next(); } QString describe() const { return QString("set page %1").arg(page); } - const int page; + int page; public: - SetPage(int page) : page(page) {} + static QSharedPointer create(int page) + { + QSharedPointer o = QSharedPointer::create(); + o->page = page; + return o; + } }; class SetStyle : public Operation { void apply(QWizard *wizard) const { wizard->setWizardStyle(style); } QString describe() const { return QString("set style %1").arg(style); } - const QWizard::WizardStyle style; + QWizard::WizardStyle style; public: - SetStyle(QWizard::WizardStyle style) : style(style) {} + static QSharedPointer create(QWizard::WizardStyle style) + { + QSharedPointer o = QSharedPointer::create(); + o->style = style; + return o; + } }; class SetOption : public Operation { void apply(QWizard *wizard) const { wizard->setOption(option, on); } QString describe() const; - const QWizard::WizardOption option; - const bool on; + QWizard::WizardOption option; + bool on; public: - SetOption(QWizard::WizardOption option, bool on) : option(option), on(on) {} + static QSharedPointer create(QWizard::WizardOption option, bool on) + { + QSharedPointer o = QSharedPointer::create(); + o->option = option; + o->on = on; + return o; + } }; class OptionInfo @@ -1672,16 +1688,16 @@ class OptionInfo tags[QWizard::HaveCustomButton3] = "15/CB3"; for (int i = 0; i < 2; ++i) { - QMap operations_; + QMap > operations_; foreach (QWizard::WizardOption option, tags.keys()) - operations_[option] = new SetOption(option, i == 1); + operations_[option] = SetOption::create(option, i == 1); operations << operations_; } } OptionInfo(OptionInfo const&); OptionInfo& operator=(OptionInfo const&); QMap tags; - QList > operations; + QList > > operations; public: static OptionInfo &instance() { @@ -1690,7 +1706,7 @@ public: } QString tag(QWizard::WizardOption option) const { return tags.value(option); } - Operation * operation(QWizard::WizardOption option, bool on) const + QSharedPointer operation(QWizard::WizardOption option, bool on) const { return operations.at(on).value(option); } QList options() const { return tags.keys(); } }; @@ -1700,10 +1716,7 @@ QString SetOption::describe() const return QString("set opt %1 %2").arg(OptionInfo::instance().tag(option)).arg(on); } -Q_DECLARE_METATYPE(Operation *) -Q_DECLARE_METATYPE(SetPage *) -Q_DECLARE_METATYPE(SetStyle *) -Q_DECLARE_METATYPE(SetOption *) +Q_DECLARE_METATYPE(QVector >) class TestGroup { @@ -1720,14 +1733,17 @@ public: combinations.clear(); } - QList &add() - { combinations << new QList; return *(combinations.last()); } + QVector > &add() + { + combinations.resize(combinations.size() + 1); + return combinations.last(); + } void createTestRows() { for (int i = 0; i < combinations.count(); ++i) { QTest::newRow((name + QString(", row %1").arg(i)).toLatin1().data()) - << (i == 0) << (type == Equality) << *(combinations.at(i)); + << (i == 0) << (type == Equality) << combinations.at(i); ++nRows_; } } @@ -1738,7 +1754,7 @@ private: QString name; Type type; int nRows_; - QList *> combinations; + QVector > > combinations; }; class IntroPage : public QWizardPage @@ -1822,9 +1838,9 @@ public: } } - void applyOperations(const QList &operations) + void applyOperations(const QVector > &operations) { - foreach (Operation * op, operations) { + foreach (const QSharedPointer &op, operations) { if (op) { op->apply(this); opsDescr += QString("(%1) ").arg(op->describe()); @@ -1844,31 +1860,29 @@ public: class CombinationsTestData { TestGroup testGroup; - QList pageOps; - QList styleOps; - QMap *> setAllOptions; + QVector > pageOps; + QVector > styleOps; + QMap > > setAllOptions; public: CombinationsTestData() { QTest::addColumn("ref"); QTest::addColumn("testEquality"); - QTest::addColumn >("operations"); - pageOps << new SetPage(0) << new SetPage(1) << new SetPage(2); - styleOps << new SetStyle(QWizard::ClassicStyle) << new SetStyle(QWizard::ModernStyle) - << new SetStyle(QWizard::MacStyle); + QTest::addColumn > >("operations"); + pageOps << SetPage::create(0) << SetPage::create(1) << SetPage::create(2); + styleOps << SetStyle::create(QWizard::ClassicStyle) << SetStyle::create(QWizard::ModernStyle) + << SetStyle::create(QWizard::MacStyle); #define SETPAGE(page) pageOps.at(page) #define SETSTYLE(style) styleOps.at(style) #define OPT(option, on) OptionInfo::instance().operation(option, on) #define CLROPT(option) OPT(option, false) #define SETOPT(option) OPT(option, true) - setAllOptions[false] = new QList; - setAllOptions[true] = new QList; foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - *setAllOptions.value(false) << CLROPT(option); - *setAllOptions.value(true) << SETOPT(option); + setAllOptions[false] << CLROPT(option); + setAllOptions[true] << SETOPT(option); } -#define CLRALLOPTS *setAllOptions.value(false) -#define SETALLOPTS *setAllOptions.value(true) +#define CLRALLOPTS setAllOptions.value(false) +#define SETALLOPTS setAllOptions.value(true) } int nRows() const { return testGroup.nRows(); } @@ -1920,7 +1934,7 @@ public: testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList setOptions = *setAllOptions.value(i == 1); + QVector > setOptions = setAllOptions.value(i == 1); testGroup.reset("testAll 3.1"); testGroup.add() << setOptions; @@ -1937,21 +1951,21 @@ public: testGroup.createTestRows(); } - foreach (Operation *pageOp, pageOps) { + foreach (const QSharedPointer &pageOp, pageOps) { testGroup.reset("testAll 4.1"); testGroup.add() << pageOp; testGroup.add() << pageOp << pageOp; testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList optionOps = *setAllOptions.value(i == 1); + QVector > optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 4.2"); testGroup.add() << optionOps << pageOp; testGroup.add() << pageOp << optionOps; testGroup.createTestRows(); foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - Operation *optionOp = OPT(option, i == 1); + QSharedPointer optionOp = OPT(option, i == 1); testGroup.reset("testAll 4.3"); testGroup.add() << optionOp << pageOp; testGroup.add() << pageOp << optionOp; @@ -1960,21 +1974,21 @@ public: } } - foreach (Operation *styleOp, styleOps) { + foreach (const QSharedPointer &styleOp, styleOps) { testGroup.reset("testAll 5.1"); testGroup.add() << styleOp; testGroup.add() << styleOp << styleOp; testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList optionOps = *setAllOptions.value(i == 1); + QVector > optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 5.2"); testGroup.add() << optionOps << styleOp; testGroup.add() << styleOp << optionOps; testGroup.createTestRows(); foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - Operation *optionOp = OPT(option, i == 1); + QSharedPointer optionOp = OPT(option, i == 1); testGroup.reset("testAll 5.3"); testGroup.add() << optionOp << styleOp; testGroup.add() << styleOp << optionOp; @@ -1983,8 +1997,8 @@ public: } } - foreach (Operation *pageOp, pageOps) { - foreach (Operation *styleOp, styleOps) { + foreach (const QSharedPointer &pageOp, pageOps) { + foreach (const QSharedPointer &styleOp, styleOps) { testGroup.reset("testAll 6.1"); testGroup.add() << pageOp; @@ -2002,7 +2016,7 @@ public: testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList optionOps = *setAllOptions.value(i == 1); + QVector > optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 6.4"); testGroup.add() << optionOps << pageOp << styleOp; testGroup.add() << pageOp << optionOps << styleOp; @@ -2013,7 +2027,7 @@ public: testGroup.createTestRows(); foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - Operation *optionOp = OPT(option, i == 1); + QSharedPointer optionOp = OPT(option, i == 1); testGroup.reset("testAll 6.5"); testGroup.add() << optionOp << pageOp << styleOp; testGroup.add() << pageOp << optionOp << styleOp; @@ -2079,7 +2093,7 @@ void tst_QWizard::combinations() QFETCH(bool, ref); QFETCH(bool, testEquality); - QFETCH(QList, operations); + QFETCH(QVector >, operations); TestWizard wizard; #if !defined(QT_NO_STYLE_WINDOWSVISTA) From 30b7278c5cf1df0b507cd3139a53b7adcc190850 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 6 Oct 2016 16:32:49 +0200 Subject: [PATCH 04/21] Remove type punning from ucstrncmp Type punning is UB. Change-Id: I0022d2a38136d80f5ddda21cea7dc0968c736242 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 48 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index ff7e7fd406e..b7f83e4b9d7 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -480,48 +480,46 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l) if (!l) return 0; - union { - const QChar *w; - const quint32 *d; - quintptr value; - } sa, sb; - sa.w = a; - sb.w = b; - // check alignment - if ((sa.value & 2) == (sb.value & 2)) { + if ((reinterpret_cast(a) & 2) == (reinterpret_cast(b) & 2)) { // both addresses have the same alignment - if (sa.value & 2) { + if (reinterpret_cast(a) & 2) { // both addresses are not aligned to 4-bytes boundaries // compare the first character - if (*sa.w != *sb.w) - return sa.w->unicode() - sb.w->unicode(); + if (*a != *b) + return a->unicode() - b->unicode(); --l; - ++sa.w; - ++sb.w; + ++a; + ++b; // now both addresses are 4-bytes aligned } // both addresses are 4-bytes aligned // do a fast 32-bit comparison - const quint32 *e = sa.d + (l >> 1); - for ( ; sa.d != e; ++sa.d, ++sb.d) { - if (*sa.d != *sb.d) { - if (*sa.w != *sb.w) - return sa.w->unicode() - sb.w->unicode(); - return sa.w[1].unicode() - sb.w[1].unicode(); + const quint32 *da = reinterpret_cast(a); + const quint32 *db = reinterpret_cast(b); + const quint32 *e = da + (l >> 1); + for ( ; da != e; ++da, ++db) { + if (*da != *db) { + a = reinterpret_cast(da); + b = reinterpret_cast(db); + if (*a != *b) + return a->unicode() - b->unicode(); + return a[1].unicode() - b[1].unicode(); } } // do we have a tail? - return (l & 1) ? sa.w->unicode() - sb.w->unicode() : 0; + a = reinterpret_cast(da); + b = reinterpret_cast(db); + return (l & 1) ? a->unicode() - b->unicode() : 0; } else { // one of the addresses isn't 4-byte aligned but the other is - const QChar *e = sa.w + l; - for ( ; sa.w != e; ++sa.w, ++sb.w) { - if (*sa.w != *sb.w) - return sa.w->unicode() - sb.w->unicode(); + const QChar *e = a + l; + for ( ; a != e; ++a, ++b) { + if (*a != *b) + return a->unicode() - b->unicode(); } } return 0; From 592614ea3ecd90ede2ae1b8e6579d1b898f474ec Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 21 Oct 2016 10:13:20 +0200 Subject: [PATCH 05/21] Don't claim all fonts are smoothly scalable on Windows Since 40ebda3efbcf00c3393cb70c9eee203c68a57311, bitmap fonts are detected as smoothly scalable on Windows. While the fontsAlwaysScalable() does say whether or not the font engine can rasterize the fonts at any size, it does not determine whether or not the result is "attractive" as the documentation for isSmoothlyScalable() says. Only outline fonts are smoothly scalable, and this fact is used in Qt Quick to determine whether we can use the distance field renderer for the font or if we have to fall back to the native renderer. The consequence was that the fonts were no longer usable in Qt Quick. We also need to revert the optimization for isBitmapScalable() since there a font that is smoothly scalable should not be identified as bitmap scalable (basically this means: Font is not smoothly scalable, but it can be scaled with bitmap scaling artifacts). [ChangeLog][QtGui][Text] Fixed a regression where raster fonts on Windows were detected as smoothly scalable and thus rendering with said fonts in Qt Quick would break. Task-number: QTBUG-56659 Change-Id: Ia7db6fee8249aca347233a488388be5c3a00c2df Reviewed-by: Lars Knoll --- src/gui/text/qfontdatabase.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index f063541249a..04081a5ca75 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -1657,9 +1657,6 @@ bool QFontDatabase::isFixedPitch(const QString &family, bool QFontDatabase::isBitmapScalable(const QString &family, const QString &style) const { - if (QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()) - return true; - bool bitmapScalable = false; QString familyName, foundryName; parseFontName(family, foundryName, familyName); @@ -1700,9 +1697,6 @@ bool QFontDatabase::isBitmapScalable(const QString &family, */ bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &style) const { - if (QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()) - return true; - bool smoothScalable = false; QString familyName, foundryName; parseFontName(family, foundryName, familyName); From f6eb570c7dee2ec92383607c614db91f31804707 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 29 Sep 2016 11:59:01 +0200 Subject: [PATCH 06/21] Darwin: normalize all watched paths to composed from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be done by all POSIX APIs for strings coming in that way, but because other code (like NSWhateverViews) will most likely return decomposed form, we make sure that those are in composed form too. Task-number: QTBUG-55896 Change-Id: I065e11cee6b59706d4346ed20d4b59b9b95163b8 Reviewed-by: Morten Johan Sørvig --- src/corelib/io/qfilesystemwatcher_fsevents.mm | 2 +- .../tst_qfilesystemwatcher.cpp | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index c6fa6c9846d..6af9e5f5ef2 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -343,7 +343,7 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList p = paths; QMutableListIterator it(p); while (it.hasNext()) { - QString origPath = it.next(); + QString origPath = it.next().normalized(QString::NormalizationForm_C); QString realPath = origPath; if (realPath.endsWith(QDir::separator())) realPath = realPath.mid(0, realPath.size() - 1); diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 026743257c3..4ede1e69f37 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -78,6 +78,8 @@ private slots: void signalsEmittedAfterFileMoved(); + void watchUnicodeCharacters(); + private: QString m_tempDirPattern; #endif // QT_NO_FILESYSTEMWATCHER @@ -763,6 +765,25 @@ void tst_QFileSystemWatcher::signalsEmittedAfterFileMoved() QVERIFY2(changedSpy.count() <= fileCount, changedSpy.receivedFilesMessage()); QTRY_COMPARE(changedSpy.count(), fileCount); } + +void tst_QFileSystemWatcher::watchUnicodeCharacters() +{ + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); + + QDir testDir(temporaryDirectory.path()); + const QString subDir(QString::fromLatin1("caf\xe9")); + QVERIFY(testDir.mkdir(subDir)); + testDir = QDir(temporaryDirectory.path() + QDir::separator() + subDir); + + QFileSystemWatcher watcher; + QVERIFY(watcher.addPath(testDir.path())); + + FileSystemWatcherSpy changedSpy(&watcher, FileSystemWatcherSpy::SpyOnDirectoryChanged); + QCOMPARE(changedSpy.count(), 0); + QVERIFY(testDir.mkdir("creme")); + QTRY_COMPARE(changedSpy.count(), 1); +} #endif // QT_NO_FILESYSTEMWATCHER QTEST_MAIN(tst_QFileSystemWatcher) From 843247e1c509ec3ce55a2e2051b83fcfa6634135 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 14 Oct 2016 13:05:00 +0200 Subject: [PATCH 07/21] Call raise on the window that contains the widget and not the widget When the mouse is clicked on the widget in a window while a popup is visible then it should raise just the window and not the widget inside it. If the widget is in a stacked layout then calling raise() on it can cause it to appear on top so avoid this by calling raise() directly on the window. Task-number: QTBUG-52670 Change-Id: Idd287c6cc7038c57e14e92f4a3e1c50985925684 Reviewed-by: Friedemann Kleint --- src/widgets/kernel/qwidgetwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 95f63025fb9..40c488857e3 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -529,7 +529,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) // activate window of the widget under mouse pointer if (!w->isActiveWindow()) { w->activateWindow(); - w->raise(); + w->window()->raise(); } QWindow *win = w->windowHandle(); From e2d8c7bf2203cbc0c7ff923caf3132881aafa0b0 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 1 Sep 2016 11:53:15 +0200 Subject: [PATCH 08/21] Don't change the size of widgets just because it is in a floating dock When a QDockWidget was floating on macOS then it would force the size of various widgets, such as buttons, comboboxes, to be the smallest needed rather than the size they had when it was docked. Task-number: QTBUG-7460 Task-number: QTBUG-52354 Change-Id: Id348180934f113f3a9a9ce5622a9af03eed04108 Reviewed-by: Jake Petroules --- src/widgets/styles/qmacstyle_mac.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 46918a2d5f0..84445bfce4e 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1034,6 +1034,8 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg #if defined(QMAC_QAQUASTYLE_SIZE_CONSTRAIN) || defined(DEBUG_SIZE_CONSTRAINT) static QAquaWidgetSize qt_aqua_guess_size(const QWidget *widg, QSize large, QSize small, QSize mini) { + Q_UNUSED(widg); + if (large == QSize(-1, -1)) { if (small != QSize(-1, -1)) return QAquaSizeSmall; @@ -1049,7 +1051,7 @@ static QAquaWidgetSize qt_aqua_guess_size(const QWidget *widg, QSize large, QSiz } #ifndef QT_NO_MAINWINDOW - if (qobject_cast(widg->window()) || qEnvironmentVariableIsSet("QWIDGET_ALL_SMALL")) { + if (qEnvironmentVariableIsSet("QWIDGET_ALL_SMALL")) { //if (small.width() != -1 || small.height() != -1) return QAquaSizeSmall; } else if (qEnvironmentVariableIsSet("QWIDGET_ALL_MINI")) { From 9c83d7f871f95b1cc03fb404bd602df32056b9cb Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 30 Sep 2016 15:39:03 -0700 Subject: [PATCH 09/21] QCocoaMenuBar: Update even if no window is attached Then we need to check if the current active (or focused) window has any menubar associated. In case there isn't, and the menubar has no window associated, then we should update immediately. The previous condition is still valid. Change-Id: I4532ccc87354d91c76b53f5433dc3944b9e29584 Task-number: QTBUG-56275 Reviewed-by: Erik Verbruggen --- src/plugins/platforms/cocoa/qcocoamenubar.h | 1 + src/plugins/platforms/cocoa/qcocoamenubar.mm | 28 +++++++++++- .../widgets/widgets/qmenubar/qmenubar.pro | 5 +++ .../widgets/widgets/qmenubar/tst_qmenubar.cpp | 24 ++++++++++ .../widgets/qmenubar/tst_qmenubar_mac.mm | 44 +++++++++++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h index e84da7aeb0a..2865dd24603 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.h +++ b/src/plugins/platforms/cocoa/qcocoamenubar.h @@ -70,6 +70,7 @@ private: static QCocoaWindow *findWindowForMenubar(); static QCocoaMenuBar *findGlobalMenubar(); + bool needsImmediateUpdate(); bool shouldDisable(QCocoaWindow *active) const; NSMenuItem *nativeItemForMenu(QCocoaMenu *menu) const; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 3523182e6d9..82aebf8cf33 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -89,6 +89,32 @@ QCocoaMenuBar::~QCocoaMenuBar() } } +bool QCocoaMenuBar::needsImmediateUpdate() +{ + if (m_window && m_window->window()->isActive()) { + return true; + } else if (!m_window) { + // Only update if the focus/active window has no + // menubar, which means it'll be using this menubar. + // This is to avoid a modification in a parentless + // menubar to affect a window-assigned menubar. + QWindow *fw = QGuiApplication::focusWindow(); + if (!fw) { + // Same if there's no focus window, BTW. + return true; + } else { + QCocoaWindow *cw = static_cast(fw->handle()); + if (cw && !cw->menubar()) + return true; + } + } + + // Either the menubar is attached to a non-active window, + // or the application's focus window has its own menubar + // (which is different from this one) + return false; +} + void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *before) { QCocoaMenu *menu = static_cast(platformMenu); @@ -129,7 +155,7 @@ void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *befor syncMenu(menu); - if (m_window && m_window->window()->isActive()) + if (needsImmediateUpdate()) updateMenuBarImmediately(); } diff --git a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro index 3fb6ae61a8f..e680cf4d7d8 100644 --- a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro +++ b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro @@ -2,3 +2,8 @@ CONFIG += testcase TARGET = tst_qmenubar QT += widgets testlib SOURCES += tst_qmenubar.cpp + +macos: { + OBJECTIVE_SOURCES += tst_qmenubar_mac.mm + LIBS += -framework AppKit +} diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index b2d15fffef4..45eae182404 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -133,6 +133,9 @@ private slots: void cornerWidgets_data(); void cornerWidgets(); void taskQTBUG53205_crashReparentNested(); +#ifdef Q_OS_MACOS + void taskQTBUG56275_reinsertMenuInParentlessQMenuBar(); +#endif protected slots: void onSimpleActivated( QAction*); @@ -1495,7 +1498,28 @@ void tst_QMenuBar::slotForTaskQTBUG53205() taskQTBUG53205MenuBar->setParent(parent); } +#ifdef Q_OS_MACOS +extern bool tst_qmenubar_taskQTBUG56275(QMenuBar *); +void tst_QMenuBar::taskQTBUG56275_reinsertMenuInParentlessQMenuBar() +{ + QMenuBar menubar; + + QMenu *menu = new QMenu("menu", &menubar); + QMenu* submenu = menu->addMenu("submenu"); + submenu->addAction("action1"); + submenu->addAction("action2"); + menu->addAction("action3"); + menubar.addMenu(menu); + + QTest::qWait(100); + menubar.clear(); + menubar.addMenu(menu); + QTest::qWait(100); + + QVERIFY(tst_qmenubar_taskQTBUG56275(&menubar)); +} +#endif // Q_OS_MACOS QTEST_MAIN(tst_QMenuBar) #include "tst_qmenubar.moc" diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm new file mode 100644 index 00000000000..4645de4d7af --- /dev/null +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import + +#include +#include + +bool tst_qmenubar_taskQTBUG56275(QMenuBar *menubar) +{ + NSMenu *mainMenu = menubar->toNSMenu(); + return mainMenu.numberOfItems == 2 + && [[mainMenu itemAtIndex:1].title isEqualToString:@"menu"]; +} From fe8f387794853b0456f554a783e2769edab9aecb Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 21 Oct 2016 21:16:10 +0200 Subject: [PATCH 10/21] don't moc OBJECTIVE_SOURCES twice since 9ff1310af, the variable's contents are simply added to SOURCES, and the variable is not cleared. and qmake does not de-duplicate ... Task-number: QTBUG-53905 Change-Id: I3e551d21cbbd2d0cbfbf7aa7efaa5babac112f9d Reviewed-by: Jake Petroules --- mkspecs/features/moc.prf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkspecs/features/moc.prf b/mkspecs/features/moc.prf index 8e8deec63c9..9cc2bf3b76d 100644 --- a/mkspecs/features/moc.prf +++ b/mkspecs/features/moc.prf @@ -56,7 +56,7 @@ moc_source.CONFIG = no_link moc_verify moc_source.dependency_type = TYPE_C moc_source.commands = ${QMAKE_FUNC_mocCmdBase} ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} moc_source.output = $$MOC_DIR/$${QMAKE_CPP_MOD_MOC}${QMAKE_FILE_BASE}$${QMAKE_EXT_CPP_MOC} -moc_source.input = SOURCES OBJECTIVE_SOURCES +moc_source.input = SOURCES moc_source.name = MOC ${QMAKE_FILE_IN} moc_source.depends += $$WIN_INCLUDETEMP silent:moc_source.commands = @echo moc ${QMAKE_FILE_IN} && $$moc_source.commands From d507cd40b6fc3b7271e3ba83c668f33b8aab8683 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 21 Oct 2016 21:18:58 +0200 Subject: [PATCH 11/21] unset OBJECTIVE_SOURCES and QMAKE_OBJECTIVE_CFLAGS after absorbing them this is a bit easier on the backwards compat code in qt creator, which needs to merge and then de-duplicate the lists itself. Change-Id: I79f9319c26af541f5efa85700878e7ddbd00e2b7 Reviewed-by: Jake Petroules --- mkspecs/features/mac/objective_c.prf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkspecs/features/mac/objective_c.prf b/mkspecs/features/mac/objective_c.prf index b3b1d4be998..ed1ad8ad384 100644 --- a/mkspecs/features/mac/objective_c.prf +++ b/mkspecs/features/mac/objective_c.prf @@ -1,6 +1,7 @@ # Objective-C/C++ sources go in SOURCES, like all other sources SOURCES += $$OBJECTIVE_SOURCES +unset(OBJECTIVE_SOURCES) # Strip C/C++ flags from QMAKE_OBJECTIVE_CFLAGS just in case QMAKE_OBJECTIVE_CFLAGS -= $$QMAKE_CFLAGS $$QMAKE_CXXFLAGS @@ -8,3 +9,4 @@ QMAKE_OBJECTIVE_CFLAGS -= $$QMAKE_CFLAGS $$QMAKE_CXXFLAGS # Add Objective-C/C++ flags to C/C++ flags, the compiler can handle it QMAKE_CFLAGS += $$QMAKE_OBJECTIVE_CFLAGS QMAKE_CXXFLAGS += $$QMAKE_OBJECTIVE_CFLAGS +unset(QMAKE_OBJECTIVE_CFLAGS) From 0cffe2135e7303bd103bdf888a345fe0a8b94cd6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 14 Sep 2016 11:29:37 -0700 Subject: [PATCH 12/21] qversiontagging.h: Don't tag binaries in static mode Though there should have been no ill-effects, they happen. Task-number: QTBUG-52605 Change-Id: I9093948278414644a416fffd147444078edc3183 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/global/qversiontagging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/global/qversiontagging.h b/src/corelib/global/qversiontagging.h index fa824d1c89e..b46bb7aa77d 100644 --- a/src/corelib/global/qversiontagging.h +++ b/src/corelib/global/qversiontagging.h @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE * There will only be one copy of the section in the output library or application. */ -#if defined(QT_BUILD_CORE_LIB) || defined(QT_BOOTSTRAPPED) || defined(QT_NO_VERSION_TAGGING) +#if defined(QT_BUILD_CORE_LIB) || defined(QT_BOOTSTRAPPED) || defined(QT_NO_VERSION_TAGGING) || defined(QT_STATIC) // don't make tags in QtCore, bootstrapped systems or if the user asked not to #elif defined(Q_CC_GNU) && !defined(Q_OS_ANDROID) # if defined(Q_PROCESSOR_X86) && (defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD_KERNEL)) From b82793e7909d38482662a8de0f16d8ab0df232ec Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Tue, 25 Oct 2016 11:43:56 +0200 Subject: [PATCH 13/21] Fix possible loss of data in conversion from size_t to int warning Change-Id: I72c74e67708f1e164a0c35e1e92d9bf3ec99ffd6 Reviewed-by: Oswald Buddenhagen Reviewed-by: Timur Pocheptsov --- qmake/generators/makefiledeps.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qmake/generators/makefiledeps.cpp b/qmake/generators/makefiledeps.cpp index ff613ea8f12..65f401affdf 100644 --- a/qmake/generators/makefiledeps.cpp +++ b/qmake/generators/makefiledeps.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #if defined(_MSC_VER) && _MSC_VER >= 1400 #include #endif @@ -983,9 +984,11 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file) continue; int matchlen = 0, extralines = 0; + size_t needle_len = strlen(interesting[interest]); + Q_ASSERT(needle_len <= INT_MAX); if (matchWhileUnsplitting(buffer, buffer_len, y, interesting[interest], - strlen(interesting[interest]), + static_cast(needle_len), &matchlen, &extralines) && y + matchlen < buffer_len && !isCWordChar(buffer[y + matchlen])) { From 047e3f8f046ac9267cc27d47a48189ae2cbfe0ef Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Sep 2016 15:14:22 -0700 Subject: [PATCH 14/21] Autotest: fix silly mistake in assigning where a comparison was intended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The file descriptor has been closed and this test is checking if we get EBADF. Change-Id: I33dc971f005a4848bb8ffffd1478eaffd99aa2e9 Reviewed-by: Jake Petroules Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index b38620fcbb8..b26db788dec 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -3446,7 +3446,7 @@ void tst_QFile::autocloseHandle() //file is closed, read should fail char buf; QCOMPARE((int)QT_READ(fd, &buf, 1), -1); - QVERIFY(errno = EBADF); + QVERIFY(errno == EBADF); } { From 60dbd80e5a26182b3ed9e2c60bb7212dfd32632b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Somers?= Date: Wed, 28 Sep 2016 10:13:27 +0200 Subject: [PATCH 15/21] Document that qFuzzyCompare does not work on NaN or infinity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a discussion in the Development mailing list it became clear that qFuzzyCompare does not work for NaN or infinity values. That was not mentioned in the method documentation though. This patch fixes that hiatus. It also clarifies how to deal with the comparing to 0.0 limitation. Change-Id: I8b6d54cc0c1136e79b0d7be1a62bc9ed394d2575 Reviewed-by: Topi Reiniö Reviewed-by: Martin Smith --- src/corelib/global/qglobal.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 6d7fbce946a..59799b07bbc 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -4109,8 +4109,10 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) Compares the floating point value \a p1 and \a p2 and returns \c true if they are considered equal, otherwise \c false. - Note that comparing values where either \a p1 or \a p2 is 0.0 will not work. - The solution to this is to compare against values greater than or equal to 1.0. + Note that comparing values where either \a p1 or \a p2 is 0.0 will not work, + nor does comparing values where one of the values is NaN or infinity. + If one of the values is always 0.0, use qFuzzyIsNull instead. If one of the + values is likely to be 0.0, one solution is to add 1.0 to both values. \snippet code/src_corelib_global_qglobal.cpp 46 From 99ce5d5e85007cb656cd48ab161be14af8f16238 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 28 Sep 2016 13:58:56 +0200 Subject: [PATCH 16/21] iOS: refactor usage of photos into optional plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting from iOS 10, apps that tries to access photos on the device need to specify the reason for this up front by adding the key 'NSPhotoLibraryUsageDescription' into Info.plist. If the key is missing, the app will be rejected from AppStore. This causes problems for the iOS plugin as it stands since parts of it already tries to access photos, e.g to show an image picker dialog if a file dialog is set to open QStandardPaths::PicturesLocation. This means that currently, all apps written with Qt will be rejected from AppStore unless the developer adds this key, whether he tries to access photos or not. To solve this, we choose to split the plugin into two parts, one that contains the core functionality, and one that contains optional support. The latter will need to be enabled explicit by the developer in the pro file, or in this case, indirectly by adding the right key to the Info.plist. This patch refactors the code in the plugin that gives access to photos into a separate optional plugin called 'nsphotolibrarysupport'. Change-Id: Ic4351eb0bbfffdf840fd88cd00bb29a25907798f Reviewed-by: Tor Arne Vestbø Reviewed-by: Jake Petroules --- src/gui/gui.pro | 1 + src/plugins/platforms/ios/ios.pro | 63 +-------------- src/plugins/platforms/ios/kernel.pro | 58 ++++++++++++++ .../nsphotolibrarysupport.pro | 22 ++++++ .../nsphotolibrarysupport/plugin.json | 3 + .../optional/nsphotolibrarysupport/plugin.mm | 64 +++++++++++++++ .../qiosfileengineassetslibrary.h | 2 +- .../qiosfileengineassetslibrary.mm | 2 +- .../qiosfileenginefactory.h | 2 +- .../qiosimagepickercontroller.h | 42 ++++++++++ .../qiosimagepickercontroller.mm | 66 ++++++++++++++++ .../platforms/ios/optional/optional.pro | 2 + src/plugins/platforms/ios/qiosfiledialog.h | 2 + src/plugins/platforms/ios/qiosfiledialog.mm | 79 ++++++++----------- src/plugins/platforms/ios/qiosintegration.h | 7 +- src/plugins/platforms/ios/qiosintegration.mm | 8 ++ .../ios/qiosoptionalplugininterface.h | 59 ++++++++++++++ 17 files changed, 370 insertions(+), 112 deletions(-) create mode 100644 src/plugins/platforms/ios/kernel.pro create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm rename src/plugins/platforms/ios/{ => optional/nsphotolibrarysupport}/qiosfileengineassetslibrary.h (98%) rename src/plugins/platforms/ios/{ => optional/nsphotolibrarysupport}/qiosfileengineassetslibrary.mm (99%) rename src/plugins/platforms/ios/{ => optional/nsphotolibrarysupport}/qiosfileenginefactory.h (98%) create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h create mode 100644 src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm create mode 100644 src/plugins/platforms/ios/optional/optional.pro create mode 100644 src/plugins/platforms/ios/qiosoptionalplugininterface.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 69434e801f6..2cdb3a7ab7e 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -9,6 +9,7 @@ QMAKE_DOCS = $$PWD/doc/qtgui.qdocconf MODULE_PLUGIN_TYPES = \ platforms \ + platforms/darwin \ xcbglintegrations \ platformthemes \ platforminputcontexts \ diff --git a/src/plugins/platforms/ios/ios.pro b/src/plugins/platforms/ios/ios.pro index 545db8c093f..594ccefcf18 100644 --- a/src/plugins/platforms/ios/ios.pro +++ b/src/plugins/platforms/ios/ios.pro @@ -1,61 +1,2 @@ -TARGET = qios - -QT += core-private gui-private platformsupport-private -LIBS += -framework Foundation -framework UIKit -framework QuartzCore -framework AssetsLibrary - -OBJECTIVE_SOURCES = \ - plugin.mm \ - qiosintegration.mm \ - qioseventdispatcher.mm \ - qioswindow.mm \ - qiosscreen.mm \ - qiosbackingstore.mm \ - qiosapplicationdelegate.mm \ - qiosapplicationstate.mm \ - qiosviewcontroller.mm \ - qioscontext.mm \ - qiosinputcontext.mm \ - qiostheme.mm \ - qiosglobal.mm \ - qiosservices.mm \ - quiview.mm \ - qiosclipboard.mm \ - quiaccessibilityelement.mm \ - qiosplatformaccessibility.mm \ - qiostextresponder.mm \ - qiosmenu.mm \ - qiosfileengineassetslibrary.mm \ - qiosfiledialog.mm - -HEADERS = \ - qiosintegration.h \ - qioseventdispatcher.h \ - qioswindow.h \ - qiosscreen.h \ - qiosbackingstore.h \ - qiosapplicationdelegate.h \ - qiosapplicationstate.h \ - qiosviewcontroller.h \ - qioscontext.h \ - qiosinputcontext.h \ - qiostheme.h \ - qiosglobal.h \ - qiosservices.h \ - quiview.h \ - qiosclipboard.h \ - quiaccessibilityelement.h \ - qiosplatformaccessibility.h \ - qiostextresponder.h \ - qiosmenu.h \ - qiosfileenginefactory.h \ - qiosfileengineassetslibrary.h \ - qiosfiledialog.h - -OTHER_FILES = \ - quiview_textinput.mm \ - quiview_accessibility.mm - -PLUGIN_TYPE = platforms -PLUGIN_CLASS_NAME = QIOSIntegrationPlugin -!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - -load(qt_plugin) +TEMPLATE = subdirs +SUBDIRS = kernel.pro optional diff --git a/src/plugins/platforms/ios/kernel.pro b/src/plugins/platforms/ios/kernel.pro new file mode 100644 index 00000000000..84035877c54 --- /dev/null +++ b/src/plugins/platforms/ios/kernel.pro @@ -0,0 +1,58 @@ +TARGET = qios + +QT += core-private gui-private platformsupport-private +LIBS += -framework Foundation -framework UIKit -framework QuartzCore + +OBJECTIVE_SOURCES = \ + plugin.mm \ + qiosintegration.mm \ + qioseventdispatcher.mm \ + qioswindow.mm \ + qiosscreen.mm \ + qiosbackingstore.mm \ + qiosapplicationdelegate.mm \ + qiosapplicationstate.mm \ + qiosviewcontroller.mm \ + qioscontext.mm \ + qiosinputcontext.mm \ + qiostheme.mm \ + qiosglobal.mm \ + qiosservices.mm \ + quiview.mm \ + qiosclipboard.mm \ + quiaccessibilityelement.mm \ + qiosplatformaccessibility.mm \ + qiostextresponder.mm \ + qiosmenu.mm \ + qiosfiledialog.mm + +HEADERS = \ + qiosintegration.h \ + qioseventdispatcher.h \ + qioswindow.h \ + qiosscreen.h \ + qiosbackingstore.h \ + qiosapplicationdelegate.h \ + qiosapplicationstate.h \ + qiosviewcontroller.h \ + qioscontext.h \ + qiosinputcontext.h \ + qiostheme.h \ + qiosglobal.h \ + qiosservices.h \ + quiview.h \ + qiosclipboard.h \ + quiaccessibilityelement.h \ + qiosplatformaccessibility.h \ + qiostextresponder.h \ + qiosmenu.h \ + qiosfiledialog.h + +OTHER_FILES = \ + quiview_textinput.mm \ + quiview_accessibility.mm + +PLUGIN_TYPE = platforms +PLUGIN_CLASS_NAME = QIOSIntegrationPlugin +!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - +load(qt_plugin) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro new file mode 100644 index 00000000000..f4588dda039 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/nsphotolibrarysupport.pro @@ -0,0 +1,22 @@ +TARGET = qiosnsphotolibrarysupport + +QT += core gui gui-private +LIBS += -framework UIKit -framework AssetsLibrary + +HEADERS = \ + qiosfileengineassetslibrary.h \ + qiosfileenginefactory.h \ + qiosimagepickercontroller.h + +OBJECTIVE_SOURCES = \ + plugin.mm \ + qiosfileengineassetslibrary.mm \ + qiosimagepickercontroller.mm \ + +OTHER_FILES = \ + plugin.json + +PLUGIN_CLASS_NAME = QIosOptionalPlugin_NSPhotoLibrary +PLUGIN_EXTENDS = - +PLUGIN_TYPE = platforms/darwin +load(qt_plugin) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json new file mode 100644 index 00000000000..4491fb3d59f --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "NSPhotoLibrarySupport" ] +} diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm new file mode 100644 index 00000000000..2ec0d33a413 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/plugin.mm @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "../../qiosoptionalplugininterface.h" +#include "../../qiosfiledialog.h" + +#include "qiosimagepickercontroller.h" +#include "qiosfileenginefactory.h" + +QT_BEGIN_NAMESPACE + +class QIosOptionalPlugin_NSPhotoLibrary : public QObject, QIosOptionalPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QIosOptionalPluginInterface_iid FILE "plugin.json") + Q_INTERFACES(QIosOptionalPluginInterface) + +public: + explicit QIosOptionalPlugin_NSPhotoLibrary(QObject* = 0) {}; + ~QIosOptionalPlugin_NSPhotoLibrary() {} + + UIViewController* createImagePickerController(QIOSFileDialog *fileDialog) const override + { + return [[[QIOSImagePickerController alloc] initWithQIOSFileDialog:fileDialog] autorelease]; + } + +private: + QIOSFileEngineFactory m_fileEngineFactory; + +}; + +QT_END_NAMESPACE + +#include "plugin.moc" diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h similarity index 98% rename from src/plugins/platforms/ios/qiosfileengineassetslibrary.h rename to src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h index 37bbc7bf232..0e29a1003e3 100644 --- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm similarity index 99% rename from src/plugins/platforms/ios/qiosfileengineassetslibrary.mm rename to src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm index bb12c164d62..2e88c37c010 100644 --- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.mm @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. diff --git a/src/plugins/platforms/ios/qiosfileenginefactory.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h similarity index 98% rename from src/plugins/platforms/ios/qiosfileenginefactory.h rename to src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h index a8604c77d14..29f543caae3 100644 --- a/src/plugins/platforms/ios/qiosfileenginefactory.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileenginefactory.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h new file mode 100644 index 00000000000..df3f6b9fa36 --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import + +#include "../../qiosfiledialog.h" + +@interface QIOSImagePickerController : UIImagePickerController { + QIOSFileDialog *m_fileDialog; +} +- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog; +@end diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm new file mode 100644 index 00000000000..f9662b964ab --- /dev/null +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosimagepickercontroller.mm @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import + +#include "qiosimagepickercontroller.h" + +@implementation QIOSImagePickerController + +- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog +{ + self = [super init]; + if (self) { + m_fileDialog = fileDialog; + [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; + [self setDelegate:self]; + } + return self; +} + +- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info +{ + Q_UNUSED(picker); + NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL]; + QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description])); + m_fileDialog->selectedFilesChanged(QList() << fileUrl); + emit m_fileDialog->accept(); +} + +- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker +{ + Q_UNUSED(picker) + emit m_fileDialog->reject(); +} + +@end diff --git a/src/plugins/platforms/ios/optional/optional.pro b/src/plugins/platforms/ios/optional/optional.pro new file mode 100644 index 00000000000..5e3421a025c --- /dev/null +++ b/src/plugins/platforms/ios/optional/optional.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = nsphotolibrarysupport diff --git a/src/plugins/platforms/ios/qiosfiledialog.h b/src/plugins/platforms/ios/qiosfiledialog.h index b4bf85edd90..668cf18caf2 100644 --- a/src/plugins/platforms/ios/qiosfiledialog.h +++ b/src/plugins/platforms/ios/qiosfiledialog.h @@ -66,6 +66,8 @@ private: QList m_selection; QEventLoop m_eventLoop; UIViewController *m_viewController; + + bool showImagePickerDialog(QWindow *parent); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosfiledialog.mm b/src/plugins/platforms/ios/qiosfiledialog.mm index 7c32784e9de..a70eb11ef89 100644 --- a/src/plugins/platforms/ios/qiosfiledialog.mm +++ b/src/plugins/platforms/ios/qiosfiledialog.mm @@ -31,52 +31,18 @@ ** ****************************************************************************/ -#include "qiosfiledialog.h" - #import #include #include +#include -@interface QIOSImagePickerController : UIImagePickerController { - QIOSFileDialog *m_fileDialog; -} -@end - -@implementation QIOSImagePickerController - -- (id)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog -{ - self = [super init]; - if (self) { - m_fileDialog = fileDialog; - [self setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; - [self setDelegate:self]; - } - return self; -} - -- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info -{ - Q_UNUSED(picker); - NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL]; - QUrl fileUrl = QUrl::fromLocalFile(QString::fromNSString([url description])); - m_fileDialog->selectedFilesChanged(QList() << fileUrl); - emit m_fileDialog->accept(); -} - -- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker -{ - Q_UNUSED(picker) - emit m_fileDialog->reject(); -} - -@end - -// -------------------------------------------------------------------------- +#include "qiosfiledialog.h" +#include "qiosintegration.h" +#include "qiosoptionalplugininterface.h" QIOSFileDialog::QIOSFileDialog() - : m_viewController(0) + : m_viewController(Q_NULLPTR) { } @@ -98,17 +64,36 @@ bool QIOSFileDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality window bool acceptOpen = options()->acceptMode() == QFileDialogOptions::AcceptOpen; QString directory = options()->initialDirectory().toLocalFile(); - if (acceptOpen && directory.startsWith(QLatin1String("assets-library:"))) { - m_viewController = [[QIOSImagePickerController alloc] initWithQIOSFileDialog:this]; - UIWindow *window = parent ? reinterpret_cast(parent->winId()).window - : [UIApplication sharedApplication].keyWindow; - [window.rootViewController presentViewController:m_viewController animated:YES completion:nil]; - return true; - } + if (acceptOpen && directory.startsWith(QLatin1String("assets-library:"))) + return showImagePickerDialog(parent); return false; } +bool QIOSFileDialog::showImagePickerDialog(QWindow *parent) +{ + if (!m_viewController) { + QFactoryLoader *plugins = QIOSIntegration::instance()->optionalPlugins(); + for (int i = 0; i < plugins->metaData().size(); ++i) { + QIosOptionalPluginInterface *plugin = qobject_cast(plugins->instance(i)); + m_viewController = [plugin->createImagePickerController(this) retain]; + if (m_viewController) + break; + } + } + + if (!m_viewController) { + qWarning() << "QIOSFileDialog: Could not resolve Qt plugin that gives access to photos on iOS"; + return false; + } + + UIWindow *window = parent ? reinterpret_cast(parent->winId()).window + : [UIApplication sharedApplication].keyWindow; + [window.rootViewController presentViewController:m_viewController animated:YES completion:nil]; + + return true; +} + void QIOSFileDialog::hide() { // QFileDialog will remember the last directory set, and open subsequent dialogs in the same @@ -120,6 +105,8 @@ void QIOSFileDialog::hide() emit directoryEntered(QUrl::fromLocalFile(QDir::currentPath())); [m_viewController dismissViewControllerAnimated:YES completion:nil]; + [m_viewController release]; + m_viewController = Q_NULLPTR; m_eventLoop.exit(); } diff --git a/src/plugins/platforms/ios/qiosintegration.h b/src/plugins/platforms/ios/qiosintegration.h index 7d23fe1d620..25eb8990cb9 100644 --- a/src/plugins/platforms/ios/qiosintegration.h +++ b/src/plugins/platforms/ios/qiosintegration.h @@ -38,8 +38,9 @@ #include #include +#include + #include "qiosapplicationstate.h" -#include "qiosfileenginefactory.h" QT_BEGIN_NAMESPACE @@ -91,6 +92,8 @@ public: void setDebugWindowManagement(bool); bool debugWindowManagement() const; + QFactoryLoader *optionalPlugins() { return m_optionalPlugins; } + private: QPlatformFontDatabase *m_fontDatabase; QPlatformClipboard *m_clipboard; @@ -99,7 +102,7 @@ private: QIOSApplicationState m_applicationState; QIOSServices *m_platformServices; mutable QPlatformAccessibility *m_accessibility; - QIOSFileEngineFactory m_fileEngineFactory; + QFactoryLoader *m_optionalPlugins; bool m_debugWindowManagement; }; diff --git a/src/plugins/platforms/ios/qiosintegration.mm b/src/plugins/platforms/ios/qiosintegration.mm index 85b5c477cc5..d33c8cf47c3 100644 --- a/src/plugins/platforms/ios/qiosintegration.mm +++ b/src/plugins/platforms/ios/qiosintegration.mm @@ -43,6 +43,7 @@ #include "qiosinputcontext.h" #include "qiostheme.h" #include "qiosservices.h" +#include "qiosoptionalplugininterface.h" #include @@ -68,6 +69,7 @@ QIOSIntegration::QIOSIntegration() , m_inputContext(0) , m_platformServices(new QIOSServices) , m_accessibility(0) + , m_optionalPlugins(new QFactoryLoader(QIosOptionalPluginInterface_iid, QLatin1String("/platforms/darwin"))) , m_debugWindowManagement(false) { if (![UIApplication sharedApplication]) { @@ -112,6 +114,9 @@ QIOSIntegration::QIOSIntegration() m_touchDevice->setCapabilities(touchCapabilities); QWindowSystemInterface::registerTouchDevice(m_touchDevice); QMacInternalPasteboardMime::initializeMimeTypes(); + + for (int i = 0; i < m_optionalPlugins->metaData().size(); ++i) + qobject_cast(m_optionalPlugins->instance(i))->initPlugin(); } QIOSIntegration::~QIOSIntegration() @@ -134,6 +139,9 @@ QIOSIntegration::~QIOSIntegration() delete m_accessibility; m_accessibility = 0; + + delete m_optionalPlugins; + m_optionalPlugins = 0; } bool QIOSIntegration::hasCapability(Capability cap) const diff --git a/src/plugins/platforms/ios/qiosoptionalplugininterface.h b/src/plugins/platforms/ios/qiosoptionalplugininterface.h new file mode 100644 index 00000000000..bcb8978e02d --- /dev/null +++ b/src/plugins/platforms/ios/qiosoptionalplugininterface.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QIOPLUGININTERFACE_H +#define QIOPLUGININTERFACE_H + +#include + +#include "qiosfiledialog.h" + +QT_BEGIN_NAMESPACE + +Q_FORWARD_DECLARE_OBJC_CLASS(UIViewController); + +#define QIosOptionalPluginInterface_iid "org.qt-project.Qt.QPA.ios.optional" + +class QIosOptionalPluginInterface +{ +public: + virtual ~QIosOptionalPluginInterface() {} + virtual void initPlugin() const {}; + virtual UIViewController* createImagePickerController(QIOSFileDialog *) const { return Q_NULLPTR; }; +}; + +Q_DECLARE_INTERFACE(QIosOptionalPluginInterface, QIosOptionalPluginInterface_iid) + +QT_END_NAMESPACE + +#endif // QIOPLUGININTERFACE_H From 78ee77f49122ac525590715a0a034965e3e59adf Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 4 Oct 2016 15:04:04 +0200 Subject: [PATCH 17/21] iOS: link photo lib plugin based on Info.plist contents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the application's Info.plist contains the key 'NSPhotoLibraryUsageDescription', we know that we can safely link in qiosnsphotolibrarysupport without violating AppStore requirements. This is a simple feature that doesn't introduce additional qmake API for doing app deployment with optional iOS QPA plugins. [ChangeLog][iOS] Starting from iOS 10, Apple requires all apps that need access to photos to have the key 'NSPhotoLibraryUsageDescription' in the Info.plist. Therefore, to get the same support in Qt (when, e.g., using a file dialog), the Info.plist assigned to QMAKE_INFO_PLIST will need this key as well. Change-Id: I7a93afe24b589cad96d5a1d9e2a155ad1671178a Reviewed-by: Tor Arne Vestbø Reviewed-by: Jake Petroules --- mkspecs/macx-ios-clang/features/default_post.prf | 8 ++++++++ qmake/doc/src/qmake-manual.qdoc | 6 ++++++ src/widgets/dialogs/qfiledialog.cpp | 3 +++ 3 files changed, 17 insertions(+) diff --git a/mkspecs/macx-ios-clang/features/default_post.prf b/mkspecs/macx-ios-clang/features/default_post.prf index 4c8a6eaae66..93e9e10ec3a 100644 --- a/mkspecs/macx-ios-clang/features/default_post.prf +++ b/mkspecs/macx-ios-clang/features/default_post.prf @@ -80,3 +80,11 @@ macx-xcode { QMAKE_CXXFLAGS += $$arch_flags QMAKE_LFLAGS += $$arch_flags } + +!xcodebuild:equals(TEMPLATE, app):!isEmpty(QMAKE_INFO_PLIST) { + # Only link in photo library support if Info.plist contains + # NSPhotoLibraryUsageDescription. Otherwise it will be rejected from AppStore. + plist_path = $$absolute_path($$QMAKE_INFO_PLIST, $$_PRO_FILE_PWD_) + system("/usr/libexec/PlistBuddy -c 'Print NSPhotoLibraryUsageDescription' $$system_quote($$plist_path) &>/dev/null"): \ + QTPLUGIN += qiosnsphotolibrarysupport +} diff --git a/qmake/doc/src/qmake-manual.qdoc b/qmake/doc/src/qmake-manual.qdoc index 7386af881ef..ccb79f4a9f4 100644 --- a/qmake/doc/src/qmake-manual.qdoc +++ b/qmake/doc/src/qmake-manual.qdoc @@ -1813,6 +1813,12 @@ which qmake will replace with the actual executable name. Other variables include @ICON@, @TYPEINFO@, @LIBRARY@, and @SHORT_VERSION@. + If building for iOS, and the \c{.plist} file contains the key + \c NSPhotoLibraryUsageDescription, qmake will include an additional plugin + to the build that adds photo access support (to, e.g., + \l{QFileDialog::setDirectory()}{QFile/QFileDialog}). See Info.plist + documentation from Apple for more information regarding this key. + \note Most of the time, the default \c{Info.plist} is good enough. \section1 QMAKE_LFLAGS diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 61f5f7b0d23..f8e42993977 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -896,6 +896,9 @@ void QFileDialogPrivate::_q_goToUrl(const QUrl &url) {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()}, a native image picker dialog will be used for accessing the user's photo album. The filename returned can be loaded using QFile and related APIs. + For this to be enabled, the Info.plist assigned to QMAKE_INFO_PLIST in the + project file must contain the key \c NSPhotoLibraryUsageDescription. See + Info.plist documentation from Apple for more information regarding this key. This feature was added in Qt 5.5. */ void QFileDialog::setDirectory(const QString &directory) From aa2e2a8d5e4712d93879098675c0a46df0fd7a41 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 25 Oct 2016 11:56:33 +0200 Subject: [PATCH 18/21] Android: Fix synthesized oblique for non-latin scripts In 5e3e34731b7880ac775e8f1fa156ce016e6820f1, a default implementation of QPlatformFontDatabase::fallbacksForFamily() was added, but this implementation included only the fonts with a matching style in the returned list. The result of this was that if a font face for a specific language did not have e.g. an italic font, then we would show missing glyph boxes instead. On Android, it would be impossible to show any italic text in Chinese, Japanese, Hebrew, or Arabic. [ChangeLog][QtGui][Text] Fixed synthesized oblique for non-latin text on platforms using the basic font database, such as Android. Task-number: QTBUG-51223 Change-Id: I494d8ad87292b65d4380a2e600c1c0dc7fc8f937 Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt --- src/gui/text/qfontdatabase.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 04081a5ca75..f1b2e84a1e2 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -805,7 +805,8 @@ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFo Q_UNUSED(family); Q_UNUSED(styleHint); - QStringList retList; + QStringList preferredFallbacks; + QStringList otherFallbacks; size_t writingSystem = std::find(scriptForWritingSystem, scriptForWritingSystem + QFontDatabase::WritingSystemsCount, @@ -826,18 +827,18 @@ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFo QtFontFoundry *foundry = f->foundries[j]; for (int k = 0; k < foundry->count; ++k) { - if (style == foundry->styles[k]->key.style) { - if (foundry->name.isEmpty()) - retList.append(f->name); - else - retList.append(f->name + QLatin1String(" [") + foundry->name + QLatin1Char(']')); - break; - } + QString name = foundry->name.isEmpty() + ? f->name + : f->name + QLatin1String(" [") + foundry->name + QLatin1Char(']'); + if (style == foundry->styles[k]->key.style) + preferredFallbacks.append(name); + else + otherFallbacks.append(name); } } } - return retList; + return preferredFallbacks + otherFallbacks; } static void initializeDb(); From b9af823ef7a4131bc61b07620e7825d757df69db Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 18 Oct 2016 13:09:37 +0200 Subject: [PATCH 19/21] qiosfileengineassetslibrary: replace Q_DECL_OVERRIDE with override Change-Id: Iba67e1a1fa86dff3c82543597351b597be69ed1f Reviewed-by: Jake Petroules --- .../qiosfileengineassetslibrary.h | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h index 0e29a1003e3..89696751c60 100644 --- a/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h +++ b/src/plugins/platforms/ios/optional/nsphotolibrarysupport/qiosfileengineassetslibrary.h @@ -45,20 +45,20 @@ public: QIOSFileEngineAssetsLibrary(const QString &fileName); ~QIOSFileEngineAssetsLibrary(); - bool open(QIODevice::OpenMode openMode) Q_DECL_OVERRIDE; - bool close() Q_DECL_OVERRIDE; - FileFlags fileFlags(FileFlags type) const Q_DECL_OVERRIDE; - qint64 size() const Q_DECL_OVERRIDE; - qint64 read(char *data, qint64 maxlen) Q_DECL_OVERRIDE; - qint64 pos() const Q_DECL_OVERRIDE; - bool seek(qint64 pos) Q_DECL_OVERRIDE; - QString fileName(FileName file) const Q_DECL_OVERRIDE; - void setFileName(const QString &file) Q_DECL_OVERRIDE; - QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const Q_DECL_OVERRIDE; + bool open(QIODevice::OpenMode openMode) override; + bool close() override; + FileFlags fileFlags(FileFlags type) const override; + qint64 size() const override; + qint64 read(char *data, qint64 maxlen) override; + qint64 pos() const override; + bool seek(qint64 pos) override; + QString fileName(FileName file) const override; + void setFileName(const QString &file) override; + QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override; #ifndef QT_NO_FILESYSTEMITERATOR - Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) Q_DECL_OVERRIDE; - Iterator *endEntryList() Q_DECL_OVERRIDE; + Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; + Iterator *endEntryList() override; #endif void setError(QFile::FileError error, const QString &str) { QAbstractFileEngine::setError(error, str); } From e8b55a6d2a6e44337b75dd0d116b1b020a437631 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 19 Oct 2016 20:22:10 +0200 Subject: [PATCH 20/21] Document qGuiApp and tweap qApp Change-Id: I2cd865da0e081251a2702c11cb83dde35444693a Reviewed-by: Edward Welbourne --- src/gui/kernel/qguiapplication.cpp | 10 ++++++++++ src/widgets/kernel/qapplication.cpp | 9 +++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 9cbcd714abd..950385f0ceb 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -344,6 +344,16 @@ void QWindowGeometrySpecification::applyTo(QWindow *window) const static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOMETRY_SPECIFICATION_INITIALIZER; +/*! + \macro qGuiApp + \relates QGuiApplication + + A global pointer referring to the unique application object. + Only valid for use when that object is a QGuiApplication. + + \sa QCoreApplication::instance(), qApp +*/ + /*! \class QGuiApplication \brief The QGuiApplication class manages the GUI application's control diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index b64d6e2159e..93ee820c98c 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -4229,13 +4229,10 @@ void QApplication::beep() \relates QApplication A global pointer referring to the unique application object. It is - equivalent to the pointer returned by the QCoreApplication::instance() - function except that, in GUI applications, it is a pointer to a - QApplication instance. + equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, + so only valid when the unique application object is a QApplication. - Only one application object can be created. - - \sa QCoreApplication::instance() + \sa QCoreApplication::instance(), qGuiApp */ /*! From 4e196159077a820e99bc8bd306d31d0ccaa17c57 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 26 Oct 2016 11:19:19 +0200 Subject: [PATCH 21/21] qmacmime: convert UTF-16 using QTextCodec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation of QMacPasteboardMimeUnicodeText didn't contain any logic to handle unicode text with a byte order mark (BOM). According to the docs (*), 'public.utf16-plain-text' can have an optional BOM. Because of that, Qt would fail encoding UTF-16 text from the pasteboard if it had a BOM. Additionally, perhaps because of a bug in iOS 10, UTF-16 text placed on the pasteboard by Qt ends up being encoded wrong by native apps, unless the text has a BOM. Rather than hard-coding UTF-16 encoding/decoding in qmacmime, we now leave it to QTextCodec. QTextCodec will add a BOM by default, and can handle decoding of UTF-16 both with, and without, a BOM. *: https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html Task-number: QTBUG-56229 Change-Id: I3a08deb0262350c67e5622cf23eb3c3a4907ec39 Reviewed-by: Tor Arne Vestbø --- src/platformsupport/clipboard/qmacmime.mm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platformsupport/clipboard/qmacmime.mm b/src/platformsupport/clipboard/qmacmime.mm index 2e3257cfcf2..cdb5d6b08e6 100644 --- a/src/platformsupport/clipboard/qmacmime.mm +++ b/src/platformsupport/clipboard/qmacmime.mm @@ -405,8 +405,7 @@ QVariant QMacPasteboardMimeUnicodeText::convertToMime(const QString &mimetype, Q if (flavor == QLatin1String("public.utf8-plain-text")) { ret = QString::fromUtf8(firstData); } else if (flavor == QLatin1String("public.utf16-plain-text")) { - ret = QString(reinterpret_cast(firstData.constData()), - firstData.size() / sizeof(QChar)); + ret = QTextCodec::codecForName("UTF-16")->toUnicode(firstData); } else { qWarning("QMime::convertToMime: unhandled mimetype: %s", qPrintable(mimetype)); } @@ -420,7 +419,7 @@ QList QMacPasteboardMimeUnicodeText::convertFromMime(const QString & if (flavor == QLatin1String("public.utf8-plain-text")) ret.append(string.toUtf8()); else if (flavor == QLatin1String("public.utf16-plain-text")) - ret.append(QByteArray((char*)string.utf16(), string.length()*2)); + ret.append(QTextCodec::codecForName("UTF-16")->fromUnicode(string)); return ret; }