2
* Copyright (C) 2017 Canonical, Ltd.
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.
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.
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/>.
18
#include "PromptsModel.h"
20
PromptsModel::PromptsModel(QObject* parent)
21
: QAbstractListModel(parent)
23
m_roleNames[TypeRole] = "type";
24
m_roleNames[TextRole] = "text";
27
PromptsModel& PromptsModel::operator=(const PromptsModel &other)
30
m_prompts = other.m_prompts;
32
Q_EMIT countChanged();
36
int PromptsModel::rowCount(const QModelIndex &parent) const
41
return m_prompts.size();
44
QVariant PromptsModel::data(const QModelIndex &index, int role) const
46
if (!index.isValid() || index.column() > 0 || index.row() >= m_prompts.size())
50
case Qt::DisplayRole: // fallthrough
51
case TextRole: return m_prompts[index.row()].prompt;
52
case TypeRole: return m_prompts[index.row()].type;
53
default: return QVariant();
57
QHash<int, QByteArray> PromptsModel::roleNames() const
62
void PromptsModel::prepend(const QString &text, PromptType type)
64
beginInsertRows(QModelIndex(), 0, 0);
65
m_prompts.prepend(PromptInfo{text, type});
68
Q_EMIT countChanged();
71
void PromptsModel::append(const QString &text, PromptType type)
73
beginInsertRows(QModelIndex(), m_prompts.size(), m_prompts.size());
74
m_prompts.append(PromptInfo{text, type});
77
Q_EMIT countChanged();
80
void PromptsModel::clear()
86
Q_EMIT countChanged();
89
bool PromptsModel::hasPrompt() const
91
Q_FOREACH(const PromptInfo &info, m_prompts) {
92
if (info.type == PromptType::Secret || info.type == PromptType::Question) {