summaryrefslogtreecommitdiffstats
path: root/src/gui/doc/snippets/textdocument-tables
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/doc/snippets/textdocument-tables')
-rw-r--r--src/gui/doc/snippets/textdocument-tables/main.cpp56
-rw-r--r--src/gui/doc/snippets/textdocument-tables/mainwindow.cpp95
-rw-r--r--src/gui/doc/snippets/textdocument-tables/mainwindow.h60
-rw-r--r--src/gui/doc/snippets/textdocument-tables/textdocument-tables.pro6
-rw-r--r--src/gui/doc/snippets/textdocument-tables/xmlwriter.cpp165
-rw-r--r--src/gui/doc/snippets/textdocument-tables/xmlwriter.h74
6 files changed, 45 insertions, 411 deletions
diff --git a/src/gui/doc/snippets/textdocument-tables/main.cpp b/src/gui/doc/snippets/textdocument-tables/main.cpp
index f37ea92dc4..87ce7e46da 100644
--- a/src/gui/doc/snippets/textdocument-tables/main.cpp
+++ b/src/gui/doc/snippets/textdocument-tables/main.cpp
@@ -1,57 +1,9 @@
-/****************************************************************************
-**
-** 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: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$
-**
-****************************************************************************/
-
-#include <QtGui>
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mainwindow.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
diff --git a/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp b/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp
index df9bd337f6..02f31f8807 100644
--- a/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp
+++ b/src/gui/doc/snippets/textdocument-tables/mainwindow.cpp
@@ -1,57 +1,9 @@
-/****************************************************************************
-**
-** 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: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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtWidgets>
#include "mainwindow.h"
-#include "xmlwriter.h"
MainWindow::MainWindow()
{
@@ -132,9 +84,9 @@ MainWindow::MainWindow()
}
//! [8]
- connect(saveAction, &QAction:triggered, this, &MainWindow::saveFile);
- connect(quitAction, &QAction:triggered, this, &MainWindow::close);
- connect(showTableAction, &QAction:triggered, this, &MainWindow::showTable);
+ connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile);
+ connect(quitAction, &QAction::triggered, this, &MainWindow::close);
+ connect(showTableAction, &QAction::triggered, this, &MainWindow::showTable);
setCentralWidget(editor);
setWindowTitle(tr("Text Document Tables"));
@@ -194,18 +146,35 @@ void MainWindow::showTable()
tableWidget->show();
}
-bool MainWindow::writeXml(const QString &fileName)
+void MainWindow::processFrame(QTextFrame *)
{
- XmlWriter documentWriter(editor->document());
+}
- QDomDocument *domDocument = documentWriter.toXml();
- QFile file(fileName);
+void MainWindow::processBlock(QTextBlock)
+{
+}
+
+void MainWindow::processTable(QTextTable *table)
+{
+ QTextFrame *frame = qobject_cast<QTextFrame *>(table);
+//! [13]
+ QTextFrame::iterator it;
+ for (it = frame->begin(); !(it.atEnd()); ++it) {
- if (file.open(QFile::WriteOnly)) {
- file.write(domDocument->toString(1).toUtf8());
- file.close();
- return true;
+ QTextFrame *childFrame = it.currentFrame();
+ QTextBlock childBlock = it.currentBlock();
+
+ if (childFrame) {
+ QTextTable *childTable = qobject_cast<QTextTable*>(childFrame);
+
+ if (childTable)
+ processTable(childTable);
+ else
+ processFrame(childFrame);
+
+ } else if (childBlock.isValid()) {
+ processBlock(childBlock);
+ }
}
- else
- return false;
+//! [13]
}
diff --git a/src/gui/doc/snippets/textdocument-tables/mainwindow.h b/src/gui/doc/snippets/textdocument-tables/mainwindow.h
index dc26cf3650..3885478e6c 100644
--- a/src/gui/doc/snippets/textdocument-tables/mainwindow.h
+++ b/src/gui/doc/snippets/textdocument-tables/mainwindow.h
@@ -1,59 +1,14 @@
-/****************************************************************************
-**
-** 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: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) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef WINDOW_H
#define WINDOW_H
#include <QMainWindow>
class QTextEdit;
+class QTextFrame;
+class QTextBlock;
+class QTextTable;
class MainWindow : public QMainWindow
{
@@ -68,8 +23,11 @@ public slots:
private:
bool writeXml(const QString &fileName);
+ void processFrame(QTextFrame *);
+ void processBlock(QTextBlock);
+ void processTable(QTextTable *table);
- QTextEdit *editor;
+ QTextEdit *editor = nullptr;
};
#endif
diff --git a/src/gui/doc/snippets/textdocument-tables/textdocument-tables.pro b/src/gui/doc/snippets/textdocument-tables/textdocument-tables.pro
deleted file mode 100644
index 91ae50f491..0000000000
--- a/src/gui/doc/snippets/textdocument-tables/textdocument-tables.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-SOURCES = main.cpp \
- mainwindow.cpp \
- xmlwriter.cpp
-HEADERS = mainwindow.h \
- xmlwriter.h
-QT += xml
diff --git a/src/gui/doc/snippets/textdocument-tables/xmlwriter.cpp b/src/gui/doc/snippets/textdocument-tables/xmlwriter.cpp
deleted file mode 100644
index e082fc8c7f..0000000000
--- a/src/gui/doc/snippets/textdocument-tables/xmlwriter.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/****************************************************************************
-**
-** 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: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$
-**
-****************************************************************************/
-
-#include <QtGui>
-
-#include "xmlwriter.h"
-
-QDomDocument *XmlWriter::toXml()
-{
- QDomImplementation implementation;
- QDomDocumentType docType = implementation.createDocumentType(
- "scribe-document", "scribe", "qt.nokia.com/scribe");
-
- document = new QDomDocument(docType);
-
- // ### This processing instruction is required to ensure that any kind
- // of encoding is given when the document is written.
- QDomProcessingInstruction process = document->createProcessingInstruction(
- "xml", "version=\"1.0\" encoding=\"utf-8\"");
- document->appendChild(process);
-
- QDomElement documentElement = document->createElement("document");
- document->appendChild(documentElement);
-
- QTextFrame *root = textDocument->rootFrame();
-
- if (root)
- processFrame(documentElement, root);
-
- return document;
-}
-
-void XmlWriter::processBlock(QDomElement &parent, const QTextBlock &block)
-{
- QDomElement blockElement = document->createElement("block");
- blockElement.setAttribute("position", block.position());
- blockElement.setAttribute("length", block.length());
- parent.appendChild(blockElement);
-
- QTextBlock::iterator it;
- for (it = block.begin(); !(it.atEnd()); ++it) {
- QTextFragment fragment = it.fragment();
-
- if (fragment.isValid()) {
- QDomElement fragmentElement = document->createElement("fragment");
- blockElement.appendChild(fragmentElement);
-
- fragmentElement.setAttribute("length", fragment.length());
- QDomText fragmentText = document->createTextNode(fragment.text());
-
- fragmentElement.appendChild(fragmentText);
- }
- }
-}
-
-void XmlWriter::processFrame(QDomElement &parent, QTextFrame *frame)
-{
- QDomElement frameElement = document->createElement("frame");
- frameElement.setAttribute("begin", frame->firstPosition());
- frameElement.setAttribute("end", frame->lastPosition());
- parent.appendChild(frameElement);
-
-//! [0]
- QDomElement frameElement = ...
-
- QTextFrame::iterator it;
- for (it = frame->begin(); !(it.atEnd()); ++it) {
-
- QTextFrame *childFrame = it.currentFrame();
- QTextBlock childBlock = it.currentBlock();
-
- if (childFrame) {
- QTextTable *childTable = qobject_cast<QTextTable*>(childFrame);
-
- if (childTable)
- processTable(frameElement, childTable);
- else
- processFrame(frameElement, childFrame);
-
- } else if (childBlock.isValid())
-//! [0] //! [1]
- processBlock(frameElement, childBlock);
- }
-//! [1]
-}
-
-void XmlWriter::processTable(QDomElement &parent, QTextTable *table)
-{
- QDomElement element = document->createElement("table");
-
- for (int row = 0; row < table->rows(); ++row) {
- for (int column = 0; column < table->columns(); ++column) {
- QTextTableCell cell = table->cellAt(row, column);
- processTableCell(element, cell);
- }
- }
- parent.appendChild(element);
-}
-
-void XmlWriter::processTableCell(QDomElement &parent, const QTextTableCell &cell)
-{
- QDomElement element = document->createElement("cell");
- element.setAttribute("row", cell.row());
- element.setAttribute("column", cell.column());
-
- QTextFrame::iterator it;
- for (it = cell.begin(); !(it.atEnd()); ++it) {
-
- QTextFrame *childFrame = it.currentFrame();
- QTextBlock childBlock = it.currentBlock();
-
- if (childFrame)
- processFrame(element, childFrame);
- else if (childBlock.isValid())
- processBlock(element, childBlock);
- }
- parent.appendChild(element);
-}
diff --git a/src/gui/doc/snippets/textdocument-tables/xmlwriter.h b/src/gui/doc/snippets/textdocument-tables/xmlwriter.h
deleted file mode 100644
index 049e55df20..0000000000
--- a/src/gui/doc/snippets/textdocument-tables/xmlwriter.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/****************************************************************************
-**
-** 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: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$
-**
-****************************************************************************/
-
-#ifndef XMLWRITER_H
-#define XMLWRITER_H
-
-#include <QDomDocument>
-
-class QTextDocument;
-
-class XmlWriter
-{
-public:
- XmlWriter(QTextDocument *document) : textDocument(document) {}
- QDomDocument *toXml();
-
-private:
- void processBlock(QDomElement &parent, const QTextBlock &block);
- void processFrame(QDomElement &parent, QTextFrame *frame);
- void processTable(QDomElement &parent, QTextTable *table);
- void processTableCell(QDomElement &parent, const QTextTableCell &cell);
-
- QDomDocument *document;
- QTextDocument *textDocument;
-};
-
-#endif