diff options
Diffstat (limited to 'examples/xml/saxbookmarks')
-rw-r--r-- | examples/xml/saxbookmarks/doc/images/saxbookmarks-example.png | bin | 26219 -> 0 bytes | |||
-rw-r--r-- | examples/xml/saxbookmarks/doc/src/saxbookmarks.qdoc | 41 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/jennifer.xbel | 69 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/main.cpp | 62 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/mainwindow.cpp | 177 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/mainwindow.h | 80 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/saxbookmarks.pro | 15 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/xbelgenerator.cpp | 124 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/xbelgenerator.h | 78 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/xbelhandler.cpp | 160 | ||||
-rw-r--r-- | examples/xml/saxbookmarks/xbelhandler.h | 88 |
11 files changed, 0 insertions, 894 deletions
diff --git a/examples/xml/saxbookmarks/doc/images/saxbookmarks-example.png b/examples/xml/saxbookmarks/doc/images/saxbookmarks-example.png Binary files differdeleted file mode 100644 index 54d793be56..0000000000 --- a/examples/xml/saxbookmarks/doc/images/saxbookmarks-example.png +++ /dev/null diff --git a/examples/xml/saxbookmarks/doc/src/saxbookmarks.qdoc b/examples/xml/saxbookmarks/doc/src/saxbookmarks.qdoc deleted file mode 100644 index 0cd89e641e..0000000000 --- a/examples/xml/saxbookmarks/doc/src/saxbookmarks.qdoc +++ /dev/null @@ -1,41 +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:FDL$ -** 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. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: https://www.gnu.org/licenses/fdl-1.3.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \example saxbookmarks - \title SAX Bookmarks Example - \brief Demonstrates how to read XBEL files. - \ingroup xml-examples - - This example uses Qt's SAX API to read and parse the files. The DOM Bookmarks - example provides an alternative way to read this type of file. - - \image saxbookmarks-example.png - - See the \l{XML Bookmark Exchange Language Resource Page} for more - information about XBEL files. -*/ diff --git a/examples/xml/saxbookmarks/jennifer.xbel b/examples/xml/saxbookmarks/jennifer.xbel deleted file mode 100644 index 2501c118af..0000000000 --- a/examples/xml/saxbookmarks/jennifer.xbel +++ /dev/null @@ -1,69 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE xbel> -<xbel version="1.0"> - <folder folded="no"> - <title>Qt Resources</title> - <bookmark href="http://qt.io/"> - <title>Qt home page</title> - </bookmark> - <bookmark href="https://www.qt.io/partners/"> - <title>Qt Partners</title> - </bookmark> - <bookmark href="https://www.qt.io/qt-training/"> - <title>Training</title> - </bookmark> - <bookmark href="http://doc.qt.io/"> - <title>Qt 5 documentation</title> - </bookmark> - <bookmark href="http://qt-project.org/faq/"> - <title>Frequently Asked Questions</title> - </bookmark> - <folder folded="yes"> - <title>Community Resources</title> - <bookmark href="http://www.qtcentre.org/content/"> - <title>Qt Centre</title> - </bookmark> - <bookmark href="http://www.qtforum.org/"> - <title>QtForum.org</title> - </bookmark> - <bookmark href="http://digitalfanatics.org/projects/qt_tutorial/"> - <title>The Independent Qt Tutorial</title> - </bookmark> - <bookmark href="http://www.qtforum.de/"> - <title>German Qt Forum</title> - </bookmark> - <bookmark href="http://www.korone.net/"> - <title>Korean Qt Community Site</title> - </bookmark> - <bookmark href="http://prog.org.ru/"> - <title>Russian Qt Forum</title> - </bookmark> - </folder> - </folder> - <folder folded="no"> - <title>Online Dictionaries</title> - <bookmark href="http://www.dictionary.com/"> - <title>Dictionary.com</title> - </bookmark> - <bookmark href="http://www.m-w.com/"> - <title>Merriam-Webster Online</title> - </bookmark> - <bookmark href="http://dictionary.cambridge.org/"> - <title>Cambridge Dictionaries Online</title> - </bookmark> - <bookmark href="http://www.onelook.com/"> - <title>OneLook Dictionary Search</title> - </bookmark> - <separator/> - <bookmark href="http://dict.tu-chemnitz.de/"> - <title>TU Chemnitz German-English Dictionary</title> - </bookmark> - <separator/> - <bookmark href="http://atilf.atilf.fr/tlf.htm"> - <title>Trésor de la Langue Française informatisé</title> - </bookmark> - <bookmark href="http://dictionnaires.atilf.fr/dictionnaires/ACADEMIE/"> - <title>Dictionnaire de l'Académie Française</title> - </bookmark> - </folder> -</xbel> diff --git a/examples/xml/saxbookmarks/main.cpp b/examples/xml/saxbookmarks/main.cpp deleted file mode 100644 index 8e577ca700..0000000000 --- a/examples/xml/saxbookmarks/main.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 <QApplication> - -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - MainWindow mainWin; - mainWin.show(); - mainWin.open(); - return app.exec(); -} diff --git a/examples/xml/saxbookmarks/mainwindow.cpp b/examples/xml/saxbookmarks/mainwindow.cpp deleted file mode 100644 index 8b7733081f..0000000000 --- a/examples/xml/saxbookmarks/mainwindow.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 <QtWidgets> - -#include "mainwindow.h" -#include "xbelgenerator.h" -#include "xbelhandler.h" - -MainWindow::MainWindow() -{ - QStringList labels; - labels << tr("Title") << tr("Location"); - - treeWidget = new QTreeWidget; - treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); - treeWidget->setHeaderLabels(labels); -#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD) - treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(treeWidget, &QWidget::customContextMenuRequested, - this, &MainWindow::onCustomContextMenuRequested); -#endif - setCentralWidget(treeWidget); - - createMenus(); - - statusBar()->showMessage(tr("Ready")); - - setWindowTitle(tr("SAX Bookmarks")); - const QSize availableSize = screen()->availableGeometry().size(); - resize(availableSize.width() / 2, availableSize.height() / 3); -} - -#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD) -void MainWindow::onCustomContextMenuRequested(const QPoint &pos) -{ - const QTreeWidgetItem *item = treeWidget->itemAt(pos); - if (!item) - return; - const QString url = item->text(1); - QMenu contextMenu; - QAction *copyAction = contextMenu.addAction(tr("Copy Link to Clipboard")); - QAction *openAction = contextMenu.addAction(tr("Open")); - QAction *action = contextMenu.exec(treeWidget->viewport()->mapToGlobal(pos)); - if (action == copyAction) - QGuiApplication::clipboard()->setText(url); - else if (action == openAction) - QDesktopServices::openUrl(QUrl(url)); -} -#endif // !QT_NO_CONTEXTMENU && !QT_NO_CLIPBOARD - -void MainWindow::open() -{ - QString fileName = - QFileDialog::getOpenFileName(this, tr("Open Bookmark File"), - QDir::currentPath(), - tr("XBEL Files (*.xbel *.xml)")); - if (fileName.isEmpty()) - return; - - treeWidget->clear(); - - XbelHandler handler(treeWidget); - QXmlSimpleReader reader; - reader.setContentHandler(&handler); - reader.setErrorHandler(&handler); - - QFile file(fileName); - if (!file.open(QFile::ReadOnly | QFile::Text)) { - QMessageBox::warning(this, tr("SAX Bookmarks"), - tr("Cannot read file %1:\n%2.") - .arg(QDir::toNativeSeparators(fileName), - file.errorString())); - return; - } - - QXmlInputSource xmlInputSource(&file); - if (reader.parse(xmlInputSource)) - statusBar()->showMessage(tr("File loaded"), 2000); -} - -void MainWindow::saveAs() -{ - QString fileName = - QFileDialog::getSaveFileName(this, tr("Save Bookmark File"), - QDir::currentPath(), - tr("XBEL Files (*.xbel *.xml)")); - if (fileName.isEmpty()) - return; - - QFile file(fileName); - if (!file.open(QFile::WriteOnly | QFile::Text)) { - QMessageBox::warning(this, tr("SAX Bookmarks"), - tr("Cannot write file %1:\n%2.") - .arg(QDir::toNativeSeparators(fileName), - file.errorString())); - return; - } - - XbelGenerator generator(treeWidget); - if (generator.write(&file)) - statusBar()->showMessage(tr("File saved"), 2000); -} - -void MainWindow::about() -{ - QMessageBox::about(this, tr("About SAX Bookmarks"), - tr("The <b>SAX Bookmarks</b> example demonstrates how to use Qt's " - "SAX classes to read XML documents and how to generate XML by " - "hand.")); -} - -void MainWindow::createMenus() -{ - QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - QAction *openAct = fileMenu->addAction(tr("&Open..."), this, &MainWindow::open); - openAct->setShortcuts(QKeySequence::Open); - - QAction *saveAsAct = fileMenu->addAction(tr("&Save As..."), this, &MainWindow::saveAs); - saveAsAct->setShortcuts(QKeySequence::SaveAs); - - QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close); - exitAct->setShortcuts(QKeySequence::Quit); - - menuBar()->addSeparator(); - - QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(tr("&About"), this, &MainWindow::about); - helpMenu->addAction(tr("About &Qt"), qApp, &QCoreApplication::quit); -} diff --git a/examples/xml/saxbookmarks/mainwindow.h b/examples/xml/saxbookmarks/mainwindow.h deleted file mode 100644 index 20a11bb202..0000000000 --- a/examples/xml/saxbookmarks/mainwindow.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 MAINWINDOW_H -#define MAINWINDOW_H - -#include <QMainWindow> - -QT_BEGIN_NAMESPACE -class QTreeWidget; -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(); - -public slots: - void open(); - void saveAs(); - void about(); -#if !defined(QT_NO_CONTEXTMENU) && !defined(QT_NO_CLIPBOARD) - void onCustomContextMenuRequested(const QPoint &pos); -#endif -private: - void createMenus(); - - QTreeWidget *treeWidget; -}; - -#endif diff --git a/examples/xml/saxbookmarks/saxbookmarks.pro b/examples/xml/saxbookmarks/saxbookmarks.pro deleted file mode 100644 index af2a124a13..0000000000 --- a/examples/xml/saxbookmarks/saxbookmarks.pro +++ /dev/null @@ -1,15 +0,0 @@ -HEADERS = mainwindow.h \ - xbelgenerator.h \ - xbelhandler.h -SOURCES = main.cpp \ - mainwindow.cpp \ - xbelgenerator.cpp \ - xbelhandler.cpp -QT += xml widgets -requires(qtConfig(filedialog)) - -EXAMPLE_FILES = frank.xbel jennifer.xbel - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/xml/saxbookmarks -INSTALLS += target diff --git a/examples/xml/saxbookmarks/xbelgenerator.cpp b/examples/xml/saxbookmarks/xbelgenerator.cpp deleted file mode 100644 index 77cb6748fe..0000000000 --- a/examples/xml/saxbookmarks/xbelgenerator.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 <QtWidgets> - -#include "xbelgenerator.h" - -XbelGenerator::XbelGenerator(const QTreeWidget *treeWidget) - : treeWidget(treeWidget) -{ -} - -bool XbelGenerator::write(QIODevice *device) -{ - out.setDevice(device); - out.setCodec("UTF-8"); - out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - << "<!DOCTYPE xbel>\n" - << "<xbel version=\"1.0\">\n"; - - for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) - generateItem(treeWidget->topLevelItem(i), 1); - - out << "</xbel>\n"; - return true; -} - -QString XbelGenerator::indent(int depth) -{ - const int IndentSize = 4; - return QString(IndentSize * depth, ' '); -} - -QString XbelGenerator::escapedText(const QString &str) -{ - QString result = str; - result.replace('&', "&"); - result.replace('<', "<"); - result.replace('>', ">"); - return result; -} - -QString XbelGenerator::escapedAttribute(const QString &str) -{ - QString result = escapedText(str); - result.replace(QLatin1Char('"'), """); - result.prepend(QLatin1Char('"')); - result.append(QLatin1Char('"')); - return result; -} - -void XbelGenerator::generateItem(const QTreeWidgetItem *item, int depth) -{ - QString tagName = item->data(0, Qt::UserRole).toString(); - if (tagName == QLatin1String("folder")) { - bool folded = !item->isExpanded(); - out << indent(depth) << "<folder folded=\"" << (folded ? "yes" : "no") - << "\">\n" - << indent(depth + 1) << "<title>" << escapedText(item->text(0)) - << "</title>\n"; - - for (int i = 0; i < item->childCount(); ++i) - generateItem(item->child(i), depth + 1); - - out << indent(depth) << "</folder>\n"; - } else if (tagName == QLatin1String("bookmark")) { - out << indent(depth) << "<bookmark"; - if (!item->text(1).isEmpty()) - out << " href=" << escapedAttribute(item->text(1)); - out << ">\n" - << indent(depth + 1) << "<title>" << escapedText(item->text(0)) - << "</title>\n" - << indent(depth) << "</bookmark>\n"; - } else if (tagName == QLatin1String("separator")) { - out << indent(depth) << "<separator/>\n"; - } -} diff --git a/examples/xml/saxbookmarks/xbelgenerator.h b/examples/xml/saxbookmarks/xbelgenerator.h deleted file mode 100644 index abfabfd75c..0000000000 --- a/examples/xml/saxbookmarks/xbelgenerator.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 XBELGENERATOR_H -#define XBELGENERATOR_H - -#include <QTextStream> - -QT_BEGIN_NAMESPACE -class QTreeWidget; -class QTreeWidgetItem; -QT_END_NAMESPACE - -class XbelGenerator -{ -public: - explicit XbelGenerator(const QTreeWidget *treeWidget); - - bool write(QIODevice *device); - -private: - static QString indent(int indentLevel); - static QString escapedText(const QString &str); - static QString escapedAttribute(const QString &str); - void generateItem(const QTreeWidgetItem *item, int depth); - - const QTreeWidget *treeWidget; - QTextStream out; -}; - -#endif diff --git a/examples/xml/saxbookmarks/xbelhandler.cpp b/examples/xml/saxbookmarks/xbelhandler.cpp deleted file mode 100644 index 62dfbf9482..0000000000 --- a/examples/xml/saxbookmarks/xbelhandler.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 <QtWidgets> - -#include "xbelhandler.h" - -static inline QString versionAttribute() { return QStringLiteral("version"); } -static inline QString hrefAttribute() { return QStringLiteral("href"); } -static inline QString foldedAttribute() { return QStringLiteral("folded"); } - -XbelHandler::XbelHandler(QTreeWidget *treeWidget) - : treeWidget(treeWidget) -{ - item = 0; - metXbelTag = false; - - QStyle *style = treeWidget->style(); - - folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirClosedIcon), - QIcon::Normal, QIcon::Off); - folderIcon.addPixmap(style->standardPixmap(QStyle::SP_DirOpenIcon), - QIcon::Normal, QIcon::On); - bookmarkIcon.addPixmap(style->standardPixmap(QStyle::SP_FileIcon)); -} - -bool XbelHandler::startElement(const QString & /* namespaceURI */, - const QString & /* localName */, - const QString &qName, - const QXmlAttributes &attributes) -{ - if (!metXbelTag && qName != QLatin1String("xbel")) { - errorStr = QObject::tr("The file is not an XBEL file."); - return false; - } - - if (qName == QLatin1String("xbel")) { - QString version = attributes.value(versionAttribute()); - if (!version.isEmpty() && version != QLatin1String("1.0")) { - errorStr = QObject::tr("The file is not an XBEL version 1.0 file."); - return false; - } - metXbelTag = true; - } else if (qName == QLatin1String("folder")) { - item = createChildItem(qName); - item->setFlags(item->flags() | Qt::ItemIsEditable); - item->setIcon(0, folderIcon); - item->setText(0, QObject::tr("Folder")); - bool folded = (attributes.value(foldedAttribute()) != QLatin1String("no")); - item->setExpanded(!folded); - } else if (qName == QLatin1String("bookmark")) { - item = createChildItem(qName); - item->setFlags(item->flags() | Qt::ItemIsEditable); - item->setIcon(0, bookmarkIcon); - item->setText(0, QObject::tr("Unknown title")); - item->setText(1, attributes.value(hrefAttribute())); - } else if (qName == QLatin1String("separator")) { - item = createChildItem(qName); - item->setFlags(item->flags() & ~Qt::ItemIsSelectable); - item->setText(0, QString(30, 0xB7)); - } - - currentText.clear(); - return true; -} - -bool XbelHandler::endElement(const QString & /* namespaceURI */, - const QString & /* localName */, - const QString &qName) -{ - if (qName == QLatin1String("title")) { - if (item) - item->setText(0, currentText); - } else if (qName == QLatin1String("folder") || qName == QLatin1String("bookmark") - || qName == QLatin1String("separator")) { - item = item->parent(); - } - return true; -} - -bool XbelHandler::characters(const QString &str) -{ - currentText += str; - return true; -} - -bool XbelHandler::fatalError(const QXmlParseException &exception) -{ - QMessageBox::information(treeWidget->window(), QObject::tr("SAX Bookmarks"), - QObject::tr("Parse error at line %1, column %2:\n" - "%3") - .arg(exception.lineNumber()) - .arg(exception.columnNumber()) - .arg(exception.message())); - return false; -} - -QString XbelHandler::errorString() const -{ - return errorStr; -} - -QTreeWidgetItem *XbelHandler::createChildItem(const QString &tagName) -{ - QTreeWidgetItem *childItem; - if (item) { - childItem = new QTreeWidgetItem(item); - } else { - childItem = new QTreeWidgetItem(treeWidget); - } - childItem->setData(0, Qt::UserRole, tagName); - return childItem; -} diff --git a/examples/xml/saxbookmarks/xbelhandler.h b/examples/xml/saxbookmarks/xbelhandler.h deleted file mode 100644 index 3f4cb109e9..0000000000 --- a/examples/xml/saxbookmarks/xbelhandler.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples 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 XBELHANDLER_H -#define XBELHANDLER_H - -#include <QIcon> -#include <QXmlDefaultHandler> - -QT_BEGIN_NAMESPACE -class QTreeWidget; -class QTreeWidgetItem; -QT_END_NAMESPACE - -class XbelHandler : public QXmlDefaultHandler -{ -public: - XbelHandler(QTreeWidget *treeWidget); - - bool startElement(const QString &namespaceURI, const QString &localName, - const QString &qName, const QXmlAttributes &attributes) override; - bool endElement(const QString &namespaceURI, const QString &localName, - const QString &qName) override; - bool characters(const QString &str) override; - bool fatalError(const QXmlParseException &exception) override; - QString errorString() const override; - -private: - QTreeWidgetItem *createChildItem(const QString &tagName); - - QTreeWidget *treeWidget; - QTreeWidgetItem *item; - QString currentText; - QString errorStr; - bool metXbelTag; - - QIcon folderIcon; - QIcon bookmarkIcon; -}; - -#endif |