Commit d29d5f21 authored by Johnny Jazeix's avatar Johnny Jazeix

core, when changing filter difficulty, enable corresponding datasets

parent ef006970
......@@ -725,6 +725,7 @@ Item {
ApplicationSettings.filterLevelMax != filterRepeater.maxFilter) {
ApplicationSettings.filterLevelMin = filterRepeater.minFilter
ApplicationSettings.filterLevelMax = filterRepeater.maxFilter
ActivityInfoTree.minMaxFiltersChanged(filterRepeater.minFilter, filterRepeater.maxFilter)
}
ApplicationSettings.saveBaseFontSize();
......
......@@ -246,8 +246,8 @@ void ActivityInfo::fillDatasets(QQmlEngine *engine)
}
}
if(m_levels.empty()) {
m_minimalDifficulty = m_difficulty;
m_maximalDifficulty = m_difficulty;
setMinimalDifficulty(m_difficulty);
setMaximalDifficulty(m_difficulty);
}
else {
computeMinMaxDifficulty();
......@@ -298,6 +298,19 @@ void ActivityInfo::setCurrentLevels()
computeMinMaxDifficulty();
}
void ActivityInfo::enableDatasetsBetweenDifficulties(quint32 levelMin, quint32 levelMax) {
QStringList newLevels;
for(auto it = m_datasets.begin(); it != m_datasets.end(); ++ it) {
Dataset *dataset = it.value();
if(levelMin <= dataset->difficulty() && dataset->difficulty() <= levelMax) {
newLevels << it.key();
}
}
setCurrentLevels(newLevels);
ApplicationSettings::getInstance()->setCurrentLevels(m_name, m_levels, false);
}
Dataset *ActivityInfo::getDataset(const QString& name) const {
return m_datasets[name];
}
......@@ -193,6 +193,7 @@ public:
void setCurrentLevels(const QStringList&);
QQmlListProperty<Dataset> datasets();
void fillDatasets(QQmlEngine *engine);
void enableDatasetsBetweenDifficulties(quint32 levelMin, quint32 levelMax);
Q_INVOKABLE Dataset *getDataset(const QString& name) const;
......
......@@ -132,8 +132,8 @@ void ActivityInfoTree::filterByTag(const QString &tag, const QString &category,
(category.isEmpty() && activity->section().indexOf(tag) != -1) ||
tag == "all" ||
(tag == "favorite" && activity->favorite())) &&
(activity->difficulty() >= ApplicationSettings::getInstance()->filterLevelMin() &&
activity->difficulty() <= ApplicationSettings::getInstance()->filterLevelMax())) {
(activity->maximalDifficulty() >= ApplicationSettings::getInstance()->filterLevelMin() &&
activity->minimalDifficulty() <= ApplicationSettings::getInstance()->filterLevelMax())) {
m_menuTree.push_back(activity);
}
}
......@@ -144,9 +144,10 @@ void ActivityInfoTree::filterByTag(const QString &tag, const QString &category,
void ActivityInfoTree::filterByDifficulty(quint32 levelMin, quint32 levelMax)
{
//todo fix here the difficulty filtering
auto it = std::remove_if(m_menuTree.begin(), m_menuTree.end(),
[&](const ActivityInfo* activity) {
return activity->difficulty() < levelMin || activity->difficulty() > levelMax;
return activity->minimalDifficulty() < levelMin || activity->maximalDifficulty() > levelMax;
});
m_menuTree.erase(it, m_menuTree.end());
}
......@@ -323,6 +324,13 @@ void ActivityInfoTree::filterBySearch(const QString& text)
Q_EMIT menuTreeChanged();
}
void ActivityInfoTree::minMaxFiltersChanged(quint32 levelMin, quint32 levelMax, bool emit) {
for(ActivityInfo *activity: m_menuTreeFull) {
activity->enableDatasetsBetweenDifficulties(levelMin, levelMax);
}
ApplicationSettings::getInstance()->sync();
}
QVariantList ActivityInfoTree::allCharacters() {
QSet<QChar> keyboardChars;
const auto constMenuTreeFull = m_menuTreeFull;
......
......@@ -57,6 +57,7 @@ protected Q_SLOTS:
bool emitChanged = true);
Q_INVOKABLE void filterBySearch(const QString& text);
Q_INVOKABLE void filterByDifficulty(quint32 levelMin, quint32 levelMax);
Q_INVOKABLE void minMaxFiltersChanged(quint32 levelMin, quint32 levelMax, bool emitChanged = true);
signals:
void menuTreeChanged();
......@@ -78,7 +79,7 @@ private:
{
bool operator()(const ActivityInfo *a, const ActivityInfo *b) const
{
return a->difficulty() < b->difficulty();
return a->minimalDifficulty() < b->minimalDifficulty();
}
};
......
......@@ -505,9 +505,9 @@ bool ApplicationSettings::isFavorite(const QString &activity)
return favorite;
}
void ApplicationSettings::setCurrentLevels(const QString &activity, const QStringList &level)
void ApplicationSettings::setCurrentLevels(const QString &activity, const QStringList &level, bool sync)
{
updateValueInConfig(LEVELS_GROUP_KEY, activity, level);
updateValueInConfig(LEVELS_GROUP_KEY, activity, level, sync);
}
QStringList ApplicationSettings::currentLevels(const QString &activity)
......@@ -529,6 +529,10 @@ template<class T> void ApplicationSettings::updateValueInConfig(const QString& g
}
}
void ApplicationSettings::sync() {
m_config.sync();
}
int ApplicationSettings::loadActivityProgress(const QString &activity)
{
int progress = 0;
......
......@@ -581,7 +581,7 @@ protected slots:
public slots:
Q_INVOKABLE bool isFavorite(const QString &activity);
Q_INVOKABLE void setFavorite(const QString &activity, bool favorite);
Q_INVOKABLE void setCurrentLevels(const QString &activity, const QStringList &level);
Q_INVOKABLE void setCurrentLevels(const QString &activity, const QStringList &level, bool sync = true);
Q_INVOKABLE QStringList currentLevels(const QString &activity);
Q_INVOKABLE void saveBaseFontSize();
......@@ -618,6 +618,10 @@ public slots:
* @param progress Last started level to save as progress value.
*/
Q_INVOKABLE void saveActivityProgress(const QString &activity, int progress);
/**
* Synchronize the changes done in the application in the configuration file.
*/
Q_INVOKABLE void sync();
signals:
void showLockedActivitiesChanged();
......
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