diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-11-06 12:42:59 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-11-06 14:11:36 +0100 |
commit | 5f238adc4c652e6e1bb34752f201cf8e377cbc25 (patch) | |
tree | 1e5a877cbafdb63ff7f3eee324de9dfa73b1c969 /src/designer/src/designer | |
parent | 7ecd60c80c506c3af8127aa12ebc5a2d64370f0f (diff) |
Designer: Use QDesktopServices to show designer help
Task-number: QTBUG-86746
Change-Id: I3533c8eecacda4f8edf31c912c3c75e707549b19
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/designer/src/designer')
-rw-r--r-- | src/designer/src/designer/.prev_CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/designer/src/designer/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/designer/src/designer/assistantclient.cpp | 180 | ||||
-rw-r--r-- | src/designer/src/designer/assistantclient.h | 72 | ||||
-rw-r--r-- | src/designer/src/designer/designer.pro | 2 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_actions.cpp | 39 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_actions.h | 5 |
7 files changed, 25 insertions, 275 deletions
diff --git a/src/designer/src/designer/.prev_CMakeLists.txt b/src/designer/src/designer/.prev_CMakeLists.txt index 0437ab492..a95b2c0fa 100644 --- a/src/designer/src/designer/.prev_CMakeLists.txt +++ b/src/designer/src/designer/.prev_CMakeLists.txt @@ -9,7 +9,6 @@ qt_internal_add_app(designer ../../../shared/fontpanel/fontpanel.cpp ../../../shared/fontpanel/fontpanel.h ../../../shared/qttoolbardialog/qttoolbardialog.cpp ../../../shared/qttoolbardialog/qttoolbardialog.h ../../../shared/qttoolbardialog/qttoolbardialog.ui appfontdialog.cpp appfontdialog.h - assistantclient.cpp assistantclient.h designer_enums.h main.cpp mainwindow.cpp mainwindow.h diff --git a/src/designer/src/designer/CMakeLists.txt b/src/designer/src/designer/CMakeLists.txt index 5de06465d..c60be4c8a 100644 --- a/src/designer/src/designer/CMakeLists.txt +++ b/src/designer/src/designer/CMakeLists.txt @@ -9,7 +9,6 @@ qt_internal_add_app(designer ../../../shared/fontpanel/fontpanel.cpp ../../../shared/fontpanel/fontpanel.h ../../../shared/qttoolbardialog/qttoolbardialog.cpp ../../../shared/qttoolbardialog/qttoolbardialog.h ../../../shared/qttoolbardialog/qttoolbardialog.ui appfontdialog.cpp appfontdialog.h - assistantclient.cpp assistantclient.h designer_enums.h main.cpp mainwindow.cpp mainwindow.h diff --git a/src/designer/src/designer/assistantclient.cpp b/src/designer/src/designer/assistantclient.cpp deleted file mode 100644 index 45fee4393..000000000 --- a/src/designer/src/designer/assistantclient.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "assistantclient.h" - -#include <QtCore/qstring.h> -#include <QtCore/qprocess.h> -#include <QtCore/qdir.h> -#include <QtCore/qlibraryinfo.h> -#include <QtCore/qdebug.h> -#include <QtCore/qfileinfo.h> -#include <QtCore/qobject.h> -#include <QtCore/qtextstream.h> -#include <QtCore/qcoreapplication.h> - -QT_BEGIN_NAMESPACE - -enum { debugAssistantClient = 0 }; - -AssistantClient::AssistantClient() = default; - -AssistantClient::~AssistantClient() -{ - if (isRunning()) { - m_process->terminate(); - m_process->waitForFinished(); - } - delete m_process; -} - -bool AssistantClient::showPage(const QString &path, QString *errorMessage) -{ - QString cmd = QStringLiteral("SetSource "); - cmd += path; - return sendCommand(cmd, errorMessage); -} - -bool AssistantClient::activateIdentifier(const QString &identifier, QString *errorMessage) -{ - QString cmd = QStringLiteral("ActivateIdentifier "); - cmd += identifier; - return sendCommand(cmd, errorMessage); -} - -bool AssistantClient::activateKeyword(const QString &keyword, QString *errorMessage) -{ - QString cmd = QStringLiteral("ActivateKeyword "); - cmd += keyword; - return sendCommand(cmd, errorMessage); -} - -bool AssistantClient::sendCommand(const QString &cmd, QString *errorMessage) -{ - if (debugAssistantClient) - qDebug() << "sendCommand " << cmd; - if (!ensureRunning(errorMessage)) - return false; - if (!m_process->isWritable() || m_process->bytesToWrite() > 0) { - *errorMessage = QCoreApplication::translate("AssistantClient", "Unable to send request: Assistant is not responding."); - return false; - } - QTextStream str(m_process); - str << cmd << QLatin1Char('\n') << Qt::endl; - return true; -} - -bool AssistantClient::isRunning() const -{ - return m_process && m_process->state() != QProcess::NotRunning; -} - -QString AssistantClient::binary() -{ - QString app = QLibraryInfo::path(QLibraryInfo::BinariesPath) + QDir::separator(); -#if !defined(Q_OS_MACOS) - app += QStringLiteral("assistant"); -#else - app += QStringLiteral("Assistant.app/Contents/MacOS/Assistant"); -#endif - -#if defined(Q_OS_WIN) - app += QStringLiteral(".exe"); -#endif - - return app; -} - -void AssistantClient::readyReadStandardError() -{ - qWarning("%s: %s", - qPrintable(QDir::toNativeSeparators(m_process->program())), - m_process->readAllStandardError().constData()); -} - -void AssistantClient::processTerminated(int exitCode, QProcess::ExitStatus exitStatus) -{ - const QString binary = QDir::toNativeSeparators(m_process->program()); - if (exitStatus != QProcess::NormalExit) - qWarning("%s: crashed.", qPrintable(binary)); - else if (exitCode != 0) - qWarning("%s: terminated with exit code %d.", qPrintable(binary), exitCode); -} - -bool AssistantClient::ensureRunning(QString *errorMessage) -{ - if (isRunning()) - return true; - - if (!m_process) { - m_process = new QProcess; - QObject::connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), - this, &AssistantClient::processTerminated); - QObject::connect(m_process, &QProcess::readyReadStandardError, - this, &AssistantClient::readyReadStandardError); - } - - const QString app = binary(); - if (!QFileInfo(app).isFile()) { - *errorMessage = QCoreApplication::translate("AssistantClient", "The binary '%1' does not exist.").arg(app); - return false; - } - if (debugAssistantClient) - qDebug() << "Running " << app; - // run - QStringList args(QStringLiteral("-enableRemoteControl")); - m_process->start(app, args); - if (!m_process->waitForStarted()) { - *errorMessage = QCoreApplication::translate("AssistantClient", "Unable to launch assistant (%1).").arg(app); - return false; - } - return true; -} - -QString AssistantClient::documentUrl(const QString &module, int qtVersion) -{ - if (qtVersion == 0) - qtVersion = QT_VERSION; - QString rc; - QTextStream(&rc) << "qthelp://org.qt-project." << module << '.' - << (qtVersion >> 16) << ((qtVersion >> 8) & 0xFF) << (qtVersion & 0xFF) - << '/' << module << '/'; - return rc; -} - -QString AssistantClient::designerManualUrl(int qtVersion) -{ - return documentUrl(QStringLiteral("qtdesigner"), qtVersion); -} - -QString AssistantClient::qtReferenceManualUrl(int qtVersion) -{ - return documentUrl(QStringLiteral("qtdoc"), qtVersion); -} - -QT_END_NAMESPACE diff --git a/src/designer/src/designer/assistantclient.h b/src/designer/src/designer/assistantclient.h deleted file mode 100644 index 94618662a..000000000 --- a/src/designer/src/designer/assistantclient.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef ASSISTANTCLIENT_H -#define ASSISTANTCLIENT_H - -#include <QtCore/qprocess.h> - -QT_BEGIN_NAMESPACE - -class QString; - -class AssistantClient : public QObject -{ - Q_OBJECT - -public: - AssistantClient(); - ~AssistantClient(); - - bool showPage(const QString &path, QString *errorMessage); - bool activateIdentifier(const QString &identifier, QString *errorMessage); - bool activateKeyword(const QString &keyword, QString *errorMessage); - - bool isRunning() const; - - static QString documentUrl(const QString &prefix, int qtVersion = 0); - // Root of the Qt Designer documentation - static QString designerManualUrl(int qtVersion = 0); - // Root of the Qt Reference documentation - static QString qtReferenceManualUrl(int qtVersion = 0); - -private slots: - void readyReadStandardError(); - void processTerminated(int exitCode, QProcess::ExitStatus exitStatus); - -private: - static QString binary(); - bool sendCommand(const QString &cmd, QString *errorMessage); - bool ensureRunning(QString *errorMessage); - - QProcess *m_process = nullptr; -}; - -QT_END_NAMESPACE - -#endif // ASSISTANTCLIENT_H diff --git a/src/designer/src/designer/designer.pro b/src/designer/src/designer/designer.pro index 6a925202a..cddef1fbc 100644 --- a/src/designer/src/designer/designer.pro +++ b/src/designer/src/designer/designer.pro @@ -33,7 +33,6 @@ HEADERS += \ designer_enums.h \ appfontdialog.h \ preferencesdialog.h \ - assistantclient.h \ mainwindow.h SOURCES += main.cpp \ @@ -50,7 +49,6 @@ SOURCES += main.cpp \ versiondialog.cpp \ appfontdialog.cpp \ preferencesdialog.cpp \ - assistantclient.cpp \ mainwindow.cpp PRECOMPILED_HEADER=qdesigner_pch.h diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp index 4b98d6493..11cb350df 100644 --- a/src/designer/src/designer/qdesigner_actions.cpp +++ b/src/designer/src/designer/qdesigner_actions.cpp @@ -70,9 +70,12 @@ #include <QtGui/qaction.h> #include <QtGui/qactiongroup.h> +#include <QtGui/qcursor.h> +#include <QtGui/qdesktopservices.h> #include <QtGui/qevent.h> #include <QtGui/qicon.h> #include <QtGui/qimage.h> +#include <QtGui/qpainter.h> #include <QtGui/qpixmap.h> #include <QtGui/qscreen.h> #if defined(QT_PRINTSUPPORT_LIB) // Some platforms may not build QtPrintSupport @@ -83,9 +86,7 @@ # define HAS_PRINTER # endif #endif -#include <QtGui/qpainter.h> #include <QtGui/qtransform.h> -#include <QtGui/qcursor.h> #include <QtCore/qsize.h> #include <QtCore/qlibraryinfo.h> @@ -987,23 +988,32 @@ QAction *QDesignerActions::minimizeAction() const void QDesignerActions::showDesignerHelp() { - QString url = AssistantClient::designerManualUrl(); - url += QStringLiteral("qtdesigner-manual.html"); - showHelp(url); + showHelp("qtdesigner-manual.html"); } void QDesignerActions::helpRequested(const QString &manual, const QString &document) { - QString url = AssistantClient::documentUrl(manual); - url += document; - showHelp(url); + Q_UNUSED(manual); + showHelp(document); } -void QDesignerActions::showHelp(const QString &url) +bool QDesignerActions::showHelp(const QString &htmlFile) { - QString errorMessage; - if (!m_assistantClient.showPage(url, &errorMessage)) - QMessageBox::warning(core()->topLevel(), tr("Assistant"), errorMessage); + const int qtVersion = QT_VERSION; + QString url; + QTextStream(&url) << "http://doc.qt.io/qt-" << (qtVersion >> 16) +// TODO: uncomment the line below just before Qt 6.0 release +// we should have then http://doc.qt.io/qt-6.0/ link valid (like in case of 5.x series). +// Currently it redirects to Qt 6 snapshot. +// << "." << ((qtVersion >> 8) & 0xFF) + << '/' << htmlFile; + + return QDesktopServices::openUrl(QUrl(url)); +} + +bool QDesignerActions::showIdentifier(const QString &identifier) +{ + return showHelp(identifier.toLower() + ".html"); } void QDesignerActions::aboutDesigner() @@ -1032,10 +1042,7 @@ void QDesignerActions::showWidgetSpecificHelp() return; } - QString errorMessage; - const bool rc = m_assistantClient.activateIdentifier(helpId, &errorMessage); - if (!rc) - QMessageBox::warning(core()->topLevel(), tr("Assistant"), errorMessage); + showIdentifier(helpId); } void QDesignerActions::updateCloseAction() diff --git a/src/designer/src/designer/qdesigner_actions.h b/src/designer/src/designer/qdesigner_actions.h index 4192a002b..715388b4e 100644 --- a/src/designer/src/designer/qdesigner_actions.h +++ b/src/designer/src/designer/qdesigner_actions.h @@ -29,7 +29,6 @@ #ifndef QDESIGNER_ACTIONS_H #define QDESIGNER_ACTIONS_H -#include "assistantclient.h" #include "qdesigner_settings.h" #include <QtCore/qobject.h> @@ -143,7 +142,8 @@ private: bool saveFormAs(QDesignerFormWindowInterface *fw); void updateRecentFileActions(); void addRecentFile(const QString &fileName); - void showHelp(const QString &help); + bool showIdentifier(const QString &identifier); + bool showHelp(const QString &htmlFile); void closePreview(); QRect fixDialogRect(const QRect &rect) const; QString fixResourceFileBackupPath(QDesignerFormWindowInterface *fwi, const QDir& backupDir); @@ -158,7 +158,6 @@ private: QDesignerWorkbench *m_workbench; QDesignerFormEditorInterface *m_core; QDesignerSettings m_settings; - AssistantClient m_assistantClient; QString m_openDirectory; QString m_saveDirectory; |