# HG changeset patch # User sheepluva # Date 1461801995 -7200 # Node ID 5c192a4751d844dc5e59278540463296eb9ef8cb # Parent 3c66845947a8997ba7e150707109fa9ff5a7fb39 exclude DLC theme from random theme selection diff -r 3c66845947a8 -r 5c192a4751d8 QTfrontend/model/ThemeModel.cpp --- a/QTfrontend/model/ThemeModel.cpp Thu Apr 28 00:41:09 2016 +0200 +++ b/QTfrontend/model/ThemeModel.cpp Thu Apr 28 02:06:35 2016 +0200 @@ -31,6 +31,21 @@ m_data = QList >(); m_themesLoaded = false; + + m_filteredNoDLC = NULL; +} + +QSortFilterProxyModel * ThemeModel::withoutDLC() +{ + if (m_filteredNoDLC == NULL) + { + m_filteredNoDLC = new QSortFilterProxyModel(this); + m_filteredNoDLC->setSourceModel(this); + // filtering based on IsDlcRole would be nicer + // but seems this model can only do string-based filtering :| + m_filteredNoDLC->setFilterRegExp(QRegExp("^[^*]")); + } + return m_filteredNoDLC; } int ThemeModel::rowCount(const QModelIndex &parent) const diff -r 3c66845947a8 -r 5c192a4751d8 QTfrontend/model/ThemeModel.h --- a/QTfrontend/model/ThemeModel.h Thu Apr 28 00:41:09 2016 +0200 +++ b/QTfrontend/model/ThemeModel.h Thu Apr 28 02:06:35 2016 +0200 @@ -25,6 +25,7 @@ #define HEDGEWARS_THEMEMODEL_H #include +#include #include #include #include @@ -44,10 +45,12 @@ int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role) const; + QSortFilterProxyModel * withoutDLC(); private: mutable QList > m_data; mutable bool m_themesLoaded; + mutable QSortFilterProxyModel * m_filteredNoDLC; void loadThemes() const; }; diff -r 3c66845947a8 -r 5c192a4751d8 QTfrontend/ui/widget/mapContainer.cpp --- a/QTfrontend/ui/widget/mapContainer.cpp Thu Apr 28 00:41:09 2016 +0200 +++ b/QTfrontend/ui/widget/mapContainer.cpp Thu Apr 28 02:06:35 2016 +0200 @@ -527,9 +527,10 @@ void HWMapContainer::setRandomTheme() { - if(!m_themeModel->rowCount()) return; - quint32 themeNum = rand() % m_themeModel->rowCount(); - updateTheme(m_themeModel->index(themeNum)); + QAbstractItemModel * tmodel = m_themeModel->withoutDLC(); + if(!tmodel->rowCount()) return; + quint32 themeNum = rand() % tmodel->rowCount(); + updateTheme(tmodel->index(themeNum,0)); emit themeChanged(m_theme); }