mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-23 21:21:08 -05:00
Turn EntryAttributesModel into a QAbstractListModel.
This commit is contained in:
parent
6140a688d7
commit
7f67019f63
@ -21,7 +21,7 @@
|
|||||||
#include "core/Tools.h"
|
#include "core/Tools.h"
|
||||||
|
|
||||||
EntryAttributesModel::EntryAttributesModel(QObject* parent)
|
EntryAttributesModel::EntryAttributesModel(QObject* parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_entryAttributes(0)
|
, m_entryAttributes(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -64,21 +64,17 @@ int EntryAttributesModel::columnCount(const QModelIndex& parent) const
|
|||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
|
|
||||||
return 2;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant EntryAttributesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant EntryAttributesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) {
|
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole) && (section == 0)) {
|
||||||
switch (section) {
|
return tr("Name");
|
||||||
case 0:
|
}
|
||||||
return tr("Name");
|
else {
|
||||||
case 1:
|
return QVariant();
|
||||||
return tr("Value");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant EntryAttributesModel::data(const QModelIndex& index, int role) const
|
QVariant EntryAttributesModel::data(const QModelIndex& index, int role) const
|
||||||
@ -87,14 +83,7 @@ QVariant EntryAttributesModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString key = m_attributes.at(index.row());
|
return m_attributes.at(index.row());
|
||||||
|
|
||||||
if (index.column() == 0) {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return m_entryAttributes->value(key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntryAttributesModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
bool EntryAttributesModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
@ -105,16 +94,13 @@ bool EntryAttributesModel::setData(const QModelIndex& index, const QVariant& val
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString oldKey = m_attributes.at(index.row());
|
QString oldKey = m_attributes.at(index.row());
|
||||||
|
QString newKey = value.toString();
|
||||||
|
|
||||||
if (index.column() == 0) {
|
if (EntryAttributes::isDefaultAttribute(newKey)
|
||||||
if (EntryAttributes::isDefaultAttribute(value.toString())) {
|
|| m_entryAttributes->keys().contains(newKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
m_entryAttributes->rename(oldKey, value.toString());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_entryAttributes->set(oldKey, value.toString());
|
|
||||||
}
|
}
|
||||||
|
m_entryAttributes->rename(oldKey, newKey);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
#ifndef KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
#ifndef KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
||||||
#define KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
#define KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
||||||
|
|
||||||
#include <QtCore/QAbstractTableModel>
|
#include <QtCore/QAbstractListModel>
|
||||||
|
|
||||||
class EntryAttributes;
|
class EntryAttributes;
|
||||||
|
|
||||||
class EntryAttributesModel : public QAbstractTableModel
|
class EntryAttributesModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -161,7 +161,6 @@ void TestEntryModel::testAttributesModel()
|
|||||||
entryAttributes->set("2nd", "789");
|
entryAttributes->set("2nd", "789");
|
||||||
|
|
||||||
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("2nd"));
|
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("2nd"));
|
||||||
QCOMPARE(model->data(model->index(0, 1)).toString(), QString("789"));
|
|
||||||
|
|
||||||
entryAttributes->remove("first");
|
entryAttributes->remove("first");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user