2
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
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, either version 2 or (at your option)
7
* version 3 of the License.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "AutoTypeAssociationsModel.h"
20
#include "core/Entry.h"
22
AutoTypeAssociationsModel::AutoTypeAssociationsModel(QObject* parent)
23
: QAbstractListModel(parent)
24
, m_autoTypeAssociations(nullptr)
29
void AutoTypeAssociationsModel::setAutoTypeAssociations(AutoTypeAssociations* autoTypeAssociations)
33
if (m_autoTypeAssociations) {
34
m_autoTypeAssociations->disconnect(this);
37
m_autoTypeAssociations = autoTypeAssociations;
39
if (m_autoTypeAssociations) {
40
connect(m_autoTypeAssociations, SIGNAL(dataChanged(int)), SLOT(associationChange(int)));
41
connect(m_autoTypeAssociations, SIGNAL(aboutToAdd(int)), SLOT(associationAboutToAdd(int)));
42
connect(m_autoTypeAssociations, SIGNAL(added(int)), SLOT(associationAdd()));
43
connect(m_autoTypeAssociations, SIGNAL(aboutToRemove(int)), SLOT(associationAboutToRemove(int)));
44
connect(m_autoTypeAssociations, SIGNAL(removed(int)), SLOT(associationRemove()));
45
connect(m_autoTypeAssociations, SIGNAL(aboutToReset()), SLOT(aboutToReset()));
46
connect(m_autoTypeAssociations, SIGNAL(reset()), SLOT(reset()));
52
void AutoTypeAssociationsModel::setEntry(Entry* entry)
57
int AutoTypeAssociationsModel::rowCount(const QModelIndex& parent) const
59
if (!m_autoTypeAssociations || parent.isValid()) {
62
return m_autoTypeAssociations->size();
66
int AutoTypeAssociationsModel::columnCount(const QModelIndex& parent) const
73
QVariant AutoTypeAssociationsModel::headerData(int section, Qt::Orientation orientation, int role) const
75
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) {
79
return tr("Sequence");
86
QVariant AutoTypeAssociationsModel::data(const QModelIndex& index, int role) const
88
if (!index.isValid()) {
92
if (role == Qt::DisplayRole) {
93
if (index.column() == 0) {
94
QString window = m_autoTypeAssociations->get(index.row()).window;
95
if (window.isEmpty()) {
99
window = m_entry->maskPasswordPlaceholders(window);
100
window = m_entry->resolveMultiplePlaceholders(window);
104
QString sequence = m_autoTypeAssociations->get(index.row()).sequence;
105
if (sequence.isEmpty()) {
106
sequence = tr("Default sequence");
115
void AutoTypeAssociationsModel::associationChange(int i)
117
emit dataChanged(index(i, 0), index(i, columnCount() - 1));
120
void AutoTypeAssociationsModel::associationAboutToAdd(int i)
122
beginInsertRows(QModelIndex(), i, i);
125
void AutoTypeAssociationsModel::associationAdd()
130
void AutoTypeAssociationsModel::associationAboutToRemove(int i)
132
beginRemoveRows(QModelIndex(), i, i);
135
void AutoTypeAssociationsModel::associationRemove()
140
void AutoTypeAssociationsModel::aboutToReset()
145
void AutoTypeAssociationsModel::reset()