116static void showHelp(QCommandLineParser &parser,
const QString &errorMessage = QString())
119 QTextStream str(&text);
120 str <<
"<html><head/><body>";
121 if (!errorMessage.isEmpty())
122 str <<
"<p>" << errorMessage <<
"</p>";
123 str <<
"<pre>" << parser.helpText().toHtmlEscaped() <<
"</pre></body></html>";
124 QMessageBox box(errorMessage.isEmpty() ? QMessageBox::Information : QMessageBox::Warning,
125 QGuiApplication::applicationDisplayName(), text,
127 box.setTextInteractionFlags(Qt::TextBrowserInteraction);
133 QString *errorMessage)
135 parser.setApplicationDescription(u"Qt Widgets Designer " QT_VERSION_STR
"\n\nUI designer for QWidget-based applications."_s);
136 const QCommandLineOption helpOption = parser.addHelpOption();
137 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
138 const QCommandLineOption tcpServerOption(u"server"_s, u"TCP Server mode"_s);
139 parser.addOption(tcpServerOption);
140 const QCommandLineOption tcpClientOption(u"client"_s, u"TCP Client mode"_s, u"port"_s);
141 parser.addOption(tcpClientOption);
142 const QCommandLineOption webHelpOption(u"web-help"_s, u"Use the Web documentation"_s);
143 parser.addOption(webHelpOption);
144 const QCommandLineOption pythonHelpOption(u"python-help"_s, u"Use the Python documentation"_s);
145 parser.addOption(pythonHelpOption);
146 const QCommandLineOption resourceDirOption(u"resourcedir"_s,
147 u"Resource directory"_s,
149 parser.addOption(resourceDirOption);
150 const QCommandLineOption internalDynamicPropertyOption(u"enableinternaldynamicproperties"_s,
151 u"Enable internal dynamic properties"_s);
152 parser.addOption(internalDynamicPropertyOption);
153 const QCommandLineOption pluginPathsOption(u"plugin-path"_s,
154 u"Default plugin path list"_s,
156 parser.addOption(pluginPathsOption);
158 const QCommandLineOption qtVersionOption(u"qt-version"_s,
159 u"Qt Version for writing .ui files"_s,
161 parser.addOption(qtVersionOption);
163 parser.addPositionalArgument(u"files"_s,
164 u"The UI files to open."_s);
166 if (!parser.parse(QCoreApplication::arguments())) {
167 *errorMessage = parser.errorText();
168 return QDesigner::ParseArgumentsError;
171 if (parser.isSet(helpOption))
172 return QDesigner::ParseArgumentsHelpRequested;
175 if (parser.isSet(u"help-all"_s))
176 parser.process(QCoreApplication::arguments());
177 options
->server = parser.isSet(tcpServerOption);
178 if (parser.isSet(tcpClientOption)) {
180 options->tcpClientPort = parser.value(tcpClientOption).toUShort(&ok);
182 *errorMessage = u"Non-numeric argument specified for -client"_s;
183 return QDesigner::ParseArgumentsError;
186 if (parser.isSet(webHelpOption))
188 else if (parser.isSet(pythonHelpOption))
190 if (parser.isSet(resourceDirOption))
191 options->resourceDir = parser.value(resourceDirOption);
192 const auto pluginPathValues = parser.values(pluginPathsOption);
193 for (
const auto &pluginPath : pluginPathValues)
194 options->pluginPaths.append(pluginPath.split(QDir::listSeparator(), Qt::SkipEmptyParts));
196 if (parser.isSet(qtVersionOption))
197 options->qtVersion = QVersionNumber::fromString(parser.value(qtVersionOption));
200 options->files = parser.positionalArguments();
201 return QDesigner::ParseArgumentsSuccess;
206 QString errorMessage;
208 QCommandLineParser parser;
209 const ParseArgumentsResult result = parseDesignerCommandLineArguments(parser, &options, &errorMessage);
210 if (result != ParseArgumentsSuccess) {
211 showHelp(parser, errorMessage);
215 if (options.tcpClientPort)
216 m_client =
new QDesignerTcpClient(options.tcpClientPort,
this);
220 printf(
"%d\n", server->serverPort());
223 if (options.enableInternalDynamicProperties)
224 QDesignerPropertySheet::setInternalDynamicPropertiesEnabled(
true);
226 std::unique_ptr<QTranslator> designerTranslator(
new QTranslator(
this));
227 if (designerTranslator->load(QLocale(), u"designer"_s, u"_"_s, options.resourceDir)) {
228 installTranslator(designerTranslator.release());
229 std::unique_ptr<QTranslator> qtTranslator(
new QTranslator(
this));
230 if (qtTranslator->load(QLocale(), u"qt"_s, u"_"_s, options.resourceDir))
231 installTranslator(qtTranslator.release());
234 m_workbench =
new QDesignerWorkbench(options);
238 Q_ASSERT(previousMessageHandler);
242 for (
auto fileName : std::as_const(options.files)) {
244 const QFileInfo fi(fileName);
245 if (fi.exists() && fi.isRelative())
246 fileName = fi.absoluteFilePath();
247 m_workbench->readInForm(fileName);
251 suppressNewFormShow =
true;
253 if (options.qtVersion.has_value()) {
254#if QT_VERSION >= QT_VERSION_CHECK(6
, 9
, 0
)
255 m_workbench->core()->integration()->setQtVersion(options.qtVersion.value());
257 auto version = QVariant::fromValue(options.qtVersion.value());
258 m_workbench
->core()->integration()->setProperty(
"qtVersion", version);
263 if (m_initializationErrors.isEmpty()) {
267 showErrorMessageBox(m_initializationErrors);
268 m_initializationErrors.clear();