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)
void ActivityInfo::fillDatasets(QQmlEngine *engine)
{
quint32 levelMin = ApplicationSettings::getInstance()->filterLevelMin();
quint32 levelMax = ApplicationSettings::getInstance()->filterLevelMax();
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);
QQmlComponent componentRoot(engine, QUrl(url));
QObject *objectRoot = componentRoot.create();
if(objectRoot != nullptr) {
Dataset *dataset = qobject_cast<Dataset*>(objectRoot);
if(levelMin > dataset->difficulty() || levelMax < dataset->difficulty()) {
dataset->setEnabled(false);
}
m_datasets[level] = dataset;
} else {
qDebug() << "ERROR: failed to load " << m_name << " " << componentRoot.errors();
......@@ -304,10 +310,14 @@ void ActivityInfo::enableDatasetsBetweenDifficulties(quint32 levelMin, quint32 l
Dataset *dataset = it.value();
if(levelMin <= dataset->difficulty() && dataset->difficulty() <= levelMax) {
newLevels << it.key();
dataset->setEnabled(true);
}
else {
dataset->setEnabled(false);
}
}
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 {
......
......@@ -23,7 +23,8 @@
Dataset::Dataset(QObject *parent):
QObject(parent),
m_objective(""),
m_difficulty(0)
m_difficulty(0),
m_enabled(true)
{
}
......@@ -57,3 +58,13 @@ void Dataset::setData(const QVariant &data)
m_data = data;
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 {
* Content of the dataset (json array).
*/
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:
/// @cond INTERNAL_DOCS
......@@ -66,17 +70,21 @@ public:
quint32 difficulty() const;
void setDifficulty(const quint32 &);
QVariant data() const;
void setData(const QVariant &data);
void setData(const QVariant &);
bool enabled() const;
void setEnabled(const bool &);
signals:
void objectiveChanged();
void difficultyChanged();
void dataChanged();
void enabledChanged();
private:
QString m_objective;
quint32 m_difficulty;
QVariant m_data;
bool m_enabled;
};
#endif // DATASET_H
......@@ -122,7 +122,7 @@ Rectangle {
difficultiesModel = []
for(var level in currentActivity.levels) {
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
......@@ -277,6 +277,7 @@ Rectangle {
id: difficultiesRepeater
delegate: Row {
height: objective.height
visible: modelData.enabled
Image {
id: difficultyIcon
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