mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-06-19 12:14:37 -04:00
parent
459cf051bf
commit
a57e8f9864
7 changed files with 46 additions and 27 deletions
|
@ -175,6 +175,11 @@ QHash<Uuid, QImage> Metadata::customIcons() const
|
||||||
return m_customIcons;
|
return m_customIcons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Uuid> Metadata::customIconsOrder() const
|
||||||
|
{
|
||||||
|
return m_customIconsOrder;
|
||||||
|
}
|
||||||
|
|
||||||
bool Metadata::recycleBinEnabled() const
|
bool Metadata::recycleBinEnabled() const
|
||||||
{
|
{
|
||||||
return m_recycleBinEnabled;
|
return m_recycleBinEnabled;
|
||||||
|
@ -328,6 +333,8 @@ void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon)
|
||||||
Q_ASSERT(!m_customIcons.contains(uuid));
|
Q_ASSERT(!m_customIcons.contains(uuid));
|
||||||
|
|
||||||
m_customIcons.insert(uuid, icon);
|
m_customIcons.insert(uuid, icon);
|
||||||
|
m_customIconsOrder.append(uuid);
|
||||||
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,6 +344,8 @@ void Metadata::removeCustomIcon(const Uuid& uuid)
|
||||||
Q_ASSERT(m_customIcons.contains(uuid));
|
Q_ASSERT(m_customIcons.contains(uuid));
|
||||||
|
|
||||||
m_customIcons.remove(uuid);
|
m_customIcons.remove(uuid);
|
||||||
|
m_customIconsOrder.removeAll(uuid);
|
||||||
|
Q_ASSERT(m_customIcons.count() == m_customIconsOrder.count());
|
||||||
Q_EMIT modified();
|
Q_EMIT modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
QImage customIcon(const Uuid& uuid) const;
|
QImage customIcon(const Uuid& uuid) const;
|
||||||
bool containsCustomIcon(const Uuid& uuid) const;
|
bool containsCustomIcon(const Uuid& uuid) const;
|
||||||
QHash<Uuid, QImage> customIcons() const;
|
QHash<Uuid, QImage> customIcons() const;
|
||||||
|
QList<Uuid> customIconsOrder() const;
|
||||||
bool recycleBinEnabled() const;
|
bool recycleBinEnabled() const;
|
||||||
Group* recycleBin();
|
Group* recycleBin();
|
||||||
const Group* recycleBin() const;
|
const Group* recycleBin() const;
|
||||||
|
@ -134,6 +135,7 @@ private:
|
||||||
// bool m_autoEnableVisualHiding;
|
// bool m_autoEnableVisualHiding;
|
||||||
|
|
||||||
QHash<Uuid, QImage> m_customIcons;
|
QHash<Uuid, QImage> m_customIcons;
|
||||||
|
QList<Uuid> m_customIconsOrder;
|
||||||
|
|
||||||
bool m_recycleBinEnabled;
|
bool m_recycleBinEnabled;
|
||||||
QPointer<Group> m_recycleBin;
|
QPointer<Group> m_recycleBin;
|
||||||
|
|
|
@ -129,9 +129,10 @@ void KeePass2XmlWriter::writeCustomIcons()
|
||||||
{
|
{
|
||||||
m_xml.writeStartElement("CustomIcons");
|
m_xml.writeStartElement("CustomIcons");
|
||||||
|
|
||||||
QHash<Uuid, QImage> customIcons = m_meta->customIcons();
|
QListIterator<Uuid> i(m_meta->customIconsOrder());
|
||||||
Q_FOREACH (const Uuid& uuid, customIcons.keys()) {
|
while (i.hasNext()) {
|
||||||
writeIcon(uuid, customIcons.value(uuid));
|
Uuid uuid = i.next();
|
||||||
|
writeIcon(uuid, m_meta->customIcon(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_xml.writeEndElement();
|
m_xml.writeEndElement();
|
||||||
|
|
|
@ -171,7 +171,8 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupN
|
||||||
if (database) {
|
if (database) {
|
||||||
m_iconsWidget->setEnabled(true);
|
m_iconsWidget->setEnabled(true);
|
||||||
|
|
||||||
m_customIconModel->setIcons(database->metadata()->customIcons());
|
m_customIconModel->setIcons(database->metadata()->customIcons(),
|
||||||
|
database->metadata()->customIconsOrder());
|
||||||
|
|
||||||
Uuid iconUuid = entry->iconUuid();
|
Uuid iconUuid = entry->iconUuid();
|
||||||
if (iconUuid.isNull()) {
|
if (iconUuid.isNull()) {
|
||||||
|
@ -436,7 +437,8 @@ void EditEntryWidget::addCustomIcon()
|
||||||
QImage image(filename);
|
QImage image(filename);
|
||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
m_database->metadata()->addCustomIcon(Uuid::random(), image.scaled(16, 16));
|
m_database->metadata()->addCustomIcon(Uuid::random(), image.scaled(16, 16));
|
||||||
m_customIconModel->setIcons(m_database->metadata()->customIcons());
|
m_customIconModel->setIcons(m_database->metadata()->customIcons(),
|
||||||
|
m_database->metadata()->customIconsOrder());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: show error
|
// TODO: show error
|
||||||
|
@ -473,7 +475,8 @@ void EditEntryWidget::removeCustomIcon()
|
||||||
|
|
||||||
if (iconUsedCount == 0) {
|
if (iconUsedCount == 0) {
|
||||||
m_database->metadata()->removeCustomIcon(iconUuid);
|
m_database->metadata()->removeCustomIcon(iconUuid);
|
||||||
m_customIconModel->setIcons(m_database->metadata()->customIcons());
|
m_customIconModel->setIcons(m_database->metadata()->customIcons(),
|
||||||
|
m_database->metadata()->customIconsOrder());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QMessageBox::information(this, tr("Can't delete icon!"),
|
QMessageBox::information(this, tr("Can't delete icon!"),
|
||||||
|
|
|
@ -54,19 +54,13 @@ CustomIconModel::CustomIconModel(QObject* parent) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomIconModel::setIcons(QHash<Uuid, QImage> icons)
|
void CustomIconModel::setIcons(QHash<Uuid, QImage> icons, QList<Uuid> iconsOrder)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
m_icons = icons;
|
m_icons = icons;
|
||||||
m_uuids.clear();
|
m_iconsOrder = iconsOrder;
|
||||||
QHash<Uuid, QImage>::const_iterator iter;
|
Q_ASSERT(m_icons.count() == m_iconsOrder.count());
|
||||||
int i = 0;
|
|
||||||
for (iter = m_icons.constBegin(); iter != m_icons.constEnd(); ++iter) {
|
|
||||||
m_uuids.insert(i, iter.key());
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
Q_ASSERT(m_uuids.count() == m_icons.size());
|
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
@ -88,7 +82,8 @@ QVariant CustomIconModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
return m_icons.value(uuidFromIndex(index));
|
Uuid uuid = m_iconsOrder.value(index.row());
|
||||||
|
return m_icons.value(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -98,16 +93,16 @@ Uuid CustomIconModel::uuidFromIndex(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(index.isValid());
|
Q_ASSERT(index.isValid());
|
||||||
|
|
||||||
return m_uuids.value(index.row());
|
return m_iconsOrder.value(index.row());
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex CustomIconModel::indexFromUuid(const Uuid& uuid) const
|
QModelIndex CustomIconModel::indexFromUuid(const Uuid& uuid) const
|
||||||
{
|
{
|
||||||
QHash<int, Uuid>::const_iterator iter;
|
int idx = m_iconsOrder.indexOf(uuid);
|
||||||
for (iter = m_uuids.constBegin(); iter != m_uuids.constEnd(); ++iter) {
|
if (idx > -1) {
|
||||||
if (iter.value() == uuid) {
|
return index(idx, 0);
|
||||||
return index(iter.key(), 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,13 @@ public:
|
||||||
|
|
||||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||||
void setIcons(QHash<Uuid, QImage> icons);
|
void setIcons(QHash<Uuid, QImage> icons, QList<Uuid> iconsOrder);
|
||||||
Uuid uuidFromIndex(const QModelIndex& index) const;
|
Uuid uuidFromIndex(const QModelIndex& index) const;
|
||||||
QModelIndex indexFromUuid(const Uuid& uuid) const;
|
QModelIndex indexFromUuid(const Uuid& uuid) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<Uuid, QImage> m_icons;
|
QHash<Uuid, QImage> m_icons;
|
||||||
QHash<int, Uuid> m_uuids;
|
QList<Uuid> m_iconsOrder;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_ICONMODELS_H
|
#endif // KEEPASSX_ICONMODELS_H
|
||||||
|
|
|
@ -207,12 +207,21 @@ void TestEntryModel::testCustomIconModel()
|
||||||
QCOMPARE(model->rowCount(), 0);
|
QCOMPARE(model->rowCount(), 0);
|
||||||
|
|
||||||
QHash<Uuid, QImage> icons;
|
QHash<Uuid, QImage> icons;
|
||||||
Uuid iconUuid = Uuid::random();
|
QList<Uuid> iconsOrder;
|
||||||
|
|
||||||
|
Uuid iconUuid(QByteArray(16, '2'));
|
||||||
QImage icon;
|
QImage icon;
|
||||||
icons.insert(iconUuid, icon);
|
icons.insert(iconUuid, icon);
|
||||||
|
iconsOrder << iconUuid;
|
||||||
|
|
||||||
model->setIcons(icons);
|
Uuid iconUuid2(QByteArray(16, '1'));
|
||||||
|
QImage icon2;
|
||||||
|
icons.insert(iconUuid2, icon2);
|
||||||
|
iconsOrder << iconUuid2;
|
||||||
|
|
||||||
|
model->setIcons(icons, iconsOrder);
|
||||||
QCOMPARE(model->uuidFromIndex(model->index(0, 0)), iconUuid);
|
QCOMPARE(model->uuidFromIndex(model->index(0, 0)), iconUuid);
|
||||||
|
QCOMPARE(model->uuidFromIndex(model->index(1, 0)), iconUuid2);
|
||||||
|
|
||||||
delete modelTest;
|
delete modelTest;
|
||||||
delete model;
|
delete model;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue