From 4807ec3368bca6138a79f8e769bb07a3abd28bb1 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Sat, 12 May 2012 01:51:41 +0200 Subject: [PATCH] Include groups in custom icon delete check. Refs #22 --- src/core/Group.cpp | 14 ++++++++++++++ src/core/Group.h | 1 + src/gui/EditEntryWidget.cpp | 29 +++++++++++++++++++---------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 460480250..1329ae285 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -378,6 +378,20 @@ QList Group::entriesRecursive(bool includeHistoryItems) const return entryList; } +QList Group::groupsRecursive(bool includeSelf) const +{ + QList groupList; + if (includeSelf) { + groupList.append(this); + } + + Q_FOREACH (Group* group, m_children) { + groupList.append(group->groupsRecursive(true)); + } + + return groupList; +} + void Group::addEntry(Entry* entry) { Q_ASSERT(entry); diff --git a/src/core/Group.h b/src/core/Group.h index 593426eda..122f0c1fa 100644 --- a/src/core/Group.h +++ b/src/core/Group.h @@ -76,6 +76,7 @@ public: QList entries(); const QList& entries() const; QList entriesRecursive(bool includeHistoryItems = false) const; + QList groupsRecursive(bool includeSelf) const; Q_SIGNALS: diff --git a/src/gui/EditEntryWidget.cpp b/src/gui/EditEntryWidget.cpp index 79f6cdb36..600303ba0 100644 --- a/src/gui/EditEntryWidget.cpp +++ b/src/gui/EditEntryWidget.cpp @@ -450,25 +450,34 @@ void EditEntryWidget::removeCustomIcon() if (m_metadata) { QModelIndex index = m_iconsUi->customIconsView->currentIndex(); if (index.isValid()) { - QList allEntries = m_metadata->database()->rootGroup()->entriesRecursive(true); - Uuid uuid = m_customIconModel->uuidFromIndex(index); - + Uuid iconUuid = m_customIconModel->uuidFromIndex(index); int iconUsedCount = 0; - QListIterator i(allEntries); - while (i.hasNext()) { - Entry* entry = i.next(); - if (uuid == entry->iconUuid() && entry != m_entry) { + + QList allEntries = m_metadata->database()->rootGroup()->entriesRecursive(true); + QListIterator iEntries(allEntries); + while (iEntries.hasNext()) { + Entry* entry = iEntries.next(); + if (iconUuid == entry->iconUuid() && entry != m_entry) { + iconUsedCount++; + } + } + + QList allGroups = m_metadata->database()->rootGroup()->groupsRecursive(true); + QListIterator iGroups(allGroups); + while (iGroups.hasNext()) { + const Group* group = iGroups.next(); + if (iconUuid == group->iconUuid()) { iconUsedCount++; } } if (iconUsedCount == 0) { - m_metadata->removeCustomIcon(uuid); + m_metadata->removeCustomIcon(iconUuid); m_customIconModel->setIcons(m_metadata->customIcons()); } else { - QMessageBox::information(this, tr("Icon still used!"), - tr("Can't delete icon. Still used by %1 entries.") + QMessageBox::information(this, tr("Can't delete icon!"), + tr("Can't delete icon. Still used by %1 items.") .arg(iconUsedCount)); } }