QTfrontend/ui/model/themesmodel.cpp
changeset 6060 fdfc01419815
parent 5332 b29d60c7cac7
equal deleted inserted replaced
6059:ddf020d0941a 6060:fdfc01419815
       
     1 
       
     2 #include "themesmodel.h"
       
     3 
       
     4 ThemesModel::ThemesModel(QStringList themes, QObject *parent) :
       
     5     QAbstractListModel(parent)
       
     6 {
       
     7 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
       
     8     m_data.reserve(themes.size());
       
     9 #endif
       
    10 
       
    11     foreach(QString theme, themes)
       
    12     {
       
    13         m_data.append(QHash<int, QVariant>());
       
    14         m_data.last().insert(Qt::DisplayRole, theme);
       
    15     }
       
    16 }
       
    17 
       
    18 int ThemesModel::rowCount(const QModelIndex &parent) const
       
    19 {
       
    20     if(parent.isValid())
       
    21         return 0;
       
    22     else
       
    23         return m_data.size();
       
    24 }
       
    25 
       
    26 QVariant ThemesModel::data(const QModelIndex &index, int role) const
       
    27 {
       
    28     if(index.column() > 0 || index.row() >= m_data.size())
       
    29         return QVariant();
       
    30     else
       
    31         return m_data.at(index.row()).value(role);
       
    32 }
       
    33 
       
    34 bool ThemesModel::setData(const QModelIndex &index, const QVariant &value, int role)
       
    35 {
       
    36     if(index.column() > 0 || index.row() >= m_data.size())
       
    37         return false;
       
    38     else
       
    39     {
       
    40         m_data[index.row()].insert(role, value);
       
    41 
       
    42         return true;
       
    43     }
       
    44 
       
    45 }
       
    46 
       
    47 
       
    48 
       
    49