Include groups in custom icon delete check.

Refs #22
This commit is contained in:
Florian Geyer 2012-05-12 01:51:41 +02:00
parent e4b6289c0b
commit 4807ec3368
3 changed files with 34 additions and 10 deletions

View File

@ -378,6 +378,20 @@ QList<Entry*> Group::entriesRecursive(bool includeHistoryItems) const
return entryList;
}
QList<const Group*> Group::groupsRecursive(bool includeSelf) const
{
QList<const Group*> 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);

View File

@ -76,6 +76,7 @@ public:
QList<Entry*> entries();
const QList<Entry*>& entries() const;
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
QList<const Group *> groupsRecursive(bool includeSelf) const;
Q_SIGNALS:

View File

@ -450,25 +450,34 @@ void EditEntryWidget::removeCustomIcon()
if (m_metadata) {
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
if (index.isValid()) {
QList<Entry*> allEntries = m_metadata->database()->rootGroup()->entriesRecursive(true);
Uuid uuid = m_customIconModel->uuidFromIndex(index);
Uuid iconUuid = m_customIconModel->uuidFromIndex(index);
int iconUsedCount = 0;
QListIterator<Entry*> i(allEntries);
while (i.hasNext()) {
Entry* entry = i.next();
if (uuid == entry->iconUuid() && entry != m_entry) {
QList<Entry*> allEntries = m_metadata->database()->rootGroup()->entriesRecursive(true);
QListIterator<Entry*> iEntries(allEntries);
while (iEntries.hasNext()) {
Entry* entry = iEntries.next();
if (iconUuid == entry->iconUuid() && entry != m_entry) {
iconUsedCount++;
}
}
QList<const Group*> allGroups = m_metadata->database()->rootGroup()->groupsRecursive(true);
QListIterator<const Group*> 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));
}
}