From 8d3b9841e1732337db67c79571567ac9294b3d7c Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 5 Sep 2018 10:03:00 +0200 Subject: [PATCH 1/7] Cocoa: change background color of selected menu items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change 582d221b29 caused a regression when drawing menu items in e.g a QComboBox. After that change, QCocoaSystemSettings would set the QPalette::Highlight color to [NSColor selectedMenuItemTextColor]. But the Highlight color is the background color, not the text color. And we also use [NSColor selectedMenuItemTextColor] as the QPalette::HighlightedText color. The result is that highlighed menu items end up with the same foreground and background color (white), which means that they "disappear". The color that we used before the patch, alternateSelectedControlColor, could be used, but has the downside that it doesn't follow the appearance color in system settings (like it should, compared to native apps). And it's also slightly to blue. But using keyboardFocusIndicatorColor seems like a perfect match. Fixes: QTBUG-69500 Change-Id: I07f091a5130a7308525743948d2a435226658a6f Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoasystemsettings.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index a6cdf4211f4..60eb8cdf68d 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -169,7 +169,11 @@ QHash qt_mac_createRolePalettes() // Cheap approximation for NSVisualEffectView (see deprecation note for selectedMenuItemTextColor) selectedMenuItemColor = [[NSColor selectedContentBackgroundColor] highlightWithLevel:0.4]; } else { - selectedMenuItemColor = [NSColor selectedMenuItemTextColor]; + // selectedMenuItemColor would presumably be the correct color to use as the background + // for selected menu items. But that color is always blue, and doesn't follow the + // appearance color in system preferences. So we therefore deliberatly choose to use + // keyboardFocusIndicatorColor instead, which appears to have the same color value. + selectedMenuItemColor = [NSColor keyboardFocusIndicatorColor]; } pal.setBrush(QPalette::Highlight, qt_mac_toQColor(selectedMenuItemColor)); qc = qt_mac_toQColor([NSColor labelColor]); From 2dca4ef19c6efccb49477baab57012b1377d1cef Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 9 Jul 2018 15:51:22 -0700 Subject: [PATCH 2/7] CBOR: Add missing clear() methods to the two container classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id59bdd8f1a804b809e22fffd153fd5174b58014d Reviewed-by: Mårten Nordheim Reviewed-by: Edward Welbourne --- src/corelib/serialization/qcborarray.cpp | 12 +++++++++++- src/corelib/serialization/qcborarray.h | 1 + src/corelib/serialization/qcbormap.cpp | 12 +++++++++++- src/corelib/serialization/qcbormap.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/corelib/serialization/qcborarray.cpp b/src/corelib/serialization/qcborarray.cpp index 05403795b05..921fcf2fca4 100644 --- a/src/corelib/serialization/qcborarray.cpp +++ b/src/corelib/serialization/qcborarray.cpp @@ -185,12 +185,22 @@ qsizetype QCborArray::size() const noexcept return d ? d->elements.size() : 0; } +/*! + Empties this array. + + \sa isEmpty() + */ +void QCborArray::clear() +{ + d.reset(); +} + /*! \fn bool QCborArray::isEmpty() const Returns true if this QCborArray is empty (that is if size() is 0). - \sa size() + \sa size(), clear() */ /*! diff --git a/src/corelib/serialization/qcborarray.h b/src/corelib/serialization/qcborarray.h index 6b07b52a02e..f24bb41759c 100644 --- a/src/corelib/serialization/qcborarray.h +++ b/src/corelib/serialization/qcborarray.h @@ -180,6 +180,7 @@ public: qsizetype size() const noexcept; bool isEmpty() const { return size() == 0; } + void clear(); QCborValue at(qsizetype i) const; QCborValue first() const { return at(0); } diff --git a/src/corelib/serialization/qcbormap.cpp b/src/corelib/serialization/qcbormap.cpp index b18945ded1e..33f92499934 100644 --- a/src/corelib/serialization/qcbormap.cpp +++ b/src/corelib/serialization/qcbormap.cpp @@ -270,7 +270,7 @@ QCborMap &QCborMap::operator=(const QCborMap &other) noexcept Returns true if this map is empty (that is, size() is 0). - \sa size() + \sa size(), clear() */ /*! @@ -283,6 +283,16 @@ qsizetype QCborMap::size() const noexcept return d ? d->elements.size() / 2 : 0; } +/*! + Empties this map. + + \sa isEmpty() + */ +void QCborMap::clear() +{ + d.reset(); +} + /*! Returns a list of all keys in this map. diff --git a/src/corelib/serialization/qcbormap.h b/src/corelib/serialization/qcbormap.h index c895abfa591..45ef430e409 100644 --- a/src/corelib/serialization/qcbormap.h +++ b/src/corelib/serialization/qcbormap.h @@ -184,6 +184,7 @@ public: qsizetype size() const noexcept Q_DECL_PURE_FUNCTION; bool isEmpty() const { return size() == 0; } + void clear(); QVector keys() const; QCborValue value(qint64 key) const From 1205f4a2292b9b63d714baeaa17cbf5ff5d8093b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 6 Sep 2018 13:06:20 -0700 Subject: [PATCH 3/7] Moc: use QVector more often It's more optimised and it vectorizes better, due to one level of indirection fewer. Change-Id: I495bc19409f348069f5bfffd1551e85092ed8dc2 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/tools/moc/generator.cpp | 4 ++-- src/tools/moc/generator.h | 6 +++--- src/tools/moc/moc.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index e499d226189..9fb980893f0 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -80,7 +80,7 @@ QT_FOR_EACH_STATIC_TYPE(RETURN_METATYPENAME_STRING) return 0; } -Generator::Generator(ClassDef *classDef, const QList &metaTypes, const QHash &knownQObjectClasses, const QHash &knownGadgets, FILE *outfile) +Generator::Generator(ClassDef *classDef, const QVector &metaTypes, const QHash &knownQObjectClasses, const QHash &knownGadgets, FILE *outfile) : out(outfile), cdef(classDef), metaTypes(metaTypes), knownQObjectClasses(knownQObjectClasses) , knownGadgets(knownGadgets) { @@ -461,7 +461,7 @@ void Generator::generateCode() // // Build extra array // - QList extraList; + QVector extraList; QHash knownExtraMetaObject = knownGadgets; knownExtraMetaObject.unite(knownQObjectClasses); diff --git a/src/tools/moc/generator.h b/src/tools/moc/generator.h index 8b801383021..134166580b5 100644 --- a/src/tools/moc/generator.h +++ b/src/tools/moc/generator.h @@ -39,7 +39,7 @@ class Generator ClassDef *cdef; QVector meta_data; public: - Generator(ClassDef *classDef, const QList &metaTypes, const QHash &knownQObjectClasses, const QHash &knownGadgets, FILE *outfile = 0); + Generator(ClassDef *classDef, const QVector &metaTypes, const QHash &knownQObjectClasses, const QHash &knownGadgets, FILE *outfile = 0); void generateCode(); private: bool registerableMetaType(const QByteArray &propertyType); @@ -64,9 +64,9 @@ private: void strreg(const QByteArray &); // registers a string int stridx(const QByteArray &); // returns a string's id - QList strings; + QVector strings; QByteArray purestSuperClass; - QList metaTypes; + QVector metaTypes; QHash knownQObjectClasses; QHash knownGadgets; }; diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 56763c5e590..d98c73e1a0f 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -65,7 +65,7 @@ struct EnumDef { QByteArray name; QByteArray enumName; - QList values; + QVector values; bool isEnumClass; // c++11 enum class EnumDef() : isEnumClass(false) {} }; @@ -207,10 +207,10 @@ public: bool noInclude; bool mustIncludeQPluginH; QByteArray includePath; - QList includeFiles; + QVector includeFiles; QVector classList; QMap interface2IdMap; - QList metaTypes; + QVector metaTypes; // map from class name to fully qualified name QHash knownQObjectClasses; QHash knownGadgets; From 8b3a6cfbfb21a71b8efc2e3a91006712238db6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 4 Sep 2018 15:54:18 +0200 Subject: [PATCH 4/7] Update QOpenGLContext::currentContext after QPlatformOpenGLContext::makeCurrent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of doing it up front and then restoring the current context if the makeCurrent call failed. By delaying the update, QPlatformOpenGLContext::makeCurrent has the option to check which context was current before the call. Change-Id: I458f5c00d7c820acbe2f8552b0513fce99b9b683 Reviewed-by: Morten Johan Sørvig Reviewed-by: Laszlo Agocs --- src/gui/kernel/qopenglcontext.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index d64d31a9e84..c5d5490ea0f 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -984,11 +984,15 @@ bool QOpenGLContext::makeCurrent(QSurface *surface) #endif } - QOpenGLContext *previous = QOpenGLContextPrivate::setCurrentContext(this); - if (!d->platformGLContext->makeCurrent(surface->surfaceHandle())) { - QOpenGLContextPrivate::setCurrentContext(previous); + if (!d->platformGLContext->makeCurrent(surface->surfaceHandle())) return false; - } + + QOpenGLContextPrivate::setCurrentContext(this); +#ifndef QT_NO_DEBUG + QOpenGLContextPrivate::toggleMakeCurrentTracker(this, true); +#endif + + d->surface = surface; static bool needsWorkaroundSet = false; static bool needsWorkaround = false; @@ -1030,14 +1034,8 @@ bool QOpenGLContext::makeCurrent(QSurface *surface) if (needsWorkaround) d->workaround_brokenFBOReadBack = true; - d->surface = surface; - d->shareGroup->d_func()->deletePendingResources(this); -#ifndef QT_NO_DEBUG - QOpenGLContextPrivate::toggleMakeCurrentTracker(this, true); -#endif - return true; } From cd499b72973a4a01d12e2e3ba66e7e16ac1feeb4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 30 Aug 2018 20:08:12 +0200 Subject: [PATCH 5/7] QLayout: Better document QLayout(QWidget *parent) behavior QLayout(QWidget *parent) directly calls parent->setLayout(this) which can lead to a runtime warning later on when someone tries to set the layout on the parent again. Task-number: QTBUG-69761 Change-Id: I21ef8895fd65f3e23e57527a6d38936e45417b63 Reviewed-by: Paul Wicking Reviewed-by: Venugopal Shivashankar --- src/widgets/kernel/qlayout.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 80ea27fee84..eac56741612 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -109,10 +109,11 @@ static int menuBarHeightForWidth(QWidget *menubar, int w) /*! Constructs a new top-level QLayout, with parent \a parent. - \a parent may not be 0. + \a parent may not be a \c nullptr. - There can be only one top-level layout for a widget. It is - returned by QWidget::layout(). + The layout is set directly as the top-level layout for + \a parent. There can be only one top-level layout for a + widget. It is returned by QWidget::layout(). */ QLayout::QLayout(QWidget *parent) : QObject(*new QLayoutPrivate, parent) From ef40cad3a974242cc8f9167288a8804239586669 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 30 Aug 2018 19:47:05 +0200 Subject: [PATCH 6/7] QTableView: Fix PageUp not getting to top when first row is hidden When the first row(s) of a QTableView is hidden, PageUp could not reach the first visible row because logicalRow(0) is taken without checking if the row is visible. Task-number: QTBUG-70215 Change-Id: Ic7820352b8988accb685ea7d16908d3fa8bf2847 Reviewed-by: Friedemann Kleint Reviewed-by: Luca Beldi Reviewed-by: Richard Moe Gustavsen Reviewed-by: David Faure --- src/widgets/itemviews/qtableview.cpp | 8 ++++++-- .../auto/widgets/itemviews/qtableview/tst_qtableview.cpp | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 9c2b3e5b54c..9725a768de7 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1816,8 +1816,12 @@ QModelIndex QTableView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifi break; case MovePageUp: { int newRow = rowAt(visualRect(current).bottom() - d->viewport->height()); - if (newRow == -1) - newRow = d->logicalRow(0); + if (newRow == -1) { + int visualRow = 0; + while (visualRow < bottom && isRowHidden(d->logicalRow(visualRow))) + ++visualRow; + newRow = d->logicalRow(visualRow); + } return d->model->index(newRow, current.column(), d->root); } case MovePageDown: { diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index e1ec38b4e79..228d03350a6 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -1353,6 +1353,11 @@ void tst_QTableView::moveCursorBiggerJump() QCOMPARE(view.indexAt(QPoint(0,0)), model.index(7,0)); QTest::keyClick(&view, Qt::Key_PageUp); QCOMPARE(view.indexAt(QPoint(0,0)), model.index(0,0)); + + QTest::keyClick(&view, Qt::Key_PageDown); + view.verticalHeader()->hideSection(0); + QTest::keyClick(&view, Qt::Key_PageUp); + QTRY_COMPARE(view.currentIndex().row(), view.rowAt(0)); } void tst_QTableView::hideRows_data() From 85917c4b72a498e86d6dd057a5b6df26c0565fc4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 7 Sep 2018 22:15:47 +0200 Subject: [PATCH 7/7] Autotests/QItemView: re-enable tst_QItemView::indexAt() tst_QItemView::indexAt() was disabled since Qt 5.0 (and maybe earlier) maybe due to it's long runtime (15s on my machine). Speed it up by checking only some special positions inside the visual rect (borders, center) as it will likely not fail on other positions but succeed for the ones which get tested. Task-number: QTBUG-22470 Change-Id: I5c7135757049176f9daca4afc1b7f40c75b9ecd9 Reviewed-by: David Faure --- .../itemviews/qitemview/tst_qitemview.cpp | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp index afd6d84486e..bbdaac5c6ff 100644 --- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp +++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp @@ -546,23 +546,26 @@ void tst_QItemView::walkScreen(QAbstractItemView *view) } } -void walkIndex(QModelIndex index, QAbstractItemView *view) +void walkIndex(const QModelIndex &index, const QAbstractItemView *view) { - QRect visualRect = view->visualRect(index); - //if (index.column() == 0) - //qDebug() << index << visualRect; - int width = visualRect.width(); - int height = visualRect.height(); + const QRect visualRect = view->visualRect(index); + const int width = visualRect.width(); + const int height = visualRect.height(); - for (int w = 0; w < width; ++w) + if (width == 0 || height == 0) + return; + + const auto widths = (width < 2) ? QVector({ 0, 1 }) : QVector({ 0, 1, width / 2, width - 2, width - 1 }); + const auto heights = (height < 2) ? QVector({ 0, 1 }) : QVector({ 0, 1, height / 2, height - 2, height - 1 }); + for (int w : widths) { - for (int h = 0; h < height; ++h) + for (int h : heights) { - QPoint point(visualRect.x()+w, visualRect.y()+h); - if (view->indexAt(point) != index) { + const QPoint point(visualRect.x() + w, visualRect.y() + h); + const auto idxAt = view->indexAt(point); + if (idxAt != index) qDebug() << "index" << index << "visualRect" << visualRect << point << view->indexAt(point); - } - QCOMPARE(view->indexAt(point), index); + QCOMPARE(idxAt, index); } } @@ -579,7 +582,7 @@ void walkIndex(QModelIndex index, QAbstractItemView *view) a bug it will point it out, but the above tests should have already found the basic bugs because it is easier to figure out the problem in those tests then this one. */ -void checkChildren(QAbstractItemView *currentView, const QModelIndex &parent = QModelIndex(), int currentDepth=0) +void checkChildren(const QAbstractItemView *currentView, const QModelIndex &parent = QModelIndex(), int currentDepth = 0) { QAbstractItemModel *currentModel = currentView->model(); @@ -623,7 +626,6 @@ void tst_QItemView::indexAt() view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->show(); view->setModel(treeModel); -#if 0 checkChildren(view); QModelIndex index = view->model()->index(0, 0); @@ -636,7 +638,6 @@ void tst_QItemView::indexAt() QPoint p(1, view->height()/2); QModelIndex idx = view->indexAt(p); QCOMPARE(idx, QModelIndex()); -#endif } void tst_QItemView::scrollTo_data()