QTfrontend/model/ThemeModel.cpp
changeset 13248 b0022324fb4e
parent 13247 4df9d8cedf7f
child 13249 d2b58cf339fe
equal deleted inserted replaced
13247:4df9d8cedf7f 13248:b0022324fb4e
    31     m_data = QList<QMap<int, QVariant> >();
    31     m_data = QList<QMap<int, QVariant> >();
    32 
    32 
    33     m_themesLoaded = false;
    33     m_themesLoaded = false;
    34 
    34 
    35     m_filteredNoDLC = NULL;
    35     m_filteredNoDLC = NULL;
       
    36     m_filteredNoHidden = NULL;
       
    37     m_filteredNoDLCOrHidden = NULL;
    36 }
    38 }
    37 
    39 
       
    40 // Filters out DLC themes, e.g. themes which do not come by default
    38 ThemeFilterProxyModel * ThemeModel::withoutDLC()
    41 ThemeFilterProxyModel * ThemeModel::withoutDLC()
    39 {
    42 {
    40     if (m_filteredNoDLC == NULL)
    43     if (m_filteredNoDLC == NULL)
    41     {
    44     {
    42         m_filteredNoDLC = new ThemeFilterProxyModel(this);
    45         m_filteredNoDLC = new ThemeFilterProxyModel(this);
    43         m_filteredNoDLC->setSourceModel(this);
    46         m_filteredNoDLC->setSourceModel(this);
    44         m_filteredNoDLC->setFilterDLC(true);
    47         m_filteredNoDLC->setFilterDLC(true);
    45     }
    48     }
    46     return m_filteredNoDLC;
    49     return m_filteredNoDLC;
       
    50 }
       
    51 
       
    52 // Filters out hidden themes, these are themes which are not supposed to be
       
    53 // seen by the user.
       
    54 ThemeFilterProxyModel * ThemeModel::withoutHidden()
       
    55 {
       
    56     if (m_filteredNoHidden == NULL)
       
    57     {
       
    58         m_filteredNoHidden = new ThemeFilterProxyModel(this);
       
    59         m_filteredNoHidden->setSourceModel(this);
       
    60         m_filteredNoHidden->setFilterHidden(true);
       
    61     }
       
    62     return m_filteredNoHidden;
       
    63 }
       
    64 
       
    65 // Combination of the two above for convenience
       
    66 ThemeFilterProxyModel * ThemeModel::withoutDLCOrHidden()
       
    67 {
       
    68     if (m_filteredNoDLCOrHidden == NULL)
       
    69     {
       
    70         m_filteredNoDLCOrHidden = new ThemeFilterProxyModel(this);
       
    71         m_filteredNoDLCOrHidden->setSourceModel(this);
       
    72         m_filteredNoDLCOrHidden->setFilterDLC(true);
       
    73         m_filteredNoDLCOrHidden->setFilterHidden(true);
       
    74     }
       
    75     return m_filteredNoDLCOrHidden;
    47 }
    76 }
    48 
    77 
    49 int ThemeModel::rowCount(const QModelIndex &parent) const
    78 int ThemeModel::rowCount(const QModelIndex &parent) const
    50 {
    79 {
    51     if(parent.isValid())
    80     if(parent.isValid())
    91     m_data.reserve(themes.size());
   120     m_data.reserve(themes.size());
    92 #endif
   121 #endif
    93 
   122 
    94     foreach (QString theme, themes)
   123     foreach (QString theme, themes)
    95     {
   124     {
       
   125         QMap<int, QVariant> dataset;
       
   126 
    96         // themes without icon are supposed to be hidden
   127         // themes without icon are supposed to be hidden
    97         QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme);
   128         QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme);
    98 
   129 
    99         if (!QFile::exists(iconpath))
   130         if (!QFile::exists(iconpath))
   100             continue;
   131             dataset.insert(IsHiddenRole, true);
   101 
       
   102         QMap<int, QVariant> dataset;
       
   103 
   132 
   104         // detect if theme is dlc
   133         // detect if theme is dlc
   105         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1/icon.png").arg(theme).toLocal8Bit().data());
   134         QString themeDir = PHYSFS_getRealDir(QString("Themes/%1/icon.png").arg(theme).toLocal8Bit().data());
   106         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
   135         bool isDLC = !themeDir.startsWith(datadir->absolutePath());
   107         dataset.insert(IsDlcRole, isDLC);
   136         dataset.insert(IsDlcRole, isDLC);