diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-04-12 09:49:30 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-04-17 21:02:32 +0200 |
commit | 69d4ecd6ef9057cb3703178277042ff7a7411459 (patch) | |
tree | 15069fb98f8f609e7caf841d9a29c9f43a4f1092 /src/corelib/doc/snippets | |
parent | 94279afff86252b8b777450a56990fa33ffbb0d7 (diff) | |
download | qtbase-69d4ecd6ef9057cb3703178277042ff7a7411459.tar.gz |
Remove unused documentation code snippets
Modules:
- Core
- Gui
- Widgets
- Open(Widgets)
- PrintSupport
- Sql
- Network
- Concurrent
- Testlib
Pick-to: 6.5
Change-Id: I63e58c01bec4bd162486020f0085227fdaa83b18
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/doc/snippets')
23 files changed, 3 insertions, 523 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp index 680a099f68..5bcee95d32 100644 --- a/src/corelib/doc/snippets/code/doc_src_containers.cpp +++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp @@ -226,13 +226,6 @@ foreach (const QString &str, map.uniqueKeys()) { //! [20] -//! [21] -forever { - ... -} -//! [21] - - //! [22] CONFIG += no_keywords //! [22] diff --git a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp index 2d6e4a430f..3bca27b966 100644 --- a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp +++ b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp @@ -22,9 +22,3 @@ class MyInstance : public QObject //! [2] Q_IMPORT_PLUGIN(qjpeg) //! [2] - - -//! [3] -TEMPLATE = app -QTPLUGIN += qjpeg qgif # image formats -//! [3] diff --git a/src/corelib/doc/snippets/code/doc_src_qset.cpp b/src/corelib/doc/snippets/code/doc_src_qset.cpp index 64e0b6e450..37f7ced3b0 100644 --- a/src/corelib/doc/snippets/code/doc_src_qset.cpp +++ b/src/corelib/doc/snippets/code/doc_src_qset.cpp @@ -111,23 +111,3 @@ QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predic if (it != set.constEnd()) cout << "Found Jeanette" << endl; //! [12] - - -//! [13] -QSet<QString> set; -set << "red" << "green" << "blue" << ... << "black"; - -QList<QString> list = set.toList(); -std::sort(list.begin(), list.end()); -//! [13] - - -//! [14] -QStringList list; -list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia"; - -QSet<QString> set = QSet<QString>::fromList(list); -set.contains("Julia"); // returns true -set.contains("Mike"); // returns true -set.size(); // returns 2 -//! [14] diff --git a/src/corelib/doc/snippets/code/doc_src_resources.cpp b/src/corelib/doc/snippets/code/doc_src_resources.cpp index 5df085d145..04ecf810ec 100644 --- a/src/corelib/doc/snippets/code/doc_src_resources.cpp +++ b/src/corelib/doc/snippets/code/doc_src_resources.cpp @@ -15,16 +15,3 @@ MyClass::MyClass() : BaseClass() ... } //! [5] - - -//! [6] -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - Q_INIT_RESOURCE(graphlib); - - QFile file(":/graph.png"); - ... - return app.exec(); -} -//! [6] diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp index f8b74cd542..4b77ab607d 100644 --- a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp @@ -6,7 +6,7 @@ #include <QApplication> #include <QPushButton> #include <QPropertyAnimation> -//! [1] + class MyButtonWidget : public QWidget { public: @@ -31,7 +31,6 @@ int main(int argc, char *argv[]) buttonAnimWidget.show(); return a.exec(); } -//! [1] //! [0] diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp index 096e36dc72..70698cd7e0 100644 --- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp @@ -32,17 +32,6 @@ Q_FLAG(Options) typedef QFlags<Enum> Flags; //! [2] - -//! [3] -int myValue = 10; -int minValue = 2; -int maxValue = 6; - -int boundedValue = qBound(minValue, myValue, maxValue); -// boundedValue == 6 -//! [3] - - //! [4] if (!driver()->isOpen() || driver()->isOpenError()) { qWarning("QSqlQuery::exec: database not open"); @@ -61,11 +50,6 @@ quint64 value = Q_UINT64_C(932838457459459); //! [6] -//! [7] -void myMsgHandler(QtMsgType, const char *); -//! [7] - - //! [8] qint64 value = Q_INT64_C(932838457459459); //! [8] @@ -579,11 +563,6 @@ qFuzzyCompare(0.0, 1.0e-200); // This will return false qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true //! [46] -//! [47] -CApaApplication *myApplicationFactory(); -//! [47] - - //! [49] void myMessageHandler(QtMsgType, const QMessageLogContext &, const QString &); //! [49] @@ -667,19 +646,6 @@ bool readConfiguration(const QFile &file) } //! [qunreachable-switch] -//! [qunreachable-return] - switch (shape) { - case Rectangle: - return rectangle(); - case Triangle: - return triangle(); - case Circle: - return circle(); - case NumShapes: - Q_UNREACHABLE_RETURN(nullptr); - } -//! [qunreachable-return] - //! [qt-version-check] #include <QtGlobal> diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp index 475bc874ec..3a8f7d2747 100644 --- a/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp @@ -10,16 +10,6 @@ file.open(QIODevice::ReadOnly); // opens "/home/readme.txt" under Unix //! [0] -//! [1] -QByteArray myEncoderFunc(const QString &fileName); -//! [1] - - -//! [2] -QString myDecoderFunc(const QByteArray &localFileName); -//! [2] - - //! [3] #include <stdio.h> diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp index bcc08c0f16..75a04e654f 100644 --- a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp @@ -84,9 +84,3 @@ out << "Qt rocks!" << Qt::endl; //! [9] stream << '\n' << Qt::flush; //! [9] - - -//! [10] -QTextStream out(&file); -out.setEncoding(QStringConverter::Utf8); -//! [10] diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp index 3f7dc07d9f..4fd7f97ae8 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp @@ -50,16 +50,6 @@ beginMoveRows(parent, 2, 2, parent, 0); beginMoveRows(parent, 2, 2, parent, 4); //! [9] -//! [10] -myData.clear(); -reset(); -//! [10] - -//! [11] -beginResetModel(); -myData.clear(); -endResetModel(); -//! [11] //! [12] class CustomDataProxy : public QSortFilterProxyModel diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp index a213ccbca6..757700786e 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp @@ -101,16 +101,6 @@ void someFunc() //! [11] -//! [12] -QPointer<QFile> fp(new QFile); -QVariant var = QVariant::fromValue(fp); -// ... -if (var.canConvert<QObject*>()) { - QObject *sp = var.value<QObject*>(); - qDebug() << sp->metaObject()->className(); // Prints 'QFile'. -} -//! [12] - //! [13] #include <memory> diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp index 2c5483abce..1f3789c635 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -129,13 +129,6 @@ void MyObject::timerEvent(QTimerEvent *event) //! [8] -//! [9] -QList<QObject *> list = window()->queryList("QAbstractButton")); -foreach (QObject *obj, list) - static_cast<QAbstractButton *>(obj)->setEnabled(false); -//! [9] - - //! [10] QPushButton *button = parentWidget->findChild<QPushButton *>("button1"); //! [10] @@ -204,22 +197,6 @@ MyWindow::MyWindow() } -//! [18] -int n = messages.count(); -showMessage(tr("%n message(s) saved", "", n)); -//! [18] - - -//! [19] -n == 1 ? tr("%n message saved") : tr("%n messages saved") -//! [19] - - -//! [20] -label->setText(tr("F\374r \310lise")); -//! [20] - - //! [21] if (receivers(SIGNAL(valueChanged(QByteArray))) > 0) { QByteArray data; @@ -383,14 +360,6 @@ public: //! [39] -//! [40] -//: This name refers to a host name. -hostNameLabel->setText(tr("Name:")); - -/*: This text refers to a C++ code example. */ -QString example = tr("Example"); -//! [40] - //! [41] QPushButton *button = parentWidget->findChild<QPushButton *>("button1", Qt::FindDirectChildrenOnly); //! [41] @@ -487,18 +456,6 @@ public: }; //! [52] -//! [meta data] -//: This is a comment for the translator. -//= qtn_foo_bar -//~ loc-layout_id foo_dialog -//~ loc-blank False -//~ magic-stuff This might mean something magic. -QString text = MyMagicClass::tr("Sim sala bim."); -//! [meta data] - -//! [explicit tr context] -QString text = QScrollBar::tr("Page up"); -//! [explicit tr context] //! [53] { diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp index e0c846a587..dcae4b6934 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp @@ -89,11 +89,6 @@ return QVariant::fromValue(s); //! [7] -//! [8] -QObject *object = getObjectFromSomewhere(); -QVariant data = QVariant::fromValue(object); -//! [8] - //! [9] QList<int> intList = {7, 11, 42}; diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp deleted file mode 100644 index 1368559b24..0000000000 --- a/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//! [0] -class Number { -public: - Number(double n) : num (n) { } - - void setNumber(double n) { num = n; } - double number() const { return num; } - -private: - double num; -}; -//! [0] - - -//! [1] -void calcSquare(Number *num) -{ - QMutexLocker locker(mutexpool.get(num)); - num.setNumber(num.number() * num.number()); -} -//! [1] diff --git a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp index e86f01a341..588e81bab1 100644 --- a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp @@ -71,14 +71,6 @@ QTime::isValid(22, 5, 62); // returns false //! [9] -//! [10] -QTime t; -t.start(); -some_lengthy_task(); -qDebug("Time elapsed: %d ms", t.elapsed()); -//! [10] - - //! [11] QDateTime now = QDateTime::currentDateTime(); QDateTime xmas(QDate(now.date().year(), 12, 25).startOfDay()); diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp index 6fc3cf5c3c..cc22ba88ce 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp @@ -90,12 +90,4 @@ Arguments: //! [3] } -{ -//! [4] -QCommandLineParser parser; -parser.setApplicationDescription(QCoreApplication::translate("main", "The best application in the world")); -parser.addHelpOption(); -//! [4] -} - } diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp index 6a8ca4f742..6edfbd0e28 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp @@ -163,18 +163,6 @@ for (i = hash.begin(); i != hash.end(); ++i) i.value() += 2; //! [18] -void erase() -{ -QHash<QString, int> hash; -//! [20] -QHash<QString, int>::const_iterator i = hash.cbegin(); -while (i != hash.cend()) { - if (i.value() > 10) - i = hash.erase(i); - else - ++i; -} -//! [20] //! [21] erase_if(hash, [](const QHash<QString, int>::iterator it) { return it.value() > 10; }); //! [21] diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp index 51d8623cab..462eb28a1e 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp @@ -107,43 +107,6 @@ inline bool operator<(const Employee &e1, const Employee &e2) //! [13] -//! [14] -QMap<QString, int> map; -... -QMap<QString, int>::const_iterator i = map.find("HDR"); -while (i != map.end() && i.key() == "HDR") { - cout << i.value() << Qt::endl; - ++i; -} -//! [14] - - -//! [15] -QMap<int, QString> map; -map.insert(1, "one"); -map.insert(5, "five"); -map.insert(10, "ten"); - -map.lowerBound(0); // returns iterator to (1, "one") -map.lowerBound(1); // returns iterator to (1, "one") -map.lowerBound(2); // returns iterator to (5, "five") -map.lowerBound(10); // returns iterator to (10, "ten") -map.lowerBound(999); // returns end() -//! [15] - - -//! [16] -QMap<QString, int> map; -... -QMap<QString, int>::const_iterator i = map.lowerBound("HDR"); -QMap<QString, int>::const_iterator upperBound = map.upperBound("HDR"); -while (i != upperBound) { - cout << i.value() << Qt::endl; - ++i; -} -//! [16] - - //! [17] QMap<int, QString> map; map.insert(1, "one"); @@ -214,36 +177,6 @@ for (i = map.cbegin(); i != map.cend(); ++i) //! [24] -//! [25] -QMultiMap<QString, int> map1, map2, map3; - -map1.insert("plenty", 100); -map1.insert("plenty", 2000); -// map1.size() == 2 - -map2.insert("plenty", 5000); -// map2.size() == 1 - -map3 = map1 + map2; -// map3.size() == 3 -//! [25] - - -//! [26] -QList<int> values = map.values("plenty"); -for (int i = 0; i < values.size(); ++i) - cout << values.at(i) << Qt::endl; -//! [26] - - -//! [27] -QMultiMap<QString, int>::iterator i = map.find("plenty"); -while (i != map.end() && i.key() == "plenty") { - cout << i.value() << Qt::endl; - ++i; -} -//! [27] - //! [keyiterator1] for (QMap<int, QString>::const_iterator it = map.cbegin(), end = map.cend(); it != end; ++it) { cout << "The key: " << it.key() << Qt::endl diff --git a/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp b/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp deleted file mode 100644 index 0b307c33c4..0000000000 --- a/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//! [0] -int ret = QMessageBox::warning(this, tr("My Application"), - tr("The document has been modified.\n" - "Do you want to save your changes?"), - QMessageBox::Save | QMessageBox::Discard - | QMessageBox::Cancel, - QMessageBox::Save); -//! [0] - - -//! [1] -QMessageBox msgBox; -msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); -switch (msgBox.exec()) { -case QMessageBox::Yes: - // yes was clicked - break; -case QMessageBox::No: - // no was clicked - break; -default: - // should never be reached - break; -} -//! [1] - - -//! [2] -QMessageBox msgBox; -QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole); -QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort); - -msgBox.exec(); - -if (msgBox.clickedButton() == connectButton) { - // connect -} else if (msgBox.clickedButton() == abortButton) { - // abort -} -//! [2] - - -//! [3] -QMessageBox messageBox(this); -QAbstractButton *disconnectButton = - messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole); -... -messageBox.exec(); -if (messageBox.clickedButton() == disconnectButton) { - ... -} -//! [3] - - -//! [4] -#include <QApplication> -#include <QMessageBox> - -int main(int argc, char *argv[]) -{ - QT_REQUIRE_VERSION(argc, argv, "6.1.2") - - QApplication app(argc, argv); - ... - return app.exec(); -} -//! [4] - -//! [5] -QMessageBox msgBox; -msgBox.setText("The document has been modified."); -msgBox.exec(); -//! [5] - -//! [6] -QMessageBox msgBox; -msgBox.setText("Do you want to save your changes?"); -msgBox.setInformativeText("The document has been modified. It was last saved 5 days ago."); -msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); -msgBox.setDefaultButton(QMessageBox::Save); -int ret = msgBox.exec(); -//! [6] - -//! [7] -switch (ret) { - case QMessageBox::Save: - // Save was clicked - break; - case QMessageBox::Discard: - // Don't Save was clicked - break; - case QMessageBox::Cancel: - // Cancel was clicked - break; - default: - // should never be reached - break; -} -//! [7] - -//! [9] -QMessageBox msgBox(this); -msgBox.setText(tr("The document has been modified.\n" - "Do you want to save your changes?")); -msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard - | QMessageBox::Cancel); -msgBox.setDefaultButton(QMessageBox::Save); -//! [9] diff --git a/src/corelib/doc/snippets/jni/src_qjniobject.cpp b/src/corelib/doc/snippets/jni/src_qjniobject.cpp index ca402fa3d7..6e66b51383 100644 --- a/src/corelib/doc/snippets/jni/src_qjniobject.cpp +++ b/src/corelib/doc/snippets/jni/src_qjniobject.cpp @@ -1,23 +1,6 @@ // Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//! [Working with lists] -QStringList getTrackTitles(const QJniObject &album) { - QStringList stringList; - QJniObject list = album.callObjectMethod("getTitles", - "()Ljava/util/List;"); - - if (list.isValid()) { - const int size = list.callMethod<jint>("size"); - for (int i = 0; i < size; ++i) { - QJniObject title = list.callObjectMethod("get", "(I)Ljava/lang/Object;", i); - stringList.append(title.toString()); - } - } - return stringList; -} -//! [Working with lists] - //! [QJniObject scope] void functionScope() { diff --git a/src/corelib/doc/snippets/qstring/stringbuilder.cpp b/src/corelib/doc/snippets/qstring/stringbuilder.cpp index 61b7a9a133..a48f9858b3 100644 --- a/src/corelib/doc/snippets/qstring/stringbuilder.cpp +++ b/src/corelib/doc/snippets/qstring/stringbuilder.cpp @@ -15,10 +15,6 @@ using namespace Qt::StringLiterals; ... //! [0] -//! [3] - DEFINES *= QT_USE_QSTRINGBUILDER -//! [3] - //! [5] #include <QStringBuilder> diff --git a/src/corelib/doc/snippets/resource-system/mainwindow.cpp b/src/corelib/doc/snippets/resource-system/mainwindow.cpp index 92456c35c4..de98aa56ec 100644 --- a/src/corelib/doc/snippets/resource-system/mainwindow.cpp +++ b/src/corelib/doc/snippets/resource-system/mainwindow.cpp @@ -1,15 +1,10 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//! [0] #include <QtWidgets> #include "mainwindow.h" -//! [0] - -//! [1] MainWindow::MainWindow() -//! [1] //! [2] { textEdit = new QPlainTextEdit; setCentralWidget(textEdit); @@ -27,11 +22,8 @@ MainWindow::MainWindow() setCurrentFile(QString()); setUnifiedTitleAndToolBarOnMac(true); } -//! [2] -//! [3] void MainWindow::closeEvent(QCloseEvent *event) -//! [3] //! [4] { if (maybeSave()) { writeSettings(); @@ -40,22 +32,16 @@ void MainWindow::closeEvent(QCloseEvent *event) event->ignore(); } } -//! [4] -//! [5] void MainWindow::newFile() -//! [5] //! [6] { if (maybeSave()) { textEdit->clear(); setCurrentFile(QString()); } } -//! [6] -//! [7] void MainWindow::open() -//! [7] //! [8] { if (maybeSave()) { QString fileName = QFileDialog::getOpenFileName(this); @@ -63,11 +49,8 @@ void MainWindow::open() loadFile(fileName); } } -//! [8] -//! [9] bool MainWindow::save() -//! [9] //! [10] { if (curFile.isEmpty()) { return saveAs(); @@ -75,11 +58,8 @@ bool MainWindow::save() return saveFile(curFile); } } -//! [10] -//! [11] bool MainWindow::saveAs() -//! [11] //! [12] { QString fileName = QFileDialog::getSaveFileName(this); if (fileName.isEmpty()) @@ -87,42 +67,31 @@ bool MainWindow::saveAs() return saveFile(fileName); } -//! [12] -//! [13] void MainWindow::about() -//! [13] //! [14] { QMessageBox::about(this, tr("About Application"), tr("The <b>Application</b> example demonstrates how to " "write modern GUI applications using Qt, with a menu bar, " "toolbars, and a status bar.")); } -//! [14] -//! [15] void MainWindow::documentWasModified() -//! [15] //! [16] { setWindowModified(textEdit->document()->isModified()); } -//! [16] -//! [17] void MainWindow::createActions() -//! [17] //! [18] { newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); newAct->setShortcuts(QKeySequence::New); newAct->setStatusTip(tr("Create a new file")); connect(newAct, &QAction::triggered, this, &MainWindow::newFile); -//! [19] openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); openAct->setShortcuts(QKeySequence::Open); openAct->setStatusTip(tr("Open an existing file")); connect(openAct, &QAction::triggered, this, &MainWindow::open); -//! [18] //! [19] saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); saveAct->setShortcuts(QKeySequence::Save); @@ -134,10 +103,8 @@ void MainWindow::createActions() saveAsAct->setStatusTip(tr("Save the document under a new name")); connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs); -//! [20] exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); -//! [20] exitAct->setStatusTip(tr("Exit the application")); connect(exitAct, &QAction::triggered, this, &MainWindow::close); @@ -165,34 +132,24 @@ void MainWindow::createActions() aboutAct->setStatusTip(tr("Show the application's About box")); connect(aboutAct, &QAction::triggered, this, &MainWindow::about); -//! [22] aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); -//! [22] -//! [23] cutAct->setEnabled(false); -//! [23] //! [24] copyAct->setEnabled(false); connect(textEdit, &QTextEdit::copyAvailable, cutAct, &QAction::setEnabled); connect(textEdit, &QTextEdit::copyAvailable, copyAct, &QAction::setEnabled); } -//! [24] -//! [25] //! [26] void MainWindow::createMenus() -//! [25] //! [27] { fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAct); -//! [28] fileMenu->addAction(openAct); -//! [28] fileMenu->addAction(saveAct); -//! [26] fileMenu->addAction(saveAsAct); fileMenu->addSeparator(); fileMenu->addAction(exitAct); @@ -208,16 +165,12 @@ void MainWindow::createMenus() helpMenu->addAction(aboutAct); helpMenu->addAction(aboutQtAct); } -//! [27] -//! [29] //! [30] void MainWindow::createToolBars() { fileToolBar = addToolBar(tr("File")); fileToolBar->addAction(newAct); -//! [29] //! [31] fileToolBar->addAction(openAct); -//! [31] fileToolBar->addAction(saveAct); editToolBar = addToolBar(tr("Edit")); @@ -225,19 +178,13 @@ void MainWindow::createToolBars() editToolBar->addAction(copyAct); editToolBar->addAction(pasteAct); } -//! [30] -//! [32] void MainWindow::createStatusBar() -//! [32] //! [33] { statusBar()->showMessage(tr("Ready")); } -//! [33] -//! [34] //! [35] void MainWindow::readSettings() -//! [34] //! [36] { QSettings settings("QtProject", "Application Example"); QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint(); @@ -245,21 +192,15 @@ void MainWindow::readSettings() resize(size); move(pos); } -//! [35] //! [36] -//! [37] //! [38] void MainWindow::writeSettings() -//! [37] //! [39] { QSettings settings("QtProject", "Application Example"); settings.setValue("pos", pos()); settings.setValue("size", size()); } -//! [38] //! [39] -//! [40] bool MainWindow::maybeSave() -//! [40] //! [41] { if (textEdit->document()->isModified()) { QMessageBox::StandardButton ret; @@ -274,11 +215,8 @@ bool MainWindow::maybeSave() } return true; } -//! [41] -//! [42] void MainWindow::loadFile(const QString &fileName) -//! [42] //! [43] { QFile file(fileName); if (!file.open(QFile::ReadOnly | QFile::Text)) { @@ -301,11 +239,8 @@ void MainWindow::loadFile(const QString &fileName) setCurrentFile(fileName); statusBar()->showMessage(tr("File loaded"), 2000); } -//! [43] -//! [44] bool MainWindow::saveFile(const QString &fileName) -//! [44] //! [45] { QFile file(fileName); if (!file.open(QFile::WriteOnly | QFile::Text)) { @@ -329,11 +264,8 @@ bool MainWindow::saveFile(const QString &fileName) statusBar()->showMessage(tr("File saved"), 2000); return true; } -//! [45] -//! [46] void MainWindow::setCurrentFile(const QString &fileName) -//! [46] //! [47] { curFile = fileName; textEdit->document()->setModified(false); @@ -344,12 +276,8 @@ void MainWindow::setCurrentFile(const QString &fileName) shownName = "untitled.txt"; setWindowFilePath(shownName); } -//! [47] -//! [48] QString MainWindow::strippedName(const QString &fullFileName) -//! [48] //! [49] { return QFileInfo(fullFileName).fileName(); } -//! [49] diff --git a/src/corelib/doc/snippets/threads/threads.cpp b/src/corelib/doc/snippets/threads/threads.cpp index 57c68cd358..502bc4bfe0 100644 --- a/src/corelib/doc/snippets/threads/threads.cpp +++ b/src/corelib/doc/snippets/threads/threads.cpp @@ -7,9 +7,7 @@ #define Counter ReentrantCounter -//! [3] class Counter -//! [3] //! [4] { public: Counter() { n = 0; } @@ -21,14 +19,11 @@ public: private: int n; }; -//! [4] #undef Counter #define Counter ThreadSafeCounter -//! [5] class Counter -//! [5] //! [6] { public: Counter() { n = 0; } @@ -41,7 +36,6 @@ private: mutable QMutex mutex; int n; }; -//! [6] typedef int SomeClass; diff --git a/src/corelib/doc/snippets/timers/analogclock.cpp b/src/corelib/doc/snippets/timers/analogclock.cpp index 4052c185c4..0e910f405b 100644 --- a/src/corelib/doc/snippets/timers/analogclock.cpp +++ b/src/corelib/doc/snippets/timers/analogclock.cpp @@ -5,7 +5,7 @@ #include "analogclock.h" -//! [0] //! [1] +//! [0] AnalogClock::AnalogClock(QWidget *parent) //! [0] //! [2] : QWidget(parent) @@ -23,11 +23,9 @@ AnalogClock::AnalogClock(QWidget *parent) resize(200, 200); //! [7] } -//! [1] //! [7] +//! [7] -//! [8] //! [9] void AnalogClock::paintEvent(QPaintEvent *) -//! [8] //! [10] { static const QPoint hourHand[3] = { QPoint(7, 8), @@ -45,64 +43,40 @@ void AnalogClock::paintEvent(QPaintEvent *) int side = qMin(width(), height()); QTime time = QTime::currentTime(); -//! [10] -//! [11] QPainter painter(this); -//! [11] //! [12] painter.setRenderHint(QPainter::Antialiasing); -//! [12] //! [13] painter.translate(width() / 2, height() / 2); -//! [13] //! [14] painter.scale(side / 200.0, side / 200.0); -//! [9] //! [14] -//! [15] painter.setPen(Qt::NoPen); -//! [15] //! [16] painter.setBrush(hourColor); -//! [16] -//! [17] //! [18] painter.save(); -//! [17] //! [19] painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0))); painter.drawConvexPolygon(hourHand, 3); painter.restore(); -//! [18] //! [19] -//! [20] painter.setPen(hourColor); -//! [20] //! [21] for (int i = 0; i < 12; ++i) { painter.drawLine(88, 0, 96, 0); painter.rotate(30.0); } -//! [21] -//! [22] painter.setPen(Qt::NoPen); -//! [22] //! [23] painter.setBrush(minuteColor); -//! [24] painter.save(); painter.rotate(6.0 * (time.minute() + time.second() / 60.0)); painter.drawConvexPolygon(minuteHand, 3); painter.restore(); -//! [23] //! [24] -//! [25] painter.setPen(minuteColor); -//! [25] //! [26] -//! [27] for (int j = 0; j < 60; ++j) { if ((j % 5) != 0) painter.drawLine(92, 0, 96, 0); painter.rotate(6.0); } -//! [27] } -//! [26] |