summaryrefslogtreecommitdiffstats
path: root/tests/manual/corelib/tools/customtype/message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/corelib/tools/customtype/message.cpp')
-rw-r--r--tests/manual/corelib/tools/customtype/message.cpp38
1 files changed, 38 insertions, 0 deletions
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]