Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmltablemodelcolumn.cpp
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
5
6#include <QtQml/qqmlinfo.h>
7
9
13
25static const QString displayRoleName = QStringLiteral("display");
26static const QString decorationRoleName = QStringLiteral("decoration");
27static const QString editRoleName = QStringLiteral("edit");
28static const QString toolTipRoleName = QStringLiteral("toolTip");
29static const QString statusTipRoleName = QStringLiteral("statusTip");
30static const QString whatsThisRoleName = QStringLiteral("whatsThis");
31
32static const QString fontRoleName = QStringLiteral("font");
33static const QString textAlignmentRoleName = QStringLiteral("textAlignment");
34static const QString backgroundRoleName = QStringLiteral("background");
35static const QString foregroundRoleName = QStringLiteral("foreground");
36static const QString checkStateRoleName = QStringLiteral("checkState");
37
38static const QString accessibleTextRoleName = QStringLiteral("accessibleText");
39static const QString accessibleDescriptionRoleName = QStringLiteral("accessibleDescription");
40
41static const QString sizeHintRoleName = QStringLiteral("sizeHint");
42
43
46{
47}
48
50{
51}
52
53#define DEFINE_ROLE_PROPERTIES(getterGetterName, getterSetterName, getterSignal, setterGetterName, setterSetterName, setterSignal, roleName) \
54QJSValue QQmlTableModelColumn::getterGetterName() const \
55{ \
56 return mGetters.value(roleName); \
57} \
58\
59void QQmlTableModelColumn::getterSetterName(const QJSValue &stringOrFunction) \
60{ \
61 if (!stringOrFunction.isString() && !stringOrFunction.isCallable()) { \
62 qmlWarning(this).quote() << "getter for " << roleName << " must be a function"; \
63 return; \
64 } \
65 if (stringOrFunction.strictlyEquals(decoration())) \
66 return; \
67\
68 mGetters[roleName] = stringOrFunction; \
69 emit decorationChanged(); \
70} \
71\
72QJSValue QQmlTableModelColumn::setterGetterName() const \
73{ \
74 return mSetters.value(roleName); \
75} \
76\
77void QQmlTableModelColumn::setterSetterName(const QJSValue &function) \
78{ \
79 if (!function.isCallable()) { \
80 qmlWarning(this).quote() << "setter for " << roleName << " must be a function"; \
81 return; \
82 } \
83\
84 if (function.strictlyEquals(getSetDisplay())) \
85 return; \
86\
87 mSetters[roleName] = function; \
88 emit setDisplayChanged(); \
89}
90
91DEFINE_ROLE_PROPERTIES(display, setDisplay, displayChanged,
92 getSetDisplay, setSetDisplay, setDisplayChanged, displayRoleName)
95DEFINE_ROLE_PROPERTIES(edit, setEdit, editChanged,
96 getSetEdit, setSetEdit, setEditChanged, editRoleName)
99DEFINE_ROLE_PROPERTIES(statusTip, setStatusTip, statusTipChanged,
100 getSetStatusTip, setSetStatusTip, setStatusTipChanged, statusTipRoleName)
103
104DEFINE_ROLE_PROPERTIES(font, setFont, fontChanged,
105 getSetFont, setSetFont, setFontChanged, fontRoleName)
108DEFINE_ROLE_PROPERTIES(background, setBackground, backgroundChanged,
109 getSetBackground, setSetBackground, setBackgroundChanged, backgroundRoleName)
112DEFINE_ROLE_PROPERTIES(checkState, setCheckState, checkStateChanged,
113 getSetCheckState, setSetCheckState, setCheckStateChanged, checkStateRoleName)
114
117DEFINE_ROLE_PROPERTIES(accessibleDescription, setAccessibleDescription, accessibleDescriptionChanged,
118 getSetAccessibleDescription, setSetAccessibleDescription, setAccessibleDescriptionChanged, accessibleDescriptionRoleName)
119
122
123QJSValue QQmlTableModelColumn::getterAtRole(const QString &roleName)
124{
125 auto it = mGetters.find(roleName);
126 if (it == mGetters.end())
127 return QJSValue();
128 return *it;
129}
130
132{
133 auto it = mSetters.find(roleName);
134 if (it == mSetters.end())
135 return QJSValue();
136 return *it;
137}
138
140{
141 return mGetters;
142}
143
145{
147 names[Qt::DisplayRole] = QLatin1String("display");
148 names[Qt::DecorationRole] = QLatin1String("decoration");
150 names[Qt::ToolTipRole] = QLatin1String("toolTip");
151 names[Qt::StatusTipRole] = QLatin1String("statusTip");
152 names[Qt::WhatsThisRole] = QLatin1String("whatsThis");
154 names[Qt::TextAlignmentRole] = QLatin1String("textAlignment");
155 names[Qt::BackgroundRole] = QLatin1String("background");
156 names[Qt::ForegroundRole] = QLatin1String("foreground");
157 names[Qt::CheckStateRole] = QLatin1String("checkState");
158 names[Qt::AccessibleTextRole] = QLatin1String("accessibleText");
159 names[Qt::AccessibleDescriptionRole] = QLatin1String("accessibleDescription");
160 names[Qt::SizeHintRole] = QLatin1String("sizeHint");
161 return names;
162}
163
165
166#include "moc_qqmltablemodelcolumn_p.cpp"
\inmodule QtCore
Definition qhash.h:818
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition qhash.h:1258
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
Definition qhash.h:1206
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
Definition qobject.h:90
QJSValue setterAtRole(const QString &roleName)
static const QHash< int, QString > supportedRoleNames()
QQmlTableModelColumn(QObject *parent=nullptr)
const QHash< QString, QJSValue > getters() const
iterator end()
Definition qset.h:140
iterator find(const T &value)
Definition qset.h:159
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QSet< QString >::iterator it
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
@ AccessibleDescriptionRole
@ AccessibleTextRole
@ WhatsThisRole
@ FontRole
@ TextAlignmentRole
@ ForegroundRole
@ DecorationRole
@ BackgroundRole
@ EditRole
@ CheckStateRole
@ StatusTipRole
@ ToolTipRole
@ DisplayRole
@ SizeHintRole
GLuint GLuint * names
static const QString decorationRoleName
static const QString checkStateRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName accessibleTextRoleName setSizeHintChanged
static QT_BEGIN_NAMESPACE const QString displayRoleName
Represents a column in a model.
static const QString fontRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName accessibleTextRoleName setSizeHint
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName setForegroundChanged
decorationRoleName toolTipRoleName setSetWhatsThis
decorationRoleName setSetToolTip
decorationRoleName toolTipRoleName getSetWhatsThis
static const QString editRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName accessibleTextRoleName sizeHintChanged
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName setSetAccessibleText
static const QString toolTipRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName accessibleTextRoleName setSetSizeHint
decorationRoleName toolTipRoleName setWhatsThisChanged
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundChanged
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName setAccessibleTextChanged
static const QString accessibleTextRoleName
decorationRoleName toolTipRoleName whatsThisRoleName setTextAlignmentChanged
decorationRoleName toolTipRoleName whatsThisRoleName setSetTextAlignment
decorationRoleName toolTipChanged
static const QString backgroundRoleName
decorationRoleName toolTipRoleName whatsThisRoleName setTextAlignment
decorationRoleName toolTipRoleName setWhatsThis
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName setForeground
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName accessibleTextChanged
decorationRoleName getSetToolTip
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName getSetForeground
decorationRoleName toolTipRoleName whatsThisChanged
static const QString whatsThisRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentChanged
static const QString sizeHintRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName accessibleTextRoleName getSetSizeHint
static const QString foregroundRoleName
decorationRoleName setToolTipChanged
#define DEFINE_ROLE_PROPERTIES(getterGetterName, getterSetterName, getterSignal, setterGetterName, setterSetterName, setterSignal, roleName)
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName setAccessibleText
static const QString accessibleDescriptionRoleName
static const QString statusTipRoleName
static const QString textAlignmentRoleName
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName foregroundRoleName getSetAccessibleText
decorationRoleName toolTipRoleName whatsThisRoleName getSetTextAlignment
decorationRoleName toolTipRoleName whatsThisRoleName textAlignmentRoleName setSetForeground
decorationRoleName setToolTip
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent