QTfrontend/model/ThemeModel.cpp
changeset 9745 258c320256dc
parent 9080 9b42757d7e71
child 9815 d4621fb76284
equal deleted inserted replaced
9744:1ee4842a9c86 9745:258c320256dc
    27 
    27 
    28 ThemeModel::ThemeModel(QObject *parent) :
    28 ThemeModel::ThemeModel(QObject *parent) :
    29     QAbstractListModel(parent)
    29     QAbstractListModel(parent)
    30 {
    30 {
    31     m_data = QList<QMap<int, QVariant> >();
    31     m_data = QList<QMap<int, QVariant> >();
       
    32 
       
    33     m_themesLoaded = false;
    32 }
    34 }
    33 
    35 
    34 int ThemeModel::rowCount(const QModelIndex &parent) const
    36 int ThemeModel::rowCount(const QModelIndex &parent) const
    35 {
    37 {
    36     if(parent.isValid())
    38     if(parent.isValid())
    37         return 0;
    39         return 0;
    38     else
    40     else
       
    41     {
       
    42         if(!m_themesLoaded)
       
    43             loadThemes();
    39         return m_data.size();
    44         return m_data.size();
       
    45     }
    40 }
    46 }
    41 
    47 
    42 
    48 
    43 QVariant ThemeModel::data(const QModelIndex &index, int role) const
    49 QVariant ThemeModel::data(const QModelIndex &index, int role) const
    44 {
    50 {
    45     if(index.column() > 0 || index.row() >= m_data.size())
    51     if(index.column() > 0 || index.row() >= m_data.size())
    46         return QVariant();
    52         return QVariant();
    47     else
    53     else
       
    54     {
       
    55         if(!m_themesLoaded)
       
    56             loadThemes();
       
    57 
    48         return m_data.at(index.row()).value(role);
    58         return m_data.at(index.row()).value(role);
       
    59     }
    49 }
    60 }
    50 
    61 
    51 
    62 
    52 void ThemeModel::loadThemes()
    63 void ThemeModel::loadThemes() const
    53 {
    64 {
    54     beginResetModel();
    65     qDebug("[LAZINESS ThemeModel::loadThemes()]");
       
    66 
       
    67     m_themesLoaded = true;
       
    68 
    55 
    69 
    56     DataManager & datamgr = DataManager::instance();
    70     DataManager & datamgr = DataManager::instance();
    57 
    71 
    58     QStringList themes =
    72     QStringList themes =
    59         datamgr.entryList("Themes", QDir::AllDirs | QDir::NoDotAndDotDot);
    73         datamgr.entryList("Themes", QDir::AllDirs | QDir::NoDotAndDotDot);
    92         QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
   106         QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme));
    93         dataset.insert(Qt::DecorationRole, preview);
   107         dataset.insert(Qt::DecorationRole, preview);
    94 
   108 
    95         m_data.append(dataset);
   109         m_data.append(dataset);
    96     }
   110     }
    97 
       
    98 
       
    99     endResetModel();
       
   100 }
   111 }