forked from qt-creator/qt-creator
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:
@@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "formwindowfile.h"
|
#include "formwindowfile.h"
|
||||||
|
#include "qtcreatorintegration.h"
|
||||||
#include "designerconstants.h"
|
#include "designerconstants.h"
|
||||||
#include "resourcehandler.h"
|
#include "resourcehandler.h"
|
||||||
|
|
||||||
@@ -230,6 +231,10 @@ bool FormWindowFile::writeFile(const Utils::FilePath &filePath, QString *errorSt
|
|||||||
{
|
{
|
||||||
if (Designer::Constants::Internal::debug)
|
if (Designer::Constants::Internal::debug)
|
||||||
qDebug() << Q_FUNC_INFO << this->filePath() << filePath;
|
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);
|
return write(filePath, format(), m_formWindow->contents(), errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
|
#include <qtsupport/qtkitaspect.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/mimeutils.h>
|
#include <utils/mimeutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -44,16 +46,20 @@
|
|||||||
#include <utils/temporaryfile.h>
|
#include <utils/temporaryfile.h>
|
||||||
|
|
||||||
#include <QDesignerFormWindowInterface>
|
#include <QDesignerFormWindowInterface>
|
||||||
|
#include <QDesignerFormWindowManagerInterface>
|
||||||
#include <QDesignerFormEditorInterface>
|
#include <QDesignerFormEditorInterface>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QLibraryInfo>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QVersionNumber>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(log, "qtc.designer", QtWarningMsg);
|
Q_LOGGING_CATEGORY(log, "qtc.designer", QtWarningMsg);
|
||||||
|
|
||||||
@@ -83,6 +89,17 @@ static void reportRenamingError(const QString &oldName, const QString &reason)
|
|||||||
.arg(oldName, 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
|
class QtCreatorIntegration::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -142,6 +159,10 @@ QtCreatorIntegration::QtCreatorIntegration(QDesignerFormEditorInterface *core, Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto *fwm = core->formWindowManager();
|
||||||
|
connect(fwm, &QDesignerFormWindowManagerInterface::activeFormWindowChanged,
|
||||||
|
this, &QtCreatorIntegration::slotActiveFormWindowChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
QtCreatorIntegration::~QtCreatorIntegration()
|
QtCreatorIntegration::~QtCreatorIntegration()
|
||||||
@@ -432,6 +453,40 @@ static ClassDocumentPtrPair
|
|||||||
return ClassDocumentPtrPair(0, Document::Ptr());
|
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,
|
void QtCreatorIntegration::slotNavigateToSlot(const QString &objectName, const QString &signalSignature,
|
||||||
const QStringList ¶meterNames)
|
const QStringList ¶meterNames)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,8 +8,11 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QUrl;
|
class QUrl;
|
||||||
|
class QVersionNumber;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace Designer {
|
namespace Designer {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -27,10 +30,14 @@ public:
|
|||||||
|
|
||||||
void updateSelection() override;
|
void updateSelection() override;
|
||||||
|
|
||||||
|
bool setQtVersionFromFile(const Utils::FilePath &filePath);
|
||||||
|
void resetQtVersion();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void creatorHelpRequested(const QUrl &url);
|
void creatorHelpRequested(const QUrl &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void slotActiveFormWindowChanged(QDesignerFormWindowInterface *formWindow);
|
||||||
void slotNavigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames);
|
void slotNavigateToSlot(const QString &objectName, const QString &signalSignature, const QStringList ¶meterNames);
|
||||||
void slotDesignerHelpRequested(const QString &manual, const QString &document);
|
void slotDesignerHelpRequested(const QString &manual, const QString &document);
|
||||||
void slotSyncSettingsToDesigner();
|
void slotSyncSettingsToDesigner();
|
||||||
@@ -44,6 +51,10 @@ private:
|
|||||||
void handleSymbolRenameStage2(QDesignerFormWindowInterface *formWindow,
|
void handleSymbolRenameStage2(QDesignerFormWindowInterface *formWindow,
|
||||||
const QString &newName, const QString &oldName);
|
const QString &newName, const QString &oldName);
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0)
|
||||||
|
void setQtVersion(const QVersionNumber &version);
|
||||||
|
#endif
|
||||||
|
|
||||||
class Private;
|
class Private;
|
||||||
Private * const d;
|
Private * const d;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user