File indexing completed on 2025-01-05 05:23:46

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2022 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef STRUCTUREENABLEDLIST_HPP
0010 #define STRUCTUREENABLEDLIST_HPP
0011 
0012 // Qt
0013 #include <QVector>
0014 #include <QHash>
0015 
0016 class QStringList;
0017 
0018 class StructureEnabledData
0019 {
0020 public:
0021     explicit StructureEnabledData(const QString& id, const QString& structure);
0022     StructureEnabledData(const StructureEnabledData& other) = default;
0023 
0024 public:
0025     QString id;
0026     QString structure;
0027     bool isEnabled;
0028 };
0029 
0030 inline StructureEnabledData::StructureEnabledData(const QString& id, const QString& structure)
0031     : id(id)
0032     , structure(structure)
0033     , isEnabled(true)
0034 {
0035 }
0036 
0037 Q_DECLARE_TYPEINFO(StructureEnabledData, Q_MOVABLE_TYPE);
0038 
0039 
0040 // Any actively disabled entries are keot in place,
0041 // in case it gets enabled again during editing
0042 // so does not lose any previous position and structures.
0043 class StructureEnabledList
0044 {
0045 public:
0046     StructureEnabledList() = default;
0047 
0048 public:
0049     void setEnabledStructures(const QStringList& enabledStructures);
0050     // drop no longer existing structures from the enabled list
0051     void removeStructures(const QHash<QString, QStringList>& structures);
0052 
0053     void setEnabled(const QString& id, bool  isEnabled);
0054 
0055     bool isEnabled(const QString& id) const;
0056     QStringList toQStringList() const;
0057 
0058     QVector<StructureEnabledData>::ConstIterator begin() const;
0059     QVector<StructureEnabledData>::ConstIterator end() const;
0060 
0061 private:
0062     QVector<StructureEnabledData> m_enabledList;
0063 };
0064 
0065 inline QVector<StructureEnabledData>::ConstIterator StructureEnabledList::begin() const
0066 {
0067     return m_enabledList.begin();
0068 }
0069 
0070 inline QVector<StructureEnabledData>::ConstIterator StructureEnabledList::end() const
0071 {
0072     return m_enabledList.end();
0073 }
0074 
0075 #endif