libosmscout 1.1.1
Loading...
Searching...
No Matches
OpeningHoursModel.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_CLIENT_QT_OPENING_HOURS_MODEL
2#define OSMSCOUT_CLIENT_QT_OPENING_HOURS_MODEL
3
4/*
5 OSMScout - a Qt backend for libosmscout and libosmscout-map
6 Copyright (C) 2023 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
24
26
27#include <QObject>
28#include <QDateTime>
29#include <QAbstractListModel>
30#include <QLocale>
31
32namespace osmscout {
33
39class OSMSCOUT_CLIENT_QT_API OpeningHoursModel : public QAbstractListModel
40{
41 Q_OBJECT
42 Q_PROPERTY(QString openingHours READ getOpeningHours WRITE setOpeningHours NOTIFY updated)
43 Q_PROPERTY(QStringList today READ getToday NOTIFY updated)
44
45signals:
46 void updated();
47 void parseError();
48
49public:
50 enum Roles {
51 DayRole = Qt::UserRole,
52 ShortDayRole = Qt::UserRole+1,
53 TimeIntervalsRole = Qt::UserRole+2,
54 IsTodayRole = Qt::UserRole+3,
55 };
56 Q_ENUM(Roles)
57
58public:
59 OpeningHoursModel() = default;
62
63 ~OpeningHoursModel() override = default;
64
67
68 Q_INVOKABLE int inline rowCount(const QModelIndex &parent = QModelIndex()) const override
69 {
70 Q_UNUSED(parent);
71 return model.size();
72 };
73
74 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
75 QHash<int, QByteArray> roleNames() const override;
76 Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override;
77
78 QStringList getToday() const;
79
80 QString getOpeningHours() const
81 {
82 return rawOpeningHours;
83 }
84
85 void setOpeningHours(const QString &openingHours);
86
87private:
88 QStringList intervalStrings(const std::vector<OpeningHours::TimeInterval> &intervals) const;
89 QString dayName(OpeningHours::WeekDay weekDay) const;
90 QString shortDayName(OpeningHours::WeekDay weekDay) const;
91
92private:
93 QString rawOpeningHours;
94 std::vector<OpeningHours::Rule> model;
95 QLocale locale;
96};
97}
98
99#endif /* OSMSCOUT_CLIENT_QT_OPENING_HOURS_MODEL */
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
WeekDay
Definition OpeningHours.h:42
QHash< int, QByteArray > roleNames() const override
OpeningHoursModel & operator=(const OpeningHoursModel &)=delete
QStringList today
Definition OpeningHoursModel.h:43
Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition OpeningHoursModel.h:68
QString openingHours
Definition OpeningHoursModel.h:42
Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override
QStringList getToday() const
QString getOpeningHours() const
Definition OpeningHoursModel.h:80
Roles
Definition OpeningHoursModel.h:50
@ IsTodayRole
Definition OpeningHoursModel.h:54
@ ShortDayRole
Definition OpeningHoursModel.h:52
@ DayRole
Definition OpeningHoursModel.h:51
@ TimeIntervalsRole
Definition OpeningHoursModel.h:53
OpeningHoursModel(OpeningHoursModel &&)=delete
~OpeningHoursModel() override=default
void setOpeningHours(const QString &openingHours)
OpeningHoursModel(const OpeningHoursModel &)=delete
OpeningHoursModel & operator=(OpeningHoursModel &&)=delete
Definition Area.h:39