File indexing completed on 2024-12-08 10:56:44

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef SCREENSMODEL_H
0008 #define SCREENSMODEL_H
0009 
0010 // local
0011 #include "../../data/screendata.h"
0012 
0013 // Qt
0014 #include <QAbstractTableModel>
0015 #include <QModelIndex>
0016 #include <QObject>
0017 
0018 namespace Latte {
0019 namespace Settings {
0020 namespace Model {
0021 
0022 class Screens : public QAbstractTableModel
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     enum ScreensRoles
0028     {
0029         IDROLE = Qt::UserRole + 1,
0030         ISSCREENACTIVEROLE,
0031         ISSELECTEDROLE,
0032         SCREENDATAROLE,
0033         SORTINGROLE
0034     };
0035 
0036     enum Columns
0037     {
0038         SCREENCOLUMN = 0,
0039         LASTCOLUMN
0040     };
0041 
0042     enum SortingPriority
0043     {
0044         NORMALPRIORITY = 10,
0045         MEDIUMPRIORITY = 100,
0046         HIGHPRIORITY = 1000,
0047         HIGHESTPRIORITY = 10000
0048     };
0049 
0050     explicit Screens(QObject *parent);
0051     ~Screens();
0052 
0053     bool hasChangedData() const;
0054     bool hasChecked() const;
0055     bool inDefaultValues() const;
0056 
0057     int rowCount() const;
0058     int rowCount(const QModelIndex &parent) const override;
0059     int columnCount(const QModelIndex &parent) const override;
0060 
0061     int row(const QString &id);
0062 
0063     QVariant data(const QModelIndex &index, int role) const override;
0064     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0065     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0066     Qt::ItemFlags flags(const QModelIndex &index) const override;
0067 
0068     void setData(const Latte::Data::ScreensTable &screens);
0069     void setSelected(const Latte::Data::ScreensTable &screens);
0070 
0071     Latte::Data::ScreensTable checkedScreens();
0072 
0073     void deselectAll();
0074     void reset();    
0075 
0076 signals:
0077     void screenDataChanged();
0078 
0079 private:
0080     void initDefaults();
0081 
0082     void clear();
0083 
0084     QString sortableId(const QString &id) const;
0085     QString sortableText(const int &priority, const QString &text) const;
0086 
0087 private:
0088     Latte::Data::ScreensTable o_screens;
0089     Latte::Data::ScreensTable c_screens;
0090 
0091 };
0092 
0093 }
0094 }
0095 }
0096 
0097 #endif