Qt Designer Plugin: Set the active Qt version on the integration

Set the Qt version as a property on QDesignerIntegration
on form window change or when saving for Qt Designer
to know which version to write.

Task-number: PYSIDE-2492
Task-number: QTBUG-118473
Task-number: QTBUG-127179
Change-Id: I1281287147e8d4108a321570785c0287ef18230c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Friedemann Kleint
2024-08-02 09:48:44 +02:00
parent cad822dfe5
commit ac03c58c85
3 changed files with 71 additions and 0 deletions

View File

@@ -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<QtCreatorIntegration *>(m_formWindow->core()->integration());
Q_ASSERT(integration);
if (!integration->setQtVersionFromFile(filePath))
integration->resetQtVersion();
return write(filePath, format(), m_formWindow->contents(), errorString);
}

View File

@@ -37,6 +37,8 @@
#include <texteditor/texteditor.h>
#include <texteditor/textdocument.h>
#include <qtsupport/qtkitaspect.h>
#include <utils/algorithm.h>
#include <utils/mimeutils.h>
#include <utils/qtcassert.h>
@@ -44,16 +46,20 @@
#include <utils/temporaryfile.h>
#include <QDesignerFormWindowInterface>
#include <QDesignerFormWindowManagerInterface>
#include <QDesignerFormEditorInterface>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QLibraryInfo>
#include <QLoggingCategory>
#include <QMessageBox>
#include <QHash>
#include <QVersionNumber>
#include <QUrl>
#include <memory>
#include <optional>
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<QVersionNumber> 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 &parameterNames)
{

View File

@@ -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 &parameterNames);
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;
};