6.5.3 clean

This commit is contained in:
kleuter
2023-11-01 18:02:52 +01:00
parent bbe896803b
commit 7018d9e6c8
2170 changed files with 57471 additions and 43550 deletions

View File

@ -0,0 +1,51 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.16)
project(interview LANGUAGES CXX)
if(NOT DEFINED INSTALL_EXAMPLESDIR)
set(INSTALL_EXAMPLESDIR "examples")
endif()
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/interview")
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
qt_standard_project_setup()
qt_add_executable(interview
main.cpp
model.cpp model.h
)
set_target_properties(interview PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
)
target_link_libraries(interview PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
)
# Resources:
set(interview_resource_files
"images/folder.png"
"images/interview.png"
"images/services.png"
)
qt_add_resources(interview "interview"
PREFIX
"/"
FILES
${interview_resource_files}
)
install(TARGETS interview
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)

View File

@ -0,0 +1,2 @@
The interview example shows the same model and selection being shared
between three different views.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -0,0 +1,16 @@
TEMPLATE = app
QT += widgets
requires(qtConfig(treeview))
HEADERS += model.h
SOURCES += model.cpp main.cpp
RESOURCES += interview.qrc
build_all:!build_pass {
CONFIG -= build_all
CONFIG += release
}
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/interview
INSTALLS += target

View File

@ -0,0 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>images/folder.png</file>
<file>images/services.png</file>
<file>images/interview.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,55 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "model.h"
#include <QApplication>
#include <QHeaderView>
#include <QListView>
#include <QSplitter>
#include <QTableView>
#include <QTreeView>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSplitter page;
QAbstractItemModel *data = new Model(1000, 10, &page);
QItemSelectionModel *selections = new QItemSelectionModel(data);
QTableView *table = new QTableView;
table->setModel(data);
table->setSelectionModel(selections);
table->horizontalHeader()->setSectionsMovable(true);
table->verticalHeader()->setSectionsMovable(true);
// Set StaticContents to enable minimal repaints on resizes.
table->viewport()->setAttribute(Qt::WA_StaticContents);
page.addWidget(table);
QTreeView *tree = new QTreeView;
tree->setModel(data);
tree->setSelectionModel(selections);
tree->setUniformRowHeights(true);
tree->header()->setStretchLastSection(false);
tree->viewport()->setAttribute(Qt::WA_StaticContents);
// Disable the focus rect to get minimal repaints when scrolling on Mac.
tree->setAttribute(Qt::WA_MacShowFocusRect, false);
page.addWidget(tree);
QListView *list = new QListView;
list->setModel(data);
list->setSelectionModel(selections);
list->setViewMode(QListView::IconMode);
list->setSelectionMode(QAbstractItemView::ExtendedSelection);
list->setAlternatingRowColors(false);
list->viewport()->setAttribute(Qt::WA_StaticContents);
list->setAttribute(Qt::WA_MacShowFocusRect, false);
page.addWidget(list);
page.setWindowIcon(QPixmap(":/images/interview.png"));
page.setWindowTitle("Interview");
page.show();
return app.exec();
}

View File

@ -0,0 +1,110 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "model.h"
#include <QPixmap>
Model::Model(int rows, int columns, QObject *parent)
: QAbstractItemModel(parent),
services(QPixmap(":/images/services.png")),
rc(rows),
cc(columns),
tree(new QList<Node>(rows, Node()))
{
}
Model::~Model()
{
delete tree;
}
QModelIndex Model::index(int row, int column, const QModelIndex &parent) const
{
if (row < rc && row >= 0 && column < cc && column >= 0) {
Node *parentNode = static_cast<Node*>(parent.internalPointer());
Node *childNode = node(row, parentNode);
if (childNode)
return createIndex(row, column, childNode);
}
return QModelIndex();
}
QModelIndex Model::parent(const QModelIndex &child) const
{
if (child.isValid()) {
Node *childNode = static_cast<Node*>(child.internalPointer());
Node *parentNode = parent(childNode);
if (parentNode)
return createIndex(row(parentNode), 0, parentNode);
}
return QModelIndex();
}
int Model::rowCount(const QModelIndex &parent) const
{
return (parent.isValid() && parent.column() != 0) ? 0 : rc;
}
int Model::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return cc;
}
QVariant Model::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole)
return QVariant("Item " + QString::number(index.row()) + ':' + QString::number(index.column()));
if (role == Qt::DecorationRole) {
if (index.column() == 0)
return iconProvider.icon(QFileIconProvider::Folder);
return iconProvider.icon(QFileIconProvider::File);
}
return QVariant();
}
QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole)
return QString::number(section);
if (role == Qt::DecorationRole)
return QVariant::fromValue(services);
return QAbstractItemModel::headerData(section, orientation, role);
}
bool Model::hasChildren(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0)
return false;
return rc > 0 && cc > 0;
}
Qt::ItemFlags Model::flags(const QModelIndex &index) const
{
if (!index.isValid())
return {};
return Qt::ItemIsDragEnabled|QAbstractItemModel::flags(index);
}
Model::Node *Model::node(int row, Node *parent) const
{
if (parent && !parent->children)
parent->children = new QList<Node>(rc, Node(parent));
QList<Node> *v = parent ? parent->children : tree;
return const_cast<Node*>(&(v->at(row)));
}
Model::Node *Model::parent(Node *child) const
{
return child ? child->parent : nullptr;
}
int Model::row(Node *node) const
{
const Node *first = node->parent ? &(node->parent->children->at(0)) : &(tree->at(0));
return node - first;
}

View File

@ -0,0 +1,53 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef MODEL_H
#define MODEL_H
#include <QAbstractItemModel>
#include <QFileIconProvider>
#include <QIcon>
#include <QList>
class Model : public QAbstractItemModel
{
Q_OBJECT
public:
Model(int rows, int columns, QObject *parent = nullptr);
~Model();
QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
bool hasChildren(const QModelIndex &parent) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
private:
struct Node
{
Node(Node *parent = nullptr) : parent(parent), children(nullptr) {}
~Node() { delete children; }
Node *parent;
QList<Node> *children;
};
Node *node(int row, Node *parent) const;
Node *parent(Node *child) const;
int row(Node *node) const;
QIcon services;
int rc;
int cc;
QList<Node> *tree;
QFileIconProvider iconProvider;
};
#endif // MODEL_H