aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/designer
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2023-07-25 13:10:22 +0200
committerEike Ziller <eike.ziller@qt.io>2023-07-28 11:58:03 +0000
commit9d9e84296aabaa2ff373790b49e494ca44d7d4ca (patch)
tree2567331598a47e4612b97d13b814596dc1013af8 /src/plugins/designer
parent3c0899d736456d52bb6f3172e3de8f4d4bc1e588 (diff)
Designer: Add -designer-qt-pluginpath argument also for Qt < 6.7
It doesn't have the public API yet, but hack it by temporarily changing the application's library path, which is used by designer for the default plugin paths. Change-Id: I658e41d1228cb89cb6e72d51f3e70b17de32127c Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/plugins/designer')
-rw-r--r--src/plugins/designer/CMakeLists.txt9
-rw-r--r--src/plugins/designer/formeditor.cpp30
-rw-r--r--src/plugins/designer/formeditorplugin.cpp8
3 files changed, 41 insertions, 6 deletions
diff --git a/src/plugins/designer/CMakeLists.txt b/src/plugins/designer/CMakeLists.txt
index eea16798a5d..581f7ec2a7e 100644
--- a/src/plugins/designer/CMakeLists.txt
+++ b/src/plugins/designer/CMakeLists.txt
@@ -14,7 +14,14 @@ if(Qt6_VERSION VERSION_GREATER_EQUAL 6.7.0)
}
],")
else()
- set(DESIGNER_PLUGIN_ARGUMENTS)
+ set(DESIGNER_PLUGIN_ARGUMENTS
+ "\"Arguments\" : [
+ {
+ \"Name\" : \"-designer-qt-pluginpath\",
+ \"Parameter\" : \"path\",
+ \"Description\" : \"Override the default search path for Qt Designer plugins\"
+ }
+ ],")
endif()
add_qtc_plugin(Designer
diff --git a/src/plugins/designer/formeditor.cpp b/src/plugins/designer/formeditor.cpp
index 9629f905266..93603e1a28e 100644
--- a/src/plugins/designer/formeditor.cpp
+++ b/src/plugins/designer/formeditor.cpp
@@ -28,6 +28,7 @@
#include <utils/infobar.h>
#include <utils/qtcassert.h>
+#include <utils/stringutils.h>
#include <utils/theme/theme.h>
#include <QDesignerFormEditorPluginInterface>
@@ -224,7 +225,18 @@ FormEditorData::FormEditorData()
m_formeditor = QDesignerComponents::createFormEditorWithPluginPaths(designerPluginPaths(),
nullptr);
#else
+ // Qt < 6.7.0 doesn't have API for changing the plugin path yet.
+ // Work around it by temporarily changing the application's library paths,
+ // which are used for Designer's plugin paths.
+ // This must be done before creating the FormEditor, and with it QDesignerPluginManager.
+ const QStringList restoreLibraryPaths = sQtPluginPath->isEmpty()
+ ? QStringList()
+ : QCoreApplication::libraryPaths();
+ if (!sQtPluginPath->isEmpty())
+ QCoreApplication::setLibraryPaths(QStringList(*sQtPluginPath));
m_formeditor = QDesignerComponents::createFormEditor(nullptr);
+ if (!sQtPluginPath->isEmpty())
+ QCoreApplication::setLibraryPaths(restoreLibraryPaths);
#endif
if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO;
@@ -894,7 +906,23 @@ void FormEditorData::print()
void setQtPluginPath(const QString &qtPluginPath)
{
QTC_CHECK(!d);
- *sQtPluginPath = qtPluginPath;
+ *sQtPluginPath = QDir::fromNativeSeparators(qtPluginPath);
+#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
+ // Cut a "/designer" postfix off, if present.
+ // For Qt < 6.7.0 we hack the plugin path by temporarily setting the application library paths
+ // and Designer adds "/designer" to these.
+ static const QString postfix = "/designer";
+ *sQtPluginPath = Utils::trimBack(*sQtPluginPath, '/');
+ if (sQtPluginPath->endsWith(postfix))
+ sQtPluginPath->chop(postfix.size());
+ if (!QFile::exists(*sQtPluginPath + postfix)) {
+ qWarning() << qPrintable(
+ QLatin1String(
+ "Warning: The path \"%1\" passed to -designer-qt-pluginpath does not exist. "
+ "Note that \"%2\" at the end is enforced.")
+ .arg(*sQtPluginPath + postfix, postfix));
+ }
+#endif
}
void addPluginPath(const QString &pluginPath)
diff --git a/src/plugins/designer/formeditorplugin.cpp b/src/plugins/designer/formeditorplugin.cpp
index 37d0f7ce5df..e839ce2b3a2 100644
--- a/src/plugins/designer/formeditorplugin.cpp
+++ b/src/plugins/designer/formeditorplugin.cpp
@@ -60,7 +60,6 @@ FormEditorPlugin::~FormEditorPlugin()
delete d;
}
-#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
static void parseArguments(const QStringList &arguments)
{
const auto doWithNext = [arguments](auto it, const std::function<void(QString)> &fun) {
@@ -71,11 +70,14 @@ static void parseArguments(const QStringList &arguments)
for (auto it = arguments.cbegin(); it != arguments.cend(); ++it) {
if (*it == "-designer-qt-pluginpath")
doWithNext(it, [](const QString &path) { setQtPluginPath(path); });
+#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
+ // -designer-pluginpath is only supported when building with Qt >= 6.7.0, which added the
+ // required API
else if (*it == "-designer-pluginpath")
doWithNext(it, [](const QString &path) { addPluginPath(path); });
+#endif
}
}
-#endif
bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
[[maybe_unused]] QString *errorString)
@@ -110,9 +112,7 @@ bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
QCoreApplication::installTranslator(qtr);
}
-#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
parseArguments(arguments);
-#endif
return true;
}