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())
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) {