Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
4
#
include
<
QIdentityProxyModel
>
5
#
include
<
QDateTime
>
6
#
include
<
QMap
>
7
#
include
<
QModelIndex
>
8
#
include
<
QVariant
>
9
10
class
SourceClass
11
{
12
public
:
13
enum
Roles
{
14
DateRole
= 1
15
};
16
};
17
18
//! [0]
19
class
DateFormatProxyModel
:
public
QIdentityProxyModel
20
{
21
// ...
22
23
void
setDateFormatString(
const
QString &formatString)
24
{
25
m_formatString = formatString;
26
}
27
28
QVariant
data
(
const
QModelIndex &index,
int
role =
Qt
::
DisplayRole
)
const
override
29
{
30
if
(role != Qt::DisplayRole)
31
return
QIdentityProxyModel::data(index, role);
32
33
const
QModelIndex sourceIndex = mapToSource(index);
34
const
QDateTime dateTime = sourceModel()->data(sourceIndex,
SourceClass
::
DateRole
).toDateTime();
35
return
dateTime.toString(m_formatString);
36
}
37
38
QMap
<
int
,
QVariant
>
itemData
(
const
QModelIndex &proxyIndex)
const
override
39
{
40
QMap<
int
, QVariant> map = QIdentityProxyModel::itemData(proxyIndex);
41
map[Qt::DisplayRole] = data(proxyIndex);
42
return
map;
43
}
44
45
private
:
46
QString m_formatString;
47
};
48
//! [0]
DateFormatProxyModel
[0]
Definition
src_gui_itemviews_qidentityproxymodel.cpp:20
DateFormatProxyModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
Definition
src_gui_itemviews_qidentityproxymodel.cpp:28
DateFormatProxyModel::itemData
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.
Definition
src_gui_itemviews_qidentityproxymodel.cpp:38
SourceClass
Definition
src_gui_itemviews_qidentityproxymodel.cpp:11
SourceClass::Roles
Roles
Definition
src_gui_itemviews_qidentityproxymodel.cpp:13
SourceClass::DateRole
@ DateRole
Definition
src_gui_itemviews_qidentityproxymodel.cpp:14
qtbase
src
corelib
doc
snippets
code
src_gui_itemviews_qidentityproxymodel.cpp
Generated on
for Qt by
1.14.0