From b683e97cbc0516e4496b3127ad579a5e02d8f668 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 29 May 2023 13:05:28 +0800 Subject: [PATCH] fix(build): suport build with Qt6 && Qt5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用条件编译将选择不同版本 Qt 接口 --- examples/dnd-example/dnd-test-server.cpp | 3 +- examples/test-taskbar/main.cpp | 1 - src/kernel/dguiapplicationhelper.cpp | 35 +++-- src/kernel/dnativesettings.cpp | 7 +- src/kernel/dwindowmanagerhelper.cpp | 164 +++++++---------------- src/util/ddciicon.cpp | 124 ++++++++++------- src/util/dimagehandlerlibs.cpp | 19 ++- src/util/dsvgrenderer.cpp | 2 +- src/util/dthumbnailprovider.cpp | 6 +- src/util/private/dbuiltiniconengine.cpp | 11 +- src/util/private/dbuiltiniconengine_p.h | 22 +-- src/util/private/dimagehandlerlibs_p.h | 2 +- tests/src/ut_dguiapplicationhelper.cpp | 2 +- tests/src/ut_dsvgrenderer.cpp | 2 +- 14 files changed, 196 insertions(+), 204 deletions(-) diff --git a/examples/dnd-example/dnd-test-server.cpp b/examples/dnd-example/dnd-test-server.cpp index 492c6629..ebcf0492 100644 --- a/examples/dnd-example/dnd-test-server.cpp +++ b/examples/dnd-example/dnd-test-server.cpp @@ -14,6 +14,7 @@ #include #include #include +#include DGUI_USE_NAMESPACE @@ -97,7 +98,7 @@ int main(int argc, char **argv) }); QObject::connect(&t, &QTimer::timeout, [&t, &pg] { - if (qrand() & 1) { + if (QRandomGenerator::global()->generate() & 1) { s->setProgress(++p); pg.setValue(p); if(p == 100) { diff --git a/examples/test-taskbar/main.cpp b/examples/test-taskbar/main.cpp index 1f74d397..70c605ab 100644 --- a/examples/test-taskbar/main.cpp +++ b/examples/test-taskbar/main.cpp @@ -6,7 +6,6 @@ #include #include -#include #include "testtaskbarwindow.h" diff --git a/src/kernel/dguiapplicationhelper.cpp b/src/kernel/dguiapplicationhelper.cpp index 5d8ce2dc..812c8a3c 100644 --- a/src/kernel/dguiapplicationhelper.cpp +++ b/src/kernel/dguiapplicationhelper.cpp @@ -121,11 +121,17 @@ class _DGuiApplicationHelper { // 临时存储一个无效的指针值, 用于此处条件变量的竞争 if (m_helper.testAndSetRelaxed(nullptr, INVALID_HELPER)) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + m_helper.storeRelaxed(creator()); + m_helper.loadRelaxed()->initialize(); + } + return m_helper.loadRelaxed(); +#else m_helper.store(creator()); m_helper.load()->initialize(); } - return m_helper.load(); +#endif } inline void clear() @@ -255,7 +261,7 @@ void DGuiApplicationHelperPrivate::staticInitApplication() if (!_globalHelper.exists()) return; - if (DGuiApplicationHelper *helper = _globalHelper->m_helper.load()) + if (DGuiApplicationHelper *helper = _globalHelper->helper()) helper->d_func()->initApplication(qGuiApp); } @@ -1211,13 +1217,21 @@ void DGuiApplicationHelper::setApplicationPalette(const DPalette &palette) qWarning() << "DGuiApplicationHelper: Plase check 'QGuiApplication::setPalette', Don't use it on DTK application."; } + auto resolve = [](const DPalette &palette) ->bool { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return palette.resolveMask(); +#else + return palette.resolve(); +#endif + }; + if (d->appPalette) { - if (palette.resolve()) { + if (resolve(palette)) { *d->appPalette = palette; } else { d->appPalette.reset(); } - } else if (palette.resolve()) { + } else if (resolve(palette)) { d->appPalette.reset(new DPalette(palette)); } else { return; @@ -1313,7 +1327,7 @@ DGuiApplicationHelper::ColorType DGuiApplicationHelper::toColorType(const QColor */ DGuiApplicationHelper::ColorType DGuiApplicationHelper::toColorType(const QPalette &palette) { - return toColorType(palette.background().color()); + return toColorType(palette.window().color()); } /*! @@ -1468,8 +1482,8 @@ bool DGuiApplicationHelper::setSingleInstance(const QString &key, DGuiApplicatio qCInfo(dgAppHelper) << "New instance: pid=" << pid << "arguments=" << arguments; // 通知新进程的信息 - if (_globalHelper.exists() && _globalHelper->m_helper.load()) - Q_EMIT _globalHelper->m_helper.load()->newProcessInstance(pid, arguments); + if (_globalHelper.exists() && _globalHelper->helper()) + Q_EMIT _globalHelper->helper()->newProcessInstance(pid, arguments); }); instance->flush(); //发送数据给新的实例 @@ -1589,7 +1603,12 @@ bool DGuiApplicationHelper::loadTranslator(const QString &fileName, const QList< QStringList missingQmfiles; for (const auto &locale : localeFallback) { QStringList translateFilenames {QString("%1_%2").arg(fileName).arg(locale.name())}; - const QStringList parseLocalNameList = locale.name().split("_", QString::SkipEmptyParts); +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + auto behavior = Qt::SkipEmptyParts; +#else + auto behavior = QString::SkipEmptyParts; +#endif + const QStringList parseLocalNameList = locale.name().split("_", behavior); if (parseLocalNameList.length() > 0) translateFilenames << QString("%1_%2").arg(fileName).arg(parseLocalNameList.at(0)); diff --git a/src/kernel/dnativesettings.cpp b/src/kernel/dnativesettings.cpp index 00ed8ba3..e5e8b97b 100644 --- a/src/kernel/dnativesettings.cpp +++ b/src/kernel/dnativesettings.cpp @@ -128,7 +128,12 @@ QDebug operator<<(QDebug debug, const DTK_GUI_NAMESPACE::DNativeSettings &settin const QByteArrayList &keys = settings.allKeys(); for (const QByteArray &key : keys) { - debug << key << settings.getSetting(key) << endl; + debug << key << settings.getSetting(key) << +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + Qt::endl; +#else + endl; +#endif } return debug; diff --git a/src/kernel/dwindowmanagerhelper.cpp b/src/kernel/dwindowmanagerhelper.cpp index 7c2fbd06..2b0f9d79 100644 --- a/src/kernel/dwindowmanagerhelper.cpp +++ b/src/kernel/dwindowmanagerhelper.cpp @@ -9,7 +9,16 @@ #include #include -#include + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + #include + #define D_XCB_WINDOW_TYPE QNativeInterface::Private::QXcbWindow::WindowType +#else + #include + #define D_XCB_WINDOW_TYPE QXcbWindowFunctions::WmWindowType +#endif + + #include #include @@ -44,81 +53,53 @@ DEFINE_CONST_CHAR(connectWindowMotifWMHintsChanged); DEFINE_CONST_CHAR(popupSystemWindowMenu); DEFINE_CONST_CHAR(setWMClassName); -static bool connectWindowManagerChangedSignal(QObject *object, std::function slot) +template +static inline ReturnT callPlatformFunction(const QByteArray &funcName, Args... args) { - QFunctionPointer connectWindowManagerChangedSignal = Q_NULLPTR; + QFunctionPointer func = Q_NULLPTR; #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectWindowManagerChangedSignal = qApp->platformFunction(_connectWindowManagerChangedSignal); + func = qApp->platformFunction(funcName); #endif - return connectWindowManagerChangedSignal && reinterpret_cast)>(connectWindowManagerChangedSignal)(object, slot); + return func ? reinterpret_cast(func)(args...) : ReturnT(); } -static bool connectHasBlurWindowChanged(QObject *object, std::function slot) +typedef bool(*func_t)(QObject *object, std::function); +static bool connectWindowManagerChangedSignal(QObject *object, std::function slot) { - QFunctionPointer connectHasBlurWindowChanged = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectHasBlurWindowChanged = qApp->platformFunction(_connectHasBlurWindowChanged); -#endif + return callPlatformFunction(_connectWindowManagerChangedSignal, object, slot); +} - return connectHasBlurWindowChanged && reinterpret_cast)>(connectHasBlurWindowChanged)(object, slot); +static bool connectHasBlurWindowChanged(QObject *object, std::function slot) +{ + return callPlatformFunction(_connectHasBlurWindowChanged, object, slot); } static bool connectHasCompositeChanged(QObject *object, std::function slot) { - QFunctionPointer connectHasCompositeChanged = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectHasCompositeChanged = qApp->platformFunction(_connectHasCompositeChanged); -#endif - - return connectHasCompositeChanged && reinterpret_cast)>(connectHasCompositeChanged)(object, slot); + return callPlatformFunction(_connectHasCompositeChanged, object, slot); } static bool connectHasNoTitlebarChanged(QObject *object, std::function slot) { - QFunctionPointer connectHasNoTitlebarChanged = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectHasNoTitlebarChanged = qApp->platformFunction(_connectHasNoTitlebarChanged); -#endif - - return connectHasNoTitlebarChanged && reinterpret_cast)>(connectHasNoTitlebarChanged)(object, slot); + return callPlatformFunction(_connectHasNoTitlebarChanged, object, slot); } static bool connectHasWallpaperEffectChanged(QObject *object, std::function slot) { - QFunctionPointer connectHasWallpaperEffectChanged = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectHasWallpaperEffectChanged = qApp->platformFunction(_connectHasWallpaperEffectChanged); -#endif - - return connectHasWallpaperEffectChanged && reinterpret_cast)>(connectHasWallpaperEffectChanged)(object, slot); + return callPlatformFunction(_connectHasWallpaperEffectChanged, object, slot); } static bool connectWindowListChanged(QObject *object, std::function slot) { - QFunctionPointer connectWindowListChanged = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectWindowListChanged = qApp->platformFunction(_connectWindowListChanged); -#endif - - return connectWindowListChanged && reinterpret_cast)>(connectWindowListChanged)(object, slot); + return callPlatformFunction(_connectWindowListChanged, object, slot); } static bool connectWindowMotifWMHintsChanged(QObject *object, std::function slot) { - QFunctionPointer connectWindowMotifWMHintsChanged = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - connectWindowMotifWMHintsChanged = qApp->platformFunction(_connectWindowMotifWMHintsChanged); -#endif - - return connectWindowMotifWMHintsChanged && reinterpret_cast)>(connectWindowMotifWMHintsChanged)(object, slot); + typedef bool(*quint32_func_t)(QObject *object, std::function); + return callPlatformFunction(_connectWindowMotifWMHintsChanged, object, slot); } class DWindowManagerHelperPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate @@ -494,7 +475,17 @@ DWindowManagerHelper::MotifDecorations DWindowManagerHelper::getMotifDecorations void DWindowManagerHelper::setWmWindowTypes(QWindow *window, WmWindowTypes types) { const int _types = static_cast(types); - QXcbWindowFunctions::setWmWindowType(window, static_cast(_types)); + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + typedef QNativeInterface::Private::QXcbWindow QXcbWindow_P; + if (auto w = dynamic_cast(window->handle())) { + w->setWindowType(static_cast(_types)); + } else { + qWarning() << "cast" << window << "to platform window failed"; + } +#else + QXcbWindowFunctions::setWmWindowType(window, static_cast(_types)); +#endif } /*! @@ -507,7 +498,7 @@ void DWindowManagerHelper::setWmWindowTypes(QWindow *window, WmWindowTypes types void DWindowManagerHelper::setWmClassName(const QByteArray &name) { typedef void (*SetWmNameType)(const QByteArray&); - return QPlatformHeaderHelper::callPlatformFunction(_setWMClassName, name); + return callPlatformFunction(_setWMClassName, name); } /*! @@ -519,15 +510,7 @@ void DWindowManagerHelper::setWmClassName(const QByteArray &name) */ void DWindowManagerHelper::popupSystemWindowMenu(const QWindow *window) { - QFunctionPointer popupSystemWindowMenu = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - popupSystemWindowMenu = qApp->platformFunction(_popupSystemWindowMenu); -#endif - - if (popupSystemWindowMenu && window->handle()) { - reinterpret_cast(popupSystemWindowMenu)(window->handle()->winId()); - } + return callPlatformFunction(_popupSystemWindowMenu, quint32(window->handle()->winId())); } /*! @@ -536,13 +519,7 @@ void DWindowManagerHelper::popupSystemWindowMenu(const QWindow *window) */ bool DWindowManagerHelper::hasBlurWindow() const { - QFunctionPointer wmHasBlurWindow = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - wmHasBlurWindow = qApp->platformFunction(_hasBlurWindow); -#endif - - return wmHasBlurWindow && reinterpret_cast(wmHasBlurWindow)(); + return callPlatformFunction(_hasBlurWindow); } /*! @@ -571,7 +548,7 @@ bool DWindowManagerHelper::hasComposite() const return true; } - return reinterpret_cast(hasComposite)(); + return callPlatformFunction(_hasComposite); } /*! @@ -580,13 +557,7 @@ bool DWindowManagerHelper::hasComposite() const */ bool DWindowManagerHelper::hasNoTitlebar() const { - QFunctionPointer hasNoTitlebar = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - hasNoTitlebar = qApp->platformFunction(_hasNoTitlebar); -#endif - - return hasNoTitlebar && reinterpret_cast(hasNoTitlebar)(); + return callPlatformFunction(_hasNoTitlebar); } /*! @@ -595,13 +566,7 @@ bool DWindowManagerHelper::hasNoTitlebar() const */ bool DWindowManagerHelper::hasWallpaperEffect() const { - QFunctionPointer hasWallpaperEffect = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - hasWallpaperEffect = qApp->platformFunction(_hasWallpaperEffect); -#endif - - return hasWallpaperEffect && reinterpret_cast(hasWallpaperEffect)(); + return callPlatformFunction(_hasWallpaperEffect); } /*! @@ -613,13 +578,7 @@ bool DWindowManagerHelper::hasWallpaperEffect() const */ QString DWindowManagerHelper::windowManagerNameString() const { - QFunctionPointer windowManagerName = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - windowManagerName = qApp->platformFunction(_windowManagerName); -#endif - - return windowManagerName ? reinterpret_cast(windowManagerName)() : QString(); + return callPlatformFunction(_windowManagerName); } /*! @@ -650,15 +609,7 @@ DWindowManagerHelper::WMName DWindowManagerHelper::windowManagerName() const */ QVector DWindowManagerHelper::allWindowIdList() const { - QFunctionPointer wmClientList = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - wmClientList = qApp->platformFunction(_getWindows); -#endif - - if (!wmClientList) return QVector(); - - return reinterpret_cast(*)()>(wmClientList)(); + return callPlatformFunction, QVector(*)()>(_getWindows); } /*! @@ -669,15 +620,7 @@ QVector DWindowManagerHelper::allWindowIdList() const */ QVector DWindowManagerHelper::currentWorkspaceWindowIdList() const { - QFunctionPointer wmClientList = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - wmClientList = qApp->platformFunction(_getCurrentWorkspaceWindows); -#endif - - if (!wmClientList) return QVector(); - - return reinterpret_cast(*)()>(wmClientList)(); + return callPlatformFunction, QVector(*)()>(_getCurrentWorkspaceWindows); } /*! @@ -732,16 +675,7 @@ QList DWindowManagerHelper::currentWorkspaceWindows() const */ quint32 DWindowManagerHelper::windowFromPoint(const QPoint &p) { - QFunctionPointer winFromPoint = Q_NULLPTR; - -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) - winFromPoint = qApp->platformFunction(_windowFromPoint); -#endif - - if (!winFromPoint) - return 0; - - return reinterpret_cast(winFromPoint)(p); + return callPlatformFunction(_windowFromPoint, p); } /*! diff --git a/src/util/ddciicon.cpp b/src/util/ddciicon.cpp index b5851f13..5f32472c 100644 --- a/src/util/ddciicon.cpp +++ b/src/util/ddciicon.cpp @@ -72,28 +72,28 @@ class EntryPropertyParser { public: static void registerSteps(); - static void doParse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties); + static void doParse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties); private: static struct Step { virtual ~Step() {} Step *nextStep = nullptr; - virtual QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) = 0; + virtual QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) = 0; } *root; struct PriorStep : public Step { - QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; + QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; }; struct FormatAndAlpha8Step : public Step { - QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; + QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; }; struct PaddingStep : public Step { - QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; + QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; }; struct PaletteStep : public Step { - QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; + QVector parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) override; }; }; @@ -113,13 +113,13 @@ void EntryPropertyParser::registerSteps() root = &priorSt; } -void EntryPropertyParser::doParse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) +void EntryPropertyParser::doParse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) { Q_ASSERT(layer); if (!root) registerSteps(); EntryPropertyParser::Step *step = root; - QVector ps = properties; + QVector ps = properties; while (step) { // If the input information flow is empty, it means that the next steps do not need to be continued if (ps.isEmpty()) @@ -129,19 +129,19 @@ void EntryPropertyParser::doParse(DDciIconEntry::ScalableLayer::Layer *layer, co } } -QVector EntryPropertyParser::PriorStep::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) +QVector EntryPropertyParser::PriorStep::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) { bool ok = false; - QVector ps = properties; + QVector ps = properties; layer->prior = ps.takeFirst().toInt(&ok); if (!ok) return {}; // error priority. return ps; } -QVector EntryPropertyParser::FormatAndAlpha8Step::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) +QVector EntryPropertyParser::FormatAndAlpha8Step::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) { - QVector ps = properties; + QVector ps = properties; const QString alpha8OrFormat = ps.takeLast().toString(); if (alpha8OrFormat.compare(ALPHA8STRING, Qt::CaseInsensitive) == 0) { // Alpha8 format @@ -155,11 +155,11 @@ QVector EntryPropertyParser::FormatAndAlpha8Step::parse(DDciIconEntr return ps; } -QVector EntryPropertyParser::PaddingStep::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) +QVector EntryPropertyParser::PaddingStep::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) { - QVector ps = properties; + QVector ps = properties; // Take the padding property - auto it = std::find_if(ps.cbegin(), ps.cend(), [](const QStringRef &p) { + auto it = std::find_if(ps.cbegin(), ps.cend(), [](const QStringView &p) { return p.endsWith(QLatin1Char('p')); }); @@ -171,13 +171,18 @@ QVector EntryPropertyParser::PaddingStep::parse(DDciIconEntry::Scala return ps; } -QVector EntryPropertyParser::PaletteStep::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) +QVector EntryPropertyParser::PaletteStep::parse(DDciIconEntry::ScalableLayer::Layer *layer, const QVector &properties) { - QVector ps = properties; - QStringRef palettes = ps.takeFirst(); + QVector ps = properties; + QStringView palettes = ps.takeFirst(); // `role_hue_saturation_lightness_red_green_blue_alpha` or `role` if (palettes.contains(QLatin1Char('_'))) { - const QVector paletteProps = palettes.split(QLatin1Char('_')); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // QVector is an alias for QList in Qt6 + const QVector paletteProps = palettes.split(QLatin1Char('_')); +#else + const QVector paletteProps = QVector::fromList(palettes.split(QLatin1Char('_'))); +#endif if (paletteProps.length() != 8) return ps; @@ -205,7 +210,7 @@ QVector EntryPropertyParser::PaletteStep::parse(DDciIconEntry::Scala } void alpha8ImageDeleter(void *image) { - delete (QImage *)image; + delete static_cast(image); } static QImage readImageData(QImageReader &reader, qreal pixmapScale, bool isAlpha8Format) @@ -227,7 +232,7 @@ static QImage readImageData(QImageReader &reader, qreal pixmapScale, bool isAlph reader.read(imagePtr); if (isAlpha8Format) { QImage tt(imagePtr->bits(), imagePtr->width(), imagePtr->width(), imagePtr->bytesPerLine(), - QImage::Format_Alpha8, alpha8ImageDeleter, (void *)imagePtr); + QImage::Format_Alpha8, alpha8ImageDeleter, static_cast(imagePtr)); return tt.scaled(scaledSize, scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } @@ -299,7 +304,8 @@ class DDciIconImagePrivate m_currentImageEndTime = std::move(other.m_currentImageEndTime); } - int index = 0; + qsizetype index = 0; + // Use std::unique_ptr instead of QScopedPointer. QScopedPointer buffer; QScopedPointer reader; int pastImageDelay = 0; @@ -336,7 +342,7 @@ class DDciIconImagePrivate } }; - QVector readers; + QVector readers; bool supportsAnimation = false; int totalMaxImageCount = 0; int maxLoopCount = -2; @@ -372,7 +378,7 @@ class DDciIconPrivate : public QSharedData DDciIconEntry *tryMatchIcon(int iconSize, DDciIcon::Theme theme, DDciIcon::Mode mode, DDciIcon::IconMatchedFlags flags = DDciIcon::None) const; static void paint(QPainter *painter, const QRectF &rect, Qt::Alignment alignment, const QVector &layers, - QVector *layerReaders, + QVector *layerReaders, const DDciIconPalette &palette, qreal pixmapScale); static void paint(QPainter *painter, const QRect &rect, qreal devicePixelRatio, Qt::Alignment alignment, const DDciIconEntry *entry, const DDciIconPalette &palette, qreal pixmapScale); @@ -391,7 +397,12 @@ class DDciIconPrivate : public QSharedData EntryNodeList icons; }; -#ifndef QT_NO_DATASTREAM +// In Qt 6, registration of comparators, and QDebug and QDataStream streaming operators is +// done automatically. Consequently, \c QMetaType::registerEqualsComparator(), +// \c QMetaType::registerComparators(), \c qRegisterMetaTypeStreamOperators() and +// \c QMetaType::registerDebugStreamOperator() do no longer exist. Calls to those methods +// have to be removed when porting to Qt 6. +#if !defined(QT_NO_DATASTREAM) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) __attribute__((constructor)) static void registerMetaType() { @@ -399,7 +410,7 @@ static void registerMetaType() } #endif -static inline bool toMode(const QStringRef &name, DDciIcon::Mode *mode) { +static inline bool toMode(const QStringView &name, DDciIcon::Mode *mode) { if (name == QLatin1String(MODE_NORMAL)) { *mode = DDciIcon::Normal; return true; @@ -423,7 +434,7 @@ static inline bool toMode(const QStringRef &name, DDciIcon::Mode *mode) { return false; } -static inline bool toTheme(const QStringRef &name, DDciIcon::Theme *theme) { +static inline bool toTheme(const QStringView &name, DDciIcon::Theme *theme) { if (name == QLatin1String(THEME_LIGHT)) { *theme = DDciIcon::Light; return true; @@ -473,7 +484,7 @@ static int findIconsByLowerBoundSize(const EntryNodeList &list, const int size, regardPaddingsAsSize ? compFun2 : compFun1); if (neighbor != list.cend()) - return neighbor - list.constBegin(); + return static_cast(neighbor - list.constBegin()); return -1; } @@ -502,10 +513,22 @@ DDciIconPrivate::~DDciIconPrivate() qDeleteAll(icon.entries); } +// Note that QStringView is a non-owning, read-only view of a QString +// so we need to make sure that the original QString object stays alive +// for as long as we're using the QStringView. +static inline QVector fromQStringList(const QStringList &list) +{ + QVector views; + views.reserve(list.size()); + std::copy(list.begin(), list.end(), std::back_inserter(views)); + + return views; +} + DDciIconEntry *DDciIconPrivate::loadIcon(const QString &parentDir, const QString &imageDir) { // Mode-Theme - const QVector &iconProps = imageDir.splitRef(QLatin1Char('.')); + const QVector &iconProps = fromQStringList(imageDir.split(QLatin1Char('.'))); if (iconProps.count() != 2) // Error file name. return nullptr; @@ -530,7 +553,7 @@ DDciIconEntry *DDciIconPrivate::loadIcon(const QString &parentDir, const QString scaleIcon.imagePixelRatio = scale; const QString &path = joinPath(stateDir, scaleString); for (const QString &layerPath : dciFile->list(path, true)) { - QVector layerProps = layerPath.splitRef(QLatin1Char('.')); + const QVector &layerProps = fromQStringList(layerPath.split(QLatin1Char('.'))); DDciIconEntry::ScalableLayer::Layer layer; EntryPropertyParser::doParse(&layer, layerProps); layer.data = dciFile->dataRef(joinPath(path, layerPath)); @@ -584,7 +607,7 @@ DDciIconEntry *DDciIconPrivate::tryMatchIcon(int iconSize, DDciIcon::Theme theme auto neighborIndex = findIconsByLowerBoundSize(icons, iconSize, flags & DDciIcon::RegardPaddingsAsSize); if (neighborIndex < 0) { - neighborIndex = icons.size() - 1; + neighborIndex = static_cast(icons.size() - 1); } const auto &listOfSize = icons.at(neighborIndex); @@ -636,7 +659,7 @@ static const DDciIconEntry::ScalableLayer &findScalableLayer(const DDciIconEntry void DDciIconPrivate::paint(QPainter *painter, const QRectF &rect, Qt::Alignment alignment, const QVector &layers, - QVector *layerReaders, + QVector *layerReaders, const DDciIconPalette &palette, qreal pixmapScale) { const bool useImageReader = layerReaders && !layerReaders->isEmpty(); @@ -644,14 +667,14 @@ void DDciIconPrivate::paint(QPainter *painter, const QRectF &rect, Qt::Alignment for (auto layerIter = layers.begin(); layerIter != layers.end(); ++layerIter) { QImage layer; if (useImageReader) { - const int index = layerIter - layers.begin(); + const qsizetype index = layerIter - layers.begin(); auto &reader = layerReaders->operator [](index); - if (reader.currentImageIsValid) { - layer = reader.currentImage; + if (reader->currentImageIsValid) { + layer = reader->currentImage; } else { - layer = readImageData(*reader.reader, pixmapScale, layerIter->isAlpha8Format); - reader.currentImage = layer; - reader.currentImageIsValid = true; + layer = readImageData(*reader->reader, pixmapScale, layerIter->isAlpha8Format); + reader->currentImage = layer; + reader->currentImageIsValid = true; } } else { if (layerIter->data.isEmpty()) @@ -981,6 +1004,7 @@ void DDciIconImage::reset() if (!d || d->pastImageCount == 0) return; + qDeleteAll(d->readers); d->readers.clear(); d->supportsAnimation = false; d->totalMaxImageCount = 0; @@ -1048,8 +1072,8 @@ bool DDciIconImage::jumpToNextImage() // Clear old images if icon animation is not last frame for (auto &reader : d->readers) { - if (reader.currentImageIsEnd(d.get())) - reader.currentImage = QImage(); + if (reader->currentImageIsEnd(d.get())) + reader->currentImage = QImage(); } } @@ -1096,12 +1120,14 @@ void DDciIconImagePrivate::init() { readers.reserve(layers.size()); for (const auto &layer : qAsConst(layers)) { - readers.append(ReaderData()); - readers.last().index = readers.size() - 1; + ReaderData *data = new ReaderData; + Q_ASSERT(data); auto buffer = new QBuffer(); - readers.last().buffer.reset(buffer); + data->buffer.reset(buffer); auto reader = new QImageReader(); - readers.last().reader.reset(reader); + data->reader.reset(reader); + readers.append(data); + data->index = readers.size() - 1; buffer->setData(layer.data); buffer->open(QIODevice::ReadOnly); @@ -1125,15 +1151,15 @@ DDciIconImagePrivate::ReaderData *DDciIconImagePrivate::readAnimationNextData() const ReaderData *next = nullptr; for (auto &reader : readers) { - if (!reader.reader->supportsAnimation()) + if (!reader->reader->supportsAnimation()) continue; // Ensure can get a valid QImageReader::nextImageDelay(), Because // using QImageReader::nextImageDelay() needs call QImageReader::read() before. - reader.initCurrentImage(this); - if (reader.currentImageIsEnd(this) && !reader.jumpToNextImage(this)) + reader->initCurrentImage(this); + if (reader->currentImageIsEnd(this) && !reader->jumpToNextImage(this)) continue; - if (!next || reader.currentImageEndTime() < next->currentImageEndTime()) - next = &reader; + if (!next || reader->currentImageEndTime() < next->currentImageEndTime()) + next = reader; } return const_cast(next); } diff --git a/src/util/dimagehandlerlibs.cpp b/src/util/dimagehandlerlibs.cpp index 02a8336c..176cbe5f 100644 --- a/src/util/dimagehandlerlibs.cpp +++ b/src/util/dimagehandlerlibs.cpp @@ -76,9 +76,9 @@ bool DLibFreeImage::isValid() return freeImage; } -QHash DLibFreeImage::findMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib) +bool DLibFreeImage::findMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, QHash &data) { - QHash data; + bool ret = false; if (freeImage) { if (FreeImage_GetMetadataCount(model, dib)) { FITAG *tag = nullptr; @@ -94,26 +94,23 @@ QHash DLibFreeImage::findMetaData(FREE_IMAGE_MDMODEL model, FI apiMutex.unlock(); data.insert(FreeImage_GetTagKey(tag), value); + ret = true; } while (FreeImage_FindNextMetadata(mdhandle, &tag)); FreeImage_FindCloseMetadata(mdhandle); } } } - return data; + return ret; } QHash DLibFreeImage::findAllMetaData(const QString &fileName) { FIBITMAP *dib = readFileToFIBITMAP(fileName, FIF_LOAD_NOPIXELS); - QMultiHash uniteMap; - uniteMap.unite(findMetaData(FIMD_EXIF_MAIN, dib)); - uniteMap.unite(findMetaData(FIMD_EXIF_EXIF, dib)); - uniteMap.unite(findMetaData(FIMD_EXIF_GPS, dib)); - uniteMap.unite(findMetaData(FIMD_EXIF_MAKERNOTE, dib)); - uniteMap.unite(findMetaData(FIMD_EXIF_INTEROP, dib)); - uniteMap.unite(findMetaData(FIMD_IPTC, dib)); - QHash admMap = uniteMap; + QHash admMap; + for (int i = FIMD_EXIF_MAIN; i <= FIMD_IPTC; ++i) { + findMetaData(FREE_IMAGE_MDMODEL(i), dib, admMap); + } QFileInfo info(fileName); if (admMap.contains("DateTime")) { diff --git a/src/util/dsvgrenderer.cpp b/src/util/dsvgrenderer.cpp index 7859f968..fa8d592f 100644 --- a/src/util/dsvgrenderer.cpp +++ b/src/util/dsvgrenderer.cpp @@ -313,7 +313,7 @@ static QByteArray updateXmlAttribute(const QString &contents) writer.writeStartElement(reader.namespaceUri().toString(), reader.name().toString()); for (const auto &attr : reader.attributes()) { - if (attr.name() == "href") { + if (attr.name() == QStringLiteral("href")) { writer.writeAttribute("xlink:href", attr.value().toString()); continue; } diff --git a/src/util/dthumbnailprovider.cpp b/src/util/dthumbnailprovider.cpp index e4fb1b28..f03ceba4 100644 --- a/src/util/dthumbnailprovider.cpp +++ b/src/util/dthumbnailprovider.cpp @@ -196,7 +196,7 @@ QString DThumbnailProvider::thumbnailFilePath(const QFileInfo &info, Size size) QImage image(thumbnail); - if (image.text(QT_STRINGIFY(Thumb::MTime)).toInt() != (int)info.lastModified().toTime_t()) + if (image.text(QT_STRINGIFY(Thumb::MTime)) != info.lastModified().toString(Qt::ISODate)) { QFile::remove(thumbnail); @@ -249,7 +249,7 @@ QString DThumbnailProvider::createThumbnail(const QFileInfo &info, DThumbnailPro { QImage image(thumbnail); - if (image.text(QT_STRINGIFY(Thumb::MTime)).toInt() != (int)info.lastModified().toTime_t()) + if (image.text(QT_STRINGIFY(Thumb::MTime)) != info.lastModified().toString(Qt::ISODate)) { QFile::remove(thumbnail); } @@ -306,7 +306,7 @@ QString DThumbnailProvider::createThumbnail(const QFileInfo &info, DThumbnailPro } image->setText(QT_STRINGIFY(Thumb::URL), fileUrl); - image->setText(QT_STRINGIFY(Thumb::MTime), QString::number(info.lastModified().toTime_t())); + image->setText(QT_STRINGIFY(Thumb::MTime), info.lastModified().toString(Qt::ISODate)); // create path QFileInfo(thumbnail).absoluteDir().mkpath("."); diff --git a/src/util/private/dbuiltiniconengine.cpp b/src/util/private/dbuiltiniconengine.cpp index 289f8883..71208738 100644 --- a/src/util/private/dbuiltiniconengine.cpp +++ b/src/util/private/dbuiltiniconengine.cpp @@ -54,7 +54,7 @@ class Q_DECL_HIDDEN ImageEntry : public QIconLoaderEngineEntry QPixmap pm; QString pmckey(pmcKey(size, mode, state)); - if (QPixmapCache::find(pmckey, pm)) { + if (QPixmapCache::find(pmckey, &pm)) { genIconTypeIcon(pm, mode); return pm; } @@ -261,7 +261,11 @@ bool DBuiltinIconEngine::write(QDataStream &out) const return true; } -QString DBuiltinIconEngine::iconName() const + +QString DBuiltinIconEngine::iconName() +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + const +#endif { return m_iconName; } @@ -341,6 +345,8 @@ void DBuiltinIconEngine::virtual_hook(int id, void *data) ensureLoaded(); switch (id) { + // Get rid of Qt4 virtual hooks ? +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) case QIconEngine::AvailableSizesHook: { QIconEngine::AvailableSizesArgument &arg @@ -364,6 +370,7 @@ void DBuiltinIconEngine::virtual_hook(int id, void *data) name = m_info.iconName; } break; +#endif case QIconEngine::IsNullHook: { *reinterpret_cast(data) = m_info.entries.isEmpty(); diff --git a/src/util/private/dbuiltiniconengine_p.h b/src/util/private/dbuiltiniconengine_p.h index 93468a74..08ae6051 100644 --- a/src/util/private/dbuiltiniconengine_p.h +++ b/src/util/private/dbuiltiniconengine_p.h @@ -17,21 +17,25 @@ class DBuiltinIconEnginePrivate; class Q_DECL_HIDDEN DBuiltinIconEngine : public QIconEngine { public: - DBuiltinIconEngine(const QString &iconName); - ~DBuiltinIconEngine(); + explicit DBuiltinIconEngine(const QString &iconName); + ~DBuiltinIconEngine() override; void paint(QPainter *painter, const QRect &rect, - QIcon::Mode mode, QIcon::State state); + QIcon::Mode mode, QIcon::State state) override; QSize actualSize(const QSize &size, QIcon::Mode mode, - QIcon::State state); + QIcon::State state) override; QPixmap pixmap(const QSize &size, QIcon::Mode mode, - QIcon::State state); + QIcon::State state) override; - QString key() const; - QIconEngine *clone() const; - bool read(QDataStream &in); - bool write(QDataStream &out) const; + QString key() const override; + QIconEngine *clone() const override; + bool read(QDataStream &in) override; + bool write(QDataStream &out) const override; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QString iconName() override; +#else QString iconName() const override; +#endif static QThemeIconInfo loadIcon(const QString &iconName, uint key); diff --git a/src/util/private/dimagehandlerlibs_p.h b/src/util/private/dimagehandlerlibs_p.h index c536efed..c163e587 100644 --- a/src/util/private/dimagehandlerlibs_p.h +++ b/src/util/private/dimagehandlerlibs_p.h @@ -37,7 +37,7 @@ class DLibFreeImage bool isValid(); - QHash findMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib); + bool findMetaData(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, QHash &data); QHash findAllMetaData(const QString &fileName); FIBITMAP *readFileToFIBITMAP(const QString &fileName, int flags = 0, FREE_IMAGE_FORMAT fif = FIF_UNKNOWN); bool writeFIBITMAPToFile(FIBITMAP *dib, const QString &fileName, int flags = 0); diff --git a/tests/src/ut_dguiapplicationhelper.cpp b/tests/src/ut_dguiapplicationhelper.cpp index aae696bd..d534d4b0 100644 --- a/tests/src/ut_dguiapplicationhelper.cpp +++ b/tests/src/ut_dguiapplicationhelper.cpp @@ -52,7 +52,7 @@ TEST_F(TDGuiApplicationHelper, testFunction) helper->generatePaletteColor(tPalette, QPalette::Window, DGuiApplicationHelper::ColorType::LightType); ASSERT_EQ(tPalette.brush(QPalette::Disabled, QPalette::Window), tPalette.brush(QPalette::Normal, QPalette::Window)); - tPalette.setColor(DPalette::Background, Qt::black); + tPalette.setColor(DPalette::Window, Qt::black); helper->generatePaletteColor(tPalette, QPalette::Highlight, DGuiApplicationHelper::ColorType::DarkType); ASSERT_TRUE(tPalette.highlight().color().isValid()); diff --git a/tests/src/ut_dsvgrenderer.cpp b/tests/src/ut_dsvgrenderer.cpp index 3a075483..d310b279 100644 --- a/tests/src/ut_dsvgrenderer.cpp +++ b/tests/src/ut_dsvgrenderer.cpp @@ -76,7 +76,7 @@ static bool testPixmapHasData(const QPixmap &pixmap) image.reinterpretAsFormat(QImage::Format_RGB32); const QRgb *bits = reinterpret_cast(image.constBits()); - const QRgb *end = bits + image.byteCount() / sizeof(QRgb); + const QRgb *end = bits + qulonglong(image.sizeInBytes()) / sizeof(QRgb); return !std::all_of(bits, end, [](QRgb r) { return r == QColor(Qt::green).rgb(); }); }