forked from qt-creator/qt-creator
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:
@@ -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
|
||||
PLUGIN_CLASS FormEditorPlugin
|
||||
CONDITION TARGET Qt::DesignerComponentsPrivate AND TARGET Qt::Designer
|
||||
|
@@ -15,5 +15,6 @@
|
||||
"Category" : "Qt Creator",
|
||||
"Description" : "Qt Designer integration.",
|
||||
"Url" : "http://www.qt.io",
|
||||
${DESIGNER_PLUGIN_ARGUMENTS}
|
||||
${IDE_PLUGIN_DEPENDENCIES}
|
||||
}
|
||||
|
@@ -78,6 +78,9 @@ static inline QIcon designerIcon(const QString &iconName)
|
||||
return icon;
|
||||
}
|
||||
|
||||
Q_GLOBAL_STATIC(QString, sQtPluginPath);
|
||||
Q_GLOBAL_STATIC(QStringList, sAdditionalPluginPaths);
|
||||
|
||||
using namespace Core;
|
||||
using namespace Designer::Constants;
|
||||
using namespace Utils;
|
||||
@@ -203,9 +206,24 @@ public:
|
||||
|
||||
static FormEditorData *d = nullptr;
|
||||
|
||||
FormEditorData::FormEditorData() :
|
||||
m_formeditor(QDesignerComponents::createFormEditor(nullptr))
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
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)
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
QTC_ASSERT(!d, return);
|
||||
@@ -871,5 +889,17 @@ void FormEditorData::print()
|
||||
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 Designer
|
||||
|
@@ -60,5 +60,8 @@ SharedTools::WidgetHost *activeWidgetHost();
|
||||
FormWindowEditor *activeEditor();
|
||||
QList<Core::IOptionsPage *> optionsPages();
|
||||
|
||||
void setQtPluginPath(const QString &qtPluginPath);
|
||||
void addPluginPath(const QString &pluginPath);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Designer
|
||||
|
@@ -60,7 +60,25 @@ FormEditorPlugin::~FormEditorPlugin()
|
||||
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;
|
||||
|
||||
@@ -91,6 +109,11 @@ void FormEditorPlugin::initialize()
|
||||
if (qtr->load(trFile, qtTrPath) || qtr->load(trFile, creatorTrPath))
|
||||
QCoreApplication::installTranslator(qtr);
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
|
||||
parseArguments(arguments);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void FormEditorPlugin::extensionsInitialized()
|
||||
|
@@ -24,7 +24,7 @@ private slots:
|
||||
#endif
|
||||
|
||||
private:
|
||||
void initialize() override;
|
||||
bool initialize(const QStringList &arguments, QString *errorString) override;
|
||||
void extensionsInitialized() override;
|
||||
|
||||
void switchSourceForm();
|
||||
|
Reference in New Issue
Block a user