File indexing completed on 2024-11-10 05:11:09

0001 /*
0002  * Copyright 2018 by Marco Martin <mart@kde.org>
0003  *
0004  * Licensed under the Apache License, Version 2.0 (the "License");
0005  * you may not use this file except in compliance with the License.
0006  * You may obtain a copy of the License at
0007  *
0008  *    http://www.apache.org/licenses/LICENSE-2.0
0009  *
0010  * Unless required by applicable law or agreed to in writing, software
0011  * distributed under the License is distributed on an "AS IS" BASIS,
0012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013  * See the License for the specific language governing permissions and
0014  * limitations under the License.
0015  *
0016  */
0017 
0018 #pragma once
0019 
0020 #include <QAbstractListModel>
0021 #include <QSortFilterProxyModel>
0022 
0023 class AbstractDelegate;
0024 class DelegatesModel;
0025 
0026 class ActiveSkillsModel : public QAbstractListModel
0027 {
0028     Q_OBJECT
0029     Q_PROPERTY(int activeIndex READ activeIndex NOTIFY activeIndexChanged)
0030     Q_PROPERTY(QStringList blackList READ blackList WRITE setBlackList NOTIFY blackListChanged)
0031     Q_PROPERTY(QStringList whiteList READ whiteList WRITE setWhiteList NOTIFY whiteListChanged)
0032 
0033 public:
0034     enum Roles {
0035         SkillId = Qt::UserRole + 1,
0036         Delegates
0037     };
0038 
0039     explicit ActiveSkillsModel(QObject *parent = nullptr);
0040     virtual ~ActiveSkillsModel();
0041 
0042     int activeIndex() const;
0043 
0044     QStringList blackList() const;
0045     void setBlackList(const QStringList &list);
0046 
0047     QStringList whiteList() const;
0048     void setWhiteList(const QStringList &list);
0049 
0050     void checkGuiActivation(const QString &skillId);
0051     bool skillAllowed(const QString skillId) const;
0052 
0053     /**
0054      * Insert new skills in the model, at a given position
0055      */
0056     void insertSkills(int position, const QStringList &skillList);
0057 
0058     /**
0059      * @returns the index for a skill, an invalid QModelIndex() if not found
0060      */
0061     QModelIndex skillIndex(const QString &skillId);
0062 
0063     QStringList activeSkills() const;
0064 
0065     DelegatesModel *delegatesModelForSkill(const QString &skillId);
0066     QHash<QString, DelegatesModel*> delegatesModels() const;
0067 
0068 //REIMPLEMENTED
0069     bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
0070     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0071     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0072     QVariant data(const QModelIndex &index, int role = SkillId) const override;
0073     QHash<int, QByteArray> roleNames() const override;
0074 
0075 Q_SIGNALS:
0076     void activeIndexChanged();
0077     void blackListChanged();
0078     void whiteListChanged();
0079     void skillActivated(const QString &skillId);
0080     void blacklistedSkillActivated(const QString &skillId);
0081 
0082 private:
0083     void syncActiveIndex();
0084     int m_activeIndex = -1;
0085     QList<QString> m_skills;
0086     QList<QString> m_blackList;
0087     QList<QString> m_whiteList;
0088     //TODO
0089     QHash<QString, DelegatesModel*> m_delegatesModels;
0090 };
0091 
0092