File indexing completed on 2024-05-12 04:39:21

0001 /*
0002     SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef CLANGTIDY_CHECKLISTMODEL_H
0008 #define CLANGTIDY_CHECKLISTMODEL_H
0009 
0010 // plugin
0011 #include "checkgroup.h"
0012 // Qt
0013 #include <QAbstractItemModel>
0014 
0015 namespace ClangTidy
0016 {
0017 
0018 class CheckSet;
0019 
0020 class CheckListModel : public QAbstractItemModel
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     enum Roles {
0026         EffectiveEnabledStateRole = Qt::UserRole+1,
0027         HasExplicitEnabledStateRole
0028     };
0029 
0030     enum ColumIds {
0031         NameColumnId = 0,
0032         CountColumnId = 1
0033     };
0034 
0035 public:
0036     explicit CheckListModel(QObject* parent = nullptr);
0037     ~CheckListModel() override;
0038 
0039 public: // QAbstractItemModel API
0040     QVariant data(const QModelIndex& index, int role) const override;
0041     int columnCount(const QModelIndex& parent) const override;
0042     int rowCount(const QModelIndex& parent) const override;
0043     QModelIndex parent(const QModelIndex& child) const override;
0044     QModelIndex index(int row, int column, const QModelIndex& parent) const override;
0045     Qt::ItemFlags flags(const QModelIndex& index) const override;
0046     bool setData(const QModelIndex& index, const QVariant& value, int role) override;
0047 
0048 public:
0049     void setCheckSet(const CheckSet* checkSet);
0050     void setEnabledChecks(const QStringList& enabledChecks);
0051     QStringList enabledChecks() const;
0052     void setEditable(bool editable);
0053 
0054 Q_SIGNALS:
0055     void enabledChecksChanged();
0056 
0057 private:
0058     int childCount(const CheckGroup* checkGroup) const;
0059     CheckGroup* checkGroup(const QModelIndex& index) const;
0060     void emitSubGroupDataChanged(const QModelIndex& subGroupIndex);
0061 
0062 private:
0063     const CheckSet* m_checkSet = nullptr;
0064 
0065     QScopedPointer<CheckGroup> m_rootCheckGroup;
0066     bool m_isDefault = true;
0067     bool m_isEditable = true;
0068 };
0069 
0070 }
0071 
0072 #endif // CHECKLISTMODEL_H