File indexing completed on 2024-09-15 04:13:44
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KOPENINGHOURS_INTERVALMODEL_H 0008 #define KOPENINGHOURS_INTERVALMODEL_H 0009 0010 #include "kopeninghours_export.h" 0011 0012 #include <KOpeningHours/OpeningHours> 0013 0014 #include <QAbstractListModel> 0015 #include <QDate> 0016 0017 #include <memory> 0018 0019 namespace KOpeningHours { 0020 0021 class IntervalModelPrivate; 0022 0023 /** Model for showing opening intervals per day. */ 0024 class KOPENINGHOURS_EXPORT IntervalModel : public QAbstractListModel 0025 { 0026 Q_OBJECT 0027 /** The opening hours expression shown in this model. */ 0028 Q_PROPERTY(KOpeningHours::OpeningHours openingHours READ openingHours WRITE setOpeningHours NOTIFY openingHoursChanged) 0029 /** Begin of the date range to show in this model. */ 0030 Q_PROPERTY(QDate beginDate READ beginDate WRITE setBeginDate NOTIFY beginDateChanged) 0031 /** End of the date range to show in this model. */ 0032 Q_PROPERTY(QDate endDate READ endDate WRITE setEndDate NOTIFY endDateChanged) 0033 0034 /** Description of the current status as a translated human-readable string. 0035 * See Display::currentState. 0036 * @deprecated use Display::currentState directly. 0037 */ 0038 Q_PROPERTY(QString currentState READ currentState NOTIFY openingHoursChanged) 0039 0040 public: 0041 explicit IntervalModel(QObject *parent = nullptr); 0042 ~IntervalModel() override; 0043 0044 OpeningHours openingHours() const; 0045 void setOpeningHours(const OpeningHours &oh); 0046 0047 QDate beginDate() const; 0048 void setBeginDate(QDate beginDate); 0049 QDate endDate() const; 0050 void setEndDate(QDate endDate); 0051 0052 enum Roles { 0053 IntervalsRole = Qt::UserRole, ///< All intervals in the current row. 0054 DateRole, ///< The date represented by the current row. 0055 DayBeginTimeRole, ///< Same as @c DateRole, but as a date/time object. 0056 ShortDayNameRole, ///< Localized short day name for the current row. 0057 IsTodayRole, ///< @c true if the row represents the current day. 0058 }; 0059 0060 int rowCount(const QModelIndex& parent = {}) const override; 0061 QVariant data(const QModelIndex &index, int role) const override; 0062 QHash<int, QByteArray> roleNames() const override; 0063 0064 /** Returns the day the week containing @p dt begins, based on the current locale. 0065 * This is useful to align the content of this model to a week. 0066 */ 0067 Q_INVOKABLE QDate beginOfWeek(const QDateTime &dt) const; 0068 0069 /** Localized formatting for time column headers. */ 0070 Q_INVOKABLE QString formatTimeColumnHeader(int hour, int minute) const; 0071 0072 Q_SIGNALS: 0073 void openingHoursChanged(); 0074 void beginDateChanged(); 0075 void endDateChanged(); 0076 0077 private: 0078 [[deprecated("use Display::currentState directly")]] QString currentState() const; 0079 std::unique_ptr<IntervalModelPrivate> d; 0080 }; 0081 0082 } 0083 0084 #endif // KOPENINGHOURS_INTERVALMODEL_H