[b431d47] | 1 | /* |
---|
| 2 | * Copyright (C) 2010 Ixonos Plc. |
---|
| 3 | * |
---|
| 4 | * This file is part of fosdem-schedule. |
---|
| 5 | * |
---|
| 6 | * fosdem-schedule is free software: you can redistribute it and/or modify it |
---|
| 7 | * under the terms of the GNU General Public License as published by the Free |
---|
| 8 | * Software Foundation, either version 2 of the License, or (at your option) |
---|
| 9 | * any later version. |
---|
| 10 | * |
---|
| 11 | * fosdem-schedule is distributed in the hope that it will be useful, but |
---|
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
| 14 | * more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License along with |
---|
| 17 | * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include "conferencemodel.h" |
---|
| 21 | |
---|
| 22 | ConferenceModel::ConferenceModel(QObject* parent) |
---|
| 23 | : QAbstractListModel(parent) |
---|
| 24 | , conferences(Conference::getAll()) |
---|
| 25 | { } |
---|
| 26 | |
---|
| 27 | int ConferenceModel::rowCount(const QModelIndex& parent) const |
---|
| 28 | { |
---|
| 29 | if (parent.isValid()) { |
---|
| 30 | return 0; |
---|
| 31 | } else { |
---|
| 32 | return conferences.size(); |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | QVariant ConferenceModel::data(const QModelIndex& index, int role) const |
---|
| 37 | { |
---|
| 38 | if (role != Qt::DisplayRole) { |
---|
| 39 | return QVariant(); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | return conferences[index.row()].title(); |
---|
| 43 | |
---|
| 44 | try { |
---|
| 45 | const Conference& c = conferenceFromIndex(index); |
---|
| 46 | return c.title(); |
---|
| 47 | } catch (OrmNoObjectException&) { |
---|
| 48 | return QVariant(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | const Conference& ConferenceModel::conferenceFromIndex(const QModelIndex& index) const |
---|
| 54 | { |
---|
| 55 | if (index.parent().isValid() |
---|
| 56 | or index.column() != 0 |
---|
| 57 | or index.row() >= conferences.size()) |
---|
| 58 | { |
---|
| 59 | throw OrmNoObjectException(); |
---|
| 60 | } |
---|
| 61 | return conferences[index.row()]; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | QModelIndex ConferenceModel::indexFromId(int id) const |
---|
| 65 | { |
---|
| 66 | for (int i = 0; i < conferences.size(); ++i) { |
---|
| 67 | if (conferences[i].id() == id) { |
---|
| 68 | return index(i, 0); |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | return QModelIndex(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void ConferenceModel::newConferenceBegin() |
---|
| 76 | { |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | void ConferenceModel::newConferenceEnd(const QString& title) |
---|
| 80 | { |
---|
| 81 | Q_UNUSED(title); |
---|
| 82 | reinit(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | void ConferenceModel::conferenceRemoved() |
---|
| 86 | { |
---|
| 87 | reinit(); |
---|
| 88 | } |
---|