Qt 6.x
The Qt SDK
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
21 return dateTime.toString(m_formatString);
22 }
23
24private:
25 QString m_formatString;
26};
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.
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:257
The QIdentityProxyModel class proxies its source model unmodified.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has userType() \l QMetaType::QDateTime,...
@ DisplayRole
GLuint index
[2]
QDateTime dateTime
[12]