diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index c4b59131e53..aab54d96313 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "formwindowfile.h" +#include "qtcreatorintegration.h" #include "designerconstants.h" #include "resourcehandler.h" @@ -230,6 +231,10 @@ bool FormWindowFile::writeFile(const Utils::FilePath &filePath, QString *errorSt { if (Designer::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << this->filePath() << filePath; + auto *integration = qobject_cast(m_formWindow->core()->integration()); + Q_ASSERT(integration); + if (!integration->setQtVersionFromFile(filePath)) + integration->resetQtVersion(); return write(filePath, format(), m_formWindow->contents(), errorString); } diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp index 5e6d8900959..d0b80e66360 100644 --- a/src/plugins/designer/qtcreatorintegration.cpp +++ b/src/plugins/designer/qtcreatorintegration.cpp @@ -37,6 +37,8 @@ #include #include +#include + #include #include #include @@ -44,16 +46,20 @@ #include #include +#include #include #include #include #include +#include #include #include #include +#include #include #include +#include Q_LOGGING_CATEGORY(log, "qtc.designer", QtWarningMsg); @@ -83,6 +89,17 @@ static void reportRenamingError(const QString &oldName, const QString &reason) .arg(oldName, reason)); } +static std::optional qtVersionFromProject(const Project *project) +{ + if (const auto *target = project->activeTarget()) { + if (const auto *kit = target->kit(); kit->isValid()) { + if (const auto *qtVersion = QtSupport::QtKitAspect::qtVersion(kit)) + return qtVersion->qtVersion(); + } + } + return std::nullopt; +} + class QtCreatorIntegration::Private { public: @@ -142,6 +159,10 @@ QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, Q } } }); + + auto *fwm = core->formWindowManager(); + connect(fwm, &QDesignerFormWindowManagerInterface::activeFormWindowChanged, + this, &QtCreatorIntegration::slotActiveFormWindowChanged); } QtCreatorIntegration::~QtCreatorIntegration() @@ -432,6 +453,40 @@ static ClassDocumentPtrPair return ClassDocumentPtrPair(0, Document::Ptr()); } +void QtCreatorIntegration::slotActiveFormWindowChanged(QDesignerFormWindowInterface *formWindow) +{ + if (formWindow == nullptr + || !setQtVersionFromFile(Utils::FilePath::fromString(formWindow->fileName()))) { + resetQtVersion(); + } +} + +// Set the file's Qt version on the integration for Qt Designer to write +// it out in the appropriate format (PYSIDE-2492, scoped enum support). +bool QtCreatorIntegration::setQtVersionFromFile(const Utils::FilePath &filePath) +{ + if (const auto *uiProject = ProjectManager::projectForFile(filePath)) { + if (auto versionOpt = qtVersionFromProject(uiProject)) { + setQtVersion(versionOpt.value()); + return true; + } + } + return false; +} + +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) +// FIXME: To be replaced by a real property setter on QDesignerIntegration +void QtCreatorIntegration::setQtVersion(const QVersionNumber &version) +{ + setProperty("qtVersion", QVariant::fromValue(version)); +} +#endif // < 6.9 + +void QtCreatorIntegration::resetQtVersion() +{ + setQtVersion(QLibraryInfo::version()); +} + void QtCreatorIntegration::slotNavigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames) { diff --git a/src/plugins/designer/qtcreatorintegration.h b/src/plugins/designer/qtcreatorintegration.h index 31e3cdcb32c..1f1496e7360 100644 --- a/src/plugins/designer/qtcreatorintegration.h +++ b/src/plugins/designer/qtcreatorintegration.h @@ -8,8 +8,11 @@ QT_BEGIN_NAMESPACE class QUrl; +class QVersionNumber; QT_END_NAMESPACE +namespace Utils { class FilePath; } + namespace Designer { namespace Internal { @@ -27,10 +30,14 @@ public: void updateSelection() override; + bool setQtVersionFromFile(const Utils::FilePath &filePath); + void resetQtVersion(); + signals: void creatorHelpRequested(const QUrl &url); private: + void slotActiveFormWindowChanged(QDesignerFormWindowInterface *formWindow); void slotNavigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames); void slotDesignerHelpRequested(const QString &manual, const QString &document); void slotSyncSettingsToDesigner(); @@ -44,6 +51,10 @@ private: void handleSymbolRenameStage2(QDesignerFormWindowInterface *formWindow, const QString &newName, const QString &oldName); +#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0) + void setQtVersion(const QVersionNumber &version); +#endif + class Private; Private * const d; };