source: src/mvc/conferencemodel.cpp @ 6df32f2

qt5
Last change on this file since 6df32f2 was 6df32f2, checked in by gregor herrmann <gregoa@…>, 10 years ago

Update GPL blurb in source files.

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[b431d47]1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 *
[6df32f2]4 * This file is part of ConfClerk.
[b431d47]5 *
[6df32f2]6 * ConfClerk is free software: you can redistribute it and/or modify it
[b431d47]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 *
[6df32f2]11 * ConfClerk is distributed in the hope that it will be useful, but
[b431d47]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
[6df32f2]17 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
[b431d47]18 */
19
20#include "conferencemodel.h"
21
22ConferenceModel::ConferenceModel(QObject* parent)
23: QAbstractListModel(parent)
24, conferences(Conference::getAll())
25{ }
26
27int ConferenceModel::rowCount(const QModelIndex& parent) const
28{
29    if (parent.isValid()) {
30        return 0;
31    } else {
32        return conferences.size();
33    }
34}
35
36QVariant 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
53const 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
64QModelIndex 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
75void ConferenceModel::newConferenceBegin()
76{
77}
78
79void ConferenceModel::newConferenceEnd(const QString& title)
80{
81    Q_UNUSED(title);
82    reinit();
83}
84
85void ConferenceModel::conferenceRemoved()
86{
87    reinit();
88}
Note: See TracBrowser for help on using the repository browser.