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