mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-08 18:58:29 -05:00
Fix sorting of advanced attribute list (#10091)
Sort advanced attribute list using locale aware sort. Fixes #6175
This commit is contained in:
parent
811887e591
commit
8ca90a070a
@ -24,6 +24,7 @@ EntryAttributesModel::EntryAttributesModel(QObject* parent)
|
|||||||
, m_entryAttributes(nullptr)
|
, m_entryAttributes(nullptr)
|
||||||
, m_nextRenameDataChange(false)
|
, m_nextRenameDataChange(false)
|
||||||
{
|
{
|
||||||
|
m_collator.setNumericMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntryAttributesModel::setEntryAttributes(EntryAttributes* entryAttributes)
|
void EntryAttributesModel::setEntryAttributes(EntryAttributes* entryAttributes)
|
||||||
@ -150,7 +151,7 @@ void EntryAttributesModel::attributeAboutToAdd(const QString& key)
|
|||||||
{
|
{
|
||||||
QList<QString> rows = m_attributes;
|
QList<QString> rows = m_attributes;
|
||||||
rows.append(key);
|
rows.append(key);
|
||||||
std::sort(rows.begin(), rows.end());
|
std::sort(rows.begin(), rows.end(), m_collator);
|
||||||
int row = rows.indexOf(key);
|
int row = rows.indexOf(key);
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
}
|
}
|
||||||
@ -180,7 +181,7 @@ void EntryAttributesModel::attributeAboutToRename(const QString& oldKey, const Q
|
|||||||
QList<QString> rows = m_attributes;
|
QList<QString> rows = m_attributes;
|
||||||
rows.removeOne(oldKey);
|
rows.removeOne(oldKey);
|
||||||
rows.append(newKey);
|
rows.append(newKey);
|
||||||
std::sort(rows.begin(), rows.end());
|
std::sort(rows.begin(), rows.end(), m_collator);
|
||||||
int newRow = rows.indexOf(newKey);
|
int newRow = rows.indexOf(newKey);
|
||||||
if (newRow > oldRow) {
|
if (newRow > oldRow) {
|
||||||
newRow++;
|
newRow++;
|
||||||
@ -232,4 +233,5 @@ void EntryAttributesModel::updateAttributes()
|
|||||||
m_attributes.append(key);
|
m_attributes.append(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::sort(m_attributes.begin(), m_attributes.end(), m_collator);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#define KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
#define KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
#include <QCollator>
|
||||||
|
|
||||||
class EntryAttributes;
|
class EntryAttributes;
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ private:
|
|||||||
EntryAttributes* m_entryAttributes;
|
EntryAttributes* m_entryAttributes;
|
||||||
QList<QString> m_attributes;
|
QList<QString> m_attributes;
|
||||||
bool m_nextRenameDataChange;
|
bool m_nextRenameDataChange;
|
||||||
|
QCollator m_collator;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
#endif // KEEPASSX_ENTRYATTRIBUTESMODEL_H
|
||||||
|
@ -201,6 +201,9 @@ void TestEntryModel::testAttributesModel()
|
|||||||
|
|
||||||
// make sure these don't generate messages
|
// make sure these don't generate messages
|
||||||
entryAttributes->set("Title", "test");
|
entryAttributes->set("Title", "test");
|
||||||
|
entryAttributes->set("UserName", "test");
|
||||||
|
entryAttributes->set("Password", "test");
|
||||||
|
entryAttributes->set("URL", "test");
|
||||||
entryAttributes->set("Notes", "test");
|
entryAttributes->set("Notes", "test");
|
||||||
|
|
||||||
QCOMPARE(spyDataChanged.count(), 1);
|
QCOMPARE(spyDataChanged.count(), 1);
|
||||||
@ -214,6 +217,16 @@ void TestEntryModel::testAttributesModel()
|
|||||||
entryAttributes->set("2nd", value, true);
|
entryAttributes->set("2nd", value, true);
|
||||||
QVERIFY(entryAttributes->isProtected("2nd"));
|
QVERIFY(entryAttributes->isProtected("2nd"));
|
||||||
QCOMPARE(entryAttributes->value("2nd"), value);
|
QCOMPARE(entryAttributes->value("2nd"), value);
|
||||||
|
entryAttributes->clear();
|
||||||
|
|
||||||
|
// test attribute sorting
|
||||||
|
entryAttributes->set("Test1", "1");
|
||||||
|
entryAttributes->set("Test11", "11");
|
||||||
|
entryAttributes->set("Test2", "2");
|
||||||
|
QCOMPARE(model->rowCount(), 3);
|
||||||
|
QCOMPARE(model->data(model->index(0, 0)).toString(), QString("Test1"));
|
||||||
|
QCOMPARE(model->data(model->index(1, 0)).toString(), QString("Test2"));
|
||||||
|
QCOMPARE(model->data(model->index(2, 0)).toString(), QString("Test11"));
|
||||||
|
|
||||||
QSignalSpy spyReset(model, SIGNAL(modelReset()));
|
QSignalSpy spyReset(model, SIGNAL(modelReset()));
|
||||||
entryAttributes->clear();
|
entryAttributes->clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user