aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols/eventcalendar/eventmodel.h
blob: 62a30df33bd372078a459914aa0dd174151a6ab8 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef CONTACTMODEL_H
#define CONTACTMODEL_H

#include <QAbstractListModel>
#include <QDate>
#include <QtQml>

#include "event.h"

class SqlEventDatabase;

class EventModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(SqlEventDatabase *eventDatabase READ eventDatabase WRITE setEventDatabase NOTIFY eventDatabaseChanged)
    Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY dateChanged)
    QML_ELEMENT
    Q_MOC_INCLUDE("sqleventdatabase.h")

public:
    EventModel(QObject *parent = nullptr);

    enum ContactRole {
        NameRole = Qt::UserRole,
        StartDateRole,
        EndDateRole
    };
    Q_ENUM(ContactRole)

    SqlEventDatabase *eventDatabase();
    void setEventDatabase(SqlEventDatabase *eventDatabase);

    QDate date() const;
    void setDate(QDate date);

    int rowCount(const QModelIndex & = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    QHash<int, QByteArray> roleNames() const;

signals:
    void eventDatabaseChanged();
    void dateChanged();

private:
    bool isValid() const;
    void repopulate();

    SqlEventDatabase *m_eventDatabase = nullptr;
    QDate m_date;
    QVector<Event> m_events;
};

#endif // CONTACTMODEL_H