Fluid
Loading...
Searching...
No Matches
yearmodel.h
Go to the documentation of this file.
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2018 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#pragma once
16
17#include <QAbstractListModel>
18#include <QDate>
19#include <QtQml>
20
21class YearModel : public QAbstractListModel
22{
23 Q_OBJECT
24 Q_PROPERTY(QDate from READ from WRITE setFrom NOTIFY fromChanged FINAL)
25 Q_PROPERTY(QDate to READ to WRITE setTo NOTIFY toChanged FINAL)
26 Q_PROPERTY(int count READ rowCount NOTIFY countChanged FINAL)
27 QML_ELEMENT
28 QML_UNCREATABLE("Cannot instantiate YearModel")
29 Q_DISABLE_COPY(YearModel)
30public:
31 explicit YearModel(QObject *parent = nullptr);
32
33 QDate from() const;
34 void setFrom(const QDate &date);
35
36 QDate to() const;
37 void setTo(const QDate &date);
38
39 QHash<int, QByteArray> roleNames() const override;
40 QVariant data(const QModelIndex &index, int role) const override;
41 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
42
43 Q_INVOKABLE int get(int index) const;
44
45 void reset();
46
47Q_SIGNALS:
49 void toChanged();
51
52private:
53 QDate m_from;
54 QDate m_to;
55 QVector<int> m_list;
56};
57
58QML_DECLARE_TYPE(YearModel)
59
Definition yearmodel.h:22
QDate from
Definition yearmodel.h:24
QDate to
Definition yearmodel.h:25
void toChanged()
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition yearmodel.cpp:69
QHash< int, QByteArray > roleNames() const override
Definition yearmodel.cpp:52
void countChanged()
void setFrom(const QDate &date)
Definition yearmodel.cpp:29
void fromChanged()
QVariant data(const QModelIndex &index, int role) const override
Definition yearmodel.cpp:59
void setTo(const QDate &date)
Definition yearmodel.cpp:43
Q_INVOKABLE int get(int index) const
Definition yearmodel.cpp:75
void reset()
Definition yearmodel.cpp:82
int count
Definition yearmodel.h:26