QTfrontend/model/roomslistmodel.cpp
changeset 6732 c906dc78091f
child 6733 5abbc345a82f
equal deleted inserted replaced
6731:ddd391083f50 6732:c906dc78091f
       
     1 #include "roomslistmodel.h"
       
     2 
       
     3 RoomsListModel::RoomsListModel(QObject *parent) :
       
     4     QAbstractTableModel(parent)
       
     5 {
       
     6     m_headerData =
       
     7     QStringList()
       
     8      << tr("Room Name")
       
     9      << tr("C")
       
    10      << tr("T")
       
    11      << tr("Owner")
       
    12      << tr("Map")
       
    13      << tr("Rules")
       
    14      << tr("Weapons");
       
    15 }
       
    16 
       
    17 QVariant RoomsListModel::headerData(int section, Qt::Orientation orientation, int role) const
       
    18 {
       
    19     if(orientation == Qt::Vertical || role != Qt::DisplayRole)
       
    20         return QVariant();
       
    21     else
       
    22         return QVariant(m_headerData.at(section));
       
    23 }
       
    24 
       
    25 int RoomsListModel::rowCount(const QModelIndex & parent) const
       
    26 {
       
    27     if(parent.isValid())
       
    28         return 0;
       
    29     else
       
    30         return m_data.size();
       
    31 }
       
    32 
       
    33 int RoomsListModel::columnCount(const QModelIndex & parent) const
       
    34 {
       
    35     if(parent.isValid())
       
    36         return 0;
       
    37     else
       
    38         return 7;
       
    39 }
       
    40 
       
    41 QVariant RoomsListModel::data(const QModelIndex &index, int role) const
       
    42 {
       
    43     if (!index.isValid() || index.row() < 0
       
    44             || index.row() >= m_data.size()
       
    45             || index.column() >= 7
       
    46             || (role != Qt::EditRole && role != Qt::DisplayRole)
       
    47        )
       
    48         return QVariant();
       
    49 
       
    50     return m_data.at(index.row()).at(index.column());
       
    51 }