File indexing completed on 2024-05-05 04:39:18

0001 /*
0002     SPDX-FileCopyrightText: 2020 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVCLAZY_CHECKSETSELECTIONLISTMODEL_H
0008 #define KDEVCLAZY_CHECKSETSELECTIONLISTMODEL_H
0009 
0010 // plugin
0011 #include "checksetselection.h"
0012 // Qt
0013 #include <QAbstractItemModel>
0014 #include <QVector>
0015 #include <QSet>
0016 
0017 namespace Clazy {
0018 class CheckSetSelectionManager;
0019 
0020 class CheckSetSelectionListModel : public QAbstractItemModel
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     explicit CheckSetSelectionListModel(CheckSetSelectionManager* checkSetSelectionManager,
0026                                         QObject* parent = nullptr);
0027     ~CheckSetSelectionListModel() override;
0028 
0029 public: // QAbstractItemModel API
0030     int rowCount(const QModelIndex& parent = {}) const override;
0031     int columnCount(const QModelIndex& parent = {}) const override;
0032     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0033     QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override;
0034     QModelIndex parent(const QModelIndex& index) const override;
0035 
0036 public:
0037     void reload();
0038     void store() const;
0039 
0040 public:
0041     bool hasCheckSetSelection(const QString& name) const;
0042     QString checkSetSelectionId(int row) const;
0043     QString checkSetSelectionName(int row) const;
0044     QString checkSetSelectionAsString(int row) const;
0045     int row(const QString& checkSetSelectionId) const;
0046     int defaultCheckSetSelectionRow() const;
0047 
0048     /// @return row of added selection
0049     int addCheckSetSelection(const QString& name);
0050     int cloneCheckSetSelection(const QString& name, int row);
0051     void removeCheckSetSelection(int row);
0052     void setDefaultCheckSetSelection(int row);
0053     void setName(int row, const QString& name);
0054     void setSelection(int row, const QString& selection);
0055 
0056 Q_SIGNALS:
0057     void defaultCheckSetSelectionChanged(const QString& checkSetSelectionId);
0058     void checkSetSelectionChanged(const QString& checkSetSelectionId);
0059 
0060 private:
0061     QString checkSetSelectionId(const QModelIndex& index) const;
0062 
0063 private:
0064     CheckSetSelectionManager* const m_checkSetSelectionManager;
0065 
0066     QVector<CheckSetSelection> m_checkSetSelections;
0067     QString m_defaultCheckSetSelectionId;
0068 
0069     // tracking changed data
0070     mutable QVector<QString> m_added;
0071     mutable QSet<QString> m_edited;
0072     mutable QVector<QString> m_removed;
0073     mutable bool m_defaultChanged = false;
0074 };
0075 
0076 }
0077 
0078 #endif