File indexing completed on 2024-04-14 14:08:45
0001 /* GCompris - ActivityInfoTree.h 0002 * 0003 * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> 0007 * 0008 * SPDX-License-Identifier: GPL-3.0-or-later 0009 */ 0010 #ifndef ACTIVITYINFOTREE_H 0011 #define ACTIVITYINFOTREE_H 0012 0013 #include "ActivityInfo.h" 0014 #include <QQmlEngine> 0015 #include <QList> 0016 #include <QDir> 0017 0018 class ActivityInfoTree : public QObject 0019 { 0020 Q_OBJECT 0021 Q_PROPERTY(ActivityInfo *rootMenu READ getRootMenu CONSTANT) 0022 Q_PROPERTY(QQmlListProperty<ActivityInfo> menuTreeFull READ getMenuTreeFull CONSTANT) 0023 Q_PROPERTY(QQmlListProperty<ActivityInfo> menuTree READ menuTree NOTIFY menuTreeChanged) 0024 Q_PROPERTY(ActivityInfo *currentActivity READ getCurrentActivity WRITE setCurrentActivity NOTIFY currentActivityChanged) 0025 Q_PROPERTY(QVariantList characters READ allCharacters CONSTANT) 0026 /** 0027 * Specify the activity to start on when running GCompris if --launch is specified in command-line. 0028 */ 0029 Q_PROPERTY(QString startingActivity MEMBER m_startingActivity NOTIFY startingActivityChanged) 0030 Q_PROPERTY(int startingLevel MEMBER m_startingLevel NOTIFY startingLevelChanged) 0031 public: 0032 static ActivityInfoTree *getInstance() 0033 { 0034 if (!m_instance) { 0035 m_instance = new ActivityInfoTree(); 0036 } 0037 return m_instance; 0038 } 0039 QQmlListProperty<ActivityInfo> menuTree(); 0040 QQmlListProperty<ActivityInfo> getMenuTreeFull(); 0041 ActivityInfo *getRootMenu() const; 0042 void setRootMenu(ActivityInfo *rootMenu); 0043 ActivityInfo *menuTree(int) const; 0044 void setCurrentActivity(ActivityInfo *currentActivity); 0045 ActivityInfo *getCurrentActivity() const; 0046 void menuTreeAppend(ActivityInfo *menu); 0047 void menuTreeAppend(QQmlEngine *engine, 0048 const QDir &menuDir, const QString &menuFile); 0049 void sortByDifficultyThenName(bool emitChanged = true); 0050 QVariantList allCharacters(); 0051 0052 static void setStartingActivity(const QString &startingActivity, int startingLevel) 0053 { 0054 m_startingActivity = startingActivity; 0055 m_startingLevel = startingLevel; 0056 } 0057 0058 protected: 0059 static ActivityInfoTree *m_instance; 0060 0061 public Q_SLOTS: 0062 Q_INVOKABLE void minMaxFiltersChanged(quint32 levelMin, quint32 levelMax, bool doSynchronize = true); 0063 Q_INVOKABLE void filterByTag(const QString &tag, const QString &category = "", bool emitChanged = true); 0064 Q_INVOKABLE void resetLevels(const QString &activity); 0065 0066 protected Q_SLOTS: 0067 Q_INVOKABLE void filterEnabledActivities(bool emitChanged = true); 0068 // create a tree from the whole list of activities with the activities created between the two versions 0069 Q_INVOKABLE void filterCreatedWithinVersions(int firstVersion, int lastVersion, 0070 bool emitChanged = true); 0071 Q_INVOKABLE void filterBySearch(const QString &text); 0072 Q_INVOKABLE void filterByDifficulty(quint32 levelMin, quint32 levelMax); 0073 Q_INVOKABLE void setCurrentActivityFromName(const QString &name); 0074 0075 Q_SIGNALS: 0076 void menuTreeChanged(); 0077 void currentActivityChanged(); 0078 void allCharactersChanged(); 0079 void startingActivityChanged(); 0080 void startingLevelChanged(); 0081 0082 private: 0083 explicit ActivityInfoTree(QObject *parent = nullptr); 0084 0085 // this is the full activity list, it never changes 0086 QList<ActivityInfo *> m_menuTreeFull; 0087 // represents the Menu view and can be filtered 0088 QList<ActivityInfo *> m_menuTree; 0089 ActivityInfo *m_rootMenu; 0090 ActivityInfo *m_currentActivity; 0091 QVariantList m_keyboardCharacters; 0092 static QString m_startingActivity; 0093 static int m_startingLevel; 0094 0095 static QList<ActivityInfo>::size_type menuTreeCount(QQmlListProperty<ActivityInfo> *property); 0096 static ActivityInfo *menuTreeAt(QQmlListProperty<ActivityInfo> *property, QList<ActivityInfo>::size_type index); 0097 0098 static QList<ActivityInfo>::size_type menuTreeFullCount(QQmlListProperty<ActivityInfo> *property); 0099 static ActivityInfo *menuTreeFullAt(QQmlListProperty<ActivityInfo> *property, QList<ActivityInfo>::size_type index); 0100 0101 static QStringList getActivityList(); 0102 0103 public: 0104 static void registerResources(); 0105 static QObject *menuTreeProvider(QQmlEngine *engine, QJSEngine *scriptEngine); 0106 void exportAsSQL(); 0107 void listActivities(); 0108 }; 0109 0110 #endif // ACTIVITYINFOTREE_H