From 37a1478787d64b34a0716421c8a47f3246e41bfd Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 20 Oct 2017 11:07:59 +0700 Subject: Cocoa QPA: Code clean up, make some bits more readable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7f37c1b0f7f72a79bb2ac5828ba54111a90a0a00 Reviewed-by: Jake Petroules Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/messages.cpp | 2 +- src/plugins/platforms/cocoa/messages.h | 11 +++++++++++ src/plugins/platforms/cocoa/qcocoamenuitem.mm | 10 +++------- src/plugins/platforms/cocoa/qcocoamenuloader.mm | 20 +++++++------------- 4 files changed, 22 insertions(+), 21 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/messages.cpp b/src/plugins/platforms/cocoa/messages.cpp index 85b814ce1c..8eea1e654e 100644 --- a/src/plugins/platforms/cocoa/messages.cpp +++ b/src/plugins/platforms/cocoa/messages.cpp @@ -75,7 +75,7 @@ QString qt_mac_applicationmenu_string(int type) QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption) { QString captionNoAmpersand(caption); - captionNoAmpersand.remove(QChar('&')); + captionNoAmpersand.remove(QLatin1Char('&')); const QString aboutString = QCoreApplication::translate("QCocoaMenuItem", "About"); if (captionNoAmpersand.startsWith(aboutString, Qt::CaseInsensitive) || caption.endsWith(aboutString, Qt::CaseInsensitive)) return QPlatformMenuItem::AboutRole; diff --git a/src/plugins/platforms/cocoa/messages.h b/src/plugins/platforms/cocoa/messages.h index a9c9cc42e5..e41898fe59 100644 --- a/src/plugins/platforms/cocoa/messages.h +++ b/src/plugins/platforms/cocoa/messages.h @@ -45,6 +45,17 @@ QT_BEGIN_NAMESPACE +enum { + ServicesAppMenuItem = 0, + HideAppMenuItem, + HideOthersAppMenuItem, + ShowAllAppMenuItem, + PreferencesAppMenuItem, + QuitAppMenuItem, + AboutAppMenuItem +}; + + QString msgAboutQt(); QString qt_mac_applicationmenu_string(int type); diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 21f2b4de85..ecbab38a83 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -370,24 +370,20 @@ NSMenuItem *QCocoaMenuItem::sync() return m_native; } -QT_BEGIN_NAMESPACE -extern QString qt_mac_applicationmenu_string(int type); -QT_END_NAMESPACE - QString QCocoaMenuItem::mergeText() { QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader]; if (m_native == [loader aboutMenuItem]) { - return qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName()); + return qt_mac_applicationmenu_string(AboutAppMenuItem).arg(qt_mac_applicationName()); } else if (m_native== [loader aboutQtMenuItem]) { if (m_text == QString("About Qt")) return msgAboutQt(); else return m_text; } else if (m_native == [loader preferencesMenuItem]) { - return qt_mac_applicationmenu_string(4); + return qt_mac_applicationmenu_string(PreferencesAppMenuItem); } else if (m_native == [loader quitMenuItem]) { - return qt_mac_applicationmenu_string(5).arg(qt_mac_applicationName()); + return qt_mac_applicationmenu_string(QuitAppMenuItem).arg(qt_mac_applicationName()); } else if (m_text.contains('\t')) { return m_text.left(m_text.indexOf('\t')); } diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index 01a3c04afb..0d9bb5009d 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -47,14 +47,8 @@ #include #include #include -#include -#include -#include #include -QT_FORWARD_DECLARE_CLASS(QCFString) -QT_FORWARD_DECLARE_CLASS(QString) - @implementation QCocoaMenuLoader + (instancetype)sharedMenuLoader @@ -314,13 +308,13 @@ QT_FORWARD_DECLARE_CLASS(QString) { #ifndef QT_NO_TRANSLATION - [servicesItem setTitle:qt_mac_applicationmenu_string(0).toNSString()]; - [hideItem setTitle:qt_mac_applicationmenu_string(1).arg(qt_mac_applicationName()).toNSString()]; - [hideAllOthersItem setTitle:qt_mac_applicationmenu_string(2).toNSString()]; - [showAllItem setTitle:qt_mac_applicationmenu_string(3).toNSString()]; - [preferencesItem setTitle:qt_mac_applicationmenu_string(4).toNSString()]; - [quitItem setTitle:qt_mac_applicationmenu_string(5).arg(qt_mac_applicationName()).toNSString()]; - [aboutItem setTitle:qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName()).toNSString()]; + [servicesItem setTitle:qt_mac_applicationmenu_string(ServicesAppMenuItem).toNSString()]; + [hideItem setTitle:qt_mac_applicationmenu_string(HideAppMenuItem).arg(qt_mac_applicationName()).toNSString()]; + [hideAllOthersItem setTitle:qt_mac_applicationmenu_string(HideOthersAppMenuItem).toNSString()]; + [showAllItem setTitle:qt_mac_applicationmenu_string(ShowAllAppMenuItem).toNSString()]; + [preferencesItem setTitle:qt_mac_applicationmenu_string(PreferencesAppMenuItem).toNSString()]; + [quitItem setTitle:qt_mac_applicationmenu_string(QuitAppMenuItem).arg(qt_mac_applicationName()).toNSString()]; + [aboutItem setTitle:qt_mac_applicationmenu_string(AboutAppMenuItem).arg(qt_mac_applicationName()).toNSString()]; #endif } -- cgit v1.2.3 From ecd183455b8039ee15b9d51fd1111992af19ed1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Wed, 11 Oct 2017 11:35:42 +0200 Subject: Refactor childIdListForAccessibleObject It has several problems: 1. It could potentially create an intArray with uninitialized elements. This could happen because the index for getting interfaces were the same as the storage index. This was not correct, because they could diverge if iface->child() returned an invalid interface. 2. The count of accessible child elements could change while iterating. This could cause out-of-bounds condition when calling SetIntArrayRegion as described in QTBUG-45855. Instead now, we call SetIntArrayRegion only once, after we have gathered all the child interface ids. Task-number: QTBUG-45855 Change-Id: I77e813158df5f563d04931ac4e296e3fc2a16e67 Reviewed-by: Frederik Gladhorn --- src/plugins/platforms/android/androidjniaccessibility.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/android/androidjniaccessibility.cpp b/src/plugins/platforms/android/androidjniaccessibility.cpp index e4d670239f..a3bc58bb89 100644 --- a/src/plugins/platforms/android/androidjniaccessibility.cpp +++ b/src/plugins/platforms/android/androidjniaccessibility.cpp @@ -105,15 +105,15 @@ namespace QtAndroidAccessibility { QAccessibleInterface *iface = interfaceFromId(objectId); if (iface && iface->isValid()) { - jintArray jArray = env->NewIntArray(jsize(iface->childCount())); - for (int i = 0; i < iface->childCount(); ++i) { + const int childCount = iface->childCount(); + QVarLengthArray ifaceIdArray(childCount); + for (int i = 0; i < childCount; ++i) { QAccessibleInterface *child = iface->child(i); - if (child && child->isValid()) { - QAccessible::Id ifaceId = QAccessible::uniqueId(child); - jint jid = ifaceId; - env->SetIntArrayRegion(jArray, i, 1, &jid); - } + if (child && child->isValid()) + ifaceIdArray.append(QAccessible::uniqueId(child)); } + jintArray jArray = env->NewIntArray(jsize(ifaceIdArray.count())); + env->SetIntArrayRegion(jArray, 0, ifaceIdArray.count(), ifaceIdArray.data()); return jArray; } -- cgit v1.2.3 From 5eb508a31717c75d804cfb55e46e867c19ae58d2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 18 Oct 2017 15:34:52 +0200 Subject: Fix clazy-strict-iterators Change-Id: I9276a85f0a8061b2636687cf694b8ed1abaa18b8 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../platforminputcontexts/compose/qcomposeplatforminputcontext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp index 6016d460fc..48693ccdb0 100644 --- a/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp +++ b/src/plugins/platforminputcontexts/compose/qcomposeplatforminputcontext.cpp @@ -222,7 +222,7 @@ bool QComposeInputContext::checkComposeTable() int next = 1; do { // if we are at the end of the table, then we have nothing to do here - if (it + next != m_composeTable.end()) { + if (it + next != m_composeTable.constEnd()) { QComposeTableElement nextElem = *(it + next); if (isDuplicate(elem, nextElem)) { elem = nextElem; -- cgit v1.2.3 From 9f0dda29d5d070f63b7f098139f01f07ec91ffdf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Oct 2017 10:24:19 +0200 Subject: Windows QPA: Restrict warning about geometry failure Print warning only for visible windows or in debug mode. Task-number: QTBUG-63661 Change-Id: I742c86afcb40455074a6de753b0b1ce6a11d55af Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowswindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 16c2e16d64..402009c70d 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -66,6 +66,7 @@ #include #include +#include #include @@ -1473,7 +1474,7 @@ void QWindowsWindow::setGeometry(const QRect &rectIn) // achieve that size (for example, window title minimal constraint), // notify and warn. setGeometry_sys(rect); - if (m_data.geometry != rect) { + if (m_data.geometry != rect && (isVisible() || QLibraryInfo::isDebugBuild())) { qWarning("%s: Unable to set geometry %dx%d+%d+%d on %s/'%s'." " Resulting geometry: %dx%d+%d+%d " "(frame: %d, %d, %d, %d, custom margin: %d, %d, %d, %d" -- cgit v1.2.3 From 3a92f7cf4f1abd7ad91bdfc7251b1f3e82bdf89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Oct 2017 15:43:30 +0200 Subject: macOS: Retain NSWindow during event delivery We have logic to deal with self.platformWindow and frame strut mouse events which happens after delivering the event to the NSWindow, but delivering it might dealloc the window, e.g. when closing it, so we need to explicitly retain it for the duration of [QNSWindow sendEvent:] Task-number: QTBUG-64023 Change-Id: I223fe3e3ac36a309da375522ba11f20f1ad6fc4f Reviewed-by: Timur Pocheptsov Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qnswindow.mm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 799704a407..5213008bd4 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -185,6 +185,10 @@ static bool isMouseEvent(NSEvent *ev) if (!self.platformWindow) return; + // Prevent deallocation of this NSWindow during event delivery, as we + // have logic further below that depends on the window being alive. + [[self retain] autorelease]; + const char *eventType = object_getClassName(theEvent); if (QWindowSystemInterface::handleNativeEvent(self.platformWindow->window(), QByteArray::fromRawData(eventType, qstrlen(eventType)), theEvent, nullptr)) { @@ -221,6 +225,7 @@ static bool isMouseEvent(NSEvent *ev) #pragma clang diagnostic ignored "-Wobjc-missing-super-calls" - (void)dealloc { + qCDebug(lcQpaCocoaWindow) << "dealloc" << self; qt_objcDynamicSuper(); } #pragma clang diagnostic pop -- cgit v1.2.3 From f4090b23b98c132c47237e4695bc4dc93170cbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Oct 2017 13:05:49 +0200 Subject: macOS: Add categorized logging of event and notification forwarding Useful for debugging issues in this area. Change-Id: Ic343ef790e20b66371028265efe2ec1816c954bd Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoawindow.mm | 17 ++++++++++++++++- src/plugins/platforms/cocoa/qnswindow.mm | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index ed942af1b1..af44564968 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -79,6 +79,8 @@ static void qt_closePopups() } } +Q_LOGGING_CATEGORY(lcCocoaNotifications, "qt.qpa.cocoa.notifications"); + static void qRegisterNotificationCallbacks() { static const QLatin1String notificationHandlerPrefix(Q_NOTIFICATION_PREFIX); @@ -110,11 +112,24 @@ static void qRegisterNotificationCallbacks() if (QNSView *qnsView = qnsview_cast(notification.object)) cocoaWindows += qnsView.platformWindow; } else { - qCWarning(lcQpaCocoaWindow) << "Unhandled notifcation" + qCWarning(lcCocoaNotifications) << "Unhandled notifcation" << notification.name << "for" << notification.object; return; } + if (lcCocoaNotifications().isDebugEnabled()) { + if (cocoaWindows.isEmpty()) { + qCDebug(lcCocoaNotifications) << "Could not find forwarding target for" << + qPrintable(notificationName) << "from" << notification.object; + } else { + QVector debugWindows; + for (QCocoaWindow *cocoaWindow : cocoaWindows) + debugWindows += cocoaWindow; + qCDebug(lcCocoaNotifications) << "Forwarding" << qPrintable(notificationName) << + "to" << debugWindows; + } + } + // FIXME: Could be a foreign window, look up by iterating top level QWindows for (QCocoaWindow *cocoaWindow : cocoaWindows) { diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index 5213008bd4..e846fa043c 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -46,6 +46,8 @@ #include #include +Q_LOGGING_CATEGORY(lcCocoaEvents, "qt.qpa.cocoa.events"); + static bool isMouseEvent(NSEvent *ev) { switch ([ev type]) { @@ -116,6 +118,22 @@ static bool isMouseEvent(NSEvent *ev) return qnsview_cast(self.contentView).platformWindow; } +- (NSString *)description +{ + NSMutableString *description = [NSMutableString stringWithString:qt_objcDynamicSuper()]; + +#ifndef QT_NO_DEBUG_STREAM + QString contentViewDescription; + QDebug debug(&contentViewDescription); + debug.nospace() << "; contentView=" << qnsview_cast(self.contentView) << ">"; + + NSRange lastCharacter = [description rangeOfComposedCharacterSequenceAtIndex:description.length - 1]; + [description replaceCharactersInRange:lastCharacter withString:contentViewDescription.toNSString()]; +#endif + + return description; +} + - (BOOL)canBecomeKeyWindow { QCocoaWindow *pw = self.platformWindow; @@ -177,6 +195,8 @@ static bool isMouseEvent(NSEvent *ev) - (void)sendEvent:(NSEvent*)theEvent { + qCDebug(lcCocoaEvents) << "Sending" << theEvent << "to" << self; + // We might get events for a NSWindow after the corresponding platform // window has been deleted, as the NSWindow can outlive the QCocoaWindow // e.g. if being retained by other parts of AppKit, or in an auto-release -- cgit v1.2.3 From 2b7cf045bfbfa5d379698fdc18a3d200487a9457 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 30 Oct 2017 15:27:57 +0100 Subject: Replace includes with qglobal.h Nothing (except the *global*.h headers themselves) is supposed to include the generated *config*.h files directly. The QtConfig forwarding header should not exist in the first place. Change-Id: I5e9edd25d905582381cdc6386804c1f3ef8716ae Reviewed-by: Oswald Buddenhagen --- src/plugins/platforms/windows/accessible/iaccessible2.cpp | 2 +- src/plugins/platforms/windows/accessible/iaccessible2.h | 2 +- src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp | 2 +- src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp | 2 +- src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h | 3 +-- 5 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp index 9239facb0c..75af65b5ab 100644 --- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp +++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp @@ -36,7 +36,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include +#include #ifndef QT_NO_ACCESSIBILITY #include "iaccessible2.h" diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.h b/src/plugins/platforms/windows/accessible/iaccessible2.h index e56106f247..d987016e15 100644 --- a/src/plugins/platforms/windows/accessible/iaccessible2.h +++ b/src/plugins/platforms/windows/accessible/iaccessible2.h @@ -39,7 +39,7 @@ #ifndef IACCESSIBLE2_H #define IACCESSIBLE2_H -#include +#include #ifndef QT_NO_ACCESSIBILITY #include "qwindowscombase.h" diff --git a/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp b/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp index e214d47137..d48cb9674f 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp +++ b/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include +#include #ifndef QT_NO_ACCESSIBILITY diff --git a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp index 47b179250a..fe2b9335cb 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp +++ b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include +#include #ifndef QT_NO_ACCESSIBILITY #include "qwindowsmsaaaccessible.h" diff --git a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h index e654f262da..5380fc2411 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h +++ b/src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h @@ -39,9 +39,8 @@ #ifndef QWINDOWSMSAAACCESSIBLE_H #define QWINDOWSMSAAACCESSIBLE_H -#include -#ifndef QT_NO_ACCESSIBILITY #include +#ifndef QT_NO_ACCESSIBILITY #include #include -- cgit v1.2.3 From d366d6dfd30de6e6f83afc807a4648f008b396e5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Oct 2017 13:21:22 +0200 Subject: Windows QPA: Restrict file dialog to file system items in Directory mode Qt cannot handle places like 'Network', etc. Task-number: QTBUG-63645 Change-Id: I53d0eedc2996af6a1ec3230e3d65a3e272aa3710 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsdialoghelpers.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index f4527bcc60..75ca090cef 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -1010,7 +1010,9 @@ void QWindowsNativeFileDialogBase::setMode(QFileDialogOptions::FileMode mode, break; case QFileDialogOptions::Directory: case QFileDialogOptions::DirectoryOnly: - flags |= FOS_PICKFOLDERS | FOS_FILEMUSTEXIST; + // QTBUG-63645: Restrict to file system items, as Qt cannot deal with + // places like 'Network', etc. + flags |= FOS_PICKFOLDERS | FOS_FILEMUSTEXIST | FOS_FORCEFILESYSTEM; break; case QFileDialogOptions::ExistingFiles: flags |= FOS_FILEMUSTEXIST | FOS_ALLOWMULTISELECT; @@ -1219,6 +1221,8 @@ void QWindowsNativeFileDialogBase::onSelectionChange() { const QList current = selectedFiles(); m_data.setSelectedFiles(current); + qDebug() << __FUNCTION__ << current << current.size(); + if (current.size() == 1) emit currentChanged(current.front()); } -- cgit v1.2.3 From b4ac5525612812dd411c93e671813d079a152e57 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Oct 2017 13:28:44 +0200 Subject: Windows QPA: Pass on Url of non-filesystem directory items Do not attempt to copy directory items, which will fail and result in empty result lists. Amends 5865e582fd537fff530c13301e5229a7b4ed21c7. Task-number: QTBUG-57070 Task-number: QTBUG-63645 Change-Id: I59efce196b28099ec8aff5a802ef0a4d9a098453 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsdialoghelpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index 75ca090cef..4b08528d17 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -1419,7 +1419,7 @@ QList QWindowsNativeOpenFileDialog::dialogResult() const for (IShellItem *item : QWindowsShellItem::itemsFromItemArray(items)) { QWindowsShellItem qItem(item); const QString path = qItem.path(); - if (path.isEmpty()) { + if (path.isEmpty() && !qItem.isDir()) { const QString temporaryCopy = createTemporaryItemCopy(qItem); if (temporaryCopy.isEmpty()) qWarning() << "Unable to create a local copy of" << qItem; -- cgit v1.2.3 From 8ba1f91d4eed03be09046bf4ef81944787316ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 26 Oct 2017 10:06:10 +0200 Subject: macOS: Add logging of screen add/remove/changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic9c9ac307441dde98bb43d656466a03805746917 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaintegration.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoascreen.h | 4 ++++ src/plugins/platforms/cocoa/qcocoascreen.mm | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index dd17848109..d185905782 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -222,6 +222,8 @@ QCocoaIntegration::Options QCocoaIntegration::options() const return mOptions; } +Q_LOGGING_CATEGORY(lcCocoaScreen, "qt.qpa.cocoa.screens"); + /*! \brief Synchronizes the screen list, adds new screens, removes deleted ones */ @@ -261,9 +263,11 @@ void QCocoaIntegration::updateScreens() if (screen) { remainingScreens.remove(screen); screen->updateGeometry(); + qCDebug(lcCocoaScreen) << "Updated properties of" << screen; } else { screen = new QCocoaScreen(i); mScreens.append(screen); + qCDebug(lcCocoaScreen) << "Adding" << screen; screenAdded(screen); } siblings << screen; @@ -280,6 +284,7 @@ void QCocoaIntegration::updateScreens() mScreens.removeOne(screen); // Prevent stale references to NSScreen during destroy screen->m_screenIndex = -1; + qCDebug(lcCocoaScreen) << "Removing" << screen; destroyScreen(screen); } } diff --git a/src/plugins/platforms/cocoa/qcocoascreen.h b/src/plugins/platforms/cocoa/qcocoascreen.h index eb17efa937..937002f493 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.h +++ b/src/plugins/platforms/cocoa/qcocoascreen.h @@ -102,6 +102,10 @@ public: QList m_siblings; }; +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug debug, const QCocoaScreen *screen); +#endif + QT_END_NAMESPACE #endif diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index 13e5220b6a..f523873bde 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -275,4 +275,22 @@ QCocoaScreen *QCocoaScreen::primaryScreen() return static_cast(QGuiApplication::primaryScreen()->handle()); } +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug debug, const QCocoaScreen *screen) +{ + QDebugStateSaver saver(debug); + debug.nospace(); + debug << "QCocoaScreen(" << (const void *)screen; + if (screen) { + debug << ", index=" << screen->m_screenIndex; + debug << ", native=" << screen->nativeScreen(); + debug << ", geometry=" << screen->geometry(); + debug << ", dpr=" << screen->devicePixelRatio(); + debug << ", name=" << screen->name(); + } + debug << ')'; + return debug; +} +#endif // !QT_NO_DEBUG_STREAM + QT_END_NAMESPACE -- cgit v1.2.3 From 435c4b2ccbbb7284918dd2d4a14f8e44c3977d98 Mon Sep 17 00:00:00 2001 From: Robert Szefner Date: Fri, 20 Oct 2017 22:51:07 +0200 Subject: QPSQL: Fix detection of PostreSQL version 9.x and later Fixed parsing version string for PostgreSQL. PostgreSQL versioning changed since version 10, see link: https://www.postgresql.org/support/versioning Extended QPSQLDriver::Protocol enum for PostreSQL 9.x and later, added underscore to item names to separate major and minor version. Changed long switch-case statements to if-else. Change-Id: Ib19ae7ba426f262e80c52670e7ecb3532ff460a0 Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 182 +++++++++++++++--------------- src/plugins/sqldrivers/psql/qsql_psql_p.h | 24 ++-- 2 files changed, 108 insertions(+), 98 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index acadc830b2..f650e4cca8 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -187,7 +187,7 @@ public: void QPSQLDriverPrivate::appendTables(QStringList &tl, QSqlQuery &t, QChar type) { QString query; - if (pro >= QPSQLDriver::Version73) { + if (pro >= QPSQLDriver::Version7_3) { query = QString::fromLatin1("select pg_class.relname, pg_namespace.nspname from pg_class " "left join pg_namespace on (pg_class.relnamespace = pg_namespace.oid) " "where (pg_class.relkind = '%1') and (pg_class.relname !~ '^Inv') " @@ -525,7 +525,7 @@ int QPSQLResult::numRowsAffected() QVariant QPSQLResult::lastInsertId() const { Q_D(const QPSQLResult); - if (d->drv_d_func()->pro >= QPSQLDriver::Version81) { + if (d->drv_d_func()->pro >= QPSQLDriver::Version8_1) { QSqlQuery qry(driver()->createResult()); // Most recent sequence value obtained from nextval if (qry.exec(QLatin1String("SELECT lastval();")) && qry.next()) @@ -697,7 +697,7 @@ void QPSQLDriverPrivate::detectBackslashEscape() { // standard_conforming_strings option introduced in 8.2 // http://www.postgresql.org/docs/8.2/static/runtime-config-compatible.html - if (pro < QPSQLDriver::Version82) { + if (pro < QPSQLDriver::Version8_2) { hasBackslashEscape = true; } else { hasBackslashEscape = false; @@ -719,11 +719,11 @@ static QPSQLDriver::Protocol qMakePSQLVersion(int vMaj, int vMin) { switch (vMin) { case 1: - return QPSQLDriver::Version71; + return QPSQLDriver::Version7_1; case 3: - return QPSQLDriver::Version73; + return QPSQLDriver::Version7_3; case 4: - return QPSQLDriver::Version74; + return QPSQLDriver::Version7_4; default: return QPSQLDriver::Version7; } @@ -733,76 +733,109 @@ static QPSQLDriver::Protocol qMakePSQLVersion(int vMaj, int vMin) { switch (vMin) { case 1: - return QPSQLDriver::Version81; + return QPSQLDriver::Version8_1; case 2: - return QPSQLDriver::Version82; + return QPSQLDriver::Version8_2; case 3: - return QPSQLDriver::Version83; + return QPSQLDriver::Version8_3; case 4: - return QPSQLDriver::Version84; + return QPSQLDriver::Version8_4; default: return QPSQLDriver::Version8; } break; } case 9: - return QPSQLDriver::Version9; + { + switch (vMin) { + case 1: + return QPSQLDriver::Version9_1; + case 2: + return QPSQLDriver::Version9_2; + case 3: + return QPSQLDriver::Version9_3; + case 4: + return QPSQLDriver::Version9_4; + case 5: + return QPSQLDriver::Version9_5; + case 6: + return QPSQLDriver::Version9_6; + default: + return QPSQLDriver::Version9; + } break; + } + case 10: + return QPSQLDriver::Version10; default: + if (vMaj > 10) + return QPSQLDriver::UnknownLaterVersion; break; } return QPSQLDriver::VersionUnknown; } +static QPSQLDriver::Protocol qFindPSQLVersion(const QString &versionString) +{ + const QRegExp rx(QStringLiteral("(\\d+)(?:\\.(\\d+))?")); + if (rx.indexIn(versionString) != -1) { + // Beginning with PostgreSQL version 10, a major release is indicated by + // increasing the first part of the version, e.g. 10 to 11. + // Before version 10, a major release was indicated by increasing either + // the first or second part of the version number, e.g. 9.5 to 9.6. + int vMaj = rx.cap(1).toInt(); + int vMin; + if (vMaj >= 10) { + vMin = 0; + } else { + if (rx.cap(2).isEmpty()) + return QPSQLDriver::VersionUnknown; + vMin = rx.cap(2).toInt(); + } + return qMakePSQLVersion(vMaj, vMin); + } + + return QPSQLDriver::VersionUnknown; +} + QPSQLDriver::Protocol QPSQLDriverPrivate::getPSQLVersion() { QPSQLDriver::Protocol serverVersion = QPSQLDriver::Version6; PGresult* result = exec("select version()"); int status = PQresultStatus(result); if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK) { - QString val = QString::fromLatin1(PQgetvalue(result, 0, 0)); - - QRegExp rx(QLatin1String("(\\d+)\\.(\\d+)")); - rx.setMinimal(true); // enforce non-greedy RegExp + serverVersion = qFindPSQLVersion( + QString::fromLatin1(PQgetvalue(result, 0, 0))); + } + PQclear(result); - if (rx.indexIn(val) != -1) { - int vMaj = rx.cap(1).toInt(); - int vMin = rx.cap(2).toInt(); - serverVersion = qMakePSQLVersion(vMaj, vMin); + QPSQLDriver::Protocol clientVersion = #if defined(PG_MAJORVERSION) - if (rx.indexIn(QLatin1String(PG_MAJORVERSION)) != -1) + qFindPSQLVersion(QLatin1String(PG_MAJORVERSION)); #elif defined(PG_VERSION) - if (rx.indexIn(QLatin1String(PG_VERSION)) != -1) + qFindPSQLVersion(QLatin1String(PG_VERSION)); #else - if (0) + QPSQLDriver::VersionUnknown; #endif - { - vMaj = rx.cap(1).toInt(); - vMin = rx.cap(2).toInt(); - QPSQLDriver::Protocol clientVersion = qMakePSQLVersion(vMaj, vMin); - - if (serverVersion >= QPSQLDriver::Version9 && clientVersion < QPSQLDriver::Version9) { - //Client version before QPSQLDriver::Version9 only supports escape mode for bytea type, - //but bytea format is set to hex by default in PSQL 9 and above. So need to force the - //server use the old escape mode when connects to the new server with old client library. - PQclear(result); - result = exec("SET bytea_output=escape; "); - status = PQresultStatus(result); - } else if (serverVersion == QPSQLDriver::VersionUnknown) { - serverVersion = clientVersion; - if (serverVersion != QPSQLDriver::VersionUnknown) - qWarning("The server version of this PostgreSQL is unknown, falling back to the client version."); - } - } - } + + if (serverVersion >= QPSQLDriver::Version9 && clientVersion < QPSQLDriver::Version9) { + // Client version before QPSQLDriver::Version9 only supports escape mode for bytea type, + // but bytea format is set to hex by default in PSQL 9 and above. So need to force the + // server use the old escape mode when connects to the new server with old client library. + result = exec("SET bytea_output=escape; "); + status = PQresultStatus(result); + PQclear(result); + } else if (serverVersion == QPSQLDriver::VersionUnknown) { + serverVersion = clientVersion; + if (serverVersion != QPSQLDriver::VersionUnknown) + qWarning("The server version of this PostgreSQL is unknown, falling back to the client version."); } - PQclear(result); - //keep the old behavior unchanged + // Keep the old behavior unchanged if (serverVersion == QPSQLDriver::VersionUnknown) serverVersion = QPSQLDriver::Version6; - if (serverVersion < QPSQLDriver::Version71) { + if (serverVersion < QPSQLDriver::Version7_1) { qWarning("This version of PostgreSQL is not supported and may not work."); } @@ -852,7 +885,7 @@ bool QPSQLDriver::hasFeature(DriverFeature f) const return true; case PreparedQueries: case PositionalPlaceholders: - return d->pro >= QPSQLDriver::Version82; + return d->pro >= QPSQLDriver::Version8_2; case BatchOperations: case NamedPlaceholders: case SimpleLocking: @@ -861,7 +894,7 @@ bool QPSQLDriver::hasFeature(DriverFeature f) const case CancelQuery: return false; case BLOB: - return d->pro >= QPSQLDriver::Version71; + return d->pro >= QPSQLDriver::Version7_1; case Unicode: return d->isUtf8; } @@ -988,12 +1021,7 @@ bool QPSQLDriver::commitTransaction() // This hack is used to tell if the transaction has succeeded for the protocol versions of // PostgreSQL below. For 7.x and other protocol versions we are left in the dark. // This hack can dissapear once there is an API to query this sort of information. - if (d->pro == QPSQLDriver::Version8 || - d->pro == QPSQLDriver::Version81 || - d->pro == QPSQLDriver::Version82 || - d->pro == QPSQLDriver::Version83 || - d->pro == QPSQLDriver::Version84 || - d->pro == QPSQLDriver::Version9) { + if (d->pro >= QPSQLDriver::Version8) { transaction_failed = qstrcmp(PQcmdStatus(res), "ROLLBACK") == 0; } @@ -1080,8 +1108,7 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const else schema = std::move(schema).toLower(); - switch(d->pro) { - case QPSQLDriver::Version6: + if (d->pro == QPSQLDriver::Version6) { stmt = QLatin1String("select pg_att1.attname, int(pg_att1.atttypid), pg_cl.relname " "from pg_attribute pg_att1, pg_attribute pg_att2, pg_class pg_cl, pg_index pg_ind " "where pg_cl.relname = '%1_pkey' " @@ -1090,9 +1117,7 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const "and pg_att1.attrelid = pg_ind.indrelid " "and pg_att1.attnum = pg_ind.indkey[pg_att2.attnum-1] " "order by pg_att2.attnum"); - break; - case QPSQLDriver::Version7: - case QPSQLDriver::Version71: + } else if (d->pro == QPSQLDriver::Version7 || d->pro == QPSQLDriver::Version7_1) { stmt = QLatin1String("select pg_att1.attname, pg_att1.atttypid::int, pg_cl.relname " "from pg_attribute pg_att1, pg_attribute pg_att2, pg_class pg_cl, pg_index pg_ind " "where pg_cl.relname = '%1_pkey' " @@ -1101,15 +1126,7 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const "and pg_att1.attrelid = pg_ind.indrelid " "and pg_att1.attnum = pg_ind.indkey[pg_att2.attnum-1] " "order by pg_att2.attnum"); - break; - case QPSQLDriver::Version73: - case QPSQLDriver::Version74: - case QPSQLDriver::Version8: - case QPSQLDriver::Version81: - case QPSQLDriver::Version82: - case QPSQLDriver::Version83: - case QPSQLDriver::Version84: - case QPSQLDriver::Version9: + } else if (d->pro >= QPSQLDriver::Version7_3) { stmt = QLatin1String("SELECT pg_attribute.attname, pg_attribute.atttypid::int, " "pg_class.relname " "FROM pg_attribute, pg_class " @@ -1124,10 +1141,8 @@ QSqlIndex QPSQLDriver::primaryIndex(const QString& tablename) const else stmt = stmt.arg(QString::fromLatin1("pg_class.relnamespace = (select oid from " "pg_namespace where pg_namespace.nspname = '%1') AND ").arg(schema)); - break; - case QPSQLDriver::VersionUnknown: - qFatal("PSQL version is unknown"); - break; + } else { + qFatal("QPSQLDriver::primaryIndex(tablename): unknown PSQL version, query statement not set"); } i.exec(stmt.arg(tbl)); @@ -1161,8 +1176,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const schema = std::move(schema).toLower(); QString stmt; - switch(d->pro) { - case QPSQLDriver::Version6: + if (d->pro == QPSQLDriver::Version6) { stmt = QLatin1String("select pg_attribute.attname, int(pg_attribute.atttypid), " "pg_attribute.attnotnull, pg_attribute.attlen, pg_attribute.atttypmod, " "int(pg_attribute.attrelid), pg_attribute.attnum " @@ -1170,8 +1184,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const "where pg_class.relname = '%1' " "and pg_attribute.attnum > 0 " "and pg_attribute.attrelid = pg_class.oid "); - break; - case QPSQLDriver::Version7: + } else if (d->pro == QPSQLDriver::Version7) { stmt = QLatin1String("select pg_attribute.attname, pg_attribute.atttypid::int, " "pg_attribute.attnotnull, pg_attribute.attlen, pg_attribute.atttypmod, " "pg_attribute.attrelid::int, pg_attribute.attnum " @@ -1179,8 +1192,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const "where pg_class.relname = '%1' " "and pg_attribute.attnum > 0 " "and pg_attribute.attrelid = pg_class.oid "); - break; - case QPSQLDriver::Version71: + } else if (d->pro == QPSQLDriver::Version7_1) { stmt = QLatin1String("select pg_attribute.attname, pg_attribute.atttypid::int, " "pg_attribute.attnotnull, pg_attribute.attlen, pg_attribute.atttypmod, " "pg_attrdef.adsrc " @@ -1191,15 +1203,7 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const "and pg_attribute.attnum > 0 " "and pg_attribute.attrelid = pg_class.oid " "order by pg_attribute.attnum "); - break; - case QPSQLDriver::Version73: - case QPSQLDriver::Version74: - case QPSQLDriver::Version8: - case QPSQLDriver::Version81: - case QPSQLDriver::Version82: - case QPSQLDriver::Version83: - case QPSQLDriver::Version84: - case QPSQLDriver::Version9: + } else if (d->pro >= QPSQLDriver::Version7_3) { stmt = QLatin1String("select pg_attribute.attname, pg_attribute.atttypid::int, " "pg_attribute.attnotnull, pg_attribute.attlen, pg_attribute.atttypmod, " "pg_attrdef.adsrc " @@ -1217,15 +1221,13 @@ QSqlRecord QPSQLDriver::record(const QString& tablename) const else stmt = stmt.arg(QString::fromLatin1("pg_class.relnamespace = (select oid from " "pg_namespace where pg_namespace.nspname = '%1')").arg(schema)); - break; - case QPSQLDriver::VersionUnknown: - qFatal("PSQL version is unknown"); - break; + } else { + qFatal("QPSQLDriver::record(tablename): unknown PSQL version, query statement not set"); } QSqlQuery query(createResult()); query.exec(stmt.arg(tbl)); - if (d->pro >= QPSQLDriver::Version71) { + if (d->pro >= QPSQLDriver::Version7_1) { while (query.next()) { int len = query.value(3).toInt(); int precision = query.value(4).toInt(); diff --git a/src/plugins/sqldrivers/psql/qsql_psql_p.h b/src/plugins/sqldrivers/psql/qsql_psql_p.h index 8468b9af93..f5cb2e9bd0 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql_p.h +++ b/src/plugins/sqldrivers/psql/qsql_psql_p.h @@ -76,15 +76,23 @@ public: VersionUnknown = -1, Version6 = 6, Version7 = 7, - Version71 = 8, - Version73 = 9, - Version74 = 10, + Version7_1 = 8, + Version7_3 = 9, + Version7_4 = 10, Version8 = 11, - Version81 = 12, - Version82 = 13, - Version83 = 14, - Version84 = 15, - Version9 = 16 + Version8_1 = 12, + Version8_2 = 13, + Version8_3 = 14, + Version8_4 = 15, + Version9 = 16, + Version9_1 = 17, + Version9_2 = 18, + Version9_3 = 19, + Version9_4 = 20, + Version9_5 = 21, + Version9_6 = 22, + Version10 = 23, + UnknownLaterVersion = 100000 }; explicit QPSQLDriver(QObject *parent=0); -- cgit v1.2.3 From ff914ea59c3788b2359ddb8d607299576b7a1296 Mon Sep 17 00:00:00 2001 From: Robert Szefner Date: Fri, 20 Oct 2017 23:31:12 +0200 Subject: QPSQL: Fix handling binary data for PostgreSQL 9.x and later Set byte_output to 'escape' mode for server version 9 and later, no matter what version of client library we use. Since setting byte_output doesn't depend on client version anymore, we can move it to separate function. This fixes qtbase\tests\auto\sql\kernel\qsqldatabase tst_QSqlDatabase::psql_escapeBytea() test (before this change test did not pass on PostgreSQL 9.6) Change-Id: I37aaa18267d7e6459c00010ed899536c01e8124e Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index f650e4cca8..aac9a1fa13 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -181,6 +181,7 @@ public: QPSQLDriver::Protocol getPSQLVersion(); bool setEncodingUtf8(); void setDatestyle(); + void setByteaOutput(); void detectBackslashEscape(); }; @@ -693,6 +694,20 @@ void QPSQLDriverPrivate::setDatestyle() PQclear(result); } +void QPSQLDriverPrivate::setByteaOutput() +{ + if (pro >= QPSQLDriver::Version9) { + // Server version before QPSQLDriver::Version9 only supports escape mode for bytea type, + // but bytea format is set to hex by default in PSQL 9 and above. So need to force the + // server to use the old escape mode when connects to the new server. + PGresult *result = exec("SET bytea_output TO escape"); + int status = PQresultStatus(result); + if (status != PGRES_COMMAND_OK) + qWarning("%s", PQerrorMessage(connection)); + PQclear(result); + } +} + void QPSQLDriverPrivate::detectBackslashEscape() { // standard_conforming_strings option introduced in 8.2 @@ -818,14 +833,7 @@ QPSQLDriver::Protocol QPSQLDriverPrivate::getPSQLVersion() QPSQLDriver::VersionUnknown; #endif - if (serverVersion >= QPSQLDriver::Version9 && clientVersion < QPSQLDriver::Version9) { - // Client version before QPSQLDriver::Version9 only supports escape mode for bytea type, - // but bytea format is set to hex by default in PSQL 9 and above. So need to force the - // server use the old escape mode when connects to the new server with old client library. - result = exec("SET bytea_output=escape; "); - status = PQresultStatus(result); - PQclear(result); - } else if (serverVersion == QPSQLDriver::VersionUnknown) { + if (serverVersion == QPSQLDriver::VersionUnknown) { serverVersion = clientVersion; if (serverVersion != QPSQLDriver::VersionUnknown) qWarning("The server version of this PostgreSQL is unknown, falling back to the client version."); @@ -957,6 +965,7 @@ bool QPSQLDriver::open(const QString & db, d->detectBackslashEscape(); d->isUtf8 = d->setEncodingUtf8(); d->setDatestyle(); + d->setByteaOutput(); setOpen(true); setOpenError(false); -- cgit v1.2.3 From b35a27676bec7f79761be83b2a7764ac0470e789 Mon Sep 17 00:00:00 2001 From: Robert Szefner Date: Fri, 20 Oct 2017 23:55:16 +0200 Subject: QPSQL: Fix check for minimum supported PostgreSQL version According to Qt documentation http://doc.qt.io/qt-5/sql-driver.html#qpsql minimum supported version of PostgreSQL is 7.3 Change-Id: I30cffaddc29fd56b534bfd259cc235ea1204a21f Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/psql/qsql_psql.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index aac9a1fa13..8f7d261bdc 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -843,7 +843,7 @@ QPSQLDriver::Protocol QPSQLDriverPrivate::getPSQLVersion() if (serverVersion == QPSQLDriver::VersionUnknown) serverVersion = QPSQLDriver::Version6; - if (serverVersion < QPSQLDriver::Version7_1) { + if (serverVersion < QPSQLDriver::Version7_3) { qWarning("This version of PostgreSQL is not supported and may not work."); } -- cgit v1.2.3 From 385589ef458715fcaa533bbd01ca421dc1040eba Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 20 Oct 2017 17:39:08 +0700 Subject: QCocoaMenu: Attach menu items when updating the menubar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of waiting for the menu delegate to update each item, we can attach an NSMenu to its NSMenuItem as soon as we update the current window's menubar. This is safe to do because we know that this is going to be the main menubar right after, so we're not orphaning any NSMenuItem from its NSMenu at the wrong moment. By doing this, we also ensure that all menus from the active menubar are reachable by the key-equivalent dispatching logic, even before we display the actual menu. This was shown in BigMenuCreator where, under the menubar's ASP and SAP menus, all A*S submenus would be disabled. Furthermore, on the same menus, SAP would show the same issue. Added test in Menurama as well. Change-Id: If6e7311072e6b53ad1cbced73623d1832aa0df8e Task-number: QTBUG-57076 Task-number: QTBUG-63712 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoamenu.h | 2 ++ src/plugins/platforms/cocoa/qcocoamenu.mm | 16 +++++++++++++++- src/plugins/platforms/cocoa/qcocoamenubar.h | 2 ++ src/plugins/platforms/cocoa/qcocoamenubar.mm | 11 ++++++++--- 4 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoamenu.h b/src/plugins/platforms/cocoa/qcocoamenu.h index 06688dbf3d..7baaf971f4 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.h +++ b/src/plugins/platforms/cocoa/qcocoamenu.h @@ -98,6 +98,8 @@ public: void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; + void syncMenuItem_helper(QPlatformMenuItem *menuItem, bool menubarUpdate); + private: QCocoaMenuItem *itemOrNull(int index) const; void insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem); diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index 3a11023a4d..8bdd0512de 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -434,6 +434,11 @@ void QCocoaMenu::timerEvent(QTimerEvent *e) } void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem) +{ + syncMenuItem_helper(menuItem, false /*menubarUpdate*/); +} + +void QCocoaMenu::syncMenuItem_helper(QPlatformMenuItem *menuItem, bool menubarUpdate) { QMacAutoReleasePool pool; QCocoaMenuItem *cocoaItem = static_cast(menuItem); @@ -444,8 +449,9 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem) const bool wasMerged = cocoaItem->isMerged(); NSMenuItem *oldItem = cocoaItem->nsItem(); + NSMenuItem *syncedItem = cocoaItem->sync(); - if (cocoaItem->sync() != oldItem) { + if (syncedItem != oldItem) { // native item was changed for some reason if (oldItem) { if (wasMerged) { @@ -463,6 +469,14 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem) // when an item's enabled state changes after menuWillOpen: scheduleUpdate(); } + + // This may be a good moment to attach this item's eventual submenu to the + // synced item, but only on the condition we're all currently hooked to the + // menunbar. A good indicator of this being the right moment is knowing that + // we got called from QCocoaMenuBar::updateMenuBarImmediately(). + if (menubarUpdate) + if (QCocoaMenu *submenu = cocoaItem->menu()) + submenu->setAttachedItem(syncedItem); } void QCocoaMenu::syncSeparatorsCollapsible(bool enable) diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h index 0725e9db68..a4ee531e91 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.h +++ b/src/plugins/platforms/cocoa/qcocoamenubar.h @@ -72,6 +72,8 @@ public: QList merged() const; NSMenuItem *itemForRole(QPlatformMenuItem::MenuRole r); + void syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate); + private: static QCocoaWindow *findWindowForMenubar(); static QCocoaMenuBar *findGlobalMenubar(); diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 3e466c9587..a4cd465dae 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -155,7 +155,7 @@ void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *befor } } - syncMenu(menu); + syncMenu_helper(menu, false /*internaCall*/); if (needsImmediateUpdate()) updateMenuBarImmediately(); @@ -182,12 +182,17 @@ void QCocoaMenuBar::removeMenu(QPlatformMenu *platformMenu) } void QCocoaMenuBar::syncMenu(QPlatformMenu *menu) +{ + syncMenu_helper(menu, false /*internaCall*/); +} + +void QCocoaMenuBar::syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate) { QMacAutoReleasePool pool; QCocoaMenu *cocoaMenu = static_cast(menu); Q_FOREACH (QCocoaMenuItem *item, cocoaMenu->items()) - cocoaMenu->syncMenuItem(item); + cocoaMenu->syncMenuItem_helper(item, menubarUpdate); BOOL shouldHide = YES; if (cocoaMenu->isVisible()) { @@ -357,7 +362,7 @@ void QCocoaMenuBar::updateMenuBarImmediately() menu->setAttachedItem(item); menu->setMenuParent(mb); // force a sync? - mb->syncMenu(menu); + mb->syncMenu_helper(menu, true /*menubarUpdate*/); menu->propagateEnabledState(!disableForModal); } -- cgit v1.2.3 From e45ffd7bf6b05062590da039e0de64707d2fb536 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 26 Oct 2017 13:26:56 +0200 Subject: Xinput: Avoid misdetecting certain trackballs as tablets The algorithm triggers on the word "cursor" in the device name, which would also happen for devices from the manufacturer Cursor Controls. Task-number: QTBUG-48034 Change-Id: I9645c0d0bc1fa951d0ea00480572fd0df0220eb5 Reviewed-by: Shawn Rutledge --- src/plugins/platforms/xcb/qxcbconnection_xi2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index 6f20ec25e3..26a9ba8d26 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -220,7 +220,7 @@ void QXcbConnection::xi2SetupDevices() isTablet = true; tabletData.pointerType = QTabletEvent::Eraser; dbgType = QLatin1String("eraser"); - } else if (name.contains("cursor")) { + } else if (name.contains("cursor") && !(name.contains("cursor controls") && name.contains("trackball"))) { isTablet = true; tabletData.pointerType = QTabletEvent::Cursor; dbgType = QLatin1String("cursor"); -- cgit v1.2.3 From 5194817941985c766bbc7f80039a58e0cf504b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 6 Nov 2017 15:08:37 +0100 Subject: Cocoa: optimize backingstore flush on 10-bit displays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Qt draws the backing store to the window using CoreGrahics, which will trigger a slow RGB32 -> RGB64 conversion when the output display is a deep color display. Disable NSWindow dynamicDepthLimit and force the depthLimit to WindowDepthTwentyforBitRGB for the common case of 8-bit-per-component raster surfaces. This was benchmarked by resizing a simple QRasterWindow test case which fills the window area using QPainter::fillRect(). Before: 67.1% rgba64_image_mark_rgb32 10.8% __vImageCopyBuffer_block_invoke 6.0% madvise 5.0% _kernelrpc_mach_vm_deallocate_trap 4.1% qt_memfill32(unsigned int*, unsigned int, int) After: 30.7% __vImageCopyBuffer_block_invoke 20.3% madvise 12.3% __vOverwriteChannelsWithScalar_ARGB8888_block_invoke 12.2% qt_memfill32(unsigned int*, unsigned int, int) 4.6% _kernelrpc_mach_vm_deallocate_trap The test program now spends significantly more of its time allocating/deallocating the backing store (madvise), and running the Qt paint event (qt_memfill32). Task-number: QTBUG-47660 Change-Id: I878be7a0e6eee4ad798f7a53f7f9f79b7950af26 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoawindow.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index c6fa6795c1..5cd4beb4f0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1887,6 +1887,21 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBeChildNSWindow, bool sh applyContentBorderThickness(window); + // Prevent CoreGraphics RGB32 -> RGB64 backing store conversions on deep color + // displays by forcing 8-bit components, unless a deep color format has been + // requested. This conversion uses significant CPU time. + QSurface::SurfaceType surfaceType = QPlatformWindow::window()->surfaceType(); + bool usesCoreGraphics = surfaceType == QSurface::RasterSurface || surfaceType == QSurface::RasterGLSurface; + QSurfaceFormat surfaceFormat = QPlatformWindow::window()->format(); + bool usesDeepColor = surfaceFormat.redBufferSize() > 8 || + surfaceFormat.greenBufferSize() > 8 || + surfaceFormat.blueBufferSize() > 8; + bool usesLayer = view().layer; + if (usesCoreGraphics && !usesDeepColor && !usesLayer) { + [window setDynamicDepthLimit:NO]; + [window setDepthLimit:NSWindowDepthTwentyfourBitRGB]; + } + return window; } -- cgit v1.2.3 From 59c5f7bd9da63621887260fc45e6669282d71ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 6 Nov 2017 14:52:13 +0100 Subject: macOS: Fall back to QWindow::icon for application icon if not set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are three ways to set the application (Dock/task switcher) icon: 1. By setting an ICON in the project file 2. By calling QGuiApplication::setWindowIcon 3. By calling QWindow::setIcon The third one was not working on macOS, despite being documented as such: "The window icon might be used by the windowing system for example to decorate the window, and/or in the task switcher." We now update the application icon based on the active window, unless a global application icon has been set using ICON, or via QGuiApplication::setWindowIcon. The reason for not allowing the window's icon to override a global application icon is that the developer may have intended to set the document icon for a window (to represent QWindow::filePath), and we don't want that to affect the Dock icon of the application. The role of QGuiApplication::setWindowIcon is a bit dubious in this, as it's documented as "This property holds the default window icon", which would indicate it should follow the same logic as above by not letting it override the global ICON set in the project file, but this would not allow runtime switching of the application icon, so the QGuiApplication property is left as is. The property should probably have been named QGuiApplication::applicationIcon initially. Task-number: QTBUG-63340 Change-Id: I94d3710a8586bb729af42f59a915b8f49dded101 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaintegration.h | 6 ++++- src/plugins/platforms/cocoa/qcocoaintegration.mm | 32 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index dc7c5916a3..2fc5156d24 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -60,8 +60,9 @@ QT_BEGIN_NAMESPACE class QCocoaScreen; -class QCocoaIntegration : public QPlatformIntegration +class QCocoaIntegration : public QObject, public QPlatformIntegration { + Q_OBJECT public: enum Option { UseFreeTypeFontEngine = 0x1 @@ -120,6 +121,9 @@ public: void beep() const Q_DECL_OVERRIDE; +private Q_SLOTS: + void focusWindowChanged(QWindow *); + private: static QCocoaIntegration *mInstance; Options mOptions; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index d185905782..55b3805df3 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -179,6 +179,9 @@ QCocoaIntegration::QCocoaIntegration(const QStringList ¶mList) QMacInternalPasteboardMime::initializeMimeTypes(); QCocoaMimeTypes::initializeMimeTypes(); QWindowSystemInterfacePrivate::TabletEvent::setPlatformSynthesizesMouse(false); + + connect(qGuiApp, &QGuiApplication::focusWindowChanged, + this, &QCocoaIntegration::focusWindowChanged); } QCocoaIntegration::~QCocoaIntegration() @@ -510,4 +513,33 @@ void QCocoaIntegration::beep() const NSBeep(); } +void QCocoaIntegration::focusWindowChanged(QWindow *focusWindow) +{ + // Don't revert icon just because we lost focus + if (!focusWindow) + return; + + static bool hasDefaultApplicationIcon = [](){ + NSImage *genericApplicationIcon = [[NSWorkspace sharedWorkspace] + iconForFileType:NSFileTypeForHFSTypeCode(kGenericApplicationIcon)]; + NSImage *applicationIcon = [NSImage imageNamed:NSImageNameApplicationIcon]; + + NSRect rect = NSMakeRect(0, 0, 32, 32); + return [applicationIcon CGImageForProposedRect:&rect context:nil hints:nil] + == [genericApplicationIcon CGImageForProposedRect:&rect context:nil hints:nil]; + }(); + + // Don't let the window icon override an explicit application icon set in the Info.plist + if (!hasDefaultApplicationIcon) + return; + + // Or an explicit application icon set on QGuiApplication + if (!qGuiApp->windowIcon().isNull()) + return; + + setApplicationIcon(focusWindow->icon()); +} + +#include "moc_qcocoaintegration.cpp" + QT_END_NAMESPACE -- cgit v1.2.3 From 3f519ffa150ce5a2d9e3ad3f147745b312d29afb Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 25 Oct 2017 09:32:48 +0700 Subject: QCocoaMenuItem: Don't clear NSMenuItem.action when setting submenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contrarily to what the comment stated, we actually rely on automatic menu validation, even for submenu items. This is visible in the menu delegate's validateMenuItem: and itemFired: methods. This solves the last visible issue in BigMenuCreator where, under ASP/ASP, ASP/SAP, SAP/ASP and SAP/SAP, all A*S submenus would be disabled. The cause was an incorrect target/action setup. Menurama still behaves as expected. Change-Id: I2599d6fb0d51f56f5d36f03b69647e35ff6c550a Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index ecbab38a83..394e0fb8e4 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -150,10 +150,6 @@ void QCocoaMenuItem::setMenu(QPlatformMenu *menu) QMacAutoReleasePool pool; m_menu = static_cast(menu); if (m_menu) { - if (m_native) { - // Skip automatic menu item validation - m_native.action = nil; - } m_menu->setMenuParent(this); m_menu->propagateEnabledState(isEnabled()); } else { -- cgit v1.2.3 From d0736e9d17d0b3ec2f7aa3f323a1edf70aa83e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 7 Nov 2017 15:03:32 +0100 Subject: Cocoa: Make High DPI drag cursor work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ide4bc50ab7173529a00fe60a04204bad0b3f275e Task-id: QTBUG-60769 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview.mm | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index ec9d25fff9..2e64204fb7 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -2068,6 +2068,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin } else { NSImage *nsimage = qt_mac_create_nsimage(pixmapCursor); + nsimage.size = NSSizeFromCGSize((pixmapCursor.size() / pixmapCursor.devicePixelRatioF()).toCGSize()); nativeCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot:NSZeroPoint]; [nsimage release]; } -- cgit v1.2.3 From c84f7554894cef0cbeeba8a61f441286e190a797 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 13 Nov 2017 11:28:41 +0100 Subject: Offscreen QPA: Use fusion style always MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent it from crashing when naively using it for example on Windows, which defaults to the Windows Vista style operating on native window handles. Change-Id: I7b1dfb00a6b6860d0f0a134653ce1142b45959ec Reviewed-by: Sami Nurmenniemi Reviewed-by: Gatis Paeglis Reviewed-by: Morten Johan Sørvig --- .../platforms/offscreen/qoffscreenintegration.cpp | 32 ++++++++++++++++++++++ .../platforms/offscreen/qoffscreenintegration.h | 3 ++ 2 files changed, 35 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp index 3eb8675d77..75bb786b28 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include @@ -167,6 +168,37 @@ QAbstractEventDispatcher *QOffscreenIntegration::createEventDispatcher() const #endif } +static QString themeName() { return QStringLiteral("offscreen"); } + +QStringList QOffscreenIntegration::themeNames() const +{ + return QStringList(themeName()); +} + +// Restrict the styles to "fusion" to prevent native styles requiring native +// window handles (eg Windows Vista style) from being used. +class OffscreenTheme : public QPlatformTheme +{ +public: + OffscreenTheme() {} + + QVariant themeHint(ThemeHint h) const override + { + switch (h) { + case StyleNames: + return QVariant(QStringList(QStringLiteral("fusion"))); + default: + break; + } + return QPlatformTheme::themeHint(h); + } +}; + +QPlatformTheme *QOffscreenIntegration::createPlatformTheme(const QString &name) const +{ + return name == themeName() ? new OffscreenTheme() : nullptr; +} + QPlatformFontDatabase *QOffscreenIntegration::fontDatabase() const { return m_fontDatabase.data(); diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.h b/src/plugins/platforms/offscreen/qoffscreenintegration.h index 569ec8fc28..f72587d11a 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration.h +++ b/src/plugins/platforms/offscreen/qoffscreenintegration.h @@ -69,6 +69,9 @@ public: QPlatformFontDatabase *fontDatabase() const Q_DECL_OVERRIDE; QAbstractEventDispatcher *createEventDispatcher() const Q_DECL_OVERRIDE; + QStringList themeNames() const; + QPlatformTheme *createPlatformTheme(const QString &name) const; + static QOffscreenIntegration *createOffscreenIntegration(); private: -- cgit v1.2.3 From 3dab19ffed61a69166045d6e90e1e114d81f85a8 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 13 Nov 2017 13:03:36 +0100 Subject: OCI: Match the constraints on the index_name column When looking for the primary index, it is possible that the constraint_name in the all_ind_columns table does not match that of the index_name. Whereas the index_name will match in this case, so the query should set the where clause on the index_name in both tables. Task-number: QTBUG-64427 Change-Id: I1bf1fb580e620b9f75f2fde1ecf408842e377365 Reviewed-by: Jesus Fernandez --- src/plugins/sqldrivers/oci/qsql_oci.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins') diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index a4793351de..9ce2fc1b55 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -2603,7 +2603,7 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const QString stmt(QLatin1String("select b.column_name, b.index_name, a.table_name, a.owner " "from all_constraints a, all_ind_columns b " "where a.constraint_type='P' " - "and b.index_name = a.constraint_name " + "and b.index_name = a.index_name " "and b.index_owner = a.owner")); bool buildIndex = false; -- cgit v1.2.3 From d7dce54ba0c018c4db92a291d322167dcf308d75 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 7 Nov 2017 11:35:46 +0700 Subject: QMacStyle: Rename Cocoa controls enum names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For easier sorting and grouping by actual Cocoa NSControl class. We also shorten the names and move the types inside QMacStylePrivate. Change-Id: Iac093fd359da66abd263aca841b870ea84337f50 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 131 +++++++++++++++-------------- src/plugins/styles/mac/qmacstyle_mac_p_p.h | 56 ++++++------ 2 files changed, 99 insertions(+), 88 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index b24ecee102..9c5ede6d47 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -1849,36 +1849,36 @@ ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags) return tds; } -static QCocoaWidget cocoaWidgetFromHIThemeButtonKind(ThemeButtonKind kind) + QMacStylePrivate::CocoaControl QMacStylePrivate::cocoaControlFromHIThemeButtonKind(ThemeButtonKind kind) { - QCocoaWidget w; + CocoaControl w; switch (kind) { case kThemePopupButton: case kThemePopupButtonSmall: case kThemePopupButtonMini: - w.first = QCocoaPopupButton; + w.first = Button_PopupButton; break; case kThemeComboBox: - w.first = QCocoaComboBox; + w.first = ComboBox; break; case kThemeArrowButton: - w.first = QCocoaDisclosureButton; + w.first = Button_Disclosure; break; case kThemeCheckBox: case kThemeCheckBoxSmall: case kThemeCheckBoxMini: - w.first = QCocoaCheckBox; + w.first = Button_CheckBox; break; case kThemeRadioButton: case kThemeRadioButtonSmall: case kThemeRadioButtonMini: - w.first = QCocoaRadioButton; + w.first = Button_RadioButton; break; case kThemePushButton: case kThemePushButtonSmall: case kThemePushButtonMini: - w.first = QCocoaPushButton; + w.first = Button_PushButton; break; default: break; @@ -1914,13 +1914,13 @@ static NSButton *makeButton(NSButtonType type, NSBezelStyle style) return b; } -NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const +NSView *QMacStylePrivate::cocoaControl(CocoaControl widget) const { NSView *bv = cocoaControls.value(widget, nil); if (!bv) { switch (widget.first) { - case QCocoaBox: { + case Box: { NSBox *bc = [[NSBox alloc] init]; bc.title = @""; bc.titlePosition = NSNoTitle; @@ -1929,48 +1929,48 @@ NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const bv = bc; break; } - case QCocoaCheckBox: + case Button_CheckBox: bv = makeButton(NSSwitchButton, NSRegularSquareBezelStyle); break; - case QCocoaDisclosureButton: + case Button_Disclosure: bv = makeButton(NSOnOffButton, NSDisclosureBezelStyle); break; - case QCocoaPopupButton: - case QCocoaPullDownButton: { + case Button_PopupButton: + case Button_PullDown: { NSPopUpButton *bc = [[NSPopUpButton alloc] init]; bc.title = @""; - if (widget.first == QCocoaPullDownButton) + if (widget.first == Button_PullDown) bc.pullsDown = YES; bv = bc; break; } - case QCocoaPushButton: + case Button_PushButton: bv = makeButton(NSMomentaryLightButton, NSRoundedBezelStyle); break; - case QCocoaRadioButton: + case Button_RadioButton: bv = makeButton(NSRadioButton, NSRegularSquareBezelStyle); break; - case QCocoaComboBox: + case ComboBox: bv = [[NSComboBox alloc] init]; break; - case QCocoaProgressIndicator: + case ProgressIndicator_Determinate: bv = [[NSProgressIndicator alloc] init]; break; - case QCocoaIndeterminateProgressIndicator: + case ProgressIndicator_Indeterminate: bv = [[QIndeterminateProgressIndicator alloc] init]; break; - case QCocoaHorizontalScroller: + case Scroller_Horizontal: bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]; break; - case QCocoaVerticalScroller: + case Scroller_Vertical: // Cocoa sets the orientation from the view's frame // at construction time, and it cannot be changed later. bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)]; break; - case QCocoaHorizontalSlider: + case Slider_Horizontal: bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)]; break; - case QCocoaVerticalSlider: + case Slider_Vertical: // Cocoa sets the orientation from the view's frame // at construction time, and it cannot be changed later. bv = [[NSSlider alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)]; @@ -1991,10 +1991,10 @@ NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const default: break; } - } else if (widget.first == QCocoaProgressIndicator || - widget.first == QCocoaIndeterminateProgressIndicator) { + } else if (widget.first == ProgressIndicator_Determinate || + widget.first == ProgressIndicator_Indeterminate) { auto *pi = static_cast(bv); - pi.indeterminate = (widget.first == QCocoaIndeterminateProgressIndicator); + pi.indeterminate = (widget.first == ProgressIndicator_Indeterminate); switch (widget.second) { case QStyleHelper::SizeSmall: pi.controlSize = NSSmallControlSize; @@ -2013,15 +2013,15 @@ NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const return bv; } -NSCell *QMacStylePrivate::cocoaCell(QCocoaWidget widget) const +NSCell *QMacStylePrivate::cocoaCell(CocoaControl widget) const { NSCell *cell = cocoaCells[widget]; if (!cell) { switch (widget.first) { - case QCocoaStepper: + case Stepper: cell = [[NSStepperCell alloc] init]; break; - case QCocoaDisclosureButton: { + case Button_Disclosure: { NSButtonCell *bc = [[NSButtonCell alloc] init]; bc.buttonType = NSOnOffButton; bc.bezelStyle = NSDisclosureBezelStyle; @@ -2049,31 +2049,31 @@ NSCell *QMacStylePrivate::cocoaCell(QCocoaWidget widget) const return cell; } -void QMacStylePrivate::drawNSViewInRect(QCocoaWidget widget, NSView *view, const QRect &qtRect, QPainter *p, bool isQWidget, QCocoaDrawRectBlock drawRectBlock) const +void QMacStylePrivate::drawNSViewInRect(CocoaControl widget, NSView *view, const QRect &qtRect, QPainter *p, bool isQWidget, DrawRectBlock drawRectBlock) const { QPoint offset; - if (widget == QCocoaWidget(QCocoaRadioButton, QStyleHelper::SizeLarge)) + if (widget == CocoaControl(Button_RadioButton, QStyleHelper::SizeLarge)) offset.setY(2); - else if (widget == QCocoaWidget(QCocoaRadioButton, QStyleHelper::SizeSmall)) + else if (widget == CocoaControl(Button_RadioButton, QStyleHelper::SizeSmall)) offset = QPoint(-1, 2); - else if (widget == QCocoaWidget(QCocoaRadioButton, QStyleHelper::SizeMini)) + else if (widget == CocoaControl(Button_RadioButton, QStyleHelper::SizeMini)) offset.setY(2); - else if (widget == QCocoaWidget(QCocoaPopupButton, QStyleHelper::SizeSmall) - || widget == QCocoaWidget(QCocoaCheckBox, QStyleHelper::SizeLarge)) + else if (widget == CocoaControl(Button_PopupButton, QStyleHelper::SizeSmall) + || widget == CocoaControl(Button_CheckBox, QStyleHelper::SizeLarge)) offset.setY(1); - else if (widget == QCocoaWidget(QCocoaCheckBox, QStyleHelper::SizeSmall)) + else if (widget == CocoaControl(Button_CheckBox, QStyleHelper::SizeSmall)) offset.setX(-1); - else if (widget == QCocoaWidget(QCocoaCheckBox, QStyleHelper::SizeMini)) + else if (widget == CocoaControl(Button_CheckBox, QStyleHelper::SizeMini)) offset = QPoint(7, 5); - else if (widget == QCocoaWidget(QCocoaPopupButton, QStyleHelper::SizeMini)) + else if (widget == CocoaControl(Button_PopupButton, QStyleHelper::SizeMini)) offset = QPoint(2, -1); - else if (widget == QCocoaWidget(QCocoaPullDownButton, QStyleHelper::SizeLarge)) + else if (widget == CocoaControl(Button_PullDown, QStyleHelper::SizeLarge)) offset = isQWidget ? QPoint(3, -1) : QPoint(-1, -3); - else if (widget == QCocoaWidget(QCocoaPullDownButton, QStyleHelper::SizeSmall)) + else if (widget == CocoaControl(Button_PullDown, QStyleHelper::SizeSmall)) offset = QPoint(2, 1); - else if (widget == QCocoaWidget(QCocoaPullDownButton, QStyleHelper::SizeMini)) + else if (widget == CocoaControl(Button_PullDown, QStyleHelper::SizeMini)) offset = QPoint(5, 0); - else if (widget == QCocoaWidget(QCocoaComboBox, QStyleHelper::SizeLarge)) + else if (widget == CocoaControl(ComboBox, QStyleHelper::SizeLarge)) offset = QPoint(3, 0); QMacCGContext ctx(p); @@ -2162,7 +2162,7 @@ void QMacStylePrivate::drawColorlessButton(const CGRect &macRect, HIThemeButtonD if (!combo && !button && bdi->value == kThemeButtonOff) { pm = activePixmap; } else if ((combo && !editableCombo) || button) { - QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi->kind); + CocoaControl cw = cocoaControlFromHIThemeButtonKind(bdi->kind); NSButton *bc = (NSButton *)cocoaControl(cw); [bc highlight:pressed]; bc.enabled = bdi->state != kThemeStateUnavailable && bdi->state != kThemeStateUnavailableInactive; @@ -3211,7 +3211,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai if (groupBox->features & QStyleOptionFrame::Flat) { QCommonStyle::drawPrimitive(pe, groupBox, p, w); } else { - const auto cw = QCocoaWidget(QCocoaBox, QStyleHelper::SizeDefault); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Box, QStyleHelper::SizeDefault); auto *box = static_cast(d->cocoaControl(cw)); d->drawNSViewInRect(cw, box, groupBox->rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { CGContextTranslateCTM(ctx, 0, rect.origin.y + rect.size.height); @@ -3397,7 +3397,8 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_IndicatorBranch: { if (!(opt->state & State_Children)) break; - NSButtonCell *triangleCell = static_cast(d->cocoaCell(QCocoaWidget(QCocoaDisclosureButton, QStyleHelper::SizeLarge))); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Button_Disclosure, QStyleHelper::SizeLarge); + NSButtonCell *triangleCell = static_cast(d->cocoaCell(cw)); [triangleCell setState:(opt->state & State_Open) ? NSOnState : NSOffState]; bool viewHasFocus = (w && w->hasFocus()) || (opt->state & State_HasFocus); [triangleCell setBackgroundStyle:((opt->state & State_Selected) && viewHasFocus) ? NSBackgroundStyleDark : NSBackgroundStyleLight]; @@ -3884,8 +3885,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } if (hasMenu && bdi.kind != kThemeBevelButton) { - QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind); - cw.first = QCocoaPullDownButton; + auto cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind); + cw.first = QMacStylePrivate::Button_PullDown; NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(cw); [pdb highlight:(bdi.state == kThemeStatePressed)]; pdb.enabled = bdi.state != kThemeStateUnavailable && bdi.state != kThemeStateUnavailableInactive; @@ -4451,7 +4452,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter const QProgressStyleAnimation *animation = qobject_cast(d->animation(opt->styleObject)); QIndeterminateProgressIndicator *ipi = nil; if (isIndeterminate || animation) - ipi = static_cast(d->cocoaControl({ QCocoaIndeterminateProgressIndicator, aquaSize })); + ipi = static_cast(d->cocoaControl({ QMacStylePrivate::ProgressIndicator_Indeterminate, aquaSize })); if (isIndeterminate) { // QIndeterminateProgressIndicator derives from NSProgressIndicator. We use a single // instance that we start animating as soon as one of the progress bars is indeterminate. @@ -4478,7 +4479,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter [ipi stopAnimation]; } - const QCocoaWidget cw = { QCocoaProgressIndicator, aquaSize }; + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::ProgressIndicator_Determinate, aquaSize); auto *pi = static_cast(d->cocoaControl(cw)); d->drawNSViewInRect(cw, pi, rect, p, w != nullptr, ^(CGContextRef ctx, const CGRect &rect) { d->setupVerticalInvertedXform(ctx, reverse, vertical, rect); @@ -5265,7 +5266,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex d->setupNSGraphicsContext(cg, NO /* flipped */); - const QCocoaWidget cw(isHorizontal ? QCocoaHorizontalScroller : QCocoaVerticalScroller, cocoaSize); + const auto controlType = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical; + const auto cw = QMacStylePrivate::CocoaControl(controlType, cocoaSize); NSScroller *scroller = static_cast(d->cocoaControl(cw)); if (isTransient) { @@ -5347,8 +5349,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex case CC_Slider: if (const QStyleOptionSlider *sl = qstyleoption_cast(opt)) { const bool isHorizontal = sl->orientation == Qt::Horizontal; + const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical; const auto cs = d->effectiveAquaSizeConstrain(opt, widget); - const auto cw = QCocoaWidget(isHorizontal ? QCocoaHorizontalSlider : QCocoaVerticalSlider, cs); + const auto cw = QMacStylePrivate::CocoaControl(ct, cs); auto *slider = static_cast(d->cocoaControl(cw)); if (!setupSlider(slider, sl)) break; @@ -5483,7 +5486,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex d->setupNSGraphicsContext(cg, NO); const auto aquaSize = d->effectiveAquaSizeConstrain(opt, widget); - NSStepperCell *cell = static_cast(d->cocoaCell(QCocoaWidget(QCocoaStepper, aquaSize))); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize); + NSStepperCell *cell = static_cast(d->cocoaCell(cw)); cell.enabled = (sb->state & State_Enabled); const CGRect newRect = [cell drawingRectForBounds:updown.toCGRect()]; @@ -5518,7 +5522,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (tds != kThemeStateInactive) QMacStylePrivate::drawCombobox(rect, bdi, p); else if (!widget && combo->editable) { - QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind); + const auto cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind); NSView *cb = d->cocoaControl(cw); QRect r = combo->rect.adjusted(3, 0, 0, 0); d->drawNSViewInRect(cw, cb, r, p, widget != 0); @@ -5822,8 +5826,9 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, const bool hasTicks = sl->tickPosition != QSlider::NoTicks; const bool isHorizontal = sl->orientation == Qt::Horizontal; + const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical; const auto cs = d->effectiveAquaSizeConstrain(opt, widget); - const auto cw = QCocoaWidget(isHorizontal ? QCocoaHorizontalSlider : QCocoaVerticalSlider, cs); + const auto cw = QMacStylePrivate::CocoaControl(ct, cs); auto *slider = static_cast(d->cocoaControl(cw)); if (!setupSlider(slider, sl)) break; @@ -5848,9 +5853,10 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, break; } - const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget); const bool isHorizontal = sb->orientation == Qt::Horizontal; - const auto cw = QCocoaWidget(isHorizontal ? QCocoaHorizontalScroller : QCocoaVerticalScroller, controlSize); + const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical; + const auto cs = d->effectiveAquaSizeConstrain(opt, widget); + const auto cw = QMacStylePrivate::CocoaControl(ct, cs); auto *scroller = static_cast(d->cocoaControl(cw)); if (!setupScroller(scroller, sb)) { sc = SC_None; @@ -5956,8 +5962,9 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op // And nothing else since 10.7 if (part != NSScrollerNoPart) { - const auto controlSize = d->effectiveAquaSizeConstrain(opt, widget); - const auto cw = QCocoaWidget(isHorizontal ? QCocoaHorizontalScroller : QCocoaVerticalScroller, controlSize); + const auto ct = isHorizontal ? QMacStylePrivate::Scroller_Horizontal : QMacStylePrivate::Scroller_Vertical; + const auto cs = d->effectiveAquaSizeConstrain(opt, widget); + const auto cw = QMacStylePrivate::CocoaControl(ct, cs); auto *scroller = static_cast(d->cocoaControl(cw)); if (setupScroller(scroller, sb)) ret = QRectF::fromCGRect([scroller rectForPart:part]).toRect(); @@ -5968,8 +5975,9 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op if (const QStyleOptionSlider *sl = qstyleoption_cast(opt)) { const bool hasTicks = sl->tickPosition != QSlider::NoTicks; const bool isHorizontal = sl->orientation == Qt::Horizontal; + const auto ct = isHorizontal ? QMacStylePrivate::Slider_Horizontal : QMacStylePrivate::Slider_Vertical; const auto cs = d->effectiveAquaSizeConstrain(opt, widget); - const auto cw = QCocoaWidget(isHorizontal ? QCocoaHorizontalSlider : QCocoaVerticalSlider, cs); + const auto cw = QMacStylePrivate::CocoaControl(ct, cs); auto *slider = static_cast(d->cocoaControl(cw)); if (!setupSlider(slider, sl)) break; @@ -6230,7 +6238,8 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op Q_UNREACHABLE(); } - NSStepperCell *cell = static_cast(d->cocoaCell(QCocoaWidget(QCocoaStepper, aquaSize))); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::Stepper, aquaSize); + NSStepperCell *cell = static_cast(d->cocoaCell(cw)); const CGRect outRect = [cell drawingRectForBounds:ret.toCGRect()]; ret = QRectF::fromCGRect(outRect).toRect(); diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index 528edfcda1..9c38831c0a 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -167,28 +167,6 @@ QT_BEGIN_NAMESPACE #define CT1(c) CT2(c, c) #define CT2(c1, c2) ((uint(c1) << 16) | uint(c2)) -enum QCocoaWidgetKind { - QCocoaBox, // QGroupBox - QCocoaCheckBox, - QCocoaComboBox, // Editable QComboBox - QCocoaDisclosureButton, // Disclosure triangle, like in QTreeView - QCocoaPopupButton, // Non-editable QComboBox - QCocoaProgressIndicator, - QCocoaIndeterminateProgressIndicator, - QCocoaPullDownButton, // QPushButton with menu - QCocoaPushButton, - QCocoaRadioButton, - QCocoaHorizontalScroller, - QCocoaVerticalScroller, - QCocoaHorizontalSlider, - QCocoaVerticalSlider, - QCocoaStepper // QSpinBox buttons -}; - -typedef QPair QCocoaWidget; - -typedef void (^QCocoaDrawRectBlock)(CGContextRef, const CGRect &); - #define SIZE(large, small, mini) \ (controlSize == QStyleHelper::SizeLarge ? (large) : controlSize == QStyleHelper::SizeSmall ? (small) : (mini)) @@ -207,6 +185,28 @@ class QMacStylePrivate : public QCommonStylePrivate { Q_DECLARE_PUBLIC(QMacStyle) public: + enum CocoaControlType { + Box, // QGroupBox + Button_CheckBox, + Button_Disclosure, // Disclosure triangle, like in QTreeView + Button_PopupButton, // Non-editable QComboBox + Button_PullDown, // QPushButton with menu + Button_PushButton, + Button_RadioButton, + ComboBox, // Editable QComboBox + ProgressIndicator_Determinate, + ProgressIndicator_Indeterminate, + Scroller_Horizontal, + Scroller_Vertical, + Slider_Horizontal, + Slider_Vertical, + Stepper // QSpinBox buttons + }; + + typedef QPair CocoaControl; + + typedef void (^DrawRectBlock)(CGContextRef, const CGRect &); + QMacStylePrivate(); ~QMacStylePrivate(); @@ -260,15 +260,17 @@ public: void setAutoDefaultButton(QObject *button) const; - NSView *cocoaControl(QCocoaWidget widget) const; - NSCell *cocoaCell(QCocoaWidget widget) const; + NSView *cocoaControl(CocoaControl widget) const; + NSCell *cocoaCell(CocoaControl widget) const; + + static CocoaControl cocoaControlFromHIThemeButtonKind(ThemeButtonKind kind); void setupNSGraphicsContext(CGContextRef cg, bool flipped) const; void restoreNSGraphicsContext(CGContextRef cg) const; void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const; - void drawNSViewInRect(QCocoaWidget widget, NSView *view, const QRect &rect, QPainter *p, bool isQWidget = true, QCocoaDrawRectBlock drawRectBlock = nil) const; + void drawNSViewInRect(CocoaControl widget, NSView *view, const QRect &rect, QPainter *p, bool isQWidget = true, DrawRectBlock drawRectBlock = nil) const; void resolveCurrentNSView(QWindow *window); void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; @@ -284,8 +286,8 @@ public: mutable QPointer focusWidget; QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver; NSView *backingStoreNSView; - mutable QHash cocoaControls; - mutable QHash cocoaCells; + mutable QHash cocoaControls; + mutable QHash cocoaCells; QFont smallSystemFont; QFont miniSystemFont; -- cgit v1.2.3 From dbc1c790431aab1d45ca8c77886dbd6438c139de Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 7 Nov 2017 14:05:21 +0700 Subject: QMacStyle: Remove unused code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6e71871b19ce12daddd4cfbbe7c1d9beede13a9b Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 66 ------------------------------ src/plugins/styles/mac/qmacstyle_mac_p.h | 4 -- src/plugins/styles/mac/qmacstyle_mac_p_p.h | 4 -- 3 files changed, 74 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 9c5ede6d47..3ae13c3282 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -569,7 +569,6 @@ static inline ThemeTabDirection getTabDirection(QTabBar::Shape shape) case QTabBar::TriangularSouth: ttd = kThemeTabSouth; break; - default: // Added to remove the warning, since all values are taken care of, really! case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: ttd = kThemeTabNorth; @@ -622,47 +621,6 @@ static QString qt_mac_removeMnemonics(const QString &original) return returnText; } -OSStatus qt_mac_shape2QRegionHelper(int inMessage, HIShapeRef, const CGRect *inRect, void *inRefcon) -{ - QRegion *region = static_cast(inRefcon); - if (!region) - return paramErr; - - switch (inMessage) { - case kHIShapeEnumerateRect: - *region += QRect(inRect->origin.x, inRect->origin.y, - inRect->size.width, inRect->size.height); - break; - case kHIShapeEnumerateInit: - // Assume the region is already setup correctly - case kHIShapeEnumerateTerminate: - default: - break; - } - return noErr; -} - -/*! - \internal - Create's a mutable shape, it's the caller's responsibility to release. - WARNING: this function clamps the coordinates to SHRT_MIN/MAX on 10.4 and below. -*/ -HIMutableShapeRef qt_mac_toHIMutableShape(const QRegion ®ion) -{ - HIMutableShapeRef shape = HIShapeCreateMutable(); - if (region.rectCount() < 2 ) { - QRect qtRect = region.boundingRect(); - CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height()); - HIShapeUnionWithRect(shape, &cgRect); - } else { - for (const QRect &qtRect : region) { - CGRect cgRect = CGRectMake(qtRect.x(), qtRect.y(), qtRect.width(), qtRect.height()); - HIShapeUnionWithRect(shape, &cgRect); - } - } - return shape; -} - bool qt_macWindowIsTextured(const QWidget *window) { if (QWindow *w = window->windowHandle()) @@ -1518,18 +1476,6 @@ void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, } } -#if QT_CONFIG(pushbutton) -bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option) -{ - QMacStyle *macStyle = qobject_cast(pushButton->style()); - if (!macStyle) - return false; - HIThemeButtonDrawInfo bdi; - macStyle->d_func()->initHIThemePushButton(option, pushButton, kThemeStateActive, &bdi); - return bdi.kind == kThemeBevelButton; -} -#endif - /** Creates a HIThemeButtonDrawInfo structure that specifies the correct button kind and other details to use for drawing the given combobox. Which button @@ -6817,16 +6763,4 @@ int QMacStyle::layoutSpacing(QSizePolicy::ControlType control1, return_SIZE(10, 8, 6); // guess } -/* -FontHash::FontHash() -{ - QHash::operator=(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFonts()); -} - -Q_GLOBAL_STATIC(FontHash, app_fonts) -FontHash *qt_app_fonts_hash() -{ - return app_fonts(); -} -*/ QT_END_NAMESPACE diff --git a/src/plugins/styles/mac/qmacstyle_mac_p.h b/src/plugins/styles/mac/qmacstyle_mac_p.h index 6011baeea2..d6874001d3 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p.h @@ -117,10 +117,6 @@ public: private: Q_DISABLE_COPY(QMacStyle) Q_DECLARE_PRIVATE(QMacStyle) - -#if QT_CONFIG(pushbutton) - friend bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option); -#endif }; QT_END_NAMESPACE diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index 9c38831c0a..b893e851fd 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -177,10 +177,6 @@ QT_BEGIN_NAMESPACE return sizes[controlSize]; \ } while (false) -#if QT_CONFIG(pushbutton) -bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option); -#endif - class QMacStylePrivate : public QCommonStylePrivate { Q_DECLARE_PUBLIC(QMacStyle) -- cgit v1.2.3 From 9af0601fd91d9a0fa6266e978c8b742a38140b7f Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 7 Nov 2017 14:15:39 +0700 Subject: QMacStyle: Replace HITheme info structs with QMSP::CocoaControl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not yet a full replacement, but a scaffolding stage until we can remove all traces of HITheme info structs. Change-Id: I10eb6a60662c6b102bc687e335d0d1bedd6a4a12 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 164 ++++++++++++++++------------- src/plugins/styles/mac/qmacstyle_mac_p_p.h | 6 +- 2 files changed, 92 insertions(+), 78 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 3ae13c3282..a8cb361969 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -1483,6 +1483,7 @@ void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, explicit user style settings, etc. */ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThemeButtonDrawInfo *bdi, + CocoaControl *cw, const QWidget *widget, const ThemeDrawState &tds) const { bdi->version = qt_mac_hitheme_version; @@ -1496,6 +1497,8 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem bdi->state = tds; QStyleHelper::WidgetSizePolicy aSize = aquaSizeConstrain(combo, widget); + cw->first = combo->editable ? ComboBox : Button_PopupButton; + cw->second = aSize; switch (aSize) { case QStyleHelper::SizeMini: bdi->kind = combo->editable ? ThemeButtonKind(kThemeComboBoxMini) @@ -1525,21 +1528,29 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem // them forever). So anyway, the height threshold should be smaller // in this case, or the style gets confused when it needs to render // or return any subcontrol size of the poor thing. - if (h < 9) + if (h < 9) { bdi->kind = kThemeComboBoxMini; - else if (h < 22) + cw->second = QStyleHelper::SizeMini; + } else if (h < 22) { bdi->kind = kThemeComboBoxSmall; - else + cw->second = QStyleHelper::SizeSmall; + } else { bdi->kind = kThemeComboBox; + cw->second = QStyleHelper::SizeLarge; + } } else #endif { - if (h < 21) + if (h < 21) { bdi->kind = kThemeComboBoxMini; - else if (h < 26) + cw->second = QStyleHelper::SizeMini; + } else if (h < 26) { bdi->kind = kThemeComboBoxSmall; - else + cw->second = QStyleHelper::SizeSmall; + } else { bdi->kind = kThemeComboBox; + cw->second = QStyleHelper::SizeLarge; + } } } else { // Even if we specify that we want the kThemePopupButton, Carbon @@ -1547,12 +1558,16 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem // do the same size check explicit to have the size of the inner // text field be correct. Therefore, do this even if the user specifies // the use of LargeButtons explicit. - if (h < 21) + if (h < 21) { bdi->kind = kThemePopupButtonMini; - else if (h < 26) + cw->second = QStyleHelper::SizeMini; + } else if (h < 26) { bdi->kind = kThemePopupButtonSmall; - else + cw->second = QStyleHelper::SizeSmall; + } else { bdi->kind = kThemePopupButton; + cw->second = QStyleHelper::SizeLarge; + } } break; } @@ -1562,51 +1577,54 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem Carbon draws comboboxes (and other views) outside the rect given as argument. Use this function to obtain the corresponding inner rect for drawing the same combobox so that it stays inside the given outerBounds. */ -CGRect QMacStylePrivate::comboboxInnerBounds(const CGRect &outerBounds, int buttonKind) +CGRect QMacStylePrivate::comboboxInnerBounds(const CGRect &outerBounds, const CocoaControl &cocoaWidget) { CGRect innerBounds = outerBounds; // Carbon draw parts of the view outside the rect. // So make the rect a bit smaller to compensate // (I wish HIThemeGetButtonBackgroundBounds worked) - switch (buttonKind){ - case kThemePopupButton: - innerBounds.origin.x += 2; - innerBounds.origin.y += 2; - innerBounds.size.width -= 5; - innerBounds.size.height -= 6; - break; - case kThemePopupButtonSmall: - innerBounds.origin.x += 3; - innerBounds.origin.y += 3; - innerBounds.size.width -= 6; - innerBounds.size.height -= 7; - break; - case kThemePopupButtonMini: - innerBounds.origin.x += 2; - innerBounds.origin.y += 2; - innerBounds.size.width -= 5; - innerBounds.size.height -= 6; - break; - case kThemeComboBox: - innerBounds.origin.x += 3; - innerBounds.origin.y += 2; - innerBounds.size.width -= 6; - innerBounds.size.height -= 8; - break; - case kThemeComboBoxSmall: - innerBounds.origin.x += 3; - innerBounds.origin.y += 3; - innerBounds.size.width -= 7; - innerBounds.size.height -= 8; - break; - case kThemeComboBoxMini: - innerBounds.origin.x += 3; - innerBounds.origin.y += 3; - innerBounds.size.width -= 4; - innerBounds.size.height -= 8; - break; - default: - break; + if (cocoaWidget.first == Button_PopupButton) { + switch (cocoaWidget.second) { + case QStyleHelper::SizeSmall: + innerBounds.origin.x += 3; + innerBounds.origin.y += 3; + innerBounds.size.width -= 6; + innerBounds.size.height -= 7; + break; + case QStyleHelper::SizeMini: + innerBounds.origin.x += 2; + innerBounds.origin.y += 2; + innerBounds.size.width -= 5; + innerBounds.size.height -= 6; + break; + case QStyleHelper::SizeLarge: + case QStyleHelper::SizeDefault: + innerBounds.origin.x += 2; + innerBounds.origin.y += 2; + innerBounds.size.width -= 5; + innerBounds.size.height -= 6; + } + } else if (cocoaWidget.first == ComboBox) { + switch (cocoaWidget.second) { + case QStyleHelper::SizeSmall: + innerBounds.origin.x += 3; + innerBounds.origin.y += 3; + innerBounds.size.width -= 7; + innerBounds.size.height -= 8; + break; + case QStyleHelper::SizeMini: + innerBounds.origin.x += 3; + innerBounds.origin.y += 3; + innerBounds.size.width -= 4; + innerBounds.size.height -= 8; + break; + case QStyleHelper::SizeLarge: + case QStyleHelper::SizeDefault: + innerBounds.origin.x += 3; + innerBounds.origin.y += 2; + innerBounds.size.width -= 6; + innerBounds.size.height -= 8; + } } return innerBounds; @@ -1650,11 +1668,11 @@ QRect QMacStylePrivate::comboboxEditBounds(const QRect &outerBounds, const HIThe create it manually by drawing a small Carbon combo onto a pixmap (use pixmap cache), chop it up, and copy it back onto the widget. Othervise, draw the combobox supplied by Carbon directly. */ -void QMacStylePrivate::drawCombobox(const CGRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p) +void QMacStylePrivate::drawCombobox(const CGRect &outerBounds, const HIThemeButtonDrawInfo &bdi, const CocoaControl &cw, QPainter *p) { if (!(bdi.kind == kThemeComboBox && outerBounds.size.height > 28)){ // We have an unscaled combobox, or popup-button; use Carbon directly. - const CGRect innerBounds = QMacStylePrivate::comboboxInnerBounds(outerBounds, bdi.kind); + const CGRect innerBounds = QMacStylePrivate::comboboxInnerBounds(outerBounds, cw); HIThemeDrawButton(&innerBounds, &bdi, QMacCGContext(p), kHIThemeOrientationNormal, 0); } else { QPixmap buffer; @@ -2045,7 +2063,7 @@ void QMacStylePrivate::resolveCurrentNSView(QWindow *window) backingStoreNSView = window ? (NSView *)window->winId() : nil; } -void QMacStylePrivate::drawColorlessButton(const CGRect &macRect, HIThemeButtonDrawInfo *bdi, +void QMacStylePrivate::drawColorlessButton(const CGRect &macRect, HIThemeButtonDrawInfo *bdi, const CocoaControl &cw, QPainter *p, const QStyleOption *opt) const { int xoff = 0, @@ -2093,7 +2111,7 @@ void QMacStylePrivate::drawColorlessButton(const CGRect &macRect, HIThemeButtonD // Carbon combos don't scale. Therefore we draw it // ourselves, if a scaled version is needed. QPainter tmpPainter(&activePixmap); - QMacStylePrivate::drawCombobox(macRect, *bdi, &tmpPainter); + QMacStylePrivate::drawCombobox(macRect, *bdi, cw, &tmpPainter); } else { QMacCGContext cg(&activePixmap); CGRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); @@ -3332,10 +3350,11 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai else bdi.value = kThemeButtonOff; CGRect macRect = opt->rect.toCGRect(); + const QMacStylePrivate::CocoaControl cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind); if (!drawColorless) HIThemeDrawButton(&macRect, &bdi, cg, kHIThemeOrientationNormal, 0); else - d->drawColorlessButton(macRect, &bdi, p, opt); + d->drawColorlessButton(macRect, &bdi, cw, p, opt); break; } case PE_FrameFocusRect: // Use the our own focus widget stuff. @@ -3830,9 +3849,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4; } - if (hasMenu && bdi.kind != kThemeBevelButton) { - auto cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind); + QMacStylePrivate::CocoaControl cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind); + if (hasMenu) cw.first = QMacStylePrivate::Button_PullDown; + if (hasMenu && bdi.kind != kThemeBevelButton) { NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(cw); [pdb highlight:(bdi.state == kThemeStatePressed)]; pdb.enabled = bdi.state != kThemeStateUnavailable && bdi.state != kThemeStateUnavailableInactive; @@ -3840,7 +3860,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter rect.adjust(0, 0, cw.second == QStyleHelper::SizeSmall ? -4 : cw.second == QStyleHelper::SizeMini ? -9 : -6, 0); d->drawNSViewInRect(cw, pdb, rect, p, w != 0); } else if (hasMenu && bdi.state == kThemeStatePressed) - d->drawColorlessButton(newRect, &bdi, p, opt); + d->drawColorlessButton(newRect, &bdi, cw, p, opt); else HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); @@ -5461,19 +5481,20 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex case CC_ComboBox: if (const QStyleOptionComboBox *combo = qstyleoption_cast(opt)){ HIThemeButtonDrawInfo bdi; - d->initComboboxBdi(combo, &bdi, widget, tds); + QMacStylePrivate::CocoaControl cw; + d->initComboboxBdi(combo, &bdi, &cw, widget, tds); CGRect rect = combo->rect.toCGRect(); if (combo->editable) rect.origin.y += tds == kThemeStateInactive ? 1 : 2; if (tds != kThemeStateInactive) - QMacStylePrivate::drawCombobox(rect, bdi, p); + QMacStylePrivate::drawCombobox(rect, bdi, cw, p); else if (!widget && combo->editable) { const auto cw = QMacStylePrivate::cocoaControlFromHIThemeButtonKind(bdi.kind); NSView *cb = d->cocoaControl(cw); QRect r = combo->rect.adjusted(3, 0, 0, 0); d->drawNSViewInRect(cw, cb, r, p, widget != 0); } else - d->drawColorlessButton(rect, &bdi, p, opt); + d->drawColorlessButton(rect, &bdi, cw, p, opt); } break; case CC_TitleBar: @@ -6017,7 +6038,8 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op case CC_ComboBox: if (const QStyleOptionComboBox *combo = qstyleoption_cast(opt)) { HIThemeButtonDrawInfo bdi; - d->initComboboxBdi(combo, &bdi, widget, d->getDrawState(opt->state)); + QMacStylePrivate::CocoaControl cw; + d->initComboboxBdi(combo, &bdi, &cw, widget, d->getDrawState(opt->state)); switch (sc) { case SC_ComboBoxEditField:{ @@ -6032,7 +6054,7 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op break; } case SC_ComboBoxListBoxPopup:{ if (combo->editable) { - const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), bdi.kind); + const CGRect inner = QMacStylePrivate::comboboxInnerBounds(combo->rect.toCGRect(), cw); QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); const int comboTop = combo->rect.top(); ret = QRect(qRound(inner.origin.x), @@ -6509,20 +6531,10 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, // We compensate for this by adding some extra space here to make room for the frame when drawing: if (const QStyleOptionComboBox *combo = qstyleoption_cast(opt)){ const auto widgetSize = d->aquaSizeConstrain(opt, widget); - int bkind = 0; - switch (widgetSize) { - default: - case QStyleHelper::SizeLarge: - bkind = combo->editable ? kThemeComboBox : kThemePopupButton; - break; - case QStyleHelper::SizeSmall: - bkind = combo->editable ? int(kThemeComboBoxSmall) : int(kThemePopupButtonSmall); - break; - case QStyleHelper::SizeMini: - bkind = combo->editable ? kThemeComboBoxMini : kThemePopupButtonMini; - break; - } - const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, bkind); + QMacStylePrivate::CocoaControl cw; + cw.first = combo->editable ? QMacStylePrivate::ComboBox : QMacStylePrivate::Button_PopupButton; + cw.second = widgetSize; + const CGRect diffRect = QMacStylePrivate::comboboxInnerBounds(CGRectZero, cw); sz.rwidth() -= qRound(diffRect.size.width); sz.rheight() -= qRound(diffRect.size.height); } else if (ct == CT_PushButton || ct == CT_ToolButton){ diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index b893e851fd..01b0a15427 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -231,6 +231,7 @@ public: // Utility functions void drawColorlessButton(const CGRect &macRect, HIThemeButtonDrawInfo *bdi, + const CocoaControl &cw, QPainter *p, const QStyleOption *opt) const; QSize pushButtonSizeFromContents(const QStyleOptionButton *btn) const; @@ -239,13 +240,14 @@ public: const HIThemeButtonDrawInfo *bdi) const; void initComboboxBdi(const QStyleOptionComboBox *combo, HIThemeButtonDrawInfo *bdi, + CocoaControl *cw, const QWidget *widget, const ThemeDrawState &tds) const; - static CGRect comboboxInnerBounds(const CGRect &outerBounds, int buttonKind); + static CGRect comboboxInnerBounds(const CGRect &outerBounds, const CocoaControl &cocoaWidget); static QRect comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi); - static void drawCombobox(const CGRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p); + static void drawCombobox(const CGRect &outerBounds, const HIThemeButtonDrawInfo &bdi, const CocoaControl &cw, QPainter *p); static void drawTableHeader(const CGRect &outerBounds, bool drawTopBorder, bool drawLeftBorder, const HIThemeButtonDrawInfo &bdi, QPainter *p); bool contentFitsInPushButton(const QStyleOptionButton *btn, HIThemeButtonDrawInfo *bdi, -- cgit v1.2.3 From 1939cb02104d8e5ca0e4169e18b8e1f400090921 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 7 Nov 2017 16:37:12 +0700 Subject: QMacStyle: Make backingStoreNSView mutable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even thought the resolve function is effectively not const, it's more straightforward to call. Change-Id: I7c881183862c3c0b326daf001b2f9e569153ee76 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 8 ++++---- src/plugins/styles/mac/qmacstyle_mac_p_p.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index a8cb361969..c7f573cc08 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -2058,7 +2058,7 @@ void QMacStylePrivate::drawNSViewInRect(CocoaControl widget, NSView *view, const restoreNSGraphicsContext(ctx); } -void QMacStylePrivate::resolveCurrentNSView(QWindow *window) +void QMacStylePrivate::resolveCurrentNSView(QWindow *window) const { backingStoreNSView = window ? (NSView *)window->winId() : nil; } @@ -3095,7 +3095,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai QMacCGContext cg(p); QWindow *window = w && w->window() ? w->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); - const_cast(d)->resolveCurrentNSView(window); + d->resolveCurrentNSView(window); switch (pe) { case PE_IndicatorArrowUp: case PE_IndicatorArrowDown: @@ -3593,7 +3593,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QMacCGContext cg(p); QWindow *window = w && w->window() ? w->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); - const_cast(d)->resolveCurrentNSView(window); + d->resolveCurrentNSView(window); switch (ce) { case CE_HeaderSection: if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { @@ -5126,7 +5126,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex QMacCGContext cg(p); QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : QStyleHelper::styleObjectWindow(opt->styleObject); - const_cast(d)->resolveCurrentNSView(window); + d->resolveCurrentNSView(window); switch (cc) { case CC_ScrollBar: if (const QStyleOptionSlider *sb = qstyleoption_cast(opt)) { diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index 01b0a15427..045753989f 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -269,7 +269,7 @@ public: void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const; void drawNSViewInRect(CocoaControl widget, NSView *view, const QRect &rect, QPainter *p, bool isQWidget = true, DrawRectBlock drawRectBlock = nil) const; - void resolveCurrentNSView(QWindow *window); + void resolveCurrentNSView(QWindow *window) const; void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; @@ -283,7 +283,7 @@ public: mutable QPointer focusWidget; QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver; - NSView *backingStoreNSView; + mutable NSView *backingStoreNSView; mutable QHash cocoaControls; mutable QHash cocoaCells; -- cgit v1.2.3 From 67e3d192398ccf06d4411acc86df7748b0de98a5 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 9 Nov 2017 13:21:23 +0700 Subject: QMacStyle: Render tool button even when a11y is missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tool buttons were being skipped a couple cases (CE_ToolButtonLabel and CC_ToolButton) when accessibility was disabled. Although unlikely anyone would disable accessibility on macOS, we fall back to the non- toolbar rendering if that were to be the case. Change-Id: Ie8ee11475efbe4b418c34842317bafeba80c3c57 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index c7f573cc08..1246f64a7d 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3786,12 +3786,11 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } else { QCommonStyle::drawControl(ce, &myTb, p, w); } - } else { + } else +#endif // QT_NO_ACCESSIBILITY + { QCommonStyle::drawControl(ce, &myTb, p, w); } -#else - Q_UNUSED(tb) -#endif } break; case CE_ToolBoxTabShape: @@ -5674,7 +5673,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex p->fillPath(path, brush); } proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget); - } else { + } else +#endif // QT_NO_ACCESSIBILITY + { ThemeButtonKind bkind = kThemeBevelButton; switch (d->aquaSizeConstrain(opt, widget)) { case QStyleHelper::SizeDefault: @@ -5757,7 +5758,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex label.rect = buttonRect.adjusted(fw, fw, -fw, -fw); proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget); } -#endif } break; #if QT_CONFIG(dial) -- cgit v1.2.3 From c1780b932268ff070387de80a617c9763263a9f0 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 9 Nov 2017 21:41:24 +0800 Subject: QMacStyle: De-HITheme item views headers and a couple arrows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This one is all manual. The arrows were manual before and the header sections are now plain rectangles. Removes one usage of HIThemeDrawButton and related logic together with a cached pixmap and its rendering. Still broken in some places, but not worse than before. In particular, sunken or selected header sections will not render the left hand side section separator properly. Look can be improved in the header label with different shades for the selected or current rows/columns. Change-Id: I6b1c1f529909341bbf72e82e5a3fc61905c75fa8 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 190 +++++++++-------------------- src/plugins/styles/mac/qmacstyle_mac_p_p.h | 2 - 2 files changed, 57 insertions(+), 135 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 1246f64a7d..c6ae7c1b79 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -311,6 +311,9 @@ static const QColor tabBarCloseButtonCrossSelected(115, 115, 115); static const int closeButtonSize = 14; static const qreal closeButtonCornerRadius = 2.0; +static const int headerSectionArrowHeight = 6; +static const int headerSectionSeparatorInset = 2; + #if QT_CONFIG(tabbar) static bool isVerticalTabs(const QTabBar::Shape shape) { return (shape == QTabBar::RoundedEast @@ -1715,69 +1718,6 @@ void QMacStylePrivate::drawCombobox(const CGRect &outerBounds, const HIThemeButt } } -/** - Carbon tableheaders don't scale (sight). So create it manually by drawing a small Carbon header - onto a pixmap (use pixmap cache), chop it up, and copy it back onto the widget. -*/ -void QMacStylePrivate::drawTableHeader(const CGRect &outerBounds, - bool drawTopBorder, bool drawLeftBorder, const HIThemeButtonDrawInfo &bdi, QPainter *p) -{ - static int headerHeight = qt_mac_aqua_get_metric(ListHeaderHeight); - - QPixmap buffer; - QString key = QString(QLatin1String("$qt_tableh%1-%2-%3")).arg(int(bdi.state)).arg(int(bdi.adornment)).arg(int(bdi.value)); - if (!QPixmapCache::find(key, buffer)) { - CGRect headerNormalRect = {{0., 0.}, {16., CGFloat(headerHeight)}}; - buffer = QPixmap(headerNormalRect.size.width, headerNormalRect.size.height); - buffer.fill(Qt::transparent); - QPainter buffPainter(&buffer); - HIThemeDrawButton(&headerNormalRect, &bdi, QMacCGContext(&buffPainter), kHIThemeOrientationNormal, 0); - buffPainter.end(); - QPixmapCache::insert(key, buffer); - } - const int buttonw = qRound(outerBounds.size.width); - const int buttonh = qRound(outerBounds.size.height); - const int framew = 1; - const int frameh_n = 4; - const int frameh_s = 3; - const int transh = buffer.height() - frameh_n - frameh_s; - int center = buttonh - frameh_s - int(transh / 2.0f) + 1; // Align bottom; - - int skipTopBorder = 0; - if (!drawTopBorder) - skipTopBorder = 1; - - p->translate(outerBounds.origin.x, outerBounds.origin.y); - - p->drawPixmap(QRect(QRect(0, -skipTopBorder, buttonw - framew , frameh_n)), buffer, QRect(framew, 0, 1, frameh_n)); - p->drawPixmap(QRect(0, buttonh - frameh_s, buttonw - framew, frameh_s), buffer, QRect(framew, buffer.height() - frameh_s, 1, frameh_s)); - // Draw upper and lower center blocks - p->drawPixmap(QRect(0, frameh_n - skipTopBorder, buttonw - framew, center - frameh_n + skipTopBorder), buffer, QRect(framew, frameh_n, 1, 1)); - p->drawPixmap(QRect(0, center, buttonw - framew, buttonh - center - frameh_s), buffer, QRect(framew, buffer.height() - frameh_s, 1, 1)); - // Draw right center block borders - p->drawPixmap(QRect(buttonw - framew, frameh_n - skipTopBorder, framew, center - frameh_n), buffer, QRect(buffer.width() - framew, frameh_n, framew, 1)); - p->drawPixmap(QRect(buttonw - framew, center, framew, buttonh - center - 1), buffer, QRect(buffer.width() - framew, buffer.height() - frameh_s, framew, 1)); - // Draw right corners - p->drawPixmap(QRect(buttonw - framew, -skipTopBorder, framew, frameh_n), buffer, QRect(buffer.width() - framew, 0, framew, frameh_n)); - p->drawPixmap(QRect(buttonw - framew, buttonh - frameh_s, framew, frameh_s), buffer, QRect(buffer.width() - framew, buffer.height() - frameh_s, framew, frameh_s)); - // Draw center transition block - p->drawPixmap(QRect(0, center - qRound(transh / 2.0f), buttonw - framew, buffer.height() - frameh_n - frameh_s), buffer, QRect(framew, frameh_n + 1, 1, transh)); - // Draw right center transition block border - p->drawPixmap(QRect(buttonw - framew, center - qRound(transh / 2.0f), framew, buffer.height() - frameh_n - frameh_s), buffer, QRect(buffer.width() - framew, frameh_n + 1, framew, transh)); - if (drawLeftBorder){ - // Draw left center block borders - p->drawPixmap(QRect(0, frameh_n - skipTopBorder, framew, center - frameh_n + skipTopBorder), buffer, QRect(0, frameh_n, framew, 1)); - p->drawPixmap(QRect(0, center, framew, buttonh - center - 1), buffer, QRect(0, buffer.height() - frameh_s, framew, 1)); - // Draw left corners - p->drawPixmap(QRect(0, -skipTopBorder, framew, frameh_n), buffer, QRect(0, 0, framew, frameh_n)); - p->drawPixmap(QRect(0, buttonh - frameh_s, framew, frameh_s), buffer, QRect(0, buffer.height() - frameh_s, framew, frameh_s)); - // Draw left center transition block border - p->drawPixmap(QRect(0, center - qRound(transh / 2.0f), framew, buffer.height() - frameh_n - frameh_s), buffer, QRect(0, frameh_n + 1, framew, transh)); - } - - p->translate(-outerBounds.origin.x, -outerBounds.origin.y); -} - QMacStylePrivate::QMacStylePrivate() : backingStoreNSView(nil) { @@ -3103,7 +3043,17 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_IndicatorArrowLeft: { p->save(); p->setRenderHint(QPainter::Antialiasing); - int xOffset = opt->direction == Qt::LeftToRight ? 2 : -1; + const int xOffset = 1; // FIXME: opt->direction == Qt::LeftToRight ? 2 : -1; + qreal halfSize = 0.5 * qMin(opt->rect.width(), opt->rect.height()); + const qreal penWidth = qMax(halfSize / 3.0, 1.25); +#if QT_CONFIG(toolbutton) + if (const QToolButton *tb = qobject_cast(w)) { + // When stroking the arrow, make sure it fits in the tool button + if (tb->arrowType() != Qt::NoArrow) + halfSize -= penWidth; + } +#endif + QMatrix matrix; matrix.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); QPainterPath path; @@ -3121,13 +3071,15 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai matrix.rotate(-90); break; } - path.moveTo(0, 5); - path.lineTo(-4, -3); - path.lineTo(4, -3); p->setMatrix(matrix); - p->setPen(Qt::NoPen); - p->setBrush(QColor(0, 0, 0, 135)); - p->drawPath(path); + + path.moveTo(-halfSize, -halfSize * 0.5); + path.lineTo(0.0, halfSize * 0.5); + path.lineTo(halfSize, -halfSize * 0.5); + + const QPen arrowPen(opt->palette.text(), penWidth, + Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); + p->strokePath(path, arrowPen); p->restore(); break; } #if QT_CONFIG(tabbar) @@ -3597,66 +3549,11 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter switch (ce) { case CE_HeaderSection: if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { - HIThemeButtonDrawInfo bdi; - bdi.version = qt_mac_hitheme_version; State flags = header->state; QRect ir = header->rect; - bdi.kind = kThemeListHeaderButton; - bdi.adornment = kThemeAdornmentNone; - bdi.state = kThemeStateActive; - if (flags & State_On) - bdi.value = kThemeButtonOn; - else - bdi.value = kThemeButtonOff; - - if (header->orientation == Qt::Horizontal){ - switch (header->position) { - case QStyleOptionHeader::Beginning: - ir.adjust(-1, -1, 0, 0); - break; - case QStyleOptionHeader::Middle: - ir.adjust(-1, -1, 0, 0); - break; - case QStyleOptionHeader::OnlyOneSection: - case QStyleOptionHeader::End: - ir.adjust(-1, -1, 1, 0); - break; - default: - break; - } - - if (header->position != QStyleOptionHeader::Beginning - && header->position != QStyleOptionHeader::OnlyOneSection) { - bdi.adornment = header->direction == Qt::LeftToRight - ? kThemeAdornmentHeaderButtonLeftNeighborSelected - : kThemeAdornmentHeaderButtonRightNeighborSelected; - } - } - - if (flags & State_Active) { - if (!(flags & State_Enabled)) - bdi.state = kThemeStateUnavailable; - else if (flags & State_Sunken) - bdi.state = kThemeStatePressed; - } else { - if (flags & State_Enabled) - bdi.state = kThemeStateInactive; - else - bdi.state = kThemeStateUnavailableInactive; - } - - if (header->sortIndicator != QStyleOptionHeader::None) { - bdi.value = kThemeButtonOn; - if (header->sortIndicator == QStyleOptionHeader::SortDown) - bdi.adornment = kThemeAdornmentHeaderButtonSortUp; - } - if (flags & State_HasFocus) - bdi.adornment = kThemeAdornmentFocus; - - ir = visualRect(header->direction, header->rect, ir); - CGRect bounds = ir.toCGRect(); +#if 0 // FIXME: What's this solving exactly? bool noVerticalHeader = true; #if QT_CONFIG(tableview) if (w) @@ -3664,12 +3561,22 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter noVerticalHeader = !table->verticalHeader()->isVisible(); #endif - bool drawTopBorder = header->orientation == Qt::Horizontal; - bool drawLeftBorder = header->orientation == Qt::Vertical - || header->position == QStyleOptionHeader::OnlyOneSection - || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader); - d->drawTableHeader(bounds, drawTopBorder, drawLeftBorder, bdi, p); + const bool drawLeftBorder = header->orientation == Qt::Vertical + || header->position == QStyleOptionHeader::OnlyOneSection + || (header->position == QStyleOptionHeader::Beginning && noVerticalHeader); +#endif + + const bool pressed = (flags & State_Sunken) && !(flags & State_On); + p->fillRect(ir, pressed ? header->palette.dark() : header->palette.button()); + p->setPen(QPen(header->palette.dark(), 1.0)); + if (header->orientation == Qt::Horizontal) + p->drawLine(QLineF(ir.right() + 0.5, ir.top() + headerSectionSeparatorInset, + ir.right() + 0.5, ir.bottom() - headerSectionSeparatorInset)); + else + p->drawLine(QLineF(ir.left() + headerSectionSeparatorInset, ir.bottom(), + ir.right() - headerSectionSeparatorInset, ir.bottom())); } + break; case CE_HeaderLabel: if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { @@ -4657,14 +4564,31 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, // Subtract width needed for arrow, if there is one if (header->sortIndicator != QStyleOptionHeader::None) { if (opt->state & State_Horizontal) - rect.setWidth(rect.width() - (opt->rect.height() / 2) - (margin * 2)); + rect.setWidth(rect.width() - (headerSectionArrowHeight) - (margin * 2)); else - rect.setHeight(rect.height() - (opt->rect.width() / 2) - (margin * 2)); + rect.setHeight(rect.height() - (headerSectionArrowHeight) - (margin * 2)); } } rect = visualRect(opt->direction, opt->rect, rect); break; } + case SE_HeaderArrow: { + int h = opt->rect.height(); + int w = opt->rect.width(); + int x = opt->rect.x(); + int y = opt->rect.y(); + int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget); + + if (opt->state & State_Horizontal) { + rect.setRect(x + w - margin * 2 - headerSectionArrowHeight, y + 5, + headerSectionArrowHeight, h - margin * 2 - 5); + } else { + rect.setRect(x + 5, y + h - margin * 2 - headerSectionArrowHeight, + w - margin * 2 - 5, headerSectionArrowHeight); + } + rect = visualRect(opt->direction, opt->rect, rect); + break; + } case SE_ProgressBarGroove: // Wrong in the secondary dimension, but accurate enough in the main dimension. rect = opt->rect; diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index 045753989f..078509d551 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -248,8 +248,6 @@ public: static QRect comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi); static void drawCombobox(const CGRect &outerBounds, const HIThemeButtonDrawInfo &bdi, const CocoaControl &cw, QPainter *p); - static void drawTableHeader(const CGRect &outerBounds, bool drawTopBorder, bool drawLeftBorder, - const HIThemeButtonDrawInfo &bdi, QPainter *p); bool contentFitsInPushButton(const QStyleOptionButton *btn, HIThemeButtonDrawInfo *bdi, ThemeButtonKind buttonKindToCheck) const; void initHIThemePushButton(const QStyleOptionButton *btn, const QWidget *widget, -- cgit v1.2.3