78void QDesigner::showErrorMessage(
const QString &message)
81 const QString qMessage =
82 message.right(message.size() -
int(designerWarningPrefix.size()));
86 showErrorMessageBox(qMessage);
88 const QMessageLogContext emptyContext;
89 previousMessageHandler(QtWarningMsg, emptyContext, message);
90 m_initializationErrors += qMessage;
91 m_initializationErrors += u'\n';
125static void showHelp(QCommandLineParser &parser,
const QString &errorMessage = QString())
128 QTextStream str(&text);
129 str <<
"<html><head/><body>";
130 if (!errorMessage.isEmpty())
131 str <<
"<p>" << errorMessage <<
"</p>";
132 str <<
"<pre>" << parser.helpText().toHtmlEscaped() <<
"</pre></body></html>";
133 QMessageBox box(errorMessage.isEmpty() ? QMessageBox::Information : QMessageBox::Warning,
134 QGuiApplication::applicationDisplayName(), text,
136 box.setTextInteractionFlags(Qt::TextBrowserInteraction);
153 QString *errorMessage)
155 parser.setApplicationDescription(u"Qt Widgets Designer " QT_VERSION_STR
"\n\nUI designer for QWidget-based applications."_s);
156 const QCommandLineOption helpOption = parser.addHelpOption();
157 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
158 const QCommandLineOption serverOption(u"server"_s,
160 parser.addOption(serverOption);
161 const QCommandLineOption clientOption(u"client"_s,
164 parser.addOption(clientOption);
165 const QCommandLineOption resourceDirOption(u"resourcedir"_s,
166 u"Resource directory"_s,
168 parser.addOption(resourceDirOption);
169 const QCommandLineOption internalDynamicPropertyOption(u"enableinternaldynamicproperties"_s,
170 u"Enable internal dynamic properties"_s);
171 parser.addOption(internalDynamicPropertyOption);
172 const QCommandLineOption pluginPathsOption(u"plugin-path"_s,
173 u"Default plugin path list"_s,
175 parser.addOption(pluginPathsOption);
177 const QCommandLineOption qtVersionOption(u"qt-version"_s,
178 u"Qt Version for writing .ui files"_s,
180 parser.addOption(qtVersionOption);
182 parser.addPositionalArgument(u"files"_s,
183 u"The UI files to open."_s);
185 if (!parser.parse(QCoreApplication::arguments())) {
186 *errorMessage = parser.errorText();
187 return QDesigner::ParseArgumentsError;
190 if (parser.isSet(helpOption))
191 return QDesigner::ParseArgumentsHelpRequested;
194 if (parser.isSet(u"help-all"_s))
195 parser.process(QCoreApplication::arguments());
196 options
->server = parser.isSet(serverOption);
197 if (parser.isSet(clientOption)) {
199 options->clientPort = parser.value(clientOption).toUShort(&ok);
201 *errorMessage = u"Non-numeric argument specified for -client"_s;
202 return QDesigner::ParseArgumentsError;
205 if (parser.isSet(resourceDirOption))
206 options->resourceDir = parser.value(resourceDirOption);
207 const auto pluginPathValues = parser.values(pluginPathsOption);
208 for (
const auto &pluginPath : pluginPathValues)
209 options->pluginPaths.append(pluginPath.split(QDir::listSeparator(), Qt::SkipEmptyParts));
211 if (parser.isSet(qtVersionOption))
212 options->qtVersion = QVersionNumber::fromString(parser.value(qtVersionOption));
215 options->files = parser.positionalArguments();
216 return QDesigner::ParseArgumentsSuccess;
221 QString errorMessage;
223 QCommandLineParser parser;
224 const ParseArgumentsResult result = parseDesignerCommandLineArguments(parser, &options, &errorMessage);
225 if (result != ParseArgumentsSuccess) {
226 showHelp(parser, errorMessage);
230 if (options.clientPort)
234 printf(
"%d\n", m_server->serverPort());
237 if (options.enableInternalDynamicProperties)
238 QDesignerPropertySheet::setInternalDynamicPropertiesEnabled(
true);
240 std::unique_ptr<QTranslator> designerTranslator(
new QTranslator(
this));
241 if (designerTranslator->load(QLocale(), u"designer"_s, u"_"_s, options.resourceDir)) {
242 installTranslator(designerTranslator.release());
243 std::unique_ptr<QTranslator> qtTranslator(
new QTranslator(
this));
244 if (qtTranslator->load(QLocale(), u"qt"_s, u"_"_s, options.resourceDir))
245 installTranslator(qtTranslator.release());
252 Q_ASSERT(previousMessageHandler);
256 for (
auto fileName : std::as_const(options.files)) {
258 const QFileInfo fi(fileName);
259 if (fi.exists() && fi.isRelative())
260 fileName = fi.absoluteFilePath();
261 m_workbench->readInForm(fileName);
265 suppressNewFormShow =
true;
267 if (options.qtVersion.has_value()) {
268#if QT_VERSION >= QT_VERSION_CHECK(6
, 9
, 0
)
269 m_workbench->core()->integration()->setQtVersion(options.qtVersion.value());
271 auto version = QVariant::fromValue(options.qtVersion.value());
272 m_workbench
->core()->integration()->setProperty(
"qtVersion", version);
277 if (m_initializationErrors.isEmpty()) {
278 if (!suppressNewFormShow)
281 showErrorMessageBox(m_initializationErrors);
282 m_initializationErrors.clear();
290 switch (ev->type()) {
291 case QEvent::FileOpen:
292 m_workbench->readInForm(
static_cast<QFileOpenEvent *>(ev)->file());
295 case QEvent::Close: {
296 QCloseEvent *closeEvent =
static_cast<QCloseEvent *>(ev);
298 if (closeEvent->isAccepted()) {
301 m_mainWindow->setCloseEventPolicy(MainWindowBase::AcceptCloseEvents);
302 eaten = QApplication::event(ev);
308 eaten = QApplication::event(ev);