diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-06-26 15:17:11 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-06-30 08:51:02 +0200 |
commit | 8937169c190246ebc85df242f85b3bda911bc5c6 (patch) | |
tree | 96268c98400fd51a6ead5fad9485c328ad4f4294 /examples/widgets | |
parent | 9c71b924304c2d1bd3ac3e13263b47131478562c (diff) |
Move simple dom model example to manual test
Pick-to: 6.5 6.6
Change-Id: I33120e3f6217ea52bdfdebea8b5faa79d9d3fd68
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/doc/src/simpledommodel.qdoc | 256 | ||||
-rw-r--r-- | examples/widgets/itemviews/CMakeLists.txt | 4 | ||||
-rw-r--r-- | examples/widgets/itemviews/itemviews.pro | 2 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/CMakeLists.txt | 40 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/domitem.cpp | 62 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/domitem.h | 29 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/dommodel.cpp | 153 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/dommodel.h | 38 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/main.cpp | 15 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/mainwindow.cpp | 47 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/mainwindow.h | 33 | ||||
-rw-r--r-- | examples/widgets/itemviews/simpledommodel/simpledommodel.pro | 14 |
12 files changed, 0 insertions, 693 deletions
diff --git a/examples/widgets/doc/src/simpledommodel.qdoc b/examples/widgets/doc/src/simpledommodel.qdoc deleted file mode 100644 index 82bd5c5d54..0000000000 --- a/examples/widgets/doc/src/simpledommodel.qdoc +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example itemviews/simpledommodel - \title Simple DOM Model Example - \ingroup examples-itemviews - \brief The Simple DOM Model example shows how an existing class can be adapted for use with - the model/view framework. - - \image simpledommodel-example.png - - Qt provides two complementary sets of classes for reading XML files: The classes based - around QXmlReader provide a SAX-style API for incremental reading of large files, and - the classes based around QDomDocument enable developers to access the contents of XML - files using a Document Object Model (DOM) API. - - In this example, we create a model that uses the DOM API to expose the structure and - contents of XML documents to views via the standard QAbstractModel interface. - - \section1 Design and Concepts - - Reading an XML document with Qt's DOM classes is a straightforward process. Typically, - the contents of a file are supplied to QDomDocument, and nodes are accessed using the - functions provided by QDomNode and its subclasses. - - \omit - For example, the following code - snippet reads the contents of a file into a QDomDocument object and traverses the - document, reading all the plain text that can be found: - - \snippet doc/src/snippets/code/doc_src_examples_simpledommodel.cpp 0 - - In principle, the functions provided by QDomNode can be used to navigate from any - given starting point in a document to the piece of data requested by another component. - Since QDomDocument maintains information about the structure of a document, we can - use this to implement the required virtual functions in a QAbstractItemModel subclass. - \endomit - - The aim is to use the structure provided by QDomDocument by wrapping QDomNode objects - in item objects similar to the \c TreeItem objects used in the - \l{Simple Tree Model Example}{Simple Tree Model} example. - - \section1 DomModel Class Definition - - Let us begin by examining the \c DomModel class: - - \snippet itemviews/simpledommodel/dommodel.h 0 - - The class definition contains all the basic functions that are needed for a - read-only model. Only the constructor and \c document() function are specific to - this model. The private \c domDocument variable is used to hold the document - that is exposed by the model; the \c rootItem variable contains a pointer to - the root item in the model. - - \section1 DomItem Class Definition - - The \c DomItem class is used to hold information about a specific QDomNode in - the document: - - \snippet itemviews/simpledommodel/domitem.h 0 - - Each \c DomItem provides a wrapper for a QDomNode obtained from the underlying - document which contains a reference to the node, it's location in the parent node's - list of child nodes, and a pointer to a parent wrapper item. - - The \c parent(), \c child(), and \c row() functions are convenience functions for - the \c DomModel to use that provide basic information about the item to be discovered - quickly. The node() function provides access to the underlying QDomNode object. - - As well as the information supplied in the constructor, the class maintains a cache - of information about any child items. This is used to provide a collection of - persistent item objects that the model can identify consistently and improve the - performance of the model when accessing child items. - - \section1 DomItem Class Implementation - - Since the \c DomItem class is only a thin wrapper around QDomNode objects, with a - few additional features to help improve performance and memory usage, we can provide - a brief outline of the class before discussing the model itself. - - The constructor simply records details of the QDomNode that needs to be wrapped: - - \snippet itemviews/simpledommodel/domitem.cpp 0 - \snippet itemviews/simpledommodel/domitem.cpp 1 - - As a result, functions to provide the parent wrapper, the row number occupied by - the item in its parent's list of children, and the underlying QDomNode for each item - are straightforward to write: - - \snippet itemviews/simpledommodel/domitem.cpp 4 - \codeline - \snippet itemviews/simpledommodel/domitem.cpp 6 - \codeline - \snippet itemviews/simpledommodel/domitem.cpp 3 - - It is necessary to maintain a collection of items which can be consistently identified - by the model. For that reason, we maintain a hash of child wrapper items that, to - minimize memory usage, is initially empty. The model uses the item's \c child() - function to help create model indexes, and this constructs wrappers for the children - of the item's QDomNode, relating the row number of each child to the newly-constructed - wrapper: - - \snippet itemviews/simpledommodel/domitem.cpp 5 - - If a QDomNode was previously wrapped, the cached wrapper is returned; otherwise, a - new wrapper is constructed and stored for valid children, and zero is returned for - invalid ones. - - The class's destructor deletes all the child items of the wrapper: - - \snippet itemviews/simpledommodel/domitem.cpp 2 - - These, in turn, will delete their children and free any QDomNode objects in use. - - \section1 DomModel Class Implementation - - The structure provided by the \c DomItem class makes the implementation of \c DomModel - similar to the \c TreeModel shown in the - \l{Simple Tree Model Example}{Simple Tree Model} example. - - The constructor accepts an existing document and a parent object for the model: - - \snippet itemviews/simpledommodel/dommodel.cpp 0 - - A shallow copy of the document is stored for future reference, and a root item is - created to provide a wrapper around the document. We assign the root item a row - number of zero only to be consistent since the root item will have no siblings. - - Since the model only contains information about the root item, the destructor only - needs to delete this one item: - - \snippet itemviews/simpledommodel/dommodel.cpp 1 - - All of the child items in the tree will be deleted by the \c DomItem destructor as - their parent items are deleted. - - \section2 Basic Properties of The Model - - Some aspects of the model do not depend on the structure of the underlying document, - and these are simple to implement. - - The number of columns exposed by the model is returned by the \c columnCount() - function: - - \snippet itemviews/simpledommodel/dommodel.cpp 2 - - This value is fixed, and does not depend on the location or type of the underlying - node in the document. We will use these three columns to display different kinds of - data from the underlying document. - - Since we only implement a read-only model, the \c flags() function is straightforward - to write: - - \snippet itemviews/simpledommodel/dommodel.cpp 5 - - Since the model is intended for use in a tree view, the \c headerData() function only - provides a horizontal header: - - \snippet itemviews/simpledommodel/dommodel.cpp 6 - - The model presents the names of nodes in the first column, element attributes in the - second, and any node values in the third. - - \section2 Navigating The Document - - The index() function creates a model index for the item with the given row, column, - and parent in the model: - - \snippet itemviews/simpledommodel/dommodel.cpp 7 - - The function first has to relate the parent index to an item that contains a node - from the underlying document. If the parent index is invalid, it refers to the root - node in the document, so we retrieve the root item that wraps it; otherwise, we - obtain a pointer to the relevant item using the QModelIndex::internalPointer() - function. We are able to extract a pointer in this way because any valid model index - will have been created by this function, and we store pointers to item objects in - any new indexes that we create with QAbstractItemModel::createIndex(): - - \snippet itemviews/simpledommodel/dommodel.cpp 8 - - A child item for the given row is provided by the parent item's \c child() function. - If a suitable child item was found then we call - \l{QAbstractItemModel::createIndex()}{createIndex()} to produce a model index for the - requested row and column, passing a pointer to the child item for it to store - internally. If no suitable child item is found, an invalid model index is returned. - - Note that the items themselves maintain ownership of their child items. This means - that the model does not need to keep track of the child items that have been created, - and can let the items themselves tidy up when they are deleted. - - The number of rows beneath a given item in the model is returned by the \c rowCount() - function, and is the number of child nodes contained by the node that corresponds to - the specified model index: - - \snippet itemviews/simpledommodel/dommodel.cpp 10 - - To obtain the relevant node in the underlying document, we access the item via the - internal pointer stored in the model index. If an invalid index is supplied, the - root item is used instead. We use the item's \c node() function to access the node - itself, and simply count the number of child nodes it contains. - - Since the model is used to represent a hierarchical data structure, it needs to - provide an implementation for the \c parent() function. This returns a model index - that corresponds to the parent of a child model index supplied as its argument: - - \snippet itemviews/simpledommodel/dommodel.cpp 9 - - For valid indexes other than the index corresponding to the root item, we obtain - a pointer to the relevant item using the method described in the \c index() function, - and use the item's \c parent() function to obtain a pointer to the parent item. - - If no valid parent item exists, or if the parent item is the root item, we can simply - follow convention and return an invalid model index. For all other parent items, we - create a model index containing the appropriate row and column numbers, and a pointer - to the parent item we just obtained. - - Data is provided by the \c data() function. For simplicity, we only provide data for - the \l{Qt::DisplayRole}{display role}, returning an invalid variant for all other - requests: - - \snippet itemviews/simpledommodel/dommodel.cpp 3 - - As before, we obtain an item pointer for the index supplied, and use it to obtain - the underlying document node. Depending on the column specified, the data we return - is obtained in different ways: - - \snippet itemviews/simpledommodel/dommodel.cpp 4 - - For the first column, we return the node's name. For the second column, we read any - attributes that the node may have, and return a string that contains a space-separated - list of attribute-value assignments. For the third column, we return any value that - the node may have; this allows the contents of text nodes to be displayed in a view. - - If data from any other column is requested, an invalid variant is returned. - - \section1 Implementation Notes - - Ideally, we would rely on the structure provided by QDomDocument to help us write - the \l{QAbstractItemModel::parent()}{parent()} and - \l{QAbstractItemModel::index()}{index()} functions that are required when subclassing - QAbstractItemModel. However, since Qt's DOM classes use their own system for - dynamically allocating memory for DOM nodes, we cannot guarantee that the QDomNode - objects returned for a given piece of information will be the same for subsequent - accesses to the document. - - We use item wrappers for each QDomNode to provide consistent pointers that the model - can use to navigate the document structure. - \omit - Since these items contain value references to the QDomNode objects themselves, this - has the side effect that the DOM nodes themselves can be used to reliably navigate - the document [not sure about this - QDom* may return different QDomNode objects for - the same piece of information]. However, this advantage is redundant since we need to - use wrapper items to obtain it. [Possible use of QDomNode cache in the model itself.] - \endomit -*/ diff --git a/examples/widgets/itemviews/CMakeLists.txt b/examples/widgets/itemviews/CMakeLists.txt index 02b531f932..30c93de51b 100644 --- a/examples/widgets/itemviews/CMakeLists.txt +++ b/examples/widgets/itemviews/CMakeLists.txt @@ -9,11 +9,7 @@ qt_internal_add_example(customsortfiltermodel) qt_internal_add_example(editabletreemodel) qt_internal_add_example(fetchmore) qt_internal_add_example(frozencolumn) -qt_internal_add_example(simpletreemodel) qt_internal_add_example(simplewidgetmapper) qt_internal_add_example(spinboxdelegate) qt_internal_add_example(spreadsheet) qt_internal_add_example(stardelegate) -if(TARGET Qt6::Xml) - qt_internal_add_example(simpledommodel) -endif() diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro index 9fa7e6c9c9..eee0f8eb18 100644 --- a/examples/widgets/itemviews/itemviews.pro +++ b/examples/widgets/itemviews/itemviews.pro @@ -7,10 +7,8 @@ SUBDIRS = addressbook \ editabletreemodel \ fetchmore \ frozencolumn \ - simpledommodel \ simpletreemodel \ simplewidgetmapper \ spinboxdelegate \ spreadsheet \ stardelegate -!qtHaveModule(xml): SUBDIRS -= simpledommodel diff --git a/examples/widgets/itemviews/simpledommodel/CMakeLists.txt b/examples/widgets/itemviews/simpledommodel/CMakeLists.txt deleted file mode 100644 index 0817fd1078..0000000000 --- a/examples/widgets/itemviews/simpledommodel/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(simpledommodel LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/simpledommodel") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Xml) - -qt_standard_project_setup() - -qt_add_executable(simpledommodel - domitem.cpp domitem.h - dommodel.cpp dommodel.h - main.cpp - mainwindow.cpp mainwindow.h -) - -set_target_properties(simpledommodel PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(simpledommodel PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets - Qt6::Xml -) - -install(TARGETS simpledommodel - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/widgets/itemviews/simpledommodel/domitem.cpp b/examples/widgets/itemviews/simpledommodel/domitem.cpp deleted file mode 100644 index b3e197b3db..0000000000 --- a/examples/widgets/itemviews/simpledommodel/domitem.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "domitem.h" - -#include <QtXml> - -//! [0] -DomItem::DomItem(const QDomNode &node, int row, DomItem *parent) - : domNode(node), -//! [0] - // Record the item's location within its parent. -//! [1] - parentItem(parent), - rowNumber(row) -{} -//! [1] - -//! [2] -DomItem::~DomItem() -{ - qDeleteAll(childItems); -} -//! [2] - -//! [3] -QDomNode DomItem::node() const -{ - return domNode; -} -//! [3] - -//! [4] -DomItem *DomItem::parent() -{ - return parentItem; -} -//! [4] - -//! [5] -DomItem *DomItem::child(int i) -{ - DomItem *childItem = childItems.value(i); - if (childItem) - return childItem; - - // if child does not yet exist, create it - if (i >= 0 && i < domNode.childNodes().count()) { - QDomNode childNode = domNode.childNodes().item(i); - childItem = new DomItem(childNode, i, this); - childItems[i] = childItem; - } - return childItem; -} -//! [5] - -//! [6] -int DomItem::row() const -{ - return rowNumber; -} -//! [6] diff --git a/examples/widgets/itemviews/simpledommodel/domitem.h b/examples/widgets/itemviews/simpledommodel/domitem.h deleted file mode 100644 index 9b02d8e88c..0000000000 --- a/examples/widgets/itemviews/simpledommodel/domitem.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef DOMITEM_H -#define DOMITEM_H - -#include <QDomNode> -#include <QHash> - -//! [0] -class DomItem -{ -public: - DomItem(const QDomNode &node, int row, DomItem *parent = nullptr); - ~DomItem(); - DomItem *child(int i); - DomItem *parent(); - QDomNode node() const; - int row() const; - -private: - QDomNode domNode; - QHash<int, DomItem *> childItems; - DomItem *parentItem; - int rowNumber; -}; -//! [0] - -#endif // DOMITEM_H diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.cpp b/examples/widgets/itemviews/simpledommodel/dommodel.cpp deleted file mode 100644 index 17f05c8be3..0000000000 --- a/examples/widgets/itemviews/simpledommodel/dommodel.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "dommodel.h" -#include "domitem.h" - -#include <QtXml> - -//! [0] -DomModel::DomModel(const QDomDocument &document, QObject *parent) - : QAbstractItemModel(parent), - domDocument(document), - rootItem(new DomItem(domDocument, 0)) -{ -} -//! [0] - -//! [1] -DomModel::~DomModel() -{ - delete rootItem; -} -//! [1] - -//! [2] -int DomModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent); - return 3; -} -//! [2] - -//! [3] -QVariant DomModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (role != Qt::DisplayRole) - return QVariant(); - - const DomItem *item = static_cast<DomItem*>(index.internalPointer()); - - const QDomNode node = item->node(); -//! [3] //! [4] - - switch (index.column()) { - case 0: - return node.nodeName(); - case 1: - { - const QDomNamedNodeMap attributeMap = node.attributes(); - QStringList attributes; - for (int i = 0; i < attributeMap.count(); ++i) { - QDomNode attribute = attributeMap.item(i); - attributes << attribute.nodeName() + "=\"" - + attribute.nodeValue() + '"'; - } - return attributes.join(' '); - } - case 2: - return node.nodeValue().split('\n').join(' '); - default: - break; - } - return QVariant(); -} -//! [4] - -//! [5] -Qt::ItemFlags DomModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - - return QAbstractItemModel::flags(index); -} -//! [5] - -//! [6] -QVariant DomModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Name"); - case 1: - return tr("Attributes"); - case 2: - return tr("Value"); - default: - break; - } - } - return QVariant(); -} -//! [6] - -//! [7] -QModelIndex DomModel::index(int row, int column, const QModelIndex &parent) const -{ - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - DomItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast<DomItem*>(parent.internalPointer()); -//! [7] - -//! [8] - DomItem *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - return QModelIndex(); -} -//! [8] - -//! [9] -QModelIndex DomModel::parent(const QModelIndex &child) const -{ - if (!child.isValid()) - return QModelIndex(); - - DomItem *childItem = static_cast<DomItem*>(child.internalPointer()); - DomItem *parentItem = childItem->parent(); - - if (!parentItem || parentItem == rootItem) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} -//! [9] - -//! [10] -int DomModel::rowCount(const QModelIndex &parent) const -{ - if (parent.column() > 0) - return 0; - - DomItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast<DomItem*>(parent.internalPointer()); - - return parentItem->node().childNodes().count(); -} -//! [10] diff --git a/examples/widgets/itemviews/simpledommodel/dommodel.h b/examples/widgets/itemviews/simpledommodel/dommodel.h deleted file mode 100644 index 109ab33e58..0000000000 --- a/examples/widgets/itemviews/simpledommodel/dommodel.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef DOMMODEL_H -#define DOMMODEL_H - -#include <QAbstractItemModel> -#include <QDomDocument> -#include <QModelIndex> - -class DomItem; - -//! [0] -class DomModel : public QAbstractItemModel -{ - Q_OBJECT - -public: - explicit DomModel(const QDomDocument &document, QObject *parent = nullptr); - ~DomModel(); - - QVariant data(const QModelIndex &index, int role) const override; - Qt::ItemFlags flags(const QModelIndex &index) const override; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const override; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const override; - QModelIndex parent(const QModelIndex &child) const override; - int rowCount(const QModelIndex &parent = QModelIndex()) const override; - int columnCount(const QModelIndex &parent = QModelIndex()) const override; - -private: - QDomDocument domDocument; - DomItem *rootItem; -}; -//! [0] - -#endif // DOMMODEL_H diff --git a/examples/widgets/itemviews/simpledommodel/main.cpp b/examples/widgets/itemviews/simpledommodel/main.cpp deleted file mode 100644 index 2ea03356f2..0000000000 --- a/examples/widgets/itemviews/simpledommodel/main.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "mainwindow.h" - -#include <QApplication> - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - MainWindow window; - window.resize(640, 480); - window.show(); - return app.exec(); -} diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp deleted file mode 100644 index ad64863fbb..0000000000 --- a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "mainwindow.h" -#include "dommodel.h" - -#include <QDomDocument> -#include <QTreeView> -#include <QMenuBar> -#include <QFileDialog> - -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), - model(new DomModel(QDomDocument(), this)), - view(new QTreeView(this)) -{ - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(tr("&Open..."), QKeySequence::Open, this, &MainWindow::openFile); - fileMenu->addAction(tr("E&xit"), QKeySequence::Quit, this, &QWidget::close); - - view->setModel(model); - - setCentralWidget(view); - setWindowTitle(tr("Simple DOM Model")); -} - -void MainWindow::openFile() -{ - QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), - xmlPath, tr("XML files (*.xml);;HTML files (*.html);;" - "SVG files (*.svg);;User Interface files (*.ui)")); - - if (!filePath.isEmpty()) { - QFile file(filePath); - if (file.open(QIODevice::ReadOnly)) { - QDomDocument document; - if (document.setContent(&file)) { - DomModel *newModel = new DomModel(document, this); - view->setModel(newModel); - delete model; - model = newModel; - xmlPath = filePath; - } - file.close(); - } - } -} diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.h b/examples/widgets/itemviews/simpledommodel/mainwindow.h deleted file mode 100644 index a82f3956c8..0000000000 --- a/examples/widgets/itemviews/simpledommodel/mainwindow.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include <QMainWindow> -#include <QString> - -class DomModel; -QT_BEGIN_NAMESPACE -class QMenu; -class QTreeView; -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - MainWindow(QWidget *parent = nullptr); - -public slots: - void openFile(); - -private: - DomModel *model; - QMenu *fileMenu; - QString xmlPath; - QTreeView *view; -}; - -#endif // MAINWINDOW_H diff --git a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro b/examples/widgets/itemviews/simpledommodel/simpledommodel.pro deleted file mode 100644 index 3d45920e36..0000000000 --- a/examples/widgets/itemviews/simpledommodel/simpledommodel.pro +++ /dev/null @@ -1,14 +0,0 @@ -HEADERS = domitem.h \ - dommodel.h \ - mainwindow.h -SOURCES = domitem.cpp \ - dommodel.cpp \ - main.cpp \ - mainwindow.cpp -QT += xml widgets -requires(qtConfig(filedialog)) - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/simpledommodel -INSTALLS += target - |