Designer: Add command line arguments for plugin paths

Add a command line argument for overriding the default plugin path
(useful if you have installed custom designer plugins in a different,
compatible Qt version), and one for adding plugin paths (for example to
separate builds of custom designer plugins that haven't been installed
anywhere).

This feature is only enabled when building with Qt >= 6.7, which added
the option to change the plugin paths for designer.

Change-Id: I990b26056477e3e41c6afe82479383d8bc7c45d0
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Eike Ziller
2023-07-25 12:24:52 +02:00
parent 8ea41af94f
commit 8d5897b8eb
6 changed files with 80 additions and 4 deletions

View File

@@ -1,3 +1,22 @@
# used in the .json.in
if(Qt6_VERSION VERSION_GREATER_EQUAL 6.7.0)
set(DESIGNER_PLUGIN_ARGUMENTS
"\"Arguments\" : [
{
\"Name\" : \"-designer-qt-pluginpath\",
\"Parameter\" : \"path\",
\"Description\" : \"Override the default search path for Qt Designer plugins\"
},
{
\"Name\" : \"-designer-pluginpath\",
\"Parameter\" : \"path\",
\"Description\" : \"Add a custom search path for Qt Designer plugins\"
}
],")
else()
set(DESIGNER_PLUGIN_ARGUMENTS)
endif()
add_qtc_plugin(Designer add_qtc_plugin(Designer
PLUGIN_CLASS FormEditorPlugin PLUGIN_CLASS FormEditorPlugin
CONDITION TARGET Qt::DesignerComponentsPrivate AND TARGET Qt::Designer CONDITION TARGET Qt::DesignerComponentsPrivate AND TARGET Qt::Designer

View File

@@ -15,5 +15,6 @@
"Category" : "Qt Creator", "Category" : "Qt Creator",
"Description" : "Qt Designer integration.", "Description" : "Qt Designer integration.",
"Url" : "http://www.qt.io", "Url" : "http://www.qt.io",
${DESIGNER_PLUGIN_ARGUMENTS}
${IDE_PLUGIN_DEPENDENCIES} ${IDE_PLUGIN_DEPENDENCIES}
} }

View File

@@ -78,6 +78,9 @@ static inline QIcon designerIcon(const QString &iconName)
return icon; return icon;
} }
Q_GLOBAL_STATIC(QString, sQtPluginPath);
Q_GLOBAL_STATIC(QStringList, sAdditionalPluginPaths);
using namespace Core; using namespace Core;
using namespace Designer::Constants; using namespace Designer::Constants;
using namespace Utils; using namespace Utils;
@@ -203,9 +206,24 @@ public:
static FormEditorData *d = nullptr; static FormEditorData *d = nullptr;
FormEditorData::FormEditorData() : #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
m_formeditor(QDesignerComponents::createFormEditor(nullptr)) static QStringList designerPluginPaths()
{ {
const QStringList qtPluginPath = sQtPluginPath->isEmpty()
? QDesignerComponents::defaultPluginPaths()
: QStringList(*sQtPluginPath);
return qtPluginPath + *sAdditionalPluginPaths;
}
#endif
FormEditorData::FormEditorData()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
m_formeditor = QDesignerComponents::createFormEditorWithPluginPaths(designerPluginPaths(),
nullptr);
#else
m_formeditor = QDesignerComponents::createFormEditor(nullptr);
#endif
if (Designer::Constants::Internal::debug) if (Designer::Constants::Internal::debug)
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QTC_ASSERT(!d, return); QTC_ASSERT(!d, return);
@@ -871,5 +889,17 @@ void FormEditorData::print()
printer->setPageOrientation(oldOrientation); printer->setPageOrientation(oldOrientation);
} }
void setQtPluginPath(const QString &qtPluginPath)
{
QTC_CHECK(!d);
*sQtPluginPath = qtPluginPath;
}
void addPluginPath(const QString &pluginPath)
{
QTC_CHECK(!d);
sAdditionalPluginPaths->append(pluginPath);
}
} // namespace Internal } // namespace Internal
} // namespace Designer } // namespace Designer

View File

@@ -60,5 +60,8 @@ SharedTools::WidgetHost *activeWidgetHost();
FormWindowEditor *activeEditor(); FormWindowEditor *activeEditor();
QList<Core::IOptionsPage *> optionsPages(); QList<Core::IOptionsPage *> optionsPages();
void setQtPluginPath(const QString &qtPluginPath);
void addPluginPath(const QString &pluginPath);
} // namespace Internal } // namespace Internal
} // namespace Designer } // namespace Designer

View File

@@ -60,7 +60,25 @@ FormEditorPlugin::~FormEditorPlugin()
delete d; delete d;
} }
void FormEditorPlugin::initialize() #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) {
++it;
if (it != arguments.cend())
fun(*it);
};
for (auto it = arguments.cbegin(); it != arguments.cend(); ++it) {
if (*it == "-designer-qt-pluginpath")
doWithNext(it, [](const QString &path) { setQtPluginPath(path); });
else if (*it == "-designer-pluginpath")
doWithNext(it, [](const QString &path) { addPluginPath(path); });
}
}
#endif
bool FormEditorPlugin::initialize([[maybe_unused]] const QStringList &arguments,
[[maybe_unused]] QString *errorString)
{ {
d = new FormEditorPluginPrivate; d = new FormEditorPluginPrivate;
@@ -91,6 +109,11 @@ void FormEditorPlugin::initialize()
if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath)) if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
QCoreApplication::installTranslator(qtr); QCoreApplication::installTranslator(qtr);
} }
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
parseArguments(arguments);
#endif
return true;
} }
void FormEditorPlugin::extensionsInitialized() void FormEditorPlugin::extensionsInitialized()

View File

@@ -24,7 +24,7 @@ private slots:
#endif #endif
private: private:
void initialize() override; bool initialize(const QStringList &arguments, QString *errorString) override;
void extensionsInitialized() override; void extensionsInitialized() override;
void switchSourceForm(); void switchSourceForm();