summaryrefslogtreecommitdiff
path: root/examples/webenginewidgets/recipebrowser/document.cpp
diff options
context:
space:
mode:
authorYigit Akcay <yigit.akcay@qt.io>2023-03-23 16:12:06 +0100
committerYigit Akcay <yigit.akcay@qt.io>2023-04-05 14:19:20 +0200
commitfe9d72d931f40eafca97c1012c03e24561c973ff (patch)
tree08e36634557eadae962bb56b82137294a384879c /examples/webenginewidgets/recipebrowser/document.cpp
parent88ef502099d535823156c31e77251dd2a723ad1c (diff)
downloadqtwebengine-fe9d72d931f40eafca97c1012c03e24561c973ff.tar.gz
Merge recipe browser, stylesheet browser and markdown editor examples
This patch merges the qtwebengine examples recipe browser, stylesheet browser and markdown editor into one single example. Pick-to: 6.5 Task-number: QTBUG-108751 Change-Id: I338707d7d3275b03bf2a2d7b65064ac91e562d7f Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'examples/webenginewidgets/recipebrowser/document.cpp')
-rw-r--r--examples/webenginewidgets/recipebrowser/document.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/webenginewidgets/recipebrowser/document.cpp b/examples/webenginewidgets/recipebrowser/document.cpp
new file mode 100644
index 000000000..c991e14f8
--- /dev/null
+++ b/examples/webenginewidgets/recipebrowser/document.cpp
@@ -0,0 +1,48 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include "document.h"
+
+#include <QSettings>
+
+Document::Document(QObject *parent) : QObject(parent)
+{
+ QSettings settings;
+ settings.beginGroup("textCollection");
+ QStringList pageTexts = settings.allKeys();
+ for (const QString &name : std::as_const(pageTexts)) {
+ QString pageText = settings.value(name).value<QString>();
+ if (!pageText.isEmpty())
+ m_textCollection.insert(name, pageText);
+ }
+ settings.endGroup();
+}
+
+void Document::setTextEdit(QPlainTextEdit *textEdit)
+{
+ m_textEdit = textEdit;
+}
+
+void Document::setCurrentPage(const QString &page)
+{
+ m_currentPage = page;
+}
+
+void Document::setInitialText(const QString &text)
+{
+ m_textEdit->setPlainText(m_textCollection.value(m_currentPage, text));
+}
+
+void Document::setText(const QString &text)
+{
+ if (text == m_currentText)
+ return;
+ m_currentText = text;
+ emit textChanged(m_currentText);
+
+ QSettings settings;
+ settings.beginGroup("textCollection");
+ settings.setValue(m_currentPage, text);
+ m_textCollection.insert(m_currentPage, text);
+ settings.endGroup();
+}