Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmltablemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQMLTABLEMODEL_P_H
5#define QQMLTABLEMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qqmlmodelsglobal_p.h"
20
21#include <QtCore/QObject>
22#include <QtCore/QHash>
23#include <QtCore/QAbstractTableModel>
24#include <QtQml/qqml.h>
25#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
26#include <QtQml/QJSValue>
27#include <QtQml/QQmlListProperty>
28
29QT_REQUIRE_CONFIG(qml_table_model);
30
32
33class Q_LABSQMLMODELS_EXPORT QQmlTableModel : public QAbstractTableModel, public QQmlParserStatus
34{
36 Q_PROPERTY(int columnCount READ columnCount NOTIFY columnCountChanged FINAL)
37 Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged FINAL)
38 Q_PROPERTY(QVariant rows READ rows WRITE setRows NOTIFY rowsChanged FINAL)
39 Q_PROPERTY(QQmlListProperty<QQmlTableModelColumn> columns READ columns CONSTANT FINAL)
41 Q_CLASSINFO("DefaultProperty", "columns")
44
45public:
46 QQmlTableModel(QObject *parent = nullptr);
47 ~QQmlTableModel() override;
48
49 QVariant rows() const;
50 void setRows(const QVariant &rows);
51
52 Q_INVOKABLE void appendRow(const QVariant &row);
53 Q_INVOKABLE void clear();
54 Q_INVOKABLE QVariant getRow(int rowIndex);
55 Q_INVOKABLE void insertRow(int rowIndex, const QVariant &row);
56 Q_INVOKABLE void moveRow(int fromRowIndex, int toRowIndex, int rows = 1);
57 Q_INVOKABLE void removeRow(int rowIndex, int rows = 1);
58 Q_INVOKABLE void setRow(int rowIndex, const QVariant &row);
59
61
65 static void columns_clear(QQmlListProperty<QQmlTableModelColumn> *property);
67 static void columns_removeLast(QQmlListProperty<QQmlTableModelColumn> *property);
68
69 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
70 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
71 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
72 Q_INVOKABLE QVariant data(const QModelIndex &index, const QString &role) const;
73 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
74 Q_INVOKABLE bool setData(const QModelIndex &index, const QString &role, const QVariant &value);
75 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::DisplayRole) override;
76 QHash<int, QByteArray> roleNames() const override;
77 Qt::ItemFlags flags(const QModelIndex &index) const override;
78
80 void columnCountChanged();
81 void rowCountChanged();
82 void rowsChanged();
83
84protected:
85 void classBegin() override;
86 void componentComplete() override;
87
89 class ColumnRoleMetadata
90 {
91 public:
92 ColumnRoleMetadata();
93 ColumnRoleMetadata(bool isStringRole, const QString &name, int type, const QString &typeName);
94
95 bool isValid() const;
96
97 // If this is false, it's a function role.
98 bool isStringRole = false;
102 };
103
104 struct ColumnMetadata
105 {
106 // Key = role name that will be made visible to the delegate
107 // Value = metadata about that role, including actual name in the model data, type, etc.
108 QHash<QString, ColumnRoleMetadata> roles;
109 };
110
111 enum NewRowOperationFlag {
112 OtherOperation, // insert(), set(), etc.
113 SetRowsOperation,
114 AppendOperation
115 };
116
117 void doSetRows(const QVariantList &rowsAsVariantList);
118 ColumnRoleMetadata fetchColumnRoleData(const QString &roleNameKey,
119 QQmlTableModelColumn *tableModelColumn, int columnIndex) const;
120 void fetchColumnMetadata();
121
122 bool validateRowType(const char *functionName, const QVariant &row) const;
123 bool validateNewRow(const char *functionName, const QVariant &row,
124 int rowIndex, NewRowOperationFlag operation = OtherOperation) const;
125 bool validateRowIndex(const char *functionName, const char *argumentName, int rowIndex) const;
126
127 void doInsert(int rowIndex, const QVariant &row);
128
129 bool componentCompleted = false;
130 QVariantList mRows;
131 QList<QQmlTableModelColumn *> mColumns;
132 int mRowCount = 0;
133 int mColumnCount = 0;
134 // Each entry contains information about the properties of the column at that index.
135 QVector<ColumnMetadata> mColumnMetadata;
136 // key = property index (0 to number of properties across all columns)
137 // value = role name
138 QHash<int, QByteArray> mRoleNames;
139};
140
142
143#endif // QQMLTABLEMODEL_P_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qhash.h:820
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
The QQmlParserStatus class provides updates on the QML parser state.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
[0]
Definition model.h:12
b clear()
Combined button and popup list for selecting options.
Definition qcompare.h:63
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const char * typeName
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLbitfield flags
GLuint name
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_CLASSINFO(name, value)
#define Q_INVOKABLE
#define Q_INTERFACES(x)
#define Q_SIGNALS
ptrdiff_t qsizetype
Definition qtypes.h:165
const char property[13]
Definition qwizard.cpp:101
mimeData setData("text/csv", csvData)
flay removeRow(2)
flay insertRow(2, "User:", le)