2
* Copyright 2011 Kurtis L. Nusbaum
4
* This file is part of UDJ.
6
* UDJ is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 2 of the License, or
9
* (at your option) any later version.
11
* UDJ is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with UDJ. If not, see <http://www.gnu.org/licenses/>.
19
#include "ParticipantsModel.hpp"
20
#include "DataStore.hpp"
26
ParticipantsModel::ParticipantsModel(DataStore* dataStore, QObject *parent)
27
:QStandardItemModel(parent),
33
SIGNAL(newParticipantList(const QVariantList&)),
35
SLOT(onNewParticipantList(const QVariantList&)));
39
void ParticipantsModel::onNewParticipantList(const QVariantList& newParticipants){
40
removeRows(0, rowCount());
42
QVariantMap participant;
43
for(int i=0; i<newParticipants.size(); ++i){
44
participant = newParticipants.at(i).toMap();
45
QStandardItem *newId = new QStandardItem(participant["id"].toString());
46
QStandardItem *newUsername = new QStandardItem(participant["username"].toString());
47
QStandardItem *newFirstName = new QStandardItem(
48
getAttrWithDefault(participant,"first_name", "Unknown"));
49
QStandardItem *newLastName = new QStandardItem(
50
getAttrWithDefault(participant,"last_name", "Unknown"));
51
QList<QStandardItem*> newRow;
52
newRow << newId << newUsername << newFirstName << newLastName;
57
QString ParticipantsModel::getAttrWithDefault(
58
const QVariantMap& user,
60
const QString& defaultValue)
62
QString value = user[attr].toString();
69
void ParticipantsModel::setHeaders(){
71
headers << tr("Id") << tr("Username") << tr("First Name") << tr("Last Name");
72
setHorizontalHeaderLabels(headers);