mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-28 00:39:43 -05:00
Make EntryAttributesModel editable.
This commit is contained in:
parent
7c094d4723
commit
6140a688d7
@ -83,22 +83,72 @@ QVariant EntryAttributesModel::headerData(int section, Qt::Orientation orientati
|
||||
|
||||
QVariant EntryAttributesModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole)) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
QString key = m_attributes.at(index.row());
|
||||
QString key = m_attributes.at(index.row());
|
||||
|
||||
if (index.column() == 0) {
|
||||
return key;
|
||||
}
|
||||
else {
|
||||
return m_entryAttributes->value(key);
|
||||
}
|
||||
if (index.column() == 0) {
|
||||
return key;
|
||||
}
|
||||
else {
|
||||
return m_entryAttributes->value(key);
|
||||
}
|
||||
}
|
||||
|
||||
bool EntryAttributesModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
if (!index.isValid() || role != Qt::EditRole || value.type() != QVariant::String
|
||||
|| value.toString().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
QString oldKey = m_attributes.at(index.row());
|
||||
|
||||
if (index.column() == 0) {
|
||||
if (EntryAttributes::isDefaultAttribute(value.toString())) {
|
||||
return false;
|
||||
}
|
||||
m_entryAttributes->rename(oldKey, value.toString());
|
||||
}
|
||||
else {
|
||||
m_entryAttributes->set(oldKey, value.toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::ItemFlags EntryAttributesModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return Qt::NoItemFlags;
|
||||
}
|
||||
else {
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex EntryAttributesModel::indexByKey(const QString& key) const
|
||||
{
|
||||
int row = m_attributes.indexOf(key);
|
||||
|
||||
if (row == -1) {
|
||||
return QModelIndex();
|
||||
}
|
||||
else {
|
||||
return index(row, 0);
|
||||
}
|
||||
}
|
||||
|
||||
QString EntryAttributesModel::keyByIndex(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return QString();
|
||||
}
|
||||
else {
|
||||
return m_attributes.at(index.row());
|
||||
}
|
||||
}
|
||||
|
||||
void EntryAttributesModel::attributeChange(QString key)
|
||||
|
@ -33,6 +33,10 @@ public:
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
QModelIndex indexByKey(const QString& key) const;
|
||||
QString keyByIndex(const QModelIndex& index) const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void attributeChange(QString key);
|
||||
|
Loading…
Reference in New Issue
Block a user