summaryrefslogtreecommitdiffstats
path: root/src/designer/src/designer/qdesigner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/designer/src/designer/qdesigner.cpp')
-rw-r--r--src/designer/src/designer/qdesigner.cpp160
1 files changed, 67 insertions, 93 deletions
diff --git a/src/designer/src/designer/qdesigner.cpp b/src/designer/src/designer/qdesigner.cpp
index bbd1451f0..0ec87e2b0 100644
--- a/src/designer/src/designer/qdesigner.cpp
+++ b/src/designer/src/designer/qdesigner.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Designer of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
// designer
#include "qdesigner.h"
@@ -41,9 +16,11 @@
#include <QtGui/qicon.h>
#include <QtWidgets/qerrormessage.h>
#include <QtCore/qmetaobject.h>
+#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qlocale.h>
+#include <QtCore/qtextstream.h>
#include <QtCore/qtimer.h>
#include <QtCore/qtranslator.h>
#include <QtCore/qfileinfo.h>
@@ -55,16 +32,18 @@
QT_BEGIN_NAMESPACE
-static const char *designerApplicationName = "Designer";
-static const char designerDisplayName[] = "Qt Designer";
-static const char *designerWarningPrefix = "Designer: ";
+using namespace Qt::StringLiterals;
+
+static constexpr auto designerApplicationName = "Designer"_L1;
+static constexpr auto designerDisplayName = "Qt Widgets Designer"_L1;
+static constexpr auto designerWarningPrefix = "Designer: "_L1;
static QtMessageHandler previousMessageHandler = nullptr;
static void designerMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
// Only Designer warnings are displayed as box
QDesigner *designerApp = qDesigner;
- if (type != QtWarningMsg || !designerApp || !msg.startsWith(QLatin1String(designerWarningPrefix))) {
+ if (type != QtWarningMsg || !designerApp || !msg.startsWith(designerWarningPrefix)) {
previousMessageHandler(type, context, msg);
return;
}
@@ -72,18 +51,15 @@ static void designerMessageHandler(QtMsgType type, const QMessageLogContext &con
}
QDesigner::QDesigner(int &argc, char **argv)
- : QApplication(argc, argv),
- m_server(nullptr),
- m_client(nullptr),
- m_workbench(0), m_suppressNewFormShow(false)
+ : QApplication(argc, argv)
{
- setOrganizationName(QStringLiteral("QtProject"));
- QGuiApplication::setApplicationDisplayName(QLatin1String(designerDisplayName));
- setApplicationName(QLatin1String(designerApplicationName));
+ setOrganizationName(u"QtProject"_s);
+ QGuiApplication::setApplicationDisplayName(designerDisplayName);
+ setApplicationName(designerApplicationName);
QDesignerComponents::initializeResources();
-#if !defined(Q_OS_OSX) && !defined(Q_OS_WIN)
- setWindowIcon(QIcon(QStringLiteral(":/qt-project.org/designer/images/designer.png")));
+#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
+ setWindowIcon(QIcon(u":/qt-project.org/designer/images/designer.png"_s));
#endif
}
@@ -98,7 +74,7 @@ void QDesigner::showErrorMessage(const QString &message)
{
// strip the prefix
const QString qMessage =
- message.right(message.size() - int(qstrlen(designerWarningPrefix)));
+ message.right(message.size() - int(designerWarningPrefix.size()));
// If there is no main window yet, just store the message.
// The QErrorMessage would otherwise be hidden by the main window.
if (m_mainWindow) {
@@ -107,7 +83,7 @@ void QDesigner::showErrorMessage(const QString &message)
const QMessageLogContext emptyContext;
previousMessageHandler(QtWarningMsg, emptyContext, message); // just in case we crash
m_initializationErrors += qMessage;
- m_initializationErrors += QLatin1Char('\n');
+ m_initializationErrors += u'\n';
}
}
@@ -123,10 +99,9 @@ void QDesigner::showErrorMessageBox(const QString &msg)
if (!m_errorMessageDialog) {
m_lastErrorMessage.clear();
m_errorMessageDialog = new QErrorMessage(m_mainWindow);
- const QString title = QCoreApplication::translate("QDesigner", "%1 - warning").arg(QLatin1String(designerApplicationName));
+ const QString title = QCoreApplication::translate("QDesigner", "%1 - warning").arg(designerApplicationName);
m_errorMessageDialog->setWindowTitle(title);
m_errorMessageDialog->setMinimumSize(QSize(600, 250));
- m_errorMessageDialog->setWindowFlags(m_errorMessageDialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
m_errorMessageDialog->showMessage(msg);
m_lastErrorMessage = msg;
@@ -161,6 +136,7 @@ struct Options
{
QStringList files;
QString resourceDir{QLibraryInfo::path(QLibraryInfo::TranslationsPath)};
+ QStringList pluginPaths;
bool server{false};
quint16 clientPort{0};
bool enableInternalDynamicProperties{false};
@@ -170,28 +146,30 @@ static inline QDesigner::ParseArgumentsResult
parseDesignerCommandLineArguments(QCommandLineParser &parser, Options *options,
QString *errorMessage)
{
- parser.setApplicationDescription(QStringLiteral("Qt Designer ")
- + QLatin1String(QT_VERSION_STR)
- + QLatin1String("\n\nUI designer for QWidget-based applications."));
+ parser.setApplicationDescription(u"Qt Widgets Designer " QT_VERSION_STR "\n\nUI designer for QWidget-based applications."_s);
const QCommandLineOption helpOption = parser.addHelpOption();
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
- const QCommandLineOption serverOption(QStringLiteral("server"),
- QStringLiteral("Server mode"));
+ const QCommandLineOption serverOption(u"server"_s,
+ u"Server mode"_s);
parser.addOption(serverOption);
- const QCommandLineOption clientOption(QStringLiteral("client"),
- QStringLiteral("Client mode"),
- QStringLiteral("port"));
+ const QCommandLineOption clientOption(u"client"_s,
+ u"Client mode"_s,
+ u"port"_s);
parser.addOption(clientOption);
- const QCommandLineOption resourceDirOption(QStringLiteral("resourcedir"),
- QStringLiteral("Resource directory"),
- QStringLiteral("directory"));
+ const QCommandLineOption resourceDirOption(u"resourcedir"_s,
+ u"Resource directory"_s,
+ u"directory"_s);
parser.addOption(resourceDirOption);
- const QCommandLineOption internalDynamicPropertyOption(QStringLiteral("enableinternaldynamicproperties"),
- QStringLiteral("Enable internal dynamic properties"));
+ const QCommandLineOption internalDynamicPropertyOption(u"enableinternaldynamicproperties"_s,
+ u"Enable internal dynamic properties"_s);
parser.addOption(internalDynamicPropertyOption);
+ const QCommandLineOption pluginPathsOption(u"plugin-path"_s,
+ u"Default plugin path list"_s,
+ u"path"_s);
+ parser.addOption(pluginPathsOption);
- parser.addPositionalArgument(QStringLiteral("files"),
- QStringLiteral("The UI files to open."));
+ parser.addPositionalArgument(u"files"_s,
+ u"The UI files to open."_s);
if (!parser.parse(QCoreApplication::arguments())) {
*errorMessage = parser.errorText();
@@ -200,17 +178,25 @@ static inline QDesigner::ParseArgumentsResult
if (parser.isSet(helpOption))
return QDesigner::ParseArgumentsHelpRequested;
+ // There is no way to retrieve the complete help text from QCommandLineParser,
+ // so, call process() to display it.
+ if (parser.isSet(u"help-all"_s))
+ parser.process(QCoreApplication::arguments()); // exits
options->server = parser.isSet(serverOption);
if (parser.isSet(clientOption)) {
bool ok;
options->clientPort = parser.value(clientOption).toUShort(&ok);
if (!ok) {
- *errorMessage = QStringLiteral("Non-numeric argument specified for -client");
+ *errorMessage = u"Non-numeric argument specified for -client"_s;
return QDesigner::ParseArgumentsError;
}
}
if (parser.isSet(resourceDirOption))
options->resourceDir = parser.value(resourceDirOption);
+ const auto pluginPathValues = parser.values(pluginPathsOption);
+ for (const auto &pluginPath : pluginPathValues)
+ options->pluginPaths.append(pluginPath.split(QDir::listSeparator(), Qt::SkipEmptyParts));
+
options->enableInternalDynamicProperties = parser.isSet(internalDynamicPropertyOption);
options->files = parser.positionalArguments();
return QDesigner::ParseArgumentsSuccess;
@@ -237,40 +223,37 @@ QDesigner::ParseArgumentsResult QDesigner::parseCommandLineArguments()
if (options.enableInternalDynamicProperties)
QDesignerPropertySheet::setInternalDynamicPropertiesEnabled(true);
- QScopedPointer<QTranslator> designerTranslator(new QTranslator(this));
- if (designerTranslator->load(QLocale(), QStringLiteral("designer"), QStringLiteral("_"), options.resourceDir)) {
- installTranslator(designerTranslator.take());
- QScopedPointer<QTranslator> qtTranslator(new QTranslator(this));
- if (qtTranslator->load(QLocale(), QStringLiteral("qt"), QStringLiteral("_"), options.resourceDir))
- installTranslator(qtTranslator.take());
+ std::unique_ptr<QTranslator> designerTranslator(new QTranslator(this));
+ if (designerTranslator->load(QLocale(), u"designer"_s, u"_"_s, options.resourceDir)) {
+ installTranslator(designerTranslator.release());
+ std::unique_ptr<QTranslator> qtTranslator(new QTranslator(this));
+ if (qtTranslator->load(QLocale(), u"qt"_s, u"_"_s, options.resourceDir))
+ installTranslator(qtTranslator.release());
}
- m_workbench = new QDesignerWorkbench();
+ m_workbench = new QDesignerWorkbench(options.pluginPaths);
emit initialized();
previousMessageHandler = qInstallMessageHandler(designerMessageHandler); // Warn when loading faulty forms
Q_ASSERT(previousMessageHandler);
- m_suppressNewFormShow = m_workbench->readInBackup();
-
- if (!options.files.isEmpty()) {
- const QStringList::const_iterator cend = options.files.constEnd();
- for (QStringList::const_iterator it = options.files.constBegin(); it != cend; ++it) {
- // Ensure absolute paths for recent file list to be unique
- QString fileName = *it;
- const QFileInfo fi(fileName);
- if (fi.exists() && fi.isRelative())
- fileName = fi.absoluteFilePath();
- m_workbench->readInForm(fileName);
- }
+ bool suppressNewFormShow = m_workbench->readInBackup();
+
+ for (auto fileName : std::as_const(options.files)) {
+ // Ensure absolute paths for recent file list to be unique
+ const QFileInfo fi(fileName);
+ if (fi.exists() && fi.isRelative())
+ fileName = fi.absoluteFilePath();
+ m_workbench->readInForm(fileName);
}
- if ( m_workbench->formWindowCount())
- m_suppressNewFormShow = true;
+
+ if (m_workbench->formWindowCount() > 0)
+ suppressNewFormShow = true;
// Show up error box with parent now if something went wrong
if (m_initializationErrors.isEmpty()) {
- if (!m_suppressNewFormShow && QDesignerSettings(m_workbench->core()).showNewFormOnStartup())
- QTimer::singleShot(100, this, &QDesigner::callCreateForm); // won't show anything if suppressed
+ if (!suppressNewFormShow)
+ m_workbench->showNewForm();
} else {
showErrorMessageBox(m_initializationErrors);
m_initializationErrors.clear();
@@ -283,10 +266,7 @@ bool QDesigner::event(QEvent *ev)
bool eaten;
switch (ev->type()) {
case QEvent::FileOpen:
- // Set it true first since, if it's a Qt 3 form, the messagebox from convert will fire the timer.
- m_suppressNewFormShow = true;
- if (!m_workbench->readInForm(static_cast<QFileOpenEvent *>(ev)->file()))
- m_suppressNewFormShow = false;
+ m_workbench->readInForm(static_cast<QFileOpenEvent *>(ev)->file());
eaten = true;
break;
case QEvent::Close: {
@@ -318,10 +298,4 @@ MainWindowBase *QDesigner::mainWindow() const
return m_mainWindow;
}
-void QDesigner::callCreateForm()
-{
- if (!m_suppressNewFormShow)
- m_workbench->actionManager()->createForm();
-}
-
QT_END_NAMESPACE