From ea9469f2b6b7f78f66c22f391b80b3374a4737ba Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 16 May 2019 15:17:12 +0200 Subject: QCompleter: Fix completion on QFileSystemModel Fix the condition introduced by that determines whether a completion is started on signal QFileSystemModel::directoryLoaded() (introduced by 416ec00e7c859a844a5bcb24c7a31147aed974c / Qt 4). Observe case sensitivity and the native separator and return true for root directories. Task-number: QTBUG-38014 Task-number: QTBUG-14292 Change-Id: Ie425c04d2df256248e84250ba777793a8106a738 Reviewed-by: Richard Moe Gustavsen --- src/widgets/util/qcompleter.cpp | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 0daa4a4b41..e41f7e7573 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -976,18 +976,48 @@ void QCompleterPrivate::showPopup(const QRect& rect) popup->show(); } +#if QT_CONFIG(filesystemmodel) +static bool isRoot(const QFileSystemModel *model, const QString &path) +{ + const auto index = model->index(path); + return index.isValid() && model->fileInfo(index).isRoot(); +} + +static bool completeOnLoaded(const QFileSystemModel *model, + const QString &nativePrefix, + const QString &path, + Qt::CaseSensitivity caseSensitivity) +{ + const auto pathSize = path.size(); + const auto prefixSize = nativePrefix.size(); + if (prefixSize < pathSize) + return false; + const QString prefix = QDir::fromNativeSeparators(nativePrefix); + if (prefixSize == pathSize) + return path.compare(prefix, caseSensitivity) == 0 && isRoot(model, path); + // The user is typing something within that directory and is not in a subdirectory yet. + const auto separator = QLatin1Char('/'); + return prefix.startsWith(path, caseSensitivity) && prefix.at(pathSize) == separator + && !prefix.rightRef(prefixSize - pathSize - 1).contains(separator); +} + void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path) { Q_Q(QCompleter); // Slot called when QFileSystemModel has finished loading. // If we hide the popup because there was no match because the model was not loaded yet, - // we re-start the completion when we get the results - if (hiddenBecauseNoMatch - && prefix.startsWith(path) && prefix != (path + QLatin1Char('/')) - && widget) { - q->complete(); + // we re-start the completion when we get the results (unless triggered by + // something else, see QTBUG-14292). + if (hiddenBecauseNoMatch && widget) { + if (auto model = qobject_cast(proxy->sourceModel())) { + if (completeOnLoaded(model, prefix, path, cs)) + q->complete(); + } } } +#else // QT_CONFIG(filesystemmodel) +void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &) {} +#endif /*! Constructs a completer object with the given \a parent. -- cgit v1.2.3 From 3386b875dd6c008d588c4a12f0127449008e8750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Mon, 4 Mar 2019 22:33:58 +0100 Subject: QHighDpi: Remove fromNativePixels()/toNativePixels() overloads Replace QWindow / QScreen / QPlatformScreen overloads with template functions that take a generic context argument. The API now no longer supports implicit conversions from QPointer to QWindow *, add explicit data() call to usage in qxcbdrag.cpp. Change-Id: I63d7f16f6356873280df58f4e7c924bf0b0eca5b Reviewed-by: Friedemann Kleint --- src/gui/kernel/qhighdpiscaling_p.h | 151 ++++++++------------------------- src/plugins/platforms/xcb/qxcbdrag.cpp | 2 +- 2 files changed, 36 insertions(+), 117 deletions(-) diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index ca35f60457..dfc6abf5ba 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -204,86 +204,42 @@ inline QPointF toNativeLocalPosition(const QPointF &pos, const QWindow *window) return pos * scaleFactor; } -inline QRect fromNativePixels(const QRect &pixelRect, const QPlatformScreen *platformScreen) +template +inline QRect fromNativePixels(const QRect &pixelRect, const C *context) { - const qreal scaleFactor = QHighDpiScaling::factor(platformScreen); - const QPoint origin = QHighDpiScaling::origin(platformScreen); + const qreal scaleFactor = QHighDpiScaling::factor(context); + const QPoint origin = QHighDpiScaling::origin(context); return QRect(fromNative(pixelRect.topLeft(), scaleFactor, origin), fromNative(pixelRect.size(), scaleFactor)); } -inline QRect toNativePixels(const QRect &pointRect, const QPlatformScreen *platformScreen) +template +inline QRect toNativePixels(const QRect &pointRect, const C *context) { - const qreal scaleFactor = QHighDpiScaling::factor(platformScreen); - const QPoint origin = QHighDpiScaling::origin(platformScreen); + const qreal scaleFactor = QHighDpiScaling::factor(context); + const QPoint origin = QHighDpiScaling::origin(context); return QRect(toNative(pointRect.topLeft(), scaleFactor, origin), toNative(pointRect.size(), scaleFactor)); } -inline QRect fromNativePixels(const QRect &pixelRect, const QScreen *screen) +template +inline QRectF toNativePixels(const QRectF &pointRect, const C *context) { - const qreal scaleFactor = QHighDpiScaling::factor(screen); - const QPoint origin = QHighDpiScaling::origin(screen); - return QRect(fromNative(pixelRect.topLeft(), scaleFactor, origin), - fromNative(pixelRect.size(), scaleFactor)); -} - -inline QRect toNativePixels(const QRect &pointRect, const QScreen *screen) -{ - const qreal scaleFactor = QHighDpiScaling::factor(screen); - const QPoint origin = QHighDpiScaling::origin(screen); - return QRect(toNative(pointRect.topLeft(), scaleFactor, origin), - toNative(pointRect.size(), scaleFactor)); -} - -inline QRect fromNativePixels(const QRect &pixelRect, const QWindow *window) -{ - const qreal scaleFactor = QHighDpiScaling::factor(window); - const QPoint origin = QHighDpiScaling::origin(window); - return QRect(fromNative(pixelRect.topLeft(), scaleFactor, origin), - fromNative(pixelRect.size(), scaleFactor)); -} - -inline QRectF toNativePixels(const QRectF &pointRect, const QScreen *screen) -{ - const qreal scaleFactor = QHighDpiScaling::factor(screen); - const QPoint origin = QHighDpiScaling::origin(screen); + const qreal scaleFactor = QHighDpiScaling::factor(context); + const QPoint origin = QHighDpiScaling::origin(context); return QRectF(toNative(pointRect.topLeft(), scaleFactor, origin), - toNative(pointRect.size(), scaleFactor)); -} - -inline QRect toNativePixels(const QRect &pointRect, const QWindow *window) -{ - const qreal scaleFactor = QHighDpiScaling::factor(window); - const QPoint origin = QHighDpiScaling::origin(window); - return QRect(toNative(pointRect.topLeft(), scaleFactor, origin), - toNative(pointRect.size(), scaleFactor)); + toNative(pointRect.size(), scaleFactor)); } -inline QRectF fromNativePixels(const QRectF &pixelRect, const QScreen *screen) +template +inline QRectF fromNativePixels(const QRectF &pixelRect, const C *context) { - const qreal scaleFactor = QHighDpiScaling::factor(screen); - const QPoint origin = QHighDpiScaling::origin(screen); + const qreal scaleFactor = QHighDpiScaling::factor(context); + const QPoint origin = QHighDpiScaling::origin(context); return QRectF(fromNative(pixelRect.topLeft(), scaleFactor, origin), fromNative(pixelRect.size(), scaleFactor)); } -inline QRectF fromNativePixels(const QRectF &pixelRect, const QWindow *window) -{ - const qreal scaleFactor = QHighDpiScaling::factor(window); - const QPoint origin = QHighDpiScaling::origin(window); - return QRectF(fromNative(pixelRect.topLeft(), scaleFactor, origin), - fromNative(pixelRect.size(), scaleFactor)); -} - -inline QRectF toNativePixels(const QRectF &pointRect, const QWindow *window) -{ - const qreal scaleFactor = QHighDpiScaling::factor(window); - const QPoint origin = QHighDpiScaling::origin(window); - return QRectF(toNative(pointRect.topLeft(), scaleFactor, origin), - toNative(pointRect.size(), scaleFactor)); -} - inline QSize fromNativePixels(const QSize &pixelSize, const QWindow *window) { return pixelSize / QHighDpiScaling::factor(window); @@ -304,44 +260,28 @@ inline QSizeF toNativePixels(const QSizeF &pointSize, const QWindow *window) return pointSize * QHighDpiScaling::factor(window); } -inline QPoint fromNativePixels(const QPoint &pixelPoint, const QScreen *screen) -{ - return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen)); -} - -inline QPoint fromNativePixels(const QPoint &pixelPoint, const QWindow *window) -{ - return fromNative(pixelPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window)); -} - -inline QPoint toNativePixels(const QPoint &pointPoint, const QScreen *screen) +template +inline QPoint fromNativePixels(const QPoint &pixelPoint, const C *context) { - return toNative(pointPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen)); + return fromNative(pixelPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context)); } -inline QPoint toNativePixels(const QPoint &pointPoint, const QWindow *window) +template +inline QPoint toNativePixels(const QPoint &pointPoint, const C *context) { - return toNative(pointPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window)); + return toNative(pointPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context)); } -inline QPointF fromNativePixels(const QPointF &pixelPoint, const QScreen *screen) +template +inline QPointF fromNativePixels(const QPointF &pixelPoint, const C *context) { - return fromNative(pixelPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen)); + return fromNative(pixelPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context)); } -inline QPointF fromNativePixels(const QPointF &pixelPoint, const QWindow *window) +template +inline QPointF toNativePixels(const QPointF &pointPoint, const C *context) { - return fromNative(pixelPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window)); -} - -inline QPointF toNativePixels(const QPointF &pointPoint, const QScreen *screen) -{ - return toNative(pointPoint, QHighDpiScaling::factor(screen), QHighDpiScaling::origin(screen)); -} - -inline QPointF toNativePixels(const QPointF &pointPoint, const QWindow *window) -{ - return toNative(pointPoint, QHighDpiScaling::factor(window), QHighDpiScaling::origin(window)); + return toNative(pointPoint, QHighDpiScaling::factor(context), QHighDpiScaling::origin(context)); } inline QMargins fromNativePixels(const QMargins &pixelMargins, const QWindow *window) @@ -406,47 +346,26 @@ inline QRegion toNativeLocalRegion(const QRegion &pointRegion, const QWindow *wi } // Any T that has operator/() -template -T fromNativePixels(const T &pixelValue, const QWindow *window) -{ - if (!QHighDpiScaling::isActive()) - return pixelValue; - - return pixelValue / QHighDpiScaling::factor(window); - -} - - //##### ????? -template -T fromNativePixels(const T &pixelValue, const QScreen *screen) +template +T fromNativePixels(const T &pixelValue, const C *context) { if (!QHighDpiScaling::isActive()) return pixelValue; - return pixelValue / QHighDpiScaling::factor(screen); + return pixelValue / QHighDpiScaling::factor(context); } // Any T that has operator*() -template -T toNativePixels(const T &pointValue, const QWindow *window) +template +T toNativePixels(const T &pointValue, const C *context) { if (!QHighDpiScaling::isActive()) return pointValue; - return pointValue * QHighDpiScaling::factor(window); + return pointValue * QHighDpiScaling::factor(context); } -template -T toNativePixels(const T &pointValue, const QScreen *screen) -{ - if (!QHighDpiScaling::isActive()) - return pointValue; - - return pointValue * QHighDpiScaling::factor(screen); -} - - // Any QVector where T has operator/() template QVector fromNativePixels(const QVector &pixelValues, const QWindow *window) diff --git a/src/plugins/platforms/xcb/qxcbdrag.cpp b/src/plugins/platforms/xcb/qxcbdrag.cpp index aa329d8cb7..1ce947165d 100644 --- a/src/plugins/platforms/xcb/qxcbdrag.cpp +++ b/src/plugins/platforms/xcb/qxcbdrag.cpp @@ -202,7 +202,7 @@ void QXcbDrag::startDrag() if (connection()->mouseGrabber() == nullptr) shapedPixmapWindow()->setMouseGrabEnabled(true); - auto nativePixelPos = QHighDpi::toNativePixels(QCursor::pos(), initiatorWindow); + auto nativePixelPos = QHighDpi::toNativePixels(QCursor::pos(), initiatorWindow.data()); move(nativePixelPos, QGuiApplication::mouseButtons(), QGuiApplication::keyboardModifiers()); } -- cgit v1.2.3 From 795af729d38343e16b0902323609cd1e959a5973 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 9 May 2019 23:50:38 +0300 Subject: Avoid rounding of the size in QGraphicsPixmapItem::boundingRect() Fixes: QTBUG-75458 Change-Id: Ib240ddc0b490ae3c0348b6bfa290ad1f51b1e071 Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/graphicsview/qgraphicsitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 30b35ad92f..dbce80b125 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -9786,9 +9786,9 @@ QRectF QGraphicsPixmapItem::boundingRect() const return QRectF(); if (d->flags & ItemIsSelectable) { qreal pw = 1.0; - return QRectF(d->offset, d->pixmap.size() / d->pixmap.devicePixelRatio()).adjusted(-pw/2, -pw/2, pw/2, pw/2); + return QRectF(d->offset, QSizeF(d->pixmap.size()) / d->pixmap.devicePixelRatio()).adjusted(-pw/2, -pw/2, pw/2, pw/2); } else { - return QRectF(d->offset, d->pixmap.size() / d->pixmap.devicePixelRatio()); + return QRectF(d->offset, QSizeF(d->pixmap.size()) / d->pixmap.devicePixelRatio()); } } -- cgit v1.2.3 From 345f86a2d8d69c6d3cbae314028902f090f39a43 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 13 May 2019 11:57:00 +1000 Subject: Avoid re-encoding embedded images when writing an ODF file If an embedded image is already encodeded as an png or jpg write the data as is instead of decoding to a QImage and re-encoding as a new image. Change-Id: I479ae1fddbf59900a500497dd1bdf7449c21f273 Reviewed-by: Lars Knoll --- src/gui/text/qtextodfwriter.cpp | 87 ++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 103e0a8222..1a96f7608f 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -43,6 +43,7 @@ #include "qtextodfwriter_p.h" +#include #include #include #include @@ -410,6 +411,29 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc writer.writeEndElement(); // list-item } +static bool probeImageData(QIODevice *device, QImage *image, QString *mimeType, qreal *width, qreal *height) +{ + QImageReader reader(device); + const QByteArray format = reader.format().toLower(); + if (format == "png") { + *mimeType = QStringLiteral("image/png"); + } else if (format == "jpg") { + *mimeType = QStringLiteral("image/jpg"); + } else if (format == "svg") { + *mimeType = QStringLiteral("image/svg+xml"); + } else { + *image = reader.read(); + return false; + } + + const QSize size = reader.size(); + + *width = size.width(); + *height = size.height(); + + return true; +} + void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const { writer.writeStartElement(drawNS, QString::fromLatin1("frame")); @@ -420,46 +444,71 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF QTextImageFormat imageFormat = fragment.charFormat().toImageFormat(); writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name()); + QByteArray data; + QString mimeType; + qreal width = 0; + qreal height = 0; + QImage image; QString name = imageFormat.name(); if (name.startsWith(QLatin1String(":/"))) // auto-detect resources name.prepend(QLatin1String("qrc")); QUrl url = QUrl(name); - const QVariant data = m_document->resource(QTextDocument::ImageResource, url); - if (data.type() == QVariant::Image) { - image = qvariant_cast(data); - } else if (data.type() == QVariant::ByteArray) { - image.loadFromData(data.toByteArray()); - } - - if (image.isNull()) { - if (image.isNull()) { // try direct loading - name = imageFormat.name(); // remove qrc:/ prefix again - image.load(name); + const QVariant variant = m_document->resource(QTextDocument::ImageResource, url); + if (variant.type() == QVariant::Image) { + image = qvariant_cast(variant); + } else if (variant.type() == QVariant::ByteArray) { + data = variant.toByteArray(); + + QBuffer buffer(&data); + buffer.open(QIODevice::ReadOnly); + probeImageData(&buffer, &image, &mimeType, &width, &height); + } else { + // try direct loading + QFile file(imageFormat.name()); + if (file.open(QIODevice::ReadOnly) && !probeImageData(&file, &image, &mimeType, &width, &height)) { + file.seek(0); + data = file.readAll(); } } if (! image.isNull()) { QBuffer imageBytes; - QString filename = m_strategy->createUniqueImageName(); + int imgQuality = imageFormat.quality(); if (imgQuality >= 100 || imgQuality < 0 || image.hasAlphaChannel()) { QImageWriter imageWriter(&imageBytes, "png"); imageWriter.write(image); - m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data()); + + data = imageBytes.data(); + mimeType = QStringLiteral("image/png"); } else { // Write images without alpha channel as jpg with quality set by QTextImageFormat QImageWriter imageWriter(&imageBytes, "jpg"); imageWriter.setQuality(imgQuality); imageWriter.write(image); - m_strategy->addFile(filename, QString::fromLatin1("image/jpg"), imageBytes.data()); + + data = imageBytes.data(); + mimeType = QStringLiteral("image/jpg"); } - // get the width/height from the format. - qreal width = imageFormat.hasProperty(QTextFormat::ImageWidth) - ? imageFormat.width() : image.width(); + + width = image.width(); + height = image.height(); + } + + if (!data.isEmpty()) { + if (imageFormat.hasProperty(QTextFormat::ImageWidth)) { + width = imageFormat.width(); + } + if (imageFormat.hasProperty(QTextFormat::ImageHeight)) { + height = imageFormat.height(); + } + + QString filename = m_strategy->createUniqueImageName(); + + m_strategy->addFile(filename, mimeType, data); + writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width)); - qreal height = imageFormat.hasProperty(QTextFormat::ImageHeight) - ? imageFormat.height() : image.height(); writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height)); writer.writeStartElement(drawNS, QString::fromLatin1("image")); writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename); -- cgit v1.2.3 From d661a22ae283c604e9e95eceeaf4e6b47e7e1753 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 13 May 2019 12:09:04 +1000 Subject: Write an anchor-type attribute when embedding images in an ODF document Without this some readers will fail to display the image or position the image at the start of a paragraph rather than inline. Change-Id: I2b9257e3193e5e68eb20112017a0c23be1d06cb0 Reviewed-by: Lars Knoll --- src/gui/text/qtextodfwriter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 1a96f7608f..1906502c10 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -510,6 +510,7 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width)); writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height)); + writer.writeAttribute(textNS, QStringLiteral("anchor-type"), QStringLiteral("as-char")); writer.writeStartElement(drawNS, QString::fromLatin1("image")); writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename); writer.writeEndElement(); // image -- cgit v1.2.3 From 48f7f65dc34a9ef97d6b4cbca5fc251a7127f1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Wed, 22 May 2019 09:32:05 +0200 Subject: QMenu size fix - Mark items dirty on screen change It seems like an optimization on the itemsDirty flag caused a bug to be re-introduced. When a popup is shown on a new screen, the itemsDirty must however be set to ensure that new correct sizes are calculated. Task-number: QTBUG-59794 Change-Id: Ifb5c233b1f9d4d38bd0cd7a9a71cc32ad3212f8c Reviewed-by: Morten Kristensen Reviewed-by: Friedemann Kleint Reviewed-by: Christian Ehrlicher --- src/widgets/kernel/qwidget.cpp | 9 ++++++--- src/widgets/kernel/qwidget_p.h | 2 +- src/widgets/widgets/qmenu.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 53d87c6113..59053f3539 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2580,14 +2580,15 @@ void QWidgetPrivate::createWinId() /*! \internal Ensures that the widget is set on the screen point is on. This is handy getting a correct -size hint before a resize in e.g QMenu and QToolTip +size hint before a resize in e.g QMenu and QToolTip. +Returns if the screen was changed. */ -void QWidgetPrivate::setScreenForPoint(const QPoint &pos) +bool QWidgetPrivate::setScreenForPoint(const QPoint &pos) { Q_Q(QWidget); if (!q->isWindow()) - return; + return false; // Find the screen for pos and make the widget undertand it is on that screen. const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr; QScreen *actualScreen = QGuiApplication::screenAt(pos); @@ -2596,7 +2597,9 @@ void QWidgetPrivate::setScreenForPoint(const QPoint &pos) createWinId(); if (windowHandle()) windowHandle()->setScreen(actualScreen); + return true; } + return false; } /*! diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 7e4ea2cc0c..ae50624c04 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -355,7 +355,7 @@ public: void createRecursively(); void createWinId(); - void setScreenForPoint(const QPoint &pos); + bool setScreenForPoint(const QPoint &pos); void createTLExtra(); void createExtra(); diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index a8cca2ae3a..5b1f609b7e 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -73,6 +73,7 @@ #endif #include "qpushbutton.h" #include "qtooltip.h" +#include #include #include #include @@ -2356,8 +2357,10 @@ void QMenu::popup(const QPoint &p, QAction *atAction) d->motions = 0; d->doChildEffects = true; d->updateLayoutDirection(); - // Ensure that we get correct sizeHints by placing this window on the right screen. - d->setScreenForPoint(p); + + // Ensure that we get correct sizeHints by placing this window on the correct screen. + if (d->setScreenForPoint(p)) + d->itemsDirty = true; const bool contextMenu = d->isContextMenu(); if (d->lastContextMenu != contextMenu) { -- cgit v1.2.3 From 0c9b449aa4ad454e37aec43c5b04c3218e12b693 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 24 May 2019 10:59:51 +0200 Subject: Doc: Clarify state of Qt Xml The state of the module is done, not deprecated, so we shouldn't recommend users to move away from it in all cases. There's also no direct replacement for the DOM API. Fixes: QTBUG-70629 Change-Id: Ifaff9757234bd68a411a3da1403c57bbbcb94693 Reviewed-by: Lars Knoll Reviewed-by: Leena Miettinen Reviewed-by: Alex Blasche --- src/xml/doc/src/qtxml-index.qdoc | 6 ++++-- src/xml/doc/src/qtxml.qdoc | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/xml/doc/src/qtxml-index.qdoc b/src/xml/doc/src/qtxml-index.qdoc index dfb9b45fa7..65c6673db0 100644 --- a/src/xml/doc/src/qtxml-index.qdoc +++ b/src/xml/doc/src/qtxml-index.qdoc @@ -30,8 +30,10 @@ \title Qt XML \brief The Qt XML module provides C++ implementations of the SAX and DOM standards for XML. - The module is not actively maintained anymore. Please use - the QXmlStreamReader and QXmlStreamWriter classes in Qt Core instead. + Note that the module will not receive additional features anymore. For reading or writing XML + documents iteratively (SAX), we recommend using Qt Core's QXmlStreamReader and + QXmlStreamWriter classes. The classes are both easier to use and more compliant with the + XML standard. To include the definitions of the module's classes, use the following directive: diff --git a/src/xml/doc/src/qtxml.qdoc b/src/xml/doc/src/qtxml.qdoc index ad9b08b623..452e39d745 100644 --- a/src/xml/doc/src/qtxml.qdoc +++ b/src/xml/doc/src/qtxml.qdoc @@ -33,8 +33,10 @@ \brief The Qt XML module provides C++ implementations of the SAX and DOM standards for XML. - The module is not actively maintained anymore. Please use - the \l{QXmlStreamReader} and \l{QXmlStreamWriter} classes in \l{Qt Core} instead. + Note that the module will not receive additional features anymore. For reading or writing XML + documents iteratively (SAX), we recommend using Qt Core's QXmlStreamReader and + QXmlStreamWriter classes. The classes are both easier to use and more compliant with the + XML standard. To include the definitions of the module's classes, use the following directive: -- cgit v1.2.3 From 14aa1f7d6ffea29647557f98e654355782f55e66 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 20 May 2019 17:02:05 +0200 Subject: Use appropriate encoding rather than UTF-8 when reading from a pipe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The qmake code to read output from dependency-generation was adding QByteArray values to a QString, thereby tacitly converting from UTF-8; this is misguided. Hopefully, the command emits its output in the same local 8-bit encoding that QString knows to convert from. Simplified needlessly verbose loops (that violated Qt coding style) in the process. Fixes: QTBUG-75904 Change-Id: I27cf81ffcb63ebc999b8e4fc57abdb9a68c4d2b3 Reviewed-by: Jörg Bornemann --- qmake/generators/makefile.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index e9dccf0c46..d53dbf9fa5 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -2002,14 +2002,11 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, tmp_out, LocalShell); dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { - QString indeps; - while(!feof(proc)) { - int read_in = (int)fread(buff, 1, 255, proc); - if(!read_in) - break; - indeps += QByteArray(buff, read_in); - } + QByteArray depData; + while (int read_in = feof(proc) ? 0 : (int)fread(buff, 1, 255, proc)) + depData.append(buff, read_in); QT_PCLOSE(proc); + const QString indeps = QString::fromLocal8Bit(depData); if(!indeps.isEmpty()) { QDir outDir(Option::output_dir); QStringList dep_cmd_deps = splitDeps(indeps, dep_lines); @@ -2090,14 +2087,11 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, out, LocalShell); dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { - QString indeps; - while(!feof(proc)) { - int read_in = (int)fread(buff, 1, 255, proc); - if(!read_in) - break; - indeps += QByteArray(buff, read_in); - } + QByteArray depData; + while (int read_in = feof(proc) ? 0 : (int)fread(buff, 1, 255, proc)) + depData.append(buff, read_in); QT_PCLOSE(proc); + const QString indeps = QString::fromLocal8Bit(depData); if(!indeps.isEmpty()) { QDir outDir(Option::output_dir); QStringList dep_cmd_deps = splitDeps(indeps, dep_lines); -- cgit v1.2.3 From cc4c0b43a54d9606f491c193df381a424ae696bf Mon Sep 17 00:00:00 2001 From: Ryan Chu Date: Fri, 3 May 2019 16:14:19 +0200 Subject: QDataStream: Fix inconsistent results of iostream with QPalette objects The value of NColorRoles got changed since 5.11. It introduced one more role called "PlaceholderText" in the ColorRole enumeration. When using QDataStream (5.12) to read QPalette objects from a file written by 5.9 (<5.11), the processing results are inconsistent. Fixes: QTBUG-74885 Change-Id: I14d57f9603a26e5890b4fd57c7e464c5b38eb3f2 Reviewed-by: Eirik Aavitsland --- src/gui/kernel/qpalette.cpp | 5 ++ .../serialization/qdatastream/tst_qdatastream.cpp | 54 +++++++++++++++++----- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 9ccfb9b819..c6805dd4e6 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -1006,6 +1006,8 @@ QDataStream &operator<<(QDataStream &s, const QPalette &p) max = QPalette::HighlightedText + 1; else if (s.version() <= QDataStream::Qt_4_3) max = QPalette::AlternateBase + 1; + else if (s.version() <= QDataStream::Qt_5_11) + max = QPalette::ToolTipText + 1; for (int r = 0; r < max; r++) s << p.d->br[grp][r]; } @@ -1046,6 +1048,9 @@ QDataStream &operator>>(QDataStream &s, QPalette &p) } else if (s.version() <= QDataStream::Qt_4_3) { p = QPalette(); max = QPalette::AlternateBase + 1; + } else if (s.version() <= QDataStream::Qt_5_11) { + p = QPalette(); + max = QPalette::ToolTipText + 1; } QBrush tmp; diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 011a0e1a85..041d9d7a09 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -174,6 +174,7 @@ private slots: void floatingPointPrecision(); + void compatibility_Qt5(); void compatibility_Qt3(); void compatibility_Qt2(); @@ -260,17 +261,17 @@ static int NColorRoles[] = { QPalette::HighlightedText + 1, // Qt_4_0, Qt_4_1 QPalette::HighlightedText + 1, // Qt_4_2 QPalette::AlternateBase + 1, // Qt_4_3 - QPalette::PlaceholderText + 1, // Qt_4_4 - QPalette::PlaceholderText + 1, // Qt_4_5 - QPalette::PlaceholderText + 1, // Qt_4_6 - QPalette::PlaceholderText + 1, // Qt_5_0 - QPalette::PlaceholderText + 1, // Qt_5_1 - QPalette::PlaceholderText + 1, // Qt_5_2 - QPalette::PlaceholderText + 1, // Qt_5_3 - QPalette::PlaceholderText + 1, // Qt_5_4 - QPalette::PlaceholderText + 1, // Qt_5_5 - QPalette::PlaceholderText + 1, // Qt_5_6 - 0 // add the correct value for Qt_5_7 here later + QPalette::ToolTipText + 1, // Qt_4_4 + QPalette::ToolTipText + 1, // Qt_4_5 + QPalette::ToolTipText + 1, // Qt_4_6, Qt_4_7, Qt_4_8, Qt_4_9 + QPalette::ToolTipText + 1, // Qt_5_0 + QPalette::ToolTipText + 1, // Qt_5_1 + QPalette::ToolTipText + 1, // Qt_5_2, Qt_5_3 + QPalette::ToolTipText + 1, // Qt_5_4, Qt_5_5 + QPalette::ToolTipText + 1, // Qt_5_6, Qt_5_7, Qt_5_8, Qt_5_9, Qt_5_10, Qt_5_11 + QPalette::PlaceholderText + 1, // Qt_5_12 + QPalette::PlaceholderText + 1, // Qt_5_13 + 0 // add the correct value for Qt_5_14 here later }; // Testing get/set functions @@ -3102,6 +3103,37 @@ void tst_QDataStream::streamRealDataTypes() } } +void tst_QDataStream::compatibility_Qt5() +{ + QLinearGradient gradient(QPointF(0,0), QPointF(1,1)); + gradient.setColorAt(0, Qt::red); + gradient.setColorAt(1, Qt::blue); + + QBrush brush(gradient); + QPalette palette; + palette.setBrush(QPalette::Button, brush); + palette.setColor(QPalette::Light, Qt::green); + + QByteArray stream; + { + QDataStream out(&stream, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_5_7); + out << palette; + out << brush; + } + QBrush in_brush; + QPalette in_palette; + { + QDataStream in(stream); + in.setVersion(QDataStream::Qt_5_7); + in >> in_palette; + in >> in_brush; + } + QCOMPARE(in_brush.style(), Qt::LinearGradientPattern); + QCOMPARE(in_palette.brush(QPalette::Button).style(), Qt::LinearGradientPattern); + QCOMPARE(in_palette.color(QPalette::Light), QColor(Qt::green)); +} + void tst_QDataStream::compatibility_Qt3() { QByteArray ba("hello"); -- cgit v1.2.3