File indexing completed on 2024-05-05 07:51:18
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2016 by Sandro S. Andrade <sandroandrade@kde.org> 0004 ** 0005 ** This program is free software; you can redistribute it and/or 0006 ** modify it under the terms of the GNU General Public License as 0007 ** published by the Free Software Foundation; either version 2 of 0008 ** the License or (at your option) version 3 or any later version 0009 ** accepted by the membership of KDE e.V. (or its successor approved 0010 ** by the membership of KDE e.V.), which shall act as a proxy 0011 ** defined in Section 14 of version 3 of the license. 0012 ** 0013 ** This program is distributed in the hope that it will be useful, 0014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 ** GNU General Public License for more details. 0017 ** 0018 ** You should have received a copy of the GNU General Public License 0019 ** along with this program. If not, see <http://www.gnu.org/licenses/>. 0020 ** 0021 ****************************************************************************/ 0022 0023 #ifndef MINUET_EXERCISECONTROLLER_H 0024 #define MINUET_EXERCISECONTROLLER_H 0025 0026 #include <interfaces/iexercisecontroller.h> 0027 0028 #include <QJsonObject> 0029 #include <QStringList> 0030 0031 namespace Minuet 0032 { 0033 class Core; 0034 0035 class ExerciseController : public IExerciseController 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 explicit ExerciseController(QObject *parent = nullptr); 0041 virtual ~ExerciseController() = default; 0042 0043 bool initialize(Core *core); 0044 virtual QString errorString() const override; 0045 0046 Q_INVOKABLE unsigned int chosenRootNote() const; 0047 0048 virtual QJsonArray exercises() const override; 0049 0050 public Q_SLOTS: 0051 virtual void randomlySelectExerciseOptions() override; 0052 0053 private: 0054 bool mergeJsonFiles(const QString directoryName, QJsonObject &targetObject, 0055 bool applyDefinitionsFlag = false, QString commonKey = nullptr, 0056 QString mergeKey = nullptr); 0057 QJsonArray applyDefinitions(QJsonArray exercises, QJsonArray definitions, 0058 QJsonObject collectedProperties = QJsonObject()); 0059 enum DefinitionFilteringMode { AndFiltering = 0, OrFiltering }; 0060 static void filterDefinitions(QJsonArray &definitions, QJsonObject &exerciseObject, 0061 const QString &filterTagsKey, 0062 DefinitionFilteringMode definitionFilteringMode); 0063 QJsonArray mergeJsonArrays(QJsonArray oldFile, QJsonArray newFile, QString commonKey = nullptr, 0064 QString mergeKey = nullptr); 0065 0066 QJsonObject m_exercises; 0067 QJsonObject m_definitions; 0068 unsigned int m_chosenRootNote; 0069 QString m_errorString; 0070 }; 0071 0072 } 0073 0074 #endif // MINUET_EXERCISECONTROLLER_H