Changeset View
Changeset View
Standalone View
Standalone View
shell/runtimesmodel.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2017 Aleix Pol Gonzalez <aleixpol@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License version 2 as published by the Free Software Foundation. | ||||
7 | | ||||
8 | This library 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 GNU | ||||
11 | Library General Public License for more details. | ||||
12 | | ||||
13 | You should have received a copy of the GNU Library General Public License | ||||
14 | along with this library; see the file COPYING.LIB. If not, write to | ||||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
16 | Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "runtimesmodel.h" | ||||
20 | | ||||
21 | KDevelop::RuntimesModel::RuntimesModel(KDevelop::RuntimeController* controller) | ||||
22 | : QAbstractListModel(controller) | ||||
23 | , m_controller(controller) | ||||
24 | { | ||||
25 | } | ||||
26 | | ||||
27 | KDevelop::IRuntime * KDevelop::RuntimesModel::runtimeAt(int row) const | ||||
28 | { | ||||
29 | return m_controller->availableRuntimes().at(row); | ||||
30 | } | ||||
31 | | ||||
32 | int KDevelop::RuntimesModel::rowCount(const QModelIndex& parent) const | ||||
33 | { | ||||
34 | return parent.isValid() ? 0 : m_controller->availableRuntimes().count(); | ||||
35 | } | ||||
36 | | ||||
37 | QVariant KDevelop::RuntimesModel::data(const QModelIndex& index, int role) const | ||||
38 | { | ||||
39 | if (!index.isValid() || index.parent().isValid() || index.row() >= m_controller->availableRuntimes().count()) | ||||
40 | return {}; | ||||
41 | | ||||
42 | const auto runtime = runtimeAt(index.row()); | ||||
43 | switch(role) { | ||||
44 | case Qt::DisplayRole: | ||||
45 | return runtime->name(); | ||||
46 | case Qt::UserRole: | ||||
47 | return QVariant::fromValue<QObject*>(runtime); | ||||
48 | } | ||||
49 | return {}; | ||||
50 | } |