KOpeningHours

intervalmodel.h
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
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 
19 namespace KOpeningHours {
20 
21 class IntervalModelPrivate;
22 
23 /** Model for showing opening intervals per day. */
24 class 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  */
37  Q_PROPERTY(QString currentState READ currentState NOTIFY openingHoursChanged)
38 
39 public:
40  explicit IntervalModel(QObject *parent = nullptr);
41  ~IntervalModel() override;
42 
43  OpeningHours openingHours() const;
44  void setOpeningHours(const OpeningHours &oh);
45 
46  QDate beginDate() const;
47  void setBeginDate(QDate beginDate);
48  QDate endDate() const;
49  void setEndDate(QDate endDate);
50 
51  enum Roles {
52  IntervalsRole = Qt::UserRole, ///< All intervals in the current row.
53  DateRole, ///< The date represented by the current row.
54  DayBeginTimeRole, ///< Same as @c DateRole, but as a date/time object.
55  ShortDayNameRole, ///< Localized short day name for the current row.
56  IsTodayRole, ///< @c true if the row represents the current day.
57  };
58 
59  int rowCount(const QModelIndex& parent = {}) const override;
60  QVariant data(const QModelIndex &index, int role) const override;
61  QHash<int, QByteArray> roleNames() const override;
62 
63  /** Returns the day the week containing @p dt begins, based on the current locale.
64  * This is useful to align the content of this model to a week.
65  */
66  Q_INVOKABLE QDate beginOfWeek(const QDateTime &dt) const;
67 
68  /** Localized formatting for time column headers. */
69  Q_INVOKABLE QString formatTimeColumnHeader(int hour, int minute) const;
70 
71 Q_SIGNALS:
72  void openingHoursChanged();
73  void beginDateChanged();
74  void endDateChanged();
75 
76 private:
77  QString currentState() const;
78  std::unique_ptr<IntervalModelPrivate> d;
79 };
80 
81 }
82 
83 #endif // KOPENINGHOURS_INTERVALMODEL_H
UserRole
@ DayBeginTimeRole
Same as DateRole, but as a date/time object.
Definition: intervalmodel.h:54
@ ShortDayNameRole
Localized short day name for the current row.
Definition: intervalmodel.h:55
@ DateRole
The date represented by the current row.
Definition: intervalmodel.h:53
An OSM opening hours specification.
Definition: openinghours.h:32
Model for showing opening intervals per day.
Definition: intervalmodel.h:24
OSM opening hours parsing and evaluation.
Definition: display.h:14
@ IsTodayRole
true if the row represents the current day.
Definition: intervalmodel.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Jun 28 2022 03:54:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.