File indexing completed on 2024-04-21 05:30:54

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef APPLETSMODEL_H
0007 #define APPLETSMODEL_H
0008 
0009 // local
0010 #include "../../data/appletdata.h"
0011 
0012 // Qt
0013 #include <QAbstractTableModel>
0014 #include <QModelIndex>
0015 #include <QList>
0016 
0017 namespace Latte {
0018 namespace Settings {
0019 namespace Model {
0020 
0021 class Applets : public QAbstractTableModel
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     enum AppletsRoles
0027     {
0028         IDROLE = Qt::UserRole + 1,
0029         NAMEROLE,
0030         ICONROLE,
0031         SELECTEDROLE,
0032         SORTINGROLE,
0033         DESCRIPTIONROLE
0034     };
0035 
0036     enum Columns
0037     {
0038         NAMECOLUMN = 0
0039     };
0040 
0041     explicit Applets(QObject *parent);
0042     ~Applets();
0043 
0044     bool hasChangedData() const;
0045     bool inDefaultValues() const;
0046 
0047     int rowCount() const;
0048     int rowCount(const QModelIndex &parent) const override;
0049     int columnCount(const QModelIndex &parent) const override;
0050 
0051     int row(const QString &id);
0052 
0053     QVariant data(const QModelIndex &index, int role) const override;
0054     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0055     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0056     Qt::ItemFlags flags(const QModelIndex &index) const override;
0057 
0058     void setData(const Latte::Data::AppletsTable &applets);
0059     void setSelected(const Latte::Data::AppletsTable &applets);
0060 
0061     Latte::Data::AppletsTable selectedApplets();
0062 
0063     void deselectAll();
0064     void reset();
0065     void selectAll();
0066 
0067 signals:
0068     void appletsDataChanged();
0069 
0070 private:
0071     void initDefaults();
0072 
0073     void clear();
0074 
0075 private:
0076     Latte::Data::AppletsTable o_applets;
0077     Latte::Data::AppletsTable c_applets;
0078 
0079     QList<QString> m_appletsWithNoPersonalData;
0080 };
0081 
0082 }
0083 }
0084 }
0085 
0086 #endif