on 01c8faa help sign in
99 lines 2.4 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 Q_D(SessionsModel);
37 m_roleNames = QAbstractListModel::roleNames();
38 m_roleNames[KeyRole] = "key";
39 m_roleNames[TypeRole] = "type";
42SessionsModel::~SessionsModel()
44 delete d_ptr;
47QVariant SessionsModel::data(const QModelIndex& index, int role) const
49 Q_D(const SessionsModel);
51 if(!index.isValid()) {
52 return QVariant();
53 }
55 int row = index.row();
57 switch (role) {
58 case QLightDM::SessionsModel::KeyRole:
59 return d->sessionItems[row].key;
60 case Qt::DisplayRole:
61 return d->sessionItems[row].name;
62 default:
63 return QVariant();
64 }
67QHash<int, QByteArray> SessionsModel::roleNames() const
69 return m_roleNames;
72int SessionsModel::rowCount(const QModelIndex& parent) const
74 Q_D(const SessionsModel);
76 if (parent.isValid()) {
77 return 0;
78 } else { // parent is root
79 return d->sessionItems.size();
80 }
83QString SessionsModel::testScenario() const
85 Q_D(const SessionsModel);
86 return d->testScenario;
89void SessionsModel::setTestScenario(QString testScenario)
91 Q_D(SessionsModel);
93 if (d->testScenario != testScenario) {
94 d->testScenario = testScenario;
95 d->resetEntries();
96 }
99} // namespace QLightDM