on e1659ca help sign in
120 lines 2.8 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
19// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
20// To use the same method of setting role name that it does, we
21// set our compatibility to Qt4 here too.
22#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
24#include "SessionsModel.h"
25#include "SessionsModelPrivate.h"
26#include <QtCore/QDir>
27#include <QtCore/QString>
29namespace QLightDM
32SessionsModel::SessionsModel(QObject* parent) :
33 QAbstractListModel(parent),
34 d_ptr(new SessionsModelPrivate(this))
36 m_roleNames = QAbstractListModel::roleNames();
37 m_roleNames[KeyRole] = "key";
38 m_roleNames[TypeRole] = "type";
41SessionsModel::~SessionsModel()
43 delete d_ptr;
46QVariant SessionsModel::data(const QModelIndex& index, int role) const
48 Q_D(const SessionsModel);
50 if(!index.isValid()) {
51 return QVariant();
52 }
54 int row = index.row();
56 switch (role) {
57 case QLightDM::SessionsModel::KeyRole:
58 return d->sessionItems[row].key;
59 case Qt::DisplayRole:
60 return d->sessionItems[row].name;
61 default:
62 return QVariant();
63 }
66QHash<int, QByteArray> SessionsModel::roleNames() const
68 return m_roleNames;
71int SessionsModel::rowCount(const QModelIndex& parent) const
73 Q_D(const SessionsModel);
75 if (parent.isValid()) {
76 return 0;
77 } else { // parent is root
78 return d->sessionItems.size();
79 }
82int SessionsModel::numSessions() const
84 Q_D(const SessionsModel);
85 return d->numSessions;
88int SessionsModel::numAvailableSessions() const
90 Q_D(const SessionsModel);
91 return d->numAvailableSessions();
94QString SessionsModel::testScenario() const
96 Q_D(const SessionsModel);
97 return d->testScenario;
100void SessionsModel::setNumSessions(int numSessions)
102 Q_D(SessionsModel);
104 if (d->numSessions != numSessions) {
105 d->numSessions = numSessions;
106 d->resetEntries();
107 }
110void SessionsModel::setTestScenario(QString testScenario)
112 Q_D(SessionsModel);
114 if (d->testScenario != testScenario) {
115 d->testScenario = testScenario;
116 d->resetEntries();
117 }
120} // namespace QLightDM