QTfrontend/model/roomslistmodel.cpp
author unc0rr
Thu, 23 Feb 2012 00:46:03 +0400
changeset 6732 c906dc78091f
child 6733 5abbc345a82f
permissions -rw-r--r--
Start switching to rooms list model. To be continued.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6732
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     1
#include "roomslistmodel.h"
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     2
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     3
RoomsListModel::RoomsListModel(QObject *parent) :
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     4
    QAbstractTableModel(parent)
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     5
{
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     6
    m_headerData =
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     7
    QStringList()
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     8
     << tr("Room Name")
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
     9
     << tr("C")
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    10
     << tr("T")
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    11
     << tr("Owner")
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    12
     << tr("Map")
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    13
     << tr("Rules")
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    14
     << tr("Weapons");
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    15
}
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    16
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    17
QVariant RoomsListModel::headerData(int section, Qt::Orientation orientation, int role) const
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    18
{
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    19
    if(orientation == Qt::Vertical || role != Qt::DisplayRole)
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    20
        return QVariant();
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    21
    else
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    22
        return QVariant(m_headerData.at(section));
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    23
}
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    24
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    25
int RoomsListModel::rowCount(const QModelIndex & parent) const
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    26
{
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    27
    if(parent.isValid())
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    28
        return 0;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    29
    else
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    30
        return m_data.size();
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    31
}
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    32
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    33
int RoomsListModel::columnCount(const QModelIndex & parent) const
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    34
{
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    35
    if(parent.isValid())
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    36
        return 0;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    37
    else
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    38
        return 7;
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    39
}
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    40
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    41
QVariant RoomsListModel::data(const QModelIndex &index, int role) const
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    42
{
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    43
    if (!index.isValid() || index.row() < 0
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    44
            || index.row() >= m_data.size()
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    45
            || index.column() >= 7
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    46
            || (role != Qt::EditRole && role != Qt::DisplayRole)
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    47
       )
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    48
        return QVariant();
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    49
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    50
    return m_data.at(index.row()).at(index.column());
c906dc78091f Start switching to rooms list model. To be continued.
unc0rr
parents:
diff changeset
    51
}