Commit 505fc748 authored by Johnny Jazeix's avatar Johnny Jazeix

core, hide datasets if not in range of difficulty

parent d29d5f21
...@@ -234,12 +234,18 @@ void ActivityInfo::setLevels(const QStringList &levels) ...@@ -234,12 +234,18 @@ void ActivityInfo::setLevels(const QStringList &levels)
void ActivityInfo::fillDatasets(QQmlEngine *engine) void ActivityInfo::fillDatasets(QQmlEngine *engine)
{ {
quint32 levelMin = ApplicationSettings::getInstance()->filterLevelMin();
quint32 levelMax = ApplicationSettings::getInstance()->filterLevelMax();
for(const QString &level: m_levels) { for(const QString &level: m_levels) {
QString url = QString("qrc:/gcompris/src/activities/%1/resource/%2/Data.qml").arg(m_name.split('/')[0]).arg(level); QString url = QString("qrc:/gcompris/src/activities/%1/resource/%2/Data.qml").arg(m_name.split('/')[0]).arg(level);
QQmlComponent componentRoot(engine, QUrl(url)); QQmlComponent componentRoot(engine, QUrl(url));
QObject *objectRoot = componentRoot.create(); QObject *objectRoot = componentRoot.create();
if(objectRoot != nullptr) { if(objectRoot != nullptr) {
Dataset *dataset = qobject_cast<Dataset*>(objectRoot); Dataset *dataset = qobject_cast<Dataset*>(objectRoot);
if(levelMin > dataset->difficulty() || levelMax < dataset->difficulty()) {
dataset->setEnabled(false);
}
m_datasets[level] = dataset; m_datasets[level] = dataset;
} else { } else {
qDebug() << "ERROR: failed to load " << m_name << " " << componentRoot.errors(); qDebug() << "ERROR: failed to load " << m_name << " " << componentRoot.errors();
...@@ -304,10 +310,14 @@ void ActivityInfo::enableDatasetsBetweenDifficulties(quint32 levelMin, quint32 l ...@@ -304,10 +310,14 @@ void ActivityInfo::enableDatasetsBetweenDifficulties(quint32 levelMin, quint32 l
Dataset *dataset = it.value(); Dataset *dataset = it.value();
if(levelMin <= dataset->difficulty() && dataset->difficulty() <= levelMax) { if(levelMin <= dataset->difficulty() && dataset->difficulty() <= levelMax) {
newLevels << it.key(); newLevels << it.key();
dataset->setEnabled(true);
}
else {
dataset->setEnabled(false);
} }
} }
setCurrentLevels(newLevels); setCurrentLevels(newLevels);
ApplicationSettings::getInstance()->setCurrentLevels(m_name, m_levels, false); ApplicationSettings::getInstance()->setCurrentLevels(m_name, m_currentLevels, false);
} }
Dataset *ActivityInfo::getDataset(const QString& name) const { Dataset *ActivityInfo::getDataset(const QString& name) const {
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
Dataset::Dataset(QObject *parent): Dataset::Dataset(QObject *parent):
QObject(parent), QObject(parent),
m_objective(""), m_objective(""),
m_difficulty(0) m_difficulty(0),
m_enabled(true)
{ {
} }
...@@ -57,3 +58,13 @@ void Dataset::setData(const QVariant &data) ...@@ -57,3 +58,13 @@ void Dataset::setData(const QVariant &data)
m_data = data; m_data = data;
emit dataChanged(); emit dataChanged();
} }
bool Dataset::enabled() const
{
return m_enabled;
}
void Dataset::setEnabled(const bool &enabled)
{
m_enabled = enabled;
emit enabledChanged();
}
...@@ -56,6 +56,10 @@ class Dataset : public QObject { ...@@ -56,6 +56,10 @@ class Dataset : public QObject {
* Content of the dataset (json array). * Content of the dataset (json array).
*/ */
Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged) Q_PROPERTY(QVariant data READ data WRITE setData NOTIFY dataChanged)
/**
* If the dataset is enabled.
*/
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public: public:
/// @cond INTERNAL_DOCS /// @cond INTERNAL_DOCS
...@@ -66,17 +70,21 @@ public: ...@@ -66,17 +70,21 @@ public:
quint32 difficulty() const; quint32 difficulty() const;
void setDifficulty(const quint32 &); void setDifficulty(const quint32 &);
QVariant data() const; QVariant data() const;
void setData(const QVariant &data); void setData(const QVariant &);
bool enabled() const;
void setEnabled(const bool &);
signals: signals:
void objectiveChanged(); void objectiveChanged();
void difficultyChanged(); void difficultyChanged();
void dataChanged(); void dataChanged();
void enabledChanged();
private: private:
QString m_objective; QString m_objective;
quint32 m_difficulty; quint32 m_difficulty;
QVariant m_data; QVariant m_data;
bool m_enabled;
}; };
#endif // DATASET_H #endif // DATASET_H
...@@ -122,7 +122,7 @@ Rectangle { ...@@ -122,7 +122,7 @@ Rectangle {
difficultiesModel = [] difficultiesModel = []
for(var level in currentActivity.levels) { for(var level in currentActivity.levels) {
var data = currentActivity.getDataset(currentActivity.levels[level]) var data = currentActivity.getDataset(currentActivity.levels[level])
difficultiesModel.push({"level": currentActivity.levels[level], "objective": data.objective, "difficulty": data.difficulty, "selectedInConfig": (chosenLevels.indexOf(currentActivity.levels[level]) != -1)}) difficultiesModel.push({"level": currentActivity.levels[level], "enabled": data.enabled, "objective": data.objective, "difficulty": data.difficulty, "selectedInConfig": (chosenLevels.indexOf(currentActivity.levels[level]) != -1)})
} }
difficultiesRepeater.model = difficultiesModel difficultiesRepeater.model = difficultiesModel
...@@ -277,6 +277,7 @@ Rectangle { ...@@ -277,6 +277,7 @@ Rectangle {
id: difficultiesRepeater id: difficultiesRepeater
delegate: Row { delegate: Row {
height: objective.height height: objective.height
visible: modelData.enabled
Image { Image {
id: difficultyIcon id: difficultyIcon
source: "qrc:/gcompris/src/core/resource/difficulty" + source: "qrc:/gcompris/src/core/resource/difficulty" +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment