From 67ad0519fd165acee4a4d2a94fa502e9e4847bd0 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 23 Mar 2009 10:34:13 +0100 Subject: Long live Qt! --- examples/xml/README | 40 ++++ examples/xml/dombookmarks/dombookmarks.pro | 18 ++ examples/xml/dombookmarks/frank.xbel | 230 ++++++++++++++++++++++ examples/xml/dombookmarks/jennifer.xbel | 93 +++++++++ examples/xml/dombookmarks/main.cpp | 53 +++++ examples/xml/dombookmarks/mainwindow.cpp | 146 ++++++++++++++ examples/xml/dombookmarks/mainwindow.h | 76 +++++++ examples/xml/dombookmarks/xbeltree.cpp | 187 ++++++++++++++++++ examples/xml/dombookmarks/xbeltree.h | 75 +++++++ examples/xml/rsslisting/main.cpp | 64 ++++++ examples/xml/rsslisting/rsslisting.cpp | 239 +++++++++++++++++++++++ examples/xml/rsslisting/rsslisting.h | 87 +++++++++ examples/xml/rsslisting/rsslisting.pro | 10 + examples/xml/saxbookmarks/frank.xbel | 230 ++++++++++++++++++++++ examples/xml/saxbookmarks/jennifer.xbel | 93 +++++++++ examples/xml/saxbookmarks/main.cpp | 53 +++++ examples/xml/saxbookmarks/mainwindow.cpp | 161 +++++++++++++++ examples/xml/saxbookmarks/mainwindow.h | 78 ++++++++ examples/xml/saxbookmarks/saxbookmarks.pro | 20 ++ examples/xml/saxbookmarks/xbelgenerator.cpp | 115 +++++++++++ examples/xml/saxbookmarks/xbelgenerator.h | 69 +++++++ examples/xml/saxbookmarks/xbelhandler.cpp | 147 ++++++++++++++ examples/xml/saxbookmarks/xbelhandler.h | 79 ++++++++ examples/xml/streambookmarks/frank.xbel | 230 ++++++++++++++++++++++ examples/xml/streambookmarks/jennifer.xbel | 93 +++++++++ examples/xml/streambookmarks/main.cpp | 55 ++++++ examples/xml/streambookmarks/mainwindow.cpp | 177 +++++++++++++++++ examples/xml/streambookmarks/mainwindow.h | 80 ++++++++ examples/xml/streambookmarks/streambookmarks.pro | 14 ++ examples/xml/streambookmarks/xbelreader.cpp | 205 +++++++++++++++++++ examples/xml/streambookmarks/xbelreader.h | 82 ++++++++ examples/xml/streambookmarks/xbelwriter.cpp | 93 +++++++++ examples/xml/streambookmarks/xbelwriter.h | 65 ++++++ examples/xml/xml.pro | 12 ++ examples/xml/xmlstreamlint/main.cpp | 128 ++++++++++++ examples/xml/xmlstreamlint/xmlstreamlint.pro | 10 + 36 files changed, 3607 insertions(+) create mode 100644 examples/xml/README create mode 100644 examples/xml/dombookmarks/dombookmarks.pro create mode 100644 examples/xml/dombookmarks/frank.xbel create mode 100644 examples/xml/dombookmarks/jennifer.xbel create mode 100644 examples/xml/dombookmarks/main.cpp create mode 100644 examples/xml/dombookmarks/mainwindow.cpp create mode 100644 examples/xml/dombookmarks/mainwindow.h create mode 100644 examples/xml/dombookmarks/xbeltree.cpp create mode 100644 examples/xml/dombookmarks/xbeltree.h create mode 100644 examples/xml/rsslisting/main.cpp create mode 100644 examples/xml/rsslisting/rsslisting.cpp create mode 100644 examples/xml/rsslisting/rsslisting.h create mode 100644 examples/xml/rsslisting/rsslisting.pro create mode 100644 examples/xml/saxbookmarks/frank.xbel create mode 100644 examples/xml/saxbookmarks/jennifer.xbel create mode 100644 examples/xml/saxbookmarks/main.cpp create mode 100644 examples/xml/saxbookmarks/mainwindow.cpp create mode 100644 examples/xml/saxbookmarks/mainwindow.h create mode 100644 examples/xml/saxbookmarks/saxbookmarks.pro create mode 100644 examples/xml/saxbookmarks/xbelgenerator.cpp create mode 100644 examples/xml/saxbookmarks/xbelgenerator.h create mode 100644 examples/xml/saxbookmarks/xbelhandler.cpp create mode 100644 examples/xml/saxbookmarks/xbelhandler.h create mode 100644 examples/xml/streambookmarks/frank.xbel create mode 100644 examples/xml/streambookmarks/jennifer.xbel create mode 100644 examples/xml/streambookmarks/main.cpp create mode 100644 examples/xml/streambookmarks/mainwindow.cpp create mode 100644 examples/xml/streambookmarks/mainwindow.h create mode 100644 examples/xml/streambookmarks/streambookmarks.pro create mode 100644 examples/xml/streambookmarks/xbelreader.cpp create mode 100644 examples/xml/streambookmarks/xbelreader.h create mode 100644 examples/xml/streambookmarks/xbelwriter.cpp create mode 100644 examples/xml/streambookmarks/xbelwriter.h create mode 100644 examples/xml/xml.pro create mode 100644 examples/xml/xmlstreamlint/main.cpp create mode 100644 examples/xml/xmlstreamlint/xmlstreamlint.pro (limited to 'examples/xml') diff --git a/examples/xml/README b/examples/xml/README new file mode 100644 index 0000000000..a6d81bb58a --- /dev/null +++ b/examples/xml/README @@ -0,0 +1,40 @@ +XML parsing and handling is supported through SAX and DOM compliant APIs. + +Qt's SAX compliant classes allow you to parse XML incrementally; the DOM +classes enable more complex document-level operations to be performed on +XML files. + + +The example launcher provided with Qt can be used to explore each of the +examples in this directory. + +Documentation for these examples can be found via the Tutorial and Examples +link in the main Qt documentation. + + +Finding the Qt Examples and Demos launcher +========================================== + +On Windows: + +The launcher can be accessed via the Windows Start menu. Select the menu +entry entitled "Qt Examples and Demos" entry in the submenu containing +the Qt tools. + +On Mac OS X: + +For the binary distribution, the qtdemo executable is installed in the +/Developer/Applications/Qt directory. For the source distribution, it is +installed alongside the other Qt tools on the path specified when Qt is +configured. + +On Unix/Linux: + +The qtdemo executable is installed alongside the other Qt tools on the path +specified when Qt is configured. + +On all platforms: + +The source code for the launcher can be found in the demos/qtdemo directory +in the Qt package. This example is built at the same time as the Qt libraries, +tools, examples, and demonstrations. diff --git a/examples/xml/dombookmarks/dombookmarks.pro b/examples/xml/dombookmarks/dombookmarks.pro new file mode 100644 index 0000000000..e55754fd5b --- /dev/null +++ b/examples/xml/dombookmarks/dombookmarks.pro @@ -0,0 +1,18 @@ +HEADERS = mainwindow.h \ + xbeltree.h +SOURCES = main.cpp \ + mainwindow.cpp \ + xbeltree.cpp +QT += xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/xml/dombookmarks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS dombookmarks.pro *.xbel +sources.path = $$[QT_INSTALL_EXAMPLES]/xml/dombookmarks +INSTALLS += target sources + +wince*: { + addFiles.sources = frank.xbel jennifer.xbel + addFiles.path = \My Documents + DEPLOYMENT += addFiles +} diff --git a/examples/xml/dombookmarks/frank.xbel b/examples/xml/dombookmarks/frank.xbel new file mode 100644 index 0000000000..d6a12c68e9 --- /dev/null +++ b/examples/xml/dombookmarks/frank.xbel @@ -0,0 +1,230 @@ + + + + + Literate Programming + + Synopsis of Literate Programming + + + Literate Programming: Propaganda and Tools + + + Literate Programming by Henrik Turbell + + + Literate Programming Library + + + Literate Programming Basics + + + Literate Programming Overview + + + POD is not Literate Programming + + + Computers That We Can Count On + + + Literate Programming - Issues and Problems + + + Literate Programming - Wiki Pages + + + What is well-commented code? + + + Bibliography on literate programming - A searchable bibliography + + + Program comprehension and code reading bibliography + + + Elucidative Programming + + + AVL Trees (TexiWeb) + + + Literate Programming on Wikiverse + + + Physically Based Rendering: From Theory to Implementation + + + + Useful C++ Links + + STL + + STL Reference Documentation + + + STL Tutorial + + + STL Reference + + + + Qt + + Qt 2.3 Reference + + + Qt 3.3 Reference + + + Qt 4.0 Reference + + + Trolltech Home Page + + + + IOStreams + + IO Stream Library + + + Binary I/O + + + I/O Stream FAQ + + + + gdb + + GDB Tutorial + + + Debugging with GDB + + + GDB Quick Reference Page (PDF) (Handy) + + + + Classes and Constructors + + Constructor FAQ + + + Organizing Classes + + + + + Software Documentation or System Documentation + + The Almighty Thud + + + Microsoft Coding Techniques and Programming Practices + + + Software and Documentation + + + The Source Code is the Design + + + What is Software Design? + + + How To Write Unmaintainable Code + + + Self Documenting Program Code Remains a Distant Goal + + + Place Tab A in Slot B + + + UML Reference Card + + + + TeX Resources + + The TeX User's Group + + + MikTeX website + + + MetaPost website + + + HEVEA is a quite complete and fast LATEX to HTML translator + + + + Portable Document Format (PDF) + + Adobe - The postscript and PDF standards + + + Reference Manual Portable Document Format + + + Adobe Acrobat Software Development Kit + + + + Literature Sites + + Guide to Special Collections (Columbia University) + + + Literary Criticism on the Web from the Internet Public Library + + + Victorian Web. + + + Voice of the Shuttle. + + + Modernist Journals Project + + + Museum of American Poetics + + + Modern American Poetry + + + FindArticles.com + + + Literary History + + + Literary Encyclopedia + + + + The University of California Press + + + Wright American Fiction, 1851-1875 + + + Documenting the American South: Beginnings to 1920 + + + Electronic Text Center at the University of Virginia + + + The Schomburg Center for Research in Black Culture + + + Alex Catalogue of Electronic Texts. + + + diff --git a/examples/xml/dombookmarks/jennifer.xbel b/examples/xml/dombookmarks/jennifer.xbel new file mode 100644 index 0000000000..597880affc --- /dev/null +++ b/examples/xml/dombookmarks/jennifer.xbel @@ -0,0 +1,93 @@ + + + + + Qt Resources + + Trolltech Partners + + Training Partners + + + Consultants and System Integrators + + + Technology Partners + + + Value Added Resellers (VARs) + + + + Community Resources + + QtForum.org + + + The Independent Qt Tutorial + + + French PROG.Qt + + + German Qt Forum + + + Korean Qt Community Site + + + Russian Qt Forum + + + Digitalfanatics: The QT 4 Resource Center + + + QtQuestions + + + + Qt Quarterly + + + Trolltech's home page + + + Qt 4.0 documentation + + + Frequently Asked Questions + + + + Online Dictionaries + + Dictionary.com + + + Merriam-Webster Online + + + Cambridge Dictionaries Online + + + OneLook Dictionary Search + + + + The New English-German Dictionary + + + TU Chemnitz German-English Dictionary + + + + Trésor de la Langue Française informatisé + + + Dictionnaire de l'Académie Française + + + Dictionnaire des synonymes + + + diff --git a/examples/xml/dombookmarks/main.cpp b/examples/xml/dombookmarks/main.cpp new file mode 100644 index 0000000000..3f0a207265 --- /dev/null +++ b/examples/xml/dombookmarks/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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/dombookmarks/mainwindow.cpp b/examples/xml/dombookmarks/mainwindow.cpp new file mode 100644 index 0000000000..6b0c1010da --- /dev/null +++ b/examples/xml/dombookmarks/mainwindow.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "xbeltree.h" + +MainWindow::MainWindow() +{ + xbelTree = new XbelTree; + setCentralWidget(xbelTree); + + createActions(); + createMenus(); + + statusBar()->showMessage(tr("Ready")); + + setWindowTitle(tr("DOM Bookmarks")); + resize(480, 320); +} + +void MainWindow::open() +{ + QString fileName = + QFileDialog::getOpenFileName(this, tr("Open Bookmark File"), + QDir::currentPath(), + tr("XBEL Files (*.xbel *.xml)")); + if (fileName.isEmpty()) + return; + + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("SAX Bookmarks"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + if (xbelTree->read(&file)) + 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(fileName) + .arg(file.errorString())); + return; + } + + if (xbelTree->write(&file)) + statusBar()->showMessage(tr("File saved"), 2000); +} + +void MainWindow::about() +{ + QMessageBox::about(this, tr("About DOM Bookmarks"), + tr("The DOM Bookmarks example demonstrates how to " + "use Qt's DOM classes to read and write XML " + "documents.")); +} + +void MainWindow::createActions() +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcut(tr("Ctrl+O")); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAsAct = new QAction(tr("&Save As..."), this); + saveAsAct->setShortcut(tr("Ctrl+S")); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAct); + fileMenu->addAction(saveAsAct); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} diff --git a/examples/xml/dombookmarks/mainwindow.h b/examples/xml/dombookmarks/mainwindow.h new file mode 100644 index 0000000000..cf30a3ec76 --- /dev/null +++ b/examples/xml/dombookmarks/mainwindow.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class XbelTree; + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void open(); + void saveAs(); + void about(); + +private: + void createActions(); + void createMenus(); + + XbelTree *xbelTree; + + QMenu *fileMenu; + QMenu *helpMenu; + QAction *openAct; + QAction *saveAsAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; + +#endif diff --git a/examples/xml/dombookmarks/xbeltree.cpp b/examples/xml/dombookmarks/xbeltree.cpp new file mode 100644 index 0000000000..37e8bb2983 --- /dev/null +++ b/examples/xml/dombookmarks/xbeltree.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xbeltree.h" + +XbelTree::XbelTree(QWidget *parent) + : QTreeWidget(parent) +{ + QStringList labels; + labels << tr("Title") << tr("Location"); + + header()->setResizeMode(QHeaderView::Stretch); + setHeaderLabels(labels); + + 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 XbelTree::read(QIODevice *device) +{ + QString errorStr; + int errorLine; + int errorColumn; + + if (!domDocument.setContent(device, true, &errorStr, &errorLine, + &errorColumn)) { + QMessageBox::information(window(), tr("DOM Bookmarks"), + tr("Parse error at line %1, column %2:\n%3") + .arg(errorLine) + .arg(errorColumn) + .arg(errorStr)); + return false; + } + + QDomElement root = domDocument.documentElement(); + if (root.tagName() != "xbel") { + QMessageBox::information(window(), tr("DOM Bookmarks"), + tr("The file is not an XBEL file.")); + return false; + } else if (root.hasAttribute("version") + && root.attribute("version") != "1.0") { + QMessageBox::information(window(), tr("DOM Bookmarks"), + tr("The file is not an XBEL version 1.0 " + "file.")); + return false; + } + + clear(); + + disconnect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)), + this, SLOT(updateDomElement(QTreeWidgetItem *, int))); + + QDomElement child = root.firstChildElement("folder"); + while (!child.isNull()) { + parseFolderElement(child); + child = child.nextSiblingElement("folder"); + } + + connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)), + this, SLOT(updateDomElement(QTreeWidgetItem *, int))); + + return true; +} + +bool XbelTree::write(QIODevice *device) +{ + const int IndentSize = 4; + + QTextStream out(device); + domDocument.save(out, IndentSize); + return true; +} + +void XbelTree::updateDomElement(QTreeWidgetItem *item, int column) +{ + QDomElement element = domElementForItem.value(item); + if (!element.isNull()) { + if (column == 0) { + QDomElement oldTitleElement = element.firstChildElement("title"); + QDomElement newTitleElement = domDocument.createElement("title"); + + QDomText newTitleText = domDocument.createTextNode(item->text(0)); + newTitleElement.appendChild(newTitleText); + + element.replaceChild(newTitleElement, oldTitleElement); + } else { + if (element.tagName() == "bookmark") + element.setAttribute("href", item->text(1)); + } + } +} + +void XbelTree::parseFolderElement(const QDomElement &element, + QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *item = createItem(element, parentItem); + + QString title = element.firstChildElement("title").text(); + if (title.isEmpty()) + title = QObject::tr("Folder"); + + item->setFlags(item->flags() | Qt::ItemIsEditable); + item->setIcon(0, folderIcon); + item->setText(0, title); + + bool folded = (element.attribute("folded") != "no"); + setItemExpanded(item, !folded); + + QDomElement child = element.firstChildElement(); + while (!child.isNull()) { + if (child.tagName() == "folder") { + parseFolderElement(child, item); + } else if (child.tagName() == "bookmark") { + QTreeWidgetItem *childItem = createItem(child, item); + + QString title = child.firstChildElement("title").text(); + if (title.isEmpty()) + title = QObject::tr("Folder"); + + childItem->setFlags(item->flags() | Qt::ItemIsEditable); + childItem->setIcon(0, bookmarkIcon); + childItem->setText(0, title); + childItem->setText(1, child.attribute("href")); + } else if (child.tagName() == "separator") { + QTreeWidgetItem *childItem = createItem(child, item); + childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable)); + childItem->setText(0, QString(30, 0xB7)); + } + child = child.nextSiblingElement(); + } +} + +QTreeWidgetItem *XbelTree::createItem(const QDomElement &element, + QTreeWidgetItem *parentItem) +{ + QTreeWidgetItem *item; + if (parentItem) { + item = new QTreeWidgetItem(parentItem); + } else { + item = new QTreeWidgetItem(this); + } + domElementForItem.insert(item, element); + return item; +} diff --git a/examples/xml/dombookmarks/xbeltree.h b/examples/xml/dombookmarks/xbeltree.h new file mode 100644 index 0000000000..4f2d304f64 --- /dev/null +++ b/examples/xml/dombookmarks/xbeltree.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XBELTREE_H +#define XBELTREE_H + +#include +#include +#include +#include + +class XbelTree : public QTreeWidget +{ + Q_OBJECT + +public: + XbelTree(QWidget *parent = 0); + + bool read(QIODevice *device); + bool write(QIODevice *device); + +private slots: + void updateDomElement(QTreeWidgetItem *item, int column); + +private: + void parseFolderElement(const QDomElement &element, + QTreeWidgetItem *parentItem = 0); + QTreeWidgetItem *createItem(const QDomElement &element, + QTreeWidgetItem *parentItem = 0); + + QDomDocument domDocument; + QHash domElementForItem; + QIcon folderIcon; + QIcon bookmarkIcon; +}; + +#endif diff --git a/examples/xml/rsslisting/main.cpp b/examples/xml/rsslisting/main.cpp new file mode 100644 index 0000000000..0c9b275815 --- /dev/null +++ b/examples/xml/rsslisting/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +main.cpp + +Provides the main function for the RSS news reader example. +*/ + +#include + +#include "rsslisting.h" + +/*! + Create an application and a main widget. Open the main widget for + user input, and exit with an appropriate return value when it is + closed. +*/ + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + RSSListing *rsslisting = new RSSListing; + rsslisting->show(); + return app.exec(); +} diff --git a/examples/xml/rsslisting/rsslisting.cpp b/examples/xml/rsslisting/rsslisting.cpp new file mode 100644 index 0000000000..9212c110ae --- /dev/null +++ b/examples/xml/rsslisting/rsslisting.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* +rsslisting.cpp + +Provides a widget for displaying news items from RDF news sources. +RDF is an XML-based format for storing items of information (see +http://www.w3.org/RDF/ for details). + +The widget itself provides a simple user interface for specifying +the URL of a news source, and controlling the downloading of news. + +The widget downloads and parses the XML asynchronously, feeding the +data to an XML reader in pieces. This allows the user to interrupt +its operation, and also allows very large data sources to be read. +*/ + + +#include +#include +#include + +#include "rsslisting.h" + + +/* + Constructs an RSSListing widget with a simple user interface, and sets + up the XML reader to use a custom handler class. + + The user interface consists of a line edit, two push buttons, and a + list view widget. The line edit is used for entering the URLs of news + sources; the push buttons start and abort the process of reading the + news. +*/ + +RSSListing::RSSListing(QWidget *parent) + : QWidget(parent) +{ + lineEdit = new QLineEdit(this); + lineEdit->setText("http://labs.trolltech.com/blogs/feed"); + + fetchButton = new QPushButton(tr("Fetch"), this); + abortButton = new QPushButton(tr("Abort"), this); + abortButton->setEnabled(false); + + treeWidget = new QTreeWidget(this); + connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*, int)), + this, SLOT(itemActivated(QTreeWidgetItem*))); + QStringList headerLabels; + headerLabels << tr("Title") << tr("Link"); + treeWidget->setHeaderLabels(headerLabels); + treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); + + connect(&http, SIGNAL(readyRead(const QHttpResponseHeader &)), + this, SLOT(readData(const QHttpResponseHeader &))); + + connect(&http, SIGNAL(requestFinished(int, bool)), + this, SLOT(finished(int, bool))); + + connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(fetch())); + connect(fetchButton, SIGNAL(clicked()), this, SLOT(fetch())); + connect(abortButton, SIGNAL(clicked()), &http, SLOT(abort())); + + QVBoxLayout *layout = new QVBoxLayout(this); + + QHBoxLayout *hboxLayout = new QHBoxLayout; + + hboxLayout->addWidget(lineEdit); + hboxLayout->addWidget(fetchButton); + hboxLayout->addWidget(abortButton); + + layout->addLayout(hboxLayout); + layout->addWidget(treeWidget); + + setWindowTitle(tr("RSS listing example")); + resize(640,480); +} + +/* + Starts fetching data from a news source specified in the line + edit widget. + + The line edit is made read only to prevent the user from modifying its + contents during the fetch; this is only for cosmetic purposes. + The fetch button is disabled, and the abort button is enabled to allow + the user to interrupt processing. The list view is cleared, and we + define the last list view item to be 0, meaning that there are no + existing items in the list. + + The HTTP handler is supplied with the raw contents of the line edit and + a fetch is initiated. We keep the ID value returned by the HTTP handler + for future reference. +*/ + +void RSSListing::fetch() +{ + lineEdit->setReadOnly(true); + fetchButton->setEnabled(false); + abortButton->setEnabled(true); + treeWidget->clear(); + + xml.clear(); + + QUrl url(lineEdit->text()); + + http.setHost(url.host()); + connectionId = http.get(url.path()); +} + +/* + Reads data received from the RDF source. + + We read all the available data, and pass it to the XML + stream reader. Then we call the XML parsing function. + + If parsing fails for any reason, we abort the fetch. +*/ + +void RSSListing::readData(const QHttpResponseHeader &resp) +{ + if (resp.statusCode() != 200) + http.abort(); + else { + xml.addData(http.readAll()); + parseXml(); + } +} + +/* + Finishes processing an HTTP request. + + The default behavior is to keep the text edit read only. + + If an error has occurred, the user interface is made available + to the user for further input, allowing a new fetch to be + started. + + If the HTTP get request has finished, we make the + user interface available to the user for further input. +*/ + +void RSSListing::finished(int id, bool error) +{ + if (error) { + qWarning("Received error during HTTP fetch."); + lineEdit->setReadOnly(false); + abortButton->setEnabled(false); + fetchButton->setEnabled(true); + } + else if (id == connectionId) { + lineEdit->setReadOnly(false); + abortButton->setEnabled(false); + fetchButton->setEnabled(true); + } +} + + +/* + Parses the XML data and creates treeWidget items accordingly. +*/ +void RSSListing::parseXml() +{ + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement()) { + if (xml.name() == "item") + linkString = xml.attributes().value("rss:about").toString(); + currentTag = xml.name().toString(); + } else if (xml.isEndElement()) { + if (xml.name() == "item") { + + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(0, titleString); + item->setText(1, linkString); + treeWidget->addTopLevelItem(item); + + titleString.clear(); + linkString.clear(); + } + + } else if (xml.isCharacters() && !xml.isWhitespace()) { + if (currentTag == "title") + titleString += xml.text().toString(); + else if (currentTag == "link") + linkString += xml.text().toString(); + } + } + if (xml.error() && xml.error() != QXmlStreamReader::PrematureEndOfDocumentError) { + qWarning() << "XML ERROR:" << xml.lineNumber() << ": " << xml.errorString(); + http.abort(); + } +} + +/* + Open the link in the browser +*/ +void RSSListing::itemActivated(QTreeWidgetItem * item) +{ + QDesktopServices::openUrl(QUrl(item->text(1))); +} diff --git a/examples/xml/rsslisting/rsslisting.h b/examples/xml/rsslisting/rsslisting.h new file mode 100644 index 0000000000..f0007deaeb --- /dev/null +++ b/examples/xml/rsslisting/rsslisting.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RSSLISTING_H +#define RSSLISTING_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QLineEdit; +class QTreeWidget; +class QTreeWidgetItem; +class QPushButton; +QT_END_NAMESPACE + +class RSSListing : public QWidget +{ + Q_OBJECT +public: + RSSListing(QWidget *widget = 0); + +public slots: + void fetch(); + void finished(int id, bool error); + void readData(const QHttpResponseHeader &); + void itemActivated(QTreeWidgetItem * item); + +private: + void parseXml(); + + QXmlStreamReader xml; + QString currentTag; + QString linkString; + QString titleString; + + QHttp http; + int connectionId; + + QLineEdit *lineEdit; + QTreeWidget *treeWidget; + QPushButton *abortButton; + QPushButton *fetchButton; +}; + +#endif + diff --git a/examples/xml/rsslisting/rsslisting.pro b/examples/xml/rsslisting/rsslisting.pro new file mode 100644 index 0000000000..95a23e9ff2 --- /dev/null +++ b/examples/xml/rsslisting/rsslisting.pro @@ -0,0 +1,10 @@ +HEADERS += rsslisting.h +SOURCES += main.cpp rsslisting.cpp +QT += network xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/xml/rsslisting +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS rsslisting.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/xml/rsslisting +INSTALLS += target sources + diff --git a/examples/xml/saxbookmarks/frank.xbel b/examples/xml/saxbookmarks/frank.xbel new file mode 100644 index 0000000000..d6a12c68e9 --- /dev/null +++ b/examples/xml/saxbookmarks/frank.xbel @@ -0,0 +1,230 @@ + + + + + Literate Programming + + Synopsis of Literate Programming + + + Literate Programming: Propaganda and Tools + + + Literate Programming by Henrik Turbell + + + Literate Programming Library + + + Literate Programming Basics + + + Literate Programming Overview + + + POD is not Literate Programming + + + Computers That We Can Count On + + + Literate Programming - Issues and Problems + + + Literate Programming - Wiki Pages + + + What is well-commented code? + + + Bibliography on literate programming - A searchable bibliography + + + Program comprehension and code reading bibliography + + + Elucidative Programming + + + AVL Trees (TexiWeb) + + + Literate Programming on Wikiverse + + + Physically Based Rendering: From Theory to Implementation + + + + Useful C++ Links + + STL + + STL Reference Documentation + + + STL Tutorial + + + STL Reference + + + + Qt + + Qt 2.3 Reference + + + Qt 3.3 Reference + + + Qt 4.0 Reference + + + Trolltech Home Page + + + + IOStreams + + IO Stream Library + + + Binary I/O + + + I/O Stream FAQ + + + + gdb + + GDB Tutorial + + + Debugging with GDB + + + GDB Quick Reference Page (PDF) (Handy) + + + + Classes and Constructors + + Constructor FAQ + + + Organizing Classes + + + + + Software Documentation or System Documentation + + The Almighty Thud + + + Microsoft Coding Techniques and Programming Practices + + + Software and Documentation + + + The Source Code is the Design + + + What is Software Design? + + + How To Write Unmaintainable Code + + + Self Documenting Program Code Remains a Distant Goal + + + Place Tab A in Slot B + + + UML Reference Card + + + + TeX Resources + + The TeX User's Group + + + MikTeX website + + + MetaPost website + + + HEVEA is a quite complete and fast LATEX to HTML translator + + + + Portable Document Format (PDF) + + Adobe - The postscript and PDF standards + + + Reference Manual Portable Document Format + + + Adobe Acrobat Software Development Kit + + + + Literature Sites + + Guide to Special Collections (Columbia University) + + + Literary Criticism on the Web from the Internet Public Library + + + Victorian Web. + + + Voice of the Shuttle. + + + Modernist Journals Project + + + Museum of American Poetics + + + Modern American Poetry + + + FindArticles.com + + + Literary History + + + Literary Encyclopedia + + + + The University of California Press + + + Wright American Fiction, 1851-1875 + + + Documenting the American South: Beginnings to 1920 + + + Electronic Text Center at the University of Virginia + + + The Schomburg Center for Research in Black Culture + + + Alex Catalogue of Electronic Texts. + + + diff --git a/examples/xml/saxbookmarks/jennifer.xbel b/examples/xml/saxbookmarks/jennifer.xbel new file mode 100644 index 0000000000..597880affc --- /dev/null +++ b/examples/xml/saxbookmarks/jennifer.xbel @@ -0,0 +1,93 @@ + + + + + Qt Resources + + Trolltech Partners + + Training Partners + + + Consultants and System Integrators + + + Technology Partners + + + Value Added Resellers (VARs) + + + + Community Resources + + QtForum.org + + + The Independent Qt Tutorial + + + French PROG.Qt + + + German Qt Forum + + + Korean Qt Community Site + + + Russian Qt Forum + + + Digitalfanatics: The QT 4 Resource Center + + + QtQuestions + + + + Qt Quarterly + + + Trolltech's home page + + + Qt 4.0 documentation + + + Frequently Asked Questions + + + + Online Dictionaries + + Dictionary.com + + + Merriam-Webster Online + + + Cambridge Dictionaries Online + + + OneLook Dictionary Search + + + + The New English-German Dictionary + + + TU Chemnitz German-English Dictionary + + + + Trésor de la Langue Française informatisé + + + Dictionnaire de l'Académie Française + + + Dictionnaire des synonymes + + + diff --git a/examples/xml/saxbookmarks/main.cpp b/examples/xml/saxbookmarks/main.cpp new file mode 100644 index 0000000000..3f0a207265 --- /dev/null +++ b/examples/xml/saxbookmarks/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#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 new file mode 100644 index 0000000000..2cba5590ea --- /dev/null +++ b/examples/xml/saxbookmarks/mainwindow.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "xbelgenerator.h" +#include "xbelhandler.h" + +MainWindow::MainWindow() +{ + QStringList labels; + labels << tr("Title") << tr("Location"); + + treeWidget = new QTreeWidget; + treeWidget->header()->setResizeMode(QHeaderView::Stretch); + treeWidget->setHeaderLabels(labels); + setCentralWidget(treeWidget); + + createActions(); + createMenus(); + + statusBar()->showMessage(tr("Ready")); + + setWindowTitle(tr("SAX Bookmarks")); + resize(480, 320); +} + +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(fileName) + .arg(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(fileName) + .arg(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 SAX Bookmarks example demonstrates how to use Qt's " + "SAX classes to read XML documents and how to generate XML by " + "hand.")); +} + +void MainWindow::createActions() +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcut(tr("Ctrl+O")); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAsAct = new QAction(tr("&Save As..."), this); + saveAsAct->setShortcut(tr("Ctrl+S")); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAct); + fileMenu->addAction(saveAsAct); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} diff --git a/examples/xml/saxbookmarks/mainwindow.h b/examples/xml/saxbookmarks/mainwindow.h new file mode 100644 index 0000000000..2c70d4ae4a --- /dev/null +++ b/examples/xml/saxbookmarks/mainwindow.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void open(); + void saveAs(); + void about(); + +private: + void createActions(); + void createMenus(); + + QTreeWidget *treeWidget; + + QMenu *fileMenu; + QMenu *helpMenu; + QAction *openAct; + QAction *saveAsAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; + +#endif diff --git a/examples/xml/saxbookmarks/saxbookmarks.pro b/examples/xml/saxbookmarks/saxbookmarks.pro new file mode 100644 index 0000000000..d0eec444b2 --- /dev/null +++ b/examples/xml/saxbookmarks/saxbookmarks.pro @@ -0,0 +1,20 @@ +HEADERS = mainwindow.h \ + xbelgenerator.h \ + xbelhandler.h +SOURCES = main.cpp \ + mainwindow.cpp \ + xbelgenerator.cpp \ + xbelhandler.cpp +QT += xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/xml/saxbookmarks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS saxbookmarks.pro *.xbel +sources.path = $$[QT_INSTALL_EXAMPLES]/xml/saxbookmarks +INSTALLS += target sources + +wince*: { + addFiles.sources = frank.xbel jennifer.xbel + addFiles.path = \My Documents + DEPLOYMENT += addFiles +} diff --git a/examples/xml/saxbookmarks/xbelgenerator.cpp b/examples/xml/saxbookmarks/xbelgenerator.cpp new file mode 100644 index 0000000000..cafaf51286 --- /dev/null +++ b/examples/xml/saxbookmarks/xbelgenerator.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xbelgenerator.h" + +XbelGenerator::XbelGenerator(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ +} + +bool XbelGenerator::write(QIODevice *device) +{ + out.setDevice(device); + out.setCodec("UTF-8"); + out << "\n" + << "\n" + << "\n"; + + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) + generateItem(treeWidget->topLevelItem(i), 1); + + out << "\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("\"", """); + result.prepend("\""); + result.append("\""); + return result; +} + +void XbelGenerator::generateItem(QTreeWidgetItem *item, int depth) +{ + QString tagName = item->data(0, Qt::UserRole).toString(); + if (tagName == "folder") { + bool folded = !treeWidget->isItemExpanded(item); + out << indent(depth) << "\n" + << indent(depth + 1) << "" << escapedText(item->text(0)) + << "\n"; + + for (int i = 0; i < item->childCount(); ++i) + generateItem(item->child(i), depth + 1); + + out << indent(depth) << "\n"; + } else if (tagName == "bookmark") { + out << indent(depth) << "text(1).isEmpty()) + out << " href=" << escapedAttribute(item->text(1)); + out << ">\n" + << indent(depth + 1) << "" << escapedText(item->text(0)) + << "\n" + << indent(depth) << "\n"; + } else if (tagName == "separator") { + out << indent(depth) << "\n"; + } +} diff --git a/examples/xml/saxbookmarks/xbelgenerator.h b/examples/xml/saxbookmarks/xbelgenerator.h new file mode 100644 index 0000000000..023d626e15 --- /dev/null +++ b/examples/xml/saxbookmarks/xbelgenerator.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XBELGENERATOR_H +#define XBELGENERATOR_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +class XbelGenerator +{ +public: + XbelGenerator(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(QTreeWidgetItem *item, int depth); + + QTreeWidget *treeWidget; + QTextStream out; +}; + +#endif diff --git a/examples/xml/saxbookmarks/xbelhandler.cpp b/examples/xml/saxbookmarks/xbelhandler.cpp new file mode 100644 index 0000000000..2fdb1fab09 --- /dev/null +++ b/examples/xml/saxbookmarks/xbelhandler.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xbelhandler.h" + +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 != "xbel") { + errorStr = QObject::tr("The file is not an XBEL file."); + return false; + } + + if (qName == "xbel") { + QString version = attributes.value("version"); + if (!version.isEmpty() && version != "1.0") { + errorStr = QObject::tr("The file is not an XBEL version 1.0 file."); + return false; + } + metXbelTag = true; + } else if (qName == "folder") { + item = createChildItem(qName); + item->setFlags(item->flags() | Qt::ItemIsEditable); + item->setIcon(0, folderIcon); + item->setText(0, QObject::tr("Folder")); + bool folded = (attributes.value("folded") != "no"); + treeWidget->setItemExpanded(item, !folded); + } else if (qName == "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("href")); + } else if (qName == "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 == "title") { + if (item) + item->setText(0, currentText); + } else if (qName == "folder" || qName == "bookmark" + || qName == "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 new file mode 100644 index 0000000000..5b6c0c03c0 --- /dev/null +++ b/examples/xml/saxbookmarks/xbelhandler.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XBELHANDLER_H +#define XBELHANDLER_H + +#include +#include + +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); + bool endElement(const QString &namespaceURI, const QString &localName, + const QString &qName); + bool characters(const QString &str); + bool fatalError(const QXmlParseException &exception); + QString errorString() const; + +private: + QTreeWidgetItem *createChildItem(const QString &tagName); + + QTreeWidget *treeWidget; + QTreeWidgetItem *item; + QString currentText; + QString errorStr; + bool metXbelTag; + + QIcon folderIcon; + QIcon bookmarkIcon; +}; + +#endif diff --git a/examples/xml/streambookmarks/frank.xbel b/examples/xml/streambookmarks/frank.xbel new file mode 100644 index 0000000000..d6a12c68e9 --- /dev/null +++ b/examples/xml/streambookmarks/frank.xbel @@ -0,0 +1,230 @@ + + + + + Literate Programming + + Synopsis of Literate Programming + + + Literate Programming: Propaganda and Tools + + + Literate Programming by Henrik Turbell + + + Literate Programming Library + + + Literate Programming Basics + + + Literate Programming Overview + + + POD is not Literate Programming + + + Computers That We Can Count On + + + Literate Programming - Issues and Problems + + + Literate Programming - Wiki Pages + + + What is well-commented code? + + + Bibliography on literate programming - A searchable bibliography + + + Program comprehension and code reading bibliography + + + Elucidative Programming + + + AVL Trees (TexiWeb) + + + Literate Programming on Wikiverse + + + Physically Based Rendering: From Theory to Implementation + + + + Useful C++ Links + + STL + + STL Reference Documentation + + + STL Tutorial + + + STL Reference + + + + Qt + + Qt 2.3 Reference + + + Qt 3.3 Reference + + + Qt 4.0 Reference + + + Trolltech Home Page + + + + IOStreams + + IO Stream Library + + + Binary I/O + + + I/O Stream FAQ + + + + gdb + + GDB Tutorial + + + Debugging with GDB + + + GDB Quick Reference Page (PDF) (Handy) + + + + Classes and Constructors + + Constructor FAQ + + + Organizing Classes + + + + + Software Documentation or System Documentation + + The Almighty Thud + + + Microsoft Coding Techniques and Programming Practices + + + Software and Documentation + + + The Source Code is the Design + + + What is Software Design? + + + How To Write Unmaintainable Code + + + Self Documenting Program Code Remains a Distant Goal + + + Place Tab A in Slot B + + + UML Reference Card + + + + TeX Resources + + The TeX User's Group + + + MikTeX website + + + MetaPost website + + + HEVEA is a quite complete and fast LATEX to HTML translator + + + + Portable Document Format (PDF) + + Adobe - The postscript and PDF standards + + + Reference Manual Portable Document Format + + + Adobe Acrobat Software Development Kit + + + + Literature Sites + + Guide to Special Collections (Columbia University) + + + Literary Criticism on the Web from the Internet Public Library + + + Victorian Web. + + + Voice of the Shuttle. + + + Modernist Journals Project + + + Museum of American Poetics + + + Modern American Poetry + + + FindArticles.com + + + Literary History + + + Literary Encyclopedia + + + + The University of California Press + + + Wright American Fiction, 1851-1875 + + + Documenting the American South: Beginnings to 1920 + + + Electronic Text Center at the University of Virginia + + + The Schomburg Center for Research in Black Culture + + + Alex Catalogue of Electronic Texts. + + + diff --git a/examples/xml/streambookmarks/jennifer.xbel b/examples/xml/streambookmarks/jennifer.xbel new file mode 100644 index 0000000000..597880affc --- /dev/null +++ b/examples/xml/streambookmarks/jennifer.xbel @@ -0,0 +1,93 @@ + + + + + Qt Resources + + Trolltech Partners + + Training Partners + + + Consultants and System Integrators + + + Technology Partners + + + Value Added Resellers (VARs) + + + + Community Resources + + QtForum.org + + + The Independent Qt Tutorial + + + French PROG.Qt + + + German Qt Forum + + + Korean Qt Community Site + + + Russian Qt Forum + + + Digitalfanatics: The QT 4 Resource Center + + + QtQuestions + + + + Qt Quarterly + + + Trolltech's home page + + + Qt 4.0 documentation + + + Frequently Asked Questions + + + + Online Dictionaries + + Dictionary.com + + + Merriam-Webster Online + + + Cambridge Dictionaries Online + + + OneLook Dictionary Search + + + + The New English-German Dictionary + + + TU Chemnitz German-English Dictionary + + + + Trésor de la Langue Française informatisé + + + Dictionnaire de l'Académie Française + + + Dictionnaire des synonymes + + + diff --git a/examples/xml/streambookmarks/main.cpp b/examples/xml/streambookmarks/main.cpp new file mode 100644 index 0000000000..58b5c5e1f5 --- /dev/null +++ b/examples/xml/streambookmarks/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" + +//! [0] +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + MainWindow mainWin; + mainWin.show(); + mainWin.open(); + return app.exec(); +} +//! [0] diff --git a/examples/xml/streambookmarks/mainwindow.cpp b/examples/xml/streambookmarks/mainwindow.cpp new file mode 100644 index 0000000000..2136b4bc9c --- /dev/null +++ b/examples/xml/streambookmarks/mainwindow.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "mainwindow.h" +#include "xbelreader.h" +#include "xbelwriter.h" + +//! [0] +MainWindow::MainWindow() +{ + QStringList labels; + labels << tr("Title") << tr("Location"); + + treeWidget = new QTreeWidget; + treeWidget->header()->setResizeMode(QHeaderView::Stretch); + treeWidget->setHeaderLabels(labels); + setCentralWidget(treeWidget); + + createActions(); + createMenus(); + + statusBar()->showMessage(tr("Ready")); + + setWindowTitle(tr("QXmlStream Bookmarks")); + resize(480, 320); +} +//! [0] + +//! [1] +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(); + + + QFile file(fileName); + if (!file.open(QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning(this, tr("QXmlStream Bookmarks"), + tr("Cannot read file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + XbelReader reader(treeWidget); + if (!reader.read(&file)) { + QMessageBox::warning(this, tr("QXmlStream Bookmarks"), + tr("Parse error in file %1 at line %2, column %3:\n%4") + .arg(fileName) + .arg(reader.lineNumber()) + .arg(reader.columnNumber()) + .arg(reader.errorString())); + } else { + statusBar()->showMessage(tr("File loaded"), 2000); + } + +} +//! [1] + +//! [2] +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("QXmlStream Bookmarks"), + tr("Cannot write file %1:\n%2.") + .arg(fileName) + .arg(file.errorString())); + return; + } + + XbelWriter writer(treeWidget); + if (writer.writeFile(&file)) + statusBar()->showMessage(tr("File saved"), 2000); +} +//! [2] + +//! [3] +void MainWindow::about() +{ + QMessageBox::about(this, tr("About QXmlStream Bookmarks"), + tr("The QXmlStream Bookmarks example demonstrates how to use Qt's " + "QXmlStream classes to read and write XML documents.")); +} +//! [3] + +//! [4] +void MainWindow::createActions() +{ + openAct = new QAction(tr("&Open..."), this); + openAct->setShortcut(tr("Ctrl+O")); + connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + + saveAsAct = new QAction(tr("&Save As..."), this); + saveAsAct->setShortcut(tr("Ctrl+S")); + connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + + exitAct = new QAction(tr("E&xit"), this); + exitAct->setShortcut(tr("Ctrl+Q")); + connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} +//! [4] + +//! [5] +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(openAct); + fileMenu->addAction(saveAsAct); + fileMenu->addAction(exitAct); + + menuBar()->addSeparator(); + + helpMenu = menuBar()->addMenu(tr("&Help")); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); +} +//! [5] diff --git a/examples/xml/streambookmarks/mainwindow.h b/examples/xml/streambookmarks/mainwindow.h new file mode 100644 index 0000000000..8bed33d7ed --- /dev/null +++ b/examples/xml/streambookmarks/mainwindow.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +QT_END_NAMESPACE + +//! [0] +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(); + +public slots: + void open(); + void saveAs(); + void about(); + +private: + void createActions(); + void createMenus(); + + QTreeWidget *treeWidget; + + QMenu *fileMenu; + QMenu *helpMenu; + QAction *openAct; + QAction *saveAsAct; + QAction *exitAct; + QAction *aboutAct; + QAction *aboutQtAct; +}; +//! [0] + +#endif diff --git a/examples/xml/streambookmarks/streambookmarks.pro b/examples/xml/streambookmarks/streambookmarks.pro new file mode 100644 index 0000000000..e66b95aa4d --- /dev/null +++ b/examples/xml/streambookmarks/streambookmarks.pro @@ -0,0 +1,14 @@ +HEADERS = mainwindow.h \ + xbelreader.h \ + xbelwriter.h +SOURCES = main.cpp \ + mainwindow.cpp \ + xbelreader.cpp \ + xbelwriter.cpp +QT += xml + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/xml/streambookmarks +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS streambookmarks.pro *.xbel +sources.path = $$[QT_INSTALL_EXAMPLES]/xml/streambookmarks +INSTALLS += target sources diff --git a/examples/xml/streambookmarks/xbelreader.cpp b/examples/xml/streambookmarks/xbelreader.cpp new file mode 100644 index 0000000000..561997adb7 --- /dev/null +++ b/examples/xml/streambookmarks/xbelreader.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xbelreader.h" + +//! [0] +XbelReader::XbelReader(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ + 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)); +} +//! [0] + +//! [1] +bool XbelReader::read(QIODevice *device) +{ + setDevice(device); + + while (!atEnd()) { + readNext(); + + if (isStartElement()) { + if (name() == "xbel" && attributes().value("version") == "1.0") + readXBEL(); + else + raiseError(QObject::tr("The file is not an XBEL version 1.0 file.")); + } + } + + return !error(); +} +//! [1] + +//! [2] +void XbelReader::readUnknownElement() +{ + Q_ASSERT(isStartElement()); + + while (!atEnd()) { + readNext(); + + if (isEndElement()) + break; + + if (isStartElement()) + readUnknownElement(); + } +} +//! [2] + +//! [3] +void XbelReader::readXBEL() +{ + Q_ASSERT(isStartElement() && name() == "xbel"); + + while (!atEnd()) { + readNext(); + + if (isEndElement()) + break; + + if (isStartElement()) { + if (name() == "folder") + readFolder(0); + else if (name() == "bookmark") + readBookmark(0); + else if (name() == "separator") + readSeparator(0); + else + readUnknownElement(); + } + } +} +//! [3] + +//! [4] +void XbelReader::readTitle(QTreeWidgetItem *item) +{ + Q_ASSERT(isStartElement() && name() == "title"); + + QString title = readElementText(); + item->setText(0, title); +} +//! [4] + +//! [5] +void XbelReader::readSeparator(QTreeWidgetItem *item) +{ + QTreeWidgetItem *separator = createChildItem(item); + separator->setFlags(item->flags() & ~Qt::ItemIsSelectable); + separator->setText(0, QString(30, 0xB7)); + readElementText(); +} +//! [5] + +void XbelReader::readFolder(QTreeWidgetItem *item) +{ + Q_ASSERT(isStartElement() && name() == "folder"); + + QTreeWidgetItem *folder = createChildItem(item); + bool folded = (attributes().value("folded") != "no"); + treeWidget->setItemExpanded(folder, !folded); + + while (!atEnd()) { + readNext(); + + if (isEndElement()) + break; + + if (isStartElement()) { + if (name() == "title") + readTitle(folder); + else if (name() == "folder") + readFolder(folder); + else if (name() == "bookmark") + readBookmark(folder); + else if (name() == "separator") + readSeparator(folder); + else + readUnknownElement(); + } + } +} + +void XbelReader::readBookmark(QTreeWidgetItem *item) +{ + Q_ASSERT(isStartElement() && name() == "bookmark"); + + QTreeWidgetItem *bookmark = createChildItem(item); + bookmark->setFlags(bookmark->flags() | Qt::ItemIsEditable); + bookmark->setIcon(0, bookmarkIcon); + bookmark->setText(0, QObject::tr("Unknown title")); + bookmark->setText(1, attributes().value("href").toString()); + while (!atEnd()) { + readNext(); + + if (isEndElement()) + break; + + if (isStartElement()) { + if (name() == "title") + readTitle(bookmark); + else + readUnknownElement(); + } + } +} + +QTreeWidgetItem *XbelReader::createChildItem(QTreeWidgetItem *item) +{ + QTreeWidgetItem *childItem; + if (item) { + childItem = new QTreeWidgetItem(item); + } else { + childItem = new QTreeWidgetItem(treeWidget); + } + childItem->setData(0, Qt::UserRole, name().toString()); + return childItem; +} diff --git a/examples/xml/streambookmarks/xbelreader.h b/examples/xml/streambookmarks/xbelreader.h new file mode 100644 index 0000000000..dc5eac94be --- /dev/null +++ b/examples/xml/streambookmarks/xbelreader.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XBELREADER_H +#define XBELREADER_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +//! [0] +class XbelReader : public QXmlStreamReader +{ +public: +//! [1] + XbelReader(QTreeWidget *treeWidget); +//! [1] + + bool read(QIODevice *device); + +private: +//! [2] + void readUnknownElement(); + void readXBEL(); + void readTitle(QTreeWidgetItem *item); + void readSeparator(QTreeWidgetItem *item); + void readFolder(QTreeWidgetItem *item); + void readBookmark(QTreeWidgetItem *item); + + QTreeWidgetItem *createChildItem(QTreeWidgetItem *item); + + QTreeWidget *treeWidget; +//! [2] + + QIcon folderIcon; + QIcon bookmarkIcon; +}; +//! [0] + +#endif diff --git a/examples/xml/streambookmarks/xbelwriter.cpp b/examples/xml/streambookmarks/xbelwriter.cpp new file mode 100644 index 0000000000..b3ce288dfb --- /dev/null +++ b/examples/xml/streambookmarks/xbelwriter.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "xbelwriter.h" + +//! [0] +XbelWriter::XbelWriter(QTreeWidget *treeWidget) + : treeWidget(treeWidget) +{ + setAutoFormatting(true); +} +//! [0] + +//! [1] +bool XbelWriter::writeFile(QIODevice *device) +{ + setDevice(device); + + writeStartDocument(); + writeDTD(""); + writeStartElement("xbel"); + writeAttribute("version", "1.0"); + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) + writeItem(treeWidget->topLevelItem(i)); + + writeEndDocument(); + return true; +} +//! [1] + +//! [2] +void XbelWriter::writeItem(QTreeWidgetItem *item) +{ + QString tagName = item->data(0, Qt::UserRole).toString(); + if (tagName == "folder") { + bool folded = !treeWidget->isItemExpanded(item); + writeStartElement(tagName); + writeAttribute("folded", folded ? "yes" : "no"); + writeTextElement("title", item->text(0)); + for (int i = 0; i < item->childCount(); ++i) + writeItem(item->child(i)); + writeEndElement(); + } else if (tagName == "bookmark") { + writeStartElement(tagName); + if (!item->text(1).isEmpty()) + writeAttribute("href", item->text(1)); + writeTextElement("title", item->text(0)); + writeEndElement(); + } else if (tagName == "separator") { + writeEmptyElement(tagName); + } +} +//! [2] diff --git a/examples/xml/streambookmarks/xbelwriter.h b/examples/xml/streambookmarks/xbelwriter.h new file mode 100644 index 0000000000..ec80e054fc --- /dev/null +++ b/examples/xml/streambookmarks/xbelwriter.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XBELWRITER_H +#define XBELWRITER_H + +#include + +QT_BEGIN_NAMESPACE +class QTreeWidget; +class QTreeWidgetItem; +QT_END_NAMESPACE + +//! [0] +class XbelWriter : public QXmlStreamWriter +{ +public: + XbelWriter(QTreeWidget *treeWidget); + bool writeFile(QIODevice *device); + +private: + void writeItem(QTreeWidgetItem *item); + QTreeWidget *treeWidget; +}; +//! [0] + +#endif diff --git a/examples/xml/xml.pro b/examples/xml/xml.pro new file mode 100644 index 0000000000..866b0cc800 --- /dev/null +++ b/examples/xml/xml.pro @@ -0,0 +1,12 @@ +TEMPLATE = subdirs +SUBDIRS = dombookmarks \ + rsslisting \ + saxbookmarks \ + streambookmarks \ + xmlstreamlint + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/xml +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xml.pro README +sources.path = $$[QT_INSTALL_EXAMPLES]/xml +INSTALLS += target sources diff --git a/examples/xml/xmlstreamlint/main.cpp b/examples/xml/xmlstreamlint/main.cpp new file mode 100644 index 0000000000..6063b84433 --- /dev/null +++ b/examples/xml/xmlstreamlint/main.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +/* + This class exists for the sole purpose of creating a translation context. +*/ +class XmlStreamLint +{ +public: + Q_DECLARE_TR_FUNCTIONS(XmlStreamLint) +}; + +int main(int argc, char *argv[]) +{ + enum ExitCode + { + Success, + ParseFailure, + ArgumentError, + WriteError, + FileFailure + }; + + QCoreApplication app(argc, argv); + + QTextStream errorStream(stderr); + + if (argc != 2) + { + errorStream << XmlStreamLint::tr( + "Usage: xmlstreamlint \n"); + return ArgumentError; + } + + QString inputFilePath(QCoreApplication::arguments().at(1)); + QFile inputFile(inputFilePath); + + if (!QFile::exists(inputFilePath)) + { + errorStream << XmlStreamLint::tr( + "File %1 does not exist.\n").arg(inputFilePath); + return FileFailure; + + } else if (!inputFile.open(QIODevice::ReadOnly)) { + errorStream << XmlStreamLint::tr( + "Failed to open file %1.\n").arg(inputFilePath); + return FileFailure; + } + + QFile outputFile; + if (!outputFile.open(stdout, QIODevice::WriteOnly)) + { + errorStream << XmlStreamLint::tr("Failed to open stdout."); + return WriteError; + } + +//! [0] + QXmlStreamReader reader(&inputFile); + QXmlStreamWriter writer(&outputFile); +//! [0] + +//! [1] + while (!reader.atEnd()) + { + reader.readNext(); + + if (reader.error()) + { + errorStream << XmlStreamLint::tr( + "Error: %1 in file %2 at line %3, column %4.\n").arg( + reader.errorString(), inputFilePath, + QString::number(reader.lineNumber()), + QString::number(reader.columnNumber())); + return ParseFailure; +//! [1] + +//! [2] + } else + writer.writeCurrentToken(reader); + } +//! [2] + + return Success; +} diff --git a/examples/xml/xmlstreamlint/xmlstreamlint.pro b/examples/xml/xmlstreamlint/xmlstreamlint.pro new file mode 100644 index 0000000000..7034e7bbbb --- /dev/null +++ b/examples/xml/xmlstreamlint/xmlstreamlint.pro @@ -0,0 +1,10 @@ +CONFIG += console +QT -= gui +QT += xml +SOURCES += main.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/xml/xmlstreamlint +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xmlstreamlint.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/xml/xmlstreamlint +INSTALLS += target sources -- cgit v1.2.3 From aecb4af947acd5e5c4a59641512269348ca97f07 Mon Sep 17 00:00:00 2001 From: Norwegian Rock Cat Date: Tue, 12 May 2009 13:03:20 +0200 Subject: Replace all instances of "Ctrl+Q" with QKeySequence::Quit. We introduce this new enum, we should be using it. --- examples/xml/dombookmarks/mainwindow.cpp | 6 +++--- examples/xml/saxbookmarks/mainwindow.cpp | 6 +++--- examples/xml/streambookmarks/mainwindow.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'examples/xml') diff --git a/examples/xml/dombookmarks/mainwindow.cpp b/examples/xml/dombookmarks/mainwindow.cpp index 6b0c1010da..7efe6fffc5 100644 --- a/examples/xml/dombookmarks/mainwindow.cpp +++ b/examples/xml/dombookmarks/mainwindow.cpp @@ -113,15 +113,15 @@ void MainWindow::about() void MainWindow::createActions() { openAct = new QAction(tr("&Open..."), this); - openAct->setShortcut(tr("Ctrl+O")); + openAct->setShortcuts(QKeySequence::Open); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); saveAsAct = new QAction(tr("&Save As..."), this); - saveAsAct->setShortcut(tr("Ctrl+S")); + saveAsAct->setShortcuts(QKeySequence::SaveAs); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); exitAct = new QAction(tr("E&xit"), this); - exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); aboutAct = new QAction(tr("&About"), this); diff --git a/examples/xml/saxbookmarks/mainwindow.cpp b/examples/xml/saxbookmarks/mainwindow.cpp index 2cba5590ea..9247eb7354 100644 --- a/examples/xml/saxbookmarks/mainwindow.cpp +++ b/examples/xml/saxbookmarks/mainwindow.cpp @@ -128,15 +128,15 @@ void MainWindow::about() void MainWindow::createActions() { openAct = new QAction(tr("&Open..."), this); - openAct->setShortcut(tr("Ctrl+O")); + openAct->setShortcuts(QKeySequence::Open); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); saveAsAct = new QAction(tr("&Save As..."), this); - saveAsAct->setShortcut(tr("Ctrl+S")); + saveAsAct->setShortcuts(QKeySequence::SaveAs); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); exitAct = new QAction(tr("E&xit"), this); - exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); aboutAct = new QAction(tr("&About"), this); diff --git a/examples/xml/streambookmarks/mainwindow.cpp b/examples/xml/streambookmarks/mainwindow.cpp index 2136b4bc9c..c6f991b866 100644 --- a/examples/xml/streambookmarks/mainwindow.cpp +++ b/examples/xml/streambookmarks/mainwindow.cpp @@ -141,15 +141,15 @@ void MainWindow::about() void MainWindow::createActions() { openAct = new QAction(tr("&Open..."), this); - openAct->setShortcut(tr("Ctrl+O")); + openAct->setShortcuts(QKeySequence::Open); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); saveAsAct = new QAction(tr("&Save As..."), this); - saveAsAct->setShortcut(tr("Ctrl+S")); + saveAsAct->setShortcuts(QKeySequence::SaveAs); connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); exitAct = new QAction(tr("E&xit"), this); - exitAct->setShortcut(tr("Ctrl+Q")); + exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); aboutAct = new QAction(tr("&About"), this); -- cgit v1.2.3