summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
blob: 52934b615920020f0e91ea569c39866665f7464b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

//! [0]
class DateFormatProxyModel : public QIdentityProxyModel
{
  // ...

  void setDateFormatString(const QString &formatString)
  {
    m_formatString = formatString;
  }

  QVariant data(const QModelIndex &index, int role) const override
  {
    if (role != Qt::DisplayRole)
      return QIdentityProxyModel::data(index, role);

    const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime();

    return dateTime.toString(m_formatString);
  }

private:
  QString m_formatString;
};
//! [0]