diff options
Diffstat (limited to 'examples/assistant')
19 files changed, 156 insertions, 864 deletions
diff --git a/examples/assistant/CMakeLists.txt b/examples/assistant/CMakeLists.txt index bed9e1c4f..3d8c97dbb 100644 --- a/examples/assistant/CMakeLists.txt +++ b/examples/assistant/CMakeLists.txt @@ -1,4 +1,2 @@ -# Generated from assistant.pro. - -add_subdirectory(simpletextviewer) -add_subdirectory(remotecontrol) +qt_internal_add_example(simpletextviewer) +qt_internal_add_example(remotecontrol) diff --git a/examples/assistant/doc/src/remotecontrol.qdoc b/examples/assistant/doc/src/remotecontrol.qdoc index c0bde2eb6..0462aae0e 100644 --- a/examples/assistant/doc/src/remotecontrol.qdoc +++ b/examples/assistant/doc/src/remotecontrol.qdoc @@ -1,34 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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 Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example remotecontrol \ingroup examples-qtassistant \title Remote Control Example + \examplecategory {Desktop} \brief Using and controlling Qt Assistant as a help viewer. */ diff --git a/examples/assistant/doc/src/simpletextviewer.qdoc b/examples/assistant/doc/src/simpletextviewer.qdoc index b8efba659..38c8d038b 100644 --- a/examples/assistant/doc/src/simpletextviewer.qdoc +++ b/examples/assistant/doc/src/simpletextviewer.qdoc @@ -1,34 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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 Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example simpletextviewer \ingroup examples-qtassistant \title Simple Text Viewer Example + \examplecategory {Desktop} \brief Using \QA as a customized help viewer for your application. diff --git a/examples/assistant/remotecontrol/CMakeLists.txt b/examples/assistant/remotecontrol/CMakeLists.txt index c8b3b5c91..8afd64315 100644 --- a/examples/assistant/remotecontrol/CMakeLists.txt +++ b/examples/assistant/remotecontrol/CMakeLists.txt @@ -1,39 +1,36 @@ -# Generated from remotecontrol.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(remotecontrol LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) - set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") + set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/assistant/remotecontrol") -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_add_executable(remotecontrol main.cpp remotecontrol.cpp remotecontrol.h remotecontrol.ui ) + set_target_properties(remotecontrol PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) + target_link_libraries(remotecontrol PUBLIC Qt::Core Qt::Gui Qt::Widgets ) - # Resources: set(remotecontrol_resource_files "enter.png" diff --git a/examples/assistant/remotecontrol/main.cpp b/examples/assistant/remotecontrol/main.cpp index ee5201b79..c4207e266 100644 --- a/examples/assistant/remotecontrol/main.cpp +++ b/examples/assistant/remotecontrol/main.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "remotecontrol.h" diff --git a/examples/assistant/remotecontrol/remotecontrol.cpp b/examples/assistant/remotecontrol/remotecontrol.cpp index 1e4bdaa5e..b4d1fe085 100644 --- a/examples/assistant/remotecontrol/remotecontrol.cpp +++ b/examples/assistant/remotecontrol/remotecontrol.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "remotecontrol.h" @@ -54,30 +7,48 @@ #include <QLibraryInfo> #include <QMessageBox> #include <QProcess> -#include <QTextStream> -RemoteControl::RemoteControl(QWidget *parent, Qt::WindowFlags flags) - : QMainWindow(parent, flags) +using namespace Qt::StringLiterals; + +RemoteControl::RemoteControl() { ui.setupUi(this); - connect(ui.indexLineEdit, SIGNAL(returnPressed()), - this, SLOT(on_indexButton_clicked())); - connect(ui.identifierLineEdit, SIGNAL(returnPressed()), - this, SLOT(on_identifierButton_clicked())); - connect(ui.urlLineEdit, SIGNAL(returnPressed()), - this, SLOT(on_urlButton_clicked())); + connect(ui.launchButton, &QPushButton::clicked, this, &RemoteControl::onLaunchClicked); + + connect(ui.indexButton, &QPushButton::clicked, this, &RemoteControl::onIndexClicked); + connect(ui.indexLineEdit, &QLineEdit::returnPressed, this, &RemoteControl::onIndexClicked); + + connect(ui.idButton, &QPushButton::clicked, this, &RemoteControl::onIdClicked); + connect(ui.idLineEdit, &QLineEdit::returnPressed, this, &RemoteControl::onIdClicked); + + connect(ui.urlButton, &QPushButton::clicked, this, &RemoteControl::onUrlClicked); + connect(ui.urlLineEdit, &QLineEdit::returnPressed, this, &RemoteControl::onUrlClicked); + + connect(ui.syncContentsButton, &QPushButton::clicked, this, + [this] { sendCommand("SyncContents"_L1); }); - QString rc; - QTextStream(&rc) << QLatin1String("qthelp://org.qt-project.qtdoc.") - << (QT_VERSION >> 16) << ((QT_VERSION >> 8) & 0xFF) - << (QT_VERSION & 0xFF) - << QLatin1String("/qtdoc/index.html"); + connect(ui.contentsCheckBox, &QCheckBox::toggled, this, [this](bool checked) { + sendCommand(checked ? "Show Contents"_L1 : "Hide Contents"_L1); + }); + connect(ui.indexCheckBox, &QCheckBox::toggled, this, + [this](bool checked) { sendCommand(checked ? "Show Index"_L1 : "Hide Index"_L1); }); + connect(ui.bookmarksCheckBox, &QCheckBox::toggled, this, [this](bool checked) { + sendCommand(checked ? "Show Bookmarks"_L1 : "Hide Bookmarks"_L1); + }); - ui.startUrlLineEdit->setText(rc); + connect(ui.actionQuit, &QAction::triggered, this, &QMainWindow::close); + + const QString versionString = QString::number(QT_VERSION_MAJOR) + + QString::number(QT_VERSION_MINOR) + QString::number(QT_VERSION_PATCH); + ui.startUrlLineEdit->setText("qthelp://org.qt-project.qtdoc."_L1 + versionString + + "/qdoc/qdoc-index.html"_L1); process = new QProcess(this); - connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), - this, SLOT(helpViewerClosed())); + connect(process, &QProcess::finished, this, [this] { + ui.launchButton->setEnabled(true); + ui.startUrlLineEdit->setEnabled(true); + ui.actionGroupBox->setEnabled(false); + }); } RemoteControl::~RemoteControl() @@ -88,97 +59,55 @@ RemoteControl::~RemoteControl() } } -void RemoteControl::on_actionQuit_triggered() -{ - close(); -} - -void RemoteControl::on_launchButton_clicked() +void RemoteControl::onLaunchClicked() { if (process->state() == QProcess::Running) return; QString app = QLibraryInfo::path(QLibraryInfo::BinariesPath); #if !defined(Q_OS_MAC) - app += QLatin1String("/assistant"); + app += "/assistant"_L1; #else - app += QLatin1String("/Assistant.app/Contents/MacOS/Assistant"); + app += "/Assistant.app/Contents/MacOS/Assistant"_L1; #endif - ui.contentsCheckBox->setChecked(true); - ui.indexCheckBox->setChecked(true); - ui.bookmarksCheckBox->setChecked(true); - - QStringList args; - args << QLatin1String("-enableRemoteControl"); - process->start(app, args); + process->start(app, {"-enableRemoteControl"_L1}); if (!process->waitForStarted()) { - QMessageBox::critical( - this, tr("Remote Control"), + QMessageBox::critical(this, tr("Remote Control"), tr("Could not start Qt Assistant from %1.").arg(QDir::toNativeSeparators(app))); return; } + ui.contentsCheckBox->setChecked(true); + ui.indexCheckBox->setChecked(true); + ui.bookmarksCheckBox->setChecked(true); + if (!ui.startUrlLineEdit->text().isEmpty()) - sendCommand(QLatin1String("SetSource ") - + ui.startUrlLineEdit->text()); + sendCommand("SetSource "_L1 + ui.startUrlLineEdit->text()); ui.launchButton->setEnabled(false); ui.startUrlLineEdit->setEnabled(false); ui.actionGroupBox->setEnabled(true); } -void RemoteControl::sendCommand(const QString &cmd) -{ - if (process->state() != QProcess::Running) - return; - process->write(cmd.toLocal8Bit() + '\n'); -} - -void RemoteControl::on_indexButton_clicked() -{ - sendCommand(QLatin1String("ActivateKeyword ") - + ui.indexLineEdit->text()); -} - -void RemoteControl::on_identifierButton_clicked() -{ - sendCommand(QLatin1String("ActivateIdentifier ") - + ui.identifierLineEdit->text()); -} - -void RemoteControl::on_urlButton_clicked() +void RemoteControl::onIndexClicked() { - sendCommand(QLatin1String("SetSource ") - + ui.urlLineEdit->text()); + sendCommand("ActivateKeyword "_L1 + ui.indexLineEdit->text()); } -void RemoteControl::on_syncContentsButton_clicked() +void RemoteControl::onIdClicked() { - sendCommand(QLatin1String("SyncContents")); + sendCommand("ActivateIdentifier "_L1 + ui.idLineEdit->text()); } -void RemoteControl::on_contentsCheckBox_toggled(bool checked) +void RemoteControl::onUrlClicked() { - sendCommand(checked ? - QLatin1String("Show Contents") : QLatin1String("Hide Contents")); + sendCommand("SetSource "_L1 + ui.urlLineEdit->text()); } -void RemoteControl::on_indexCheckBox_toggled(bool checked) -{ - sendCommand(checked ? - QLatin1String("Show Index") : QLatin1String("Hide Index")); -} - -void RemoteControl::on_bookmarksCheckBox_toggled(bool checked) -{ - sendCommand(checked ? - QLatin1String("Show Bookmarks") : QLatin1String("Hide Bookmarks")); -} - -void RemoteControl::helpViewerClosed() +void RemoteControl::sendCommand(const QString &cmd) { - ui.launchButton->setEnabled(true); - ui.startUrlLineEdit->setEnabled(true); - ui.actionGroupBox->setEnabled(false); + if (process->state() != QProcess::Running) + return; + process->write(cmd.toLocal8Bit() + '\n'); } diff --git a/examples/assistant/remotecontrol/remotecontrol.h b/examples/assistant/remotecontrol/remotecontrol.h index f59ffb7aa..ea707ba22 100644 --- a/examples/assistant/remotecontrol/remotecontrol.h +++ b/examples/assistant/remotecontrol/remotecontrol.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef REMOTECONTROL_H #define REMOTECONTROL_H @@ -64,24 +17,18 @@ class RemoteControl : public QMainWindow Q_OBJECT public: - RemoteControl(QWidget *parent = nullptr, Qt::WindowFlags flags = {}); + RemoteControl(); ~RemoteControl(); private: Ui::RemoteControlClass ui; QProcess *process; -private slots: - void on_launchButton_clicked(); - void on_actionQuit_triggered(); - void on_indexButton_clicked(); - void on_identifierButton_clicked(); - void on_urlButton_clicked(); - void on_syncContentsButton_clicked(); - void on_contentsCheckBox_toggled(bool checked); - void on_indexCheckBox_toggled(bool checked); - void on_bookmarksCheckBox_toggled(bool checked); - void helpViewerClosed(); +private: + void onLaunchClicked(); + void onIndexClicked(); + void onIdClicked(); + void onUrlClicked(); void sendCommand(const QString &cmd); }; diff --git a/examples/assistant/remotecontrol/remotecontrol.ui b/examples/assistant/remotecontrol/remotecontrol.ui index 1cfc7f540..525754710 100644 --- a/examples/assistant/remotecontrol/remotecontrol.ui +++ b/examples/assistant/remotecontrol/remotecontrol.ui @@ -109,10 +109,10 @@ <number>0</number> </property> <item> - <widget class="QLineEdit" name="identifierLineEdit" /> + <widget class="QLineEdit" name="idLineEdit" /> </item> <item> - <widget class="QToolButton" name="identifierButton" > + <widget class="QToolButton" name="idButton" > <property name="text" > <string/> </property> diff --git a/examples/assistant/simpletextviewer/.prev_CMakeLists.txt b/examples/assistant/simpletextviewer/.prev_CMakeLists.txt deleted file mode 100644 index 772115941..000000000 --- a/examples/assistant/simpletextviewer/.prev_CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Generated from simpletextviewer.pro. - -cmake_minimum_required(VERSION 3.14) -project(simpletextviewer LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/assistant/simpletextviewer") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(simpletextviewer - assistant.cpp assistant.h - findfiledialog.cpp findfiledialog.h - main.cpp - mainwindow.cpp mainwindow.h - textedit.cpp textedit.h -) -set_target_properties(simpletextviewer PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_compile_definitions(simpletextviewer PUBLIC - SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\" -) - -target_link_libraries(simpletextviewer PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - -install(TARGETS simpletextviewer - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/assistant/simpletextviewer/CMakeLists.txt b/examples/assistant/simpletextviewer/CMakeLists.txt index fb4f100be..8d459a261 100644 --- a/examples/assistant/simpletextviewer/CMakeLists.txt +++ b/examples/assistant/simpletextviewer/CMakeLists.txt @@ -1,23 +1,18 @@ -# Generated from simpletextviewer.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(simpletextviewer LANGUAGES CXX) -set(CMAKE_INCLUDE_CURRENT_DIR ON) - set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") + set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/assistant/simpletextviewer") -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_add_executable(simpletextviewer assistant.cpp assistant.h @@ -26,12 +21,14 @@ qt_add_executable(simpletextviewer mainwindow.cpp mainwindow.h textedit.cpp textedit.h ) + set_target_properties(simpletextviewer PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) + target_compile_definitions(simpletextviewer PUBLIC - SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" # special case + SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" ) target_link_libraries(simpletextviewer PUBLIC diff --git a/examples/assistant/simpletextviewer/assistant.cpp b/examples/assistant/simpletextviewer/assistant.cpp index 321649d17..cd83723e9 100644 --- a/examples/assistant/simpletextviewer/assistant.cpp +++ b/examples/assistant/simpletextviewer/assistant.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "assistant.h" @@ -57,7 +10,7 @@ #include <QMessageBox> #include <QStandardPaths> -Assistant::Assistant() = default; +using namespace Qt::StringLiterals; //! [0] Assistant::~Assistant() @@ -83,40 +36,40 @@ void Assistant::showDocumentation(const QString &page) } //! [1] -QString documentationDirectory() +static QString documentationDirectory() { QStringList paths; #ifdef SRCDIR - paths.append(QLatin1String(SRCDIR)); + paths.append(QLatin1StringView(SRCDIR)); #endif paths.append(QLibraryInfo::path(QLibraryInfo::ExamplesPath)); paths.append(QCoreApplication::applicationDirPath()); paths.append(QStandardPaths::standardLocations(QStandardPaths::AppDataLocation)); - for (const auto &dir : qAsConst(paths)) { - const QString path = dir + QLatin1String("/documentation"); + for (const auto &dir : std::as_const(paths)) { + const QString path = dir + "/documentation"_L1; if (QFileInfo::exists(path)) return path; } - return QString(); + return {}; } //! [2] bool Assistant::startAssistant() { if (m_process.isNull()) { - m_process.reset(new QProcess()); + m_process.reset(new QProcess); QObject::connect(m_process.data(), &QProcess::finished, m_process.data(), [this](int exitCode, QProcess::ExitStatus status) { - this->finished(exitCode, status); - }); + finished(exitCode, status); + }); } if (m_process->state() != QProcess::Running) { QString app = QLibraryInfo::path(QLibraryInfo::BinariesPath); #ifndef Q_OS_DARWIN - app += QLatin1String("/assistant"); + app += "/assistant"_L1; #else - app += QLatin1String("/Assistant.app/Contents/MacOS/Assistant"); + app += "/Assistant.app/Contents/MacOS/Assistant"_L1; #endif const QString collectionDirectory = documentationDirectory(); @@ -125,15 +78,15 @@ bool Assistant::startAssistant() return false; } - QStringList args{QLatin1String("-collectionFile"), - collectionDirectory + QLatin1String("/simpletextviewer.qhc"), - QLatin1String("-enableRemoteControl")}; + const QStringList args{"-collectionFile"_L1, + collectionDirectory + "/simpletextviewer.qhc"_L1, + "-enableRemoteControl"_L1}; m_process->start(app, args); - if (!m_process->waitForStarted()) { + if (!m_process->waitForStarted(3000)) { showError(tr("Unable to launch Qt Assistant (%1): %2") - .arg(QDir::toNativeSeparators(app), m_process->errorString())); + .arg(QDir::toNativeSeparators(app), m_process->errorString())); return false; } } @@ -143,16 +96,14 @@ bool Assistant::startAssistant() void Assistant::showError(const QString &message) { - QMessageBox::critical(QApplication::activeWindow(), - tr("Simple Text Viewer"), message); + QMessageBox::critical(QApplication::activeWindow(), tr("Simple Text Viewer"), message); } void Assistant::finished(int exitCode, QProcess::ExitStatus status) { const QString stdErr = QString::fromLocal8Bit(m_process->readAllStandardError()); - if (status != QProcess::NormalExit) { - showError(tr("Assistant crashed: ").arg(stdErr)); - } else if (exitCode != 0) { + if (status != QProcess::NormalExit) + showError(tr("Assistant crashed: %1").arg(stdErr)); + else if (exitCode != 0) showError(tr("Assistant exited with %1: %2").arg(exitCode).arg(stdErr)); - } } diff --git a/examples/assistant/simpletextviewer/assistant.h b/examples/assistant/simpletextviewer/assistant.h index c513c3428..1cbc8b9e2 100644 --- a/examples/assistant/simpletextviewer/assistant.h +++ b/examples/assistant/simpletextviewer/assistant.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef ASSISTANT_H #define ASSISTANT_H @@ -56,13 +9,11 @@ #include <QScopedPointer> #include <QString> - class Assistant { Q_DECLARE_TR_FUNCTIONS(Assistant) public: - Assistant(); ~Assistant(); void showDocumentation(const QString &file); diff --git a/examples/assistant/simpletextviewer/findfiledialog.cpp b/examples/assistant/simpletextviewer/findfiledialog.cpp index fec9e6e43..7dccfb074 100644 --- a/examples/assistant/simpletextviewer/findfiledialog.cpp +++ b/examples/assistant/simpletextviewer/findfiledialog.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "assistant.h" #include "findfiledialog.h" @@ -67,9 +20,9 @@ //! [0] FindFileDialog::FindFileDialog(TextEdit *editor, Assistant *assistant) : QDialog(editor) + , currentEditor(editor) + , currentAssistant(assistant) { - currentAssistant = assistant; - currentEditor = editor; //! [0] createButtons(); @@ -89,8 +42,8 @@ FindFileDialog::FindFileDialog(TextEdit *editor, Assistant *assistant) void FindFileDialog::browse() { - QString currentDirectory = directoryComboBox->currentText(); - QString newDirectory = QFileDialog::getExistingDirectory(this, + const QString currentDirectory = directoryComboBox->currentText(); + const QString newDirectory = QFileDialog::getExistingDirectory(this, tr("Select Directory"), currentDirectory); if (!newDirectory.isEmpty()) { directoryComboBox->addItem(QDir::toNativeSeparators(newDirectory)); @@ -108,12 +61,12 @@ void FindFileDialog::help() void FindFileDialog::openFile() { - auto item = foundFilesTree->currentItem(); + QTreeWidgetItem *item = foundFilesTree->currentItem(); if (!item) return; - QString fileName = item->text(0); - QString path = QDir(directoryComboBox->currentText()).filePath(fileName); + const QString fileName = item->text(0); + const QString path = QDir(directoryComboBox->currentText()).filePath(fileName); currentEditor->setContents(path); close(); @@ -122,8 +75,7 @@ void FindFileDialog::openFile() void FindFileDialog::update() { findFiles(); - buttonBox->button(QDialogButtonBox::Open)->setEnabled( - foundFilesTree->topLevelItemCount() > 0); + buttonBox->button(QDialogButtonBox::Open)->setEnabled(foundFilesTree->topLevelItemCount() > 0); } void FindFileDialog::findFiles() @@ -131,9 +83,9 @@ void FindFileDialog::findFiles() QString wildCard = fileNameComboBox->currentText(); if (!wildCard.endsWith('*')) wildCard += '*'; - QRegularExpression filePattern(QRegularExpression::wildcardToRegularExpression(wildCard)); + const QRegularExpression filePattern(QRegularExpression::wildcardToRegularExpression(wildCard)); - QDir directory(directoryComboBox->currentText()); + const QDir directory(directoryComboBox->currentText()); const QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks); QStringList matchingFiles; @@ -149,10 +101,8 @@ void FindFileDialog::showFiles(const QStringList &files) { foundFilesTree->clear(); - for (int i = 0; i < files.count(); ++i) { - QTreeWidgetItem *item = new QTreeWidgetItem(foundFilesTree); - item->setText(0, files[i]); - } + for (const QString &file : files) + new QTreeWidgetItem(foundFilesTree, {file}); if (files.count() > 0) foundFilesTree->setCurrentItem(foundFilesTree->topLevelItem(0)); @@ -178,19 +128,14 @@ void FindFileDialog::createComboBoxes() fileNameComboBox = new QComboBox; fileNameComboBox->setEditable(true); - fileNameComboBox->setSizePolicy(QSizePolicy::Expanding, - QSizePolicy::Preferred); + fileNameComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); directoryComboBox->setMinimumContentsLength(30); - directoryComboBox->setSizeAdjustPolicy( - QComboBox::AdjustToContents); - directoryComboBox->setSizePolicy(QSizePolicy::Expanding, - QSizePolicy::Preferred); - - connect(fileNameComboBox, &QComboBox::editTextChanged, - this, &FindFileDialog::update); - connect(directoryComboBox, &QComboBox::currentTextChanged, - this, &FindFileDialog::update); + directoryComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); + directoryComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + connect(fileNameComboBox, &QComboBox::editTextChanged, this, &FindFileDialog::update); + connect(directoryComboBox, &QComboBox::currentTextChanged, this, &FindFileDialog::update); } void FindFileDialog::createFilesTree() @@ -201,8 +146,7 @@ void FindFileDialog::createFilesTree() foundFilesTree->setRootIsDecorated(false); foundFilesTree->setSelectionMode(QAbstractItemView::SingleSelection); - connect(foundFilesTree, &QTreeWidget::itemActivated, - this, &FindFileDialog::openFile); + connect(foundFilesTree, &QTreeWidget::itemActivated, this, &FindFileDialog::openFile); } void FindFileDialog::createLabels() diff --git a/examples/assistant/simpletextviewer/findfiledialog.h b/examples/assistant/simpletextviewer/findfiledialog.h index 605da0954..7e77938dd 100644 --- a/examples/assistant/simpletextviewer/findfiledialog.h +++ b/examples/assistant/simpletextviewer/findfiledialog.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef FINDFILEDIALOG_H #define FINDFILEDIALOG_H @@ -59,7 +12,6 @@ class QDialogButtonBox; class QLabel; class QToolButton; class QTreeWidget; -class QTreeWidgetItem; QT_END_NAMESPACE class Assistant; @@ -89,8 +41,8 @@ private: void createLabels(); void createLayout(); - Assistant *currentAssistant; TextEdit *currentEditor; + Assistant *currentAssistant; QTreeWidget *foundFilesTree; QComboBox *directoryComboBox; diff --git a/examples/assistant/simpletextviewer/main.cpp b/examples/assistant/simpletextviewer/main.cpp index 55c1039f8..fb0633cc4 100644 --- a/examples/assistant/simpletextviewer/main.cpp +++ b/examples/assistant/simpletextviewer/main.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "mainwindow.h" diff --git a/examples/assistant/simpletextviewer/mainwindow.cpp b/examples/assistant/simpletextviewer/mainwindow.cpp index 37ae6c041..124596134 100644 --- a/examples/assistant/simpletextviewer/mainwindow.cpp +++ b/examples/assistant/simpletextviewer/mainwindow.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "assistant.h" #include "findfiledialog.h" @@ -60,14 +13,16 @@ #include <QMenuBar> #include <QMessageBox> +using namespace Qt::StringLiterals; + // ![0] MainWindow::MainWindow() + : textViewer(new TextEdit) + , assistant(new Assistant) { - assistant = new Assistant; // ![0] - textViewer = new TextEdit; textViewer->setContents(QLibraryInfo::path(QLibraryInfo::ExamplesPath) - + QLatin1String("/assistant/simpletextviewer/documentation/intro.html")); + + "/assistant/simpletextviewer/documentation/intro.html"_L1); setCentralWidget(textViewer); createActions(); @@ -150,7 +105,6 @@ void MainWindow::createMenus() helpMenu->addAction(aboutAct); helpMenu->addAction(aboutQtAct); - menuBar()->addMenu(fileMenu); menuBar()->addMenu(helpMenu); } diff --git a/examples/assistant/simpletextviewer/mainwindow.h b/examples/assistant/simpletextviewer/mainwindow.h index 1c7f21761..59b5472f0 100644 --- a/examples/assistant/simpletextviewer/mainwindow.h +++ b/examples/assistant/simpletextviewer/mainwindow.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef MAINWINDOW_H #define MAINWINDOW_H @@ -80,8 +33,8 @@ private: void createActions(); void createMenus(); - Assistant *assistant; TextEdit *textViewer; + Assistant *assistant; QMenu *fileMenu; QMenu *helpMenu; diff --git a/examples/assistant/simpletextviewer/textedit.cpp b/examples/assistant/simpletextviewer/textedit.cpp index 18cd767eb..2f52f73a1 100644 --- a/examples/assistant/simpletextviewer/textedit.cpp +++ b/examples/assistant/simpletextviewer/textedit.cpp @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #include "textedit.h" @@ -61,11 +14,11 @@ TextEdit::TextEdit(QWidget *parent) void TextEdit::setContents(const QString &fileName) { - QFileInfo fi(fileName); + const QFileInfo fi(fileName); srcUrl = QUrl::fromLocalFile(fi.absoluteFilePath()); QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { - QString data(file.readAll()); + const QString data(QString::fromUtf8(file.readAll())); if (fileName.endsWith(".html")) setHtml(data); else diff --git a/examples/assistant/simpletextviewer/textedit.h b/examples/assistant/simpletextviewer/textedit.h index b1cb243fb..d75ce2b87 100644 --- a/examples/assistant/simpletextviewer/textedit.h +++ b/examples/assistant/simpletextviewer/textedit.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef TEXTEDIT_H #define TEXTEDIT_H |