Kirigami-addons

yearmodel.cpp
1// SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org>
2// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
3// SPDX-License-Identifier: LGPL-2.0-or-later
4
5#include "yearmodel.h"
6
7#include <QDate>
8#include <QCalendar>
9#include <QLocale>
10
11YearModel::YearModel(QObject *parent)
12 : QAbstractListModel(parent)
13{
14 setYear(QDate::currentDate().year());
15}
16
17YearModel::~YearModel()
18{}
19
20int YearModel::year() const
21{
22 return m_year;
23}
24
25void YearModel::setYear(int year)
26{
27 if (m_year == year) {
28 return;
29 }
30 if (QCalendar().monthsInYear(m_year) != QCalendar().monthsInYear(year)) {
32 m_year = year;
34 Q_EMIT yearChanged();
35 return;
36 }
37 m_year = year;
38 Q_EMIT yearChanged();
39}
40
41int YearModel::rowCount(const QModelIndex &parent) const
42{
43 if (!parent.isValid()) {
44 return QCalendar().monthsInYear(m_year);
45 }
46 return 0;
47}
48
49QVariant YearModel::data(const QModelIndex &index, int role) const
50{
51 if (!checkIndex(index, CheckIndexOption::IndexIsValid)) {
52 return QVariant();
53 }
54 if (role == Qt::DisplayRole) {
55 // model indexes 0-11, months are 1-12
57 }
58 return QVariant();
59}
60
61
62#include "moc_yearmodel.cpp"
bool checkIndex(const QModelIndex &index, CheckIndexOptions options) const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
int monthsInYear(int year) const const
QDate currentDate()
QString monthName(int month, FormatType type) const const
int row() const const
Q_EMITQ_EMIT
QObject * parent() const const
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.