KOpeningHours

intervalmodel.h
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KOPENINGHOURS_INTERVALMODEL_H
8#define KOPENINGHOURS_INTERVALMODEL_H
9
10#include "kopeninghours_export.h"
11
12#include <KOpeningHours/OpeningHours>
13
14#include <QAbstractListModel>
15#include <QDate>
16
17#include <memory>
18
19namespace KOpeningHours {
20
21class IntervalModelPrivate;
22
23/** Model for showing opening intervals per day. */
24class KOPENINGHOURS_EXPORT IntervalModel : public QAbstractListModel
25{
26 Q_OBJECT
27 /** The opening hours expression shown in this model. */
28 Q_PROPERTY(KOpeningHours::OpeningHours openingHours READ openingHours WRITE setOpeningHours NOTIFY openingHoursChanged)
29 /** Begin of the date range to show in this model. */
30 Q_PROPERTY(QDate beginDate READ beginDate WRITE setBeginDate NOTIFY beginDateChanged)
31 /** End of the date range to show in this model. */
32 Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged)
33
34 /** Description of the current status as a translated human-readable string.
35 * See Display::currentState.
36 * @deprecated use Display::currentState directly.
37 */
38 Q_PROPERTY(QString currentState READ currentState NOTIFY openingHoursChanged)
39
40public:
41 explicit IntervalModel(QObject *parent = nullptr);
42 ~IntervalModel() override;
43
44 OpeningHours openingHours() const;
45 void setOpeningHours(const OpeningHours &oh);
46
47 QDate beginDate() const;
48 void setBeginDate(QDate beginDate);
49 QDate endDate() const;
50 void setEndDate(QDate endDate);
51
52 enum Roles {
53 IntervalsRole = Qt::UserRole, ///< All intervals in the current row.
54 DateRole, ///< The date represented by the current row.
55 DayBeginTimeRole, ///< Same as @c DateRole, but as a date/time object.
56 ShortDayNameRole, ///< Localized short day name for the current row.
57 IsTodayRole, ///< @c true if the row represents the current day.
58 };
59
60 int rowCount(const QModelIndex& parent = {}) const override;
61 QVariant data(const QModelIndex &index, int role) const override;
62 QHash<int, QByteArray> roleNames() const override;
63
64 /** Returns the day the week containing @p dt begins, based on the current locale.
65 * This is useful to align the content of this model to a week.
66 */
67 Q_INVOKABLE QDate beginOfWeek(const QDateTime &dt) const;
68
69 /** Localized formatting for time column headers. */
70 Q_INVOKABLE QString formatTimeColumnHeader(int hour, int minute) const;
71
72Q_SIGNALS:
73 void openingHoursChanged();
74 void beginDateChanged();
75 void endDateChanged();
76
77private:
78 [[deprecated("use Display::currentState directly")]] QString currentState() const;
79 std::unique_ptr<IntervalModelPrivate> d;
80};
81
82}
83
84#endif // KOPENINGHOURS_INTERVALMODEL_H
Model for showing opening intervals per day.
@ DateRole
The date represented by the current row.
@ IsTodayRole
true if the row represents the current day.
@ DayBeginTimeRole
Same as DateRole, but as a date/time object.
@ ShortDayNameRole
Localized short day name for the current row.
An OSM opening hours specification.
OSM opening hours parsing and evaluation.
Definition display.h:16
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.