summaryrefslogtreecommitdiffstats
path: root/examples/widgets/itemviews/simpledommodel
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/itemviews/simpledommodel')
-rw-r--r--examples/widgets/itemviews/simpledommodel/CMakeLists.txt37
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.cpp62
-rw-r--r--examples/widgets/itemviews/simpledommodel/domitem.h29
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.cpp153
-rw-r--r--examples/widgets/itemviews/simpledommodel/dommodel.h38
-rw-r--r--examples/widgets/itemviews/simpledommodel/main.cpp15
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.cpp47
-rw-r--r--examples/widgets/itemviews/simpledommodel/mainwindow.h33
-rw-r--r--examples/widgets/itemviews/simpledommodel/simpledommodel.pro14
9 files changed, 0 insertions, 428 deletions
diff --git a/examples/widgets/itemviews/simpledommodel/CMakeLists.txt b/examples/widgets/itemviews/simpledommodel/CMakeLists.txt
deleted file mode 100644
index d6ad561216..0000000000
--- a/examples/widgets/itemviews/simpledommodel/CMakeLists.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-cmake_minimum_required(VERSION 3.16)
-project(simpledommodel LANGUAGES CXX)
-
-set(CMAKE_AUTOMOC ON)
-
-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_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 PUBLIC
- Qt::Core
- Qt::Gui
- Qt::Widgets
- Qt::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
-