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
src_gui_itemviews_qidentityproxymodel.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
6{
7 // ...
8
9 void setDateFormatString(const QString &formatString)
10 {
11 m_formatString = formatString;
12 }
13
14 QVariant data(const QModelIndex &index, int role) const override
15 {
16 if (role != Qt::DisplayRole)
17 return QIdentityProxyModel::data(index, role);
18
19 const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime();
20 return dateTime.toString(m_formatString);
21 }
22
23 QMap<int, QVariant> itemData(const QModelIndex &proxyIndex) const override
24 {
25 QMap<int, QVariant> map = QIdentityProxyModel::itemData(proxyIndex);
26 map[Qt::DisplayRole] = data(proxyIndex);
27 return map;
28 }
29
30private:
31 QString m_formatString;
32};
QVariant data(const QModelIndex &index, int role) const override
Returns the data stored under the given role for the item referred to by the index.
QMap< int, QVariant > itemData(const QModelIndex &proxyIndex) const override
Returns a map with values for all predefined roles in the model for the item at the given index.
virtual QMap< int, QVariant > itemData(const QModelIndex &index) const
Returns a map with values for all predefined roles in the model for the item at the given index.
virtual Q_INVOKABLE QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
QAbstractItemModel * sourceModel
the source model of this proxy model.
\inmodule QtCore\reentrant
Definition qdatetime.h:283
The QIdentityProxyModel class proxies its source model unmodified.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
QMap< QString, QString > map
[6]
@ DisplayRole
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QDateTime dateTime
[12]