diff options
Diffstat (limited to 'tests/manual/corelib/tools')
19 files changed, 340 insertions, 6 deletions
diff --git a/tests/manual/corelib/tools/CMakeLists.txt b/tests/manual/corelib/tools/CMakeLists.txt new file mode 100644 index 0000000000..4300db8859 --- /dev/null +++ b/tests/manual/corelib/tools/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +add_subdirectory(customtype) +add_subdirectory(customtypesending) +# Needs conversion from qmake: +# add_subdirectory(qhash) +# add_subdirectory(qlist) +# add_subdirectory(qmap) +# add_subdirectory(qset) +# add_subdirectory(qvarlengtharray) +# add_subdirectory(qvector) diff --git a/tests/manual/corelib/tools/customtype/CMakeLists.txt b/tests/manual/corelib/tools/customtype/CMakeLists.txt new file mode 100644 index 0000000000..4cb1c024b3 --- /dev/null +++ b/tests/manual/corelib/tools/customtype/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +qt_internal_add_manual_test(customtype + GUI + SOURCES + main.cpp + message.cpp message.h + LIBRARIES + Qt6::Core + Qt6::Gui + Qt6::Widgets +) diff --git a/tests/manual/corelib/tools/customtype/customtype.pro b/tests/manual/corelib/tools/customtype/customtype.pro new file mode 100644 index 0000000000..0a5a90f541 --- /dev/null +++ b/tests/manual/corelib/tools/customtype/customtype.pro @@ -0,0 +1,7 @@ +HEADERS = message.h +SOURCES = main.cpp \ + message.cpp +QT += widgets +INCLUDEPATH += . +TARGET = customtype + diff --git a/tests/manual/corelib/tools/customtype/main.cpp b/tests/manual/corelib/tools/customtype/main.cpp new file mode 100644 index 0000000000..2368db6ec0 --- /dev/null +++ b/tests/manual/corelib/tools/customtype/main.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QCoreApplication> +#include <QDebug> +#include <QVariant> +#include "message.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + QStringList headers; + headers << "Subject: Hello World" + << "From: address@example.com"; + QString body = "This is a test.\r\n"; + +//! [printing a custom type] + Message message(body, headers); + qDebug() << "Original:" << message; +//! [printing a custom type] + +//! [storing a custom value] + QVariant stored; + stored.setValue(message); +//! [storing a custom value] + + qDebug() << "Stored:" << stored; + +//! [retrieving a custom value] + Message retrieved = qvariant_cast<Message>(stored); + qDebug() << "Retrieved:" << retrieved; + retrieved = qvariant_cast<Message>(stored); + qDebug() << "Retrieved:" << retrieved; +//! [retrieving a custom value] + + return 0; +} diff --git a/tests/manual/corelib/tools/customtype/message.cpp b/tests/manual/corelib/tools/customtype/message.cpp new file mode 100644 index 0000000000..221480d56f --- /dev/null +++ b/tests/manual/corelib/tools/customtype/message.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "message.h" + +#include <QDebug> + +Message::Message(const QString &body, const QStringList &headers) + : m_body(body), m_headers(headers) +{ +} + +//! [custom type streaming operator] +QDebug operator<<(QDebug dbg, const Message &message) +{ + QDebugStateSaver saver(dbg); + QList<QStringView> pieces = message.body().split(u"\r\n", Qt::SkipEmptyParts); + if (pieces.isEmpty()) + dbg.nospace() << "Message()"; + else if (pieces.size() == 1) + dbg.nospace() << "Message(" << pieces.first() << ")"; + else + dbg.nospace() << "Message(" << pieces.first() << " ...)"; + return dbg; +} +//! [custom type streaming operator] + +//! [getter functions] +QStringView Message::body() const +{ + return m_body; +} + +QStringList Message::headers() const +{ + return m_headers; +} +//! [getter functions] diff --git a/tests/manual/corelib/tools/customtype/message.h b/tests/manual/corelib/tools/customtype/message.h new file mode 100644 index 0000000000..3b91938eb7 --- /dev/null +++ b/tests/manual/corelib/tools/customtype/message.h @@ -0,0 +1,38 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MESSAGE_H +#define MESSAGE_H + +#include <QMetaType> +#include <QStringList> + +//! [custom type definition] +class Message +{ +public: + Message() = default; + ~Message() = default; + Message(const Message &) = default; + Message &operator=(const Message &) = default; + + Message(const QString &body, const QStringList &headers); + + QStringView body() const; + QStringList headers() const; + +private: + QString m_body; + QStringList m_headers; +}; +//! [custom type definition] + +//! [custom type meta-type declaration] +Q_DECLARE_METATYPE(Message); +//! [custom type meta-type declaration] + +//! [custom type streaming operator] +QDebug operator<<(QDebug dbg, const Message &message); +//! [custom type streaming operator] + +#endif diff --git a/tests/manual/corelib/tools/customtypesending/CMakeLists.txt b/tests/manual/corelib/tools/customtypesending/CMakeLists.txt new file mode 100644 index 0000000000..c22d5e23c1 --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +qt_internal_add_manual_test(customtypesending + GUI + SOURCES + main.cpp + message.cpp message.h + window.cpp window.h + LIBRARIES + Qt6::Core + Qt6::Gui + Qt6::Widgets +) diff --git a/tests/manual/corelib/tools/customtypesending/customtypesending.pro b/tests/manual/corelib/tools/customtypesending/customtypesending.pro new file mode 100644 index 0000000000..d316787f76 --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/customtypesending.pro @@ -0,0 +1,9 @@ +HEADERS = message.h \ + window.h +SOURCES = main.cpp \ + message.cpp \ + window.cpp +QT += widgets +INCLUDEPATH += . +TARGET = customtypesending + diff --git a/tests/manual/corelib/tools/customtypesending/main.cpp b/tests/manual/corelib/tools/customtypesending/main.cpp new file mode 100644 index 0000000000..a8f95ffe8e --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/main.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QApplication> +#include "message.h" +#include "window.h" + +//! [main function] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QStringList headers; + headers << "Subject: Hello World" + << "From: address@example.com"; + QString body = "This is a test.\r\n"; + Message message(body, headers); + + Window window1; + window1.setMessage(message); + + Window window2; + QObject::connect(&window1, &Window::messageSent, + &window2, &Window::setMessage); + QObject::connect(&window2, &Window::messageSent, + &window1, &Window::setMessage); + window1.show(); + window2.show(); + return app.exec(); +} +//! [main function] diff --git a/tests/manual/corelib/tools/customtypesending/message.cpp b/tests/manual/corelib/tools/customtypesending/message.cpp new file mode 100644 index 0000000000..a7a8722673 --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/message.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "message.h" + +Message::Message(const QString &body, const QStringList &headers) + : m_body(body), m_headers(headers) +{ +} + +QString Message::body() const +{ + return m_body; +} + +QStringList Message::headers() const +{ + return m_headers; +} diff --git a/tests/manual/corelib/tools/customtypesending/message.h b/tests/manual/corelib/tools/customtypesending/message.h new file mode 100644 index 0000000000..b16c92f177 --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/message.h @@ -0,0 +1,34 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MESSAGE_H +#define MESSAGE_H + +#include <QMetaType> +#include <QStringList> + +//! [custom type definition] +class Message +{ +public: + Message() = default; + ~Message() = default; + Message(const Message &) = default; + Message &operator=(const Message &) = default; + + Message(const QString &body, const QStringList &headers); + + QString body() const; + QStringList headers() const; + +private: + QString m_body; + QStringList m_headers; +}; +//! [custom type definition] + +//! [custom type meta-type declaration] +Q_DECLARE_METATYPE(Message); +//! [custom type meta-type declaration] + +#endif diff --git a/tests/manual/corelib/tools/customtypesending/window.cpp b/tests/manual/corelib/tools/customtypesending/window.cpp new file mode 100644 index 0000000000..fc158f10e6 --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/window.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtWidgets> +#include "window.h" + +//! [Window constructor] +Window::Window(QWidget *parent) + : QWidget(parent), editor(new QTextEdit(this)) +{ + QPushButton *sendButton = new QPushButton(tr("&Send message")); + + connect(sendButton, &QPushButton::clicked, + this, &Window::sendMessage); + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(); + buttonLayout->addWidget(sendButton); + buttonLayout->addStretch(); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(editor); + layout->addLayout(buttonLayout); + + setWindowTitle(tr("Custom Type Sending")); +} +//! [Window constructor] + +//! [sending a message] +void Window::sendMessage() +{ + thisMessage = Message(editor->toPlainText(), thisMessage.headers()); + emit messageSent(thisMessage); +} +//! [sending a message] + +//! [receiving a message] +void Window::setMessage(const Message &message) +{ + thisMessage = message; + editor->setPlainText(thisMessage.body()); +} +//! [receiving a message] diff --git a/tests/manual/corelib/tools/customtypesending/window.h b/tests/manual/corelib/tools/customtypesending/window.h new file mode 100644 index 0000000000..974e7a7629 --- /dev/null +++ b/tests/manual/corelib/tools/customtypesending/window.h @@ -0,0 +1,35 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef WINDOW_H +#define WINDOW_H + +#include <QWidget> +#include "message.h" + +QT_FORWARD_DECLARE_CLASS(QTextEdit) + +//! [Window class definition] +class Window : public QWidget +{ + Q_OBJECT + +public: + Window(QWidget *parent = nullptr); + +signals: + void messageSent(const Message &message); + +public slots: + void setMessage(const Message &message); + +private slots: + void sendMessage(); + +private: + Message thisMessage; + QTextEdit *editor; +}; +//! [Window class definition] + +#endif diff --git a/tests/manual/corelib/tools/qhash/main.cpp b/tests/manual/corelib/tools/qhash/main.cpp index 1ce65dca68..6c9006ace2 100644 --- a/tests/manual/corelib/tools/qhash/main.cpp +++ b/tests/manual/corelib/tools/qhash/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QHash> diff --git a/tests/manual/corelib/tools/qlist/main.cpp b/tests/manual/corelib/tools/qlist/main.cpp index 60a8a5c4af..2f3e8c0c73 100644 --- a/tests/manual/corelib/tools/qlist/main.cpp +++ b/tests/manual/corelib/tools/qlist/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QList> diff --git a/tests/manual/corelib/tools/qmap/main.cpp b/tests/manual/corelib/tools/qmap/main.cpp index a1efdb7d09..b3c163e515 100644 --- a/tests/manual/corelib/tools/qmap/main.cpp +++ b/tests/manual/corelib/tools/qmap/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only //#define Q_NO_DEBUGMAP_PARENT_TEST // Comment in line above to skip the parent test. diff --git a/tests/manual/corelib/tools/qset/main.cpp b/tests/manual/corelib/tools/qset/main.cpp index 114f95641b..6b86d2fb06 100644 --- a/tests/manual/corelib/tools/qset/main.cpp +++ b/tests/manual/corelib/tools/qset/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QSet> diff --git a/tests/manual/corelib/tools/qvarlengtharray/main.cpp b/tests/manual/corelib/tools/qvarlengtharray/main.cpp index fdc0cbe6da..0ad8d75b6c 100644 --- a/tests/manual/corelib/tools/qvarlengtharray/main.cpp +++ b/tests/manual/corelib/tools/qvarlengtharray/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QVarLengthArray> diff --git a/tests/manual/corelib/tools/qvector/main.cpp b/tests/manual/corelib/tools/qvector/main.cpp index 13f6997351..40462f272f 100644 --- a/tests/manual/corelib/tools/qvector/main.cpp +++ b/tests/manual/corelib/tools/qvector/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Thorbjørn Lund Martsum - tmartsum[at]gmail.com -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QVector> |