Warning, file /utilities/daykountdown/src/kountdownmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com> 0003 // 0004 // SPDX-LicenseRef: GPL-3.0-or-later 0005 0006 #pragma once 0007 0008 #include <QAbstractListModel> 0009 #include <QSqlDatabase> 0010 #include <QSqlQuery> 0011 #include <QSqlTableModel> 0012 0013 /** 0014 * @brief Store all the kountdowns. 0015 */ 0016 class KountdownModel : public QSqlTableModel 0017 { 0018 // Macro that enables wide-ranging object functionality provided by Qt 0019 Q_OBJECT 0020 0021 public: 0022 enum Roles { 0023 NameRole = Qt::UserRole + 1, 0024 DescriptionRole, 0025 DateRole, 0026 DateInMsRole, 0027 ColourRole, 0028 }; 0029 0030 // Used for more semantic arguments to model sorting function 0031 enum SortTypes { 0032 CreationAsc, 0033 CreationDesc, 0034 AlphabeticalAsc, 0035 AlphabeticalDesc, 0036 DateAsc, 0037 DateDesc, 0038 }; 0039 Q_ENUMS(SortTypes); 0040 0041 public: 0042 // Constructor function 0043 KountdownModel(QObject *parent = nullptr); 0044 0045 // Destructor function 0046 virtual ~KountdownModel() override = default; 0047 0048 QHash<int, QByteArray> roleNames() const override; 0049 QVariant data(const QModelIndex &index, int role) const override; 0050 0051 // Q_INVOKABLE methods can be called within the QML 0052 Q_INVOKABLE bool addKountdown(const QString& name, const QString& description, const QDateTime& date, QString colour); 0053 Q_INVOKABLE bool editKountdown(int index, const QString& name, const QString& description, const QDateTime& date, QString colour); 0054 Q_INVOKABLE bool removeKountdown(int index); 0055 Q_INVOKABLE bool removeAllKountdowns(); 0056 Q_INVOKABLE void sortModel(int sort_by); 0057 0058 private: 0059 QSqlDatabase m_db; 0060 };