Use default icon if no icon is selected in entry/group edit.

This commit is contained in:
Florian Geyer 2012-05-15 16:50:42 +02:00
parent 621ec80bbe
commit da713b0993
4 changed files with 56 additions and 25 deletions

View File

@ -27,6 +27,7 @@
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include "core/Entry.h" #include "core/Entry.h"
#include "core/Metadata.h"
#include "core/Tools.h" #include "core/Tools.h"
#include "gui/EditWidgetIcons.h" #include "gui/EditWidgetIcons.h"
#include "gui/EntryAttachmentsModel.h" #include "gui/EntryAttachmentsModel.h"
@ -175,7 +176,10 @@ void EditEntryWidget::saveEntry()
IconStruct iconStruct = m_iconsWidget->save(); IconStruct iconStruct = m_iconsWidget->save();
if (iconStruct.uuid.isNull()) { if (iconStruct.number < 0) {
m_entry->setIcon(Entry::DefaultIconNumber);
}
else if (iconStruct.uuid.isNull()) {
m_entry->setIcon(iconStruct.number); m_entry->setIcon(iconStruct.number);
} }
else { else {
@ -187,6 +191,7 @@ void EditEntryWidget::saveEntry()
} }
m_entry = 0; m_entry = 0;
m_database = 0;
m_entryAttributes->clear(); m_entryAttributes->clear();
m_entryAttachments->clear(); m_entryAttachments->clear();
@ -195,7 +200,13 @@ void EditEntryWidget::saveEntry()
void EditEntryWidget::cancel() void EditEntryWidget::cancel()
{ {
if (!m_entry->iconUuid().isNull() &&
!m_database->metadata()->containsCustomIcon(m_entry->iconUuid())) {
m_entry->setIcon(Entry::DefaultIconNumber);
}
m_entry = 0; m_entry = 0;
m_database = 0;
m_entryAttributes->clear(); m_entryAttributes->clear();
m_entryAttachments->clear(); m_entryAttachments->clear();

View File

@ -19,6 +19,7 @@
#include "ui_EditGroupWidgetMain.h" #include "ui_EditGroupWidgetMain.h"
#include "ui_EditWidget.h" #include "ui_EditWidget.h"
#include "core/Metadata.h"
#include "gui/EditWidgetIcons.h" #include "gui/EditWidgetIcons.h"
EditGroupWidget::EditGroupWidget(QWidget* parent) EditGroupWidget::EditGroupWidget(QWidget* parent)
@ -49,6 +50,7 @@ EditGroupWidget::~EditGroupWidget()
void EditGroupWidget::loadGroup(Group* group, bool create, Database* database) void EditGroupWidget::loadGroup(Group* group, bool create, Database* database)
{ {
m_group = group; m_group = group;
m_database = database;
if (create) { if (create) {
headlineLabel()->setText(tr("Add group")); headlineLabel()->setText(tr("Add group"));
@ -76,7 +78,10 @@ void EditGroupWidget::save()
IconStruct iconStruct = m_editGroupWidgetIcons->save(); IconStruct iconStruct = m_editGroupWidgetIcons->save();
if (iconStruct.uuid.isNull()) { if (iconStruct.number < 0) {
m_group->setIcon(Group::DefaultIconNumber);
}
else if (iconStruct.uuid.isNull()) {
m_group->setIcon(iconStruct.number); m_group->setIcon(iconStruct.number);
} }
else { else {
@ -84,11 +89,18 @@ void EditGroupWidget::save()
} }
m_group = 0; m_group = 0;
m_database = 0;
Q_EMIT editFinished(true); Q_EMIT editFinished(true);
} }
void EditGroupWidget::cancel() void EditGroupWidget::cancel()
{ {
if (!m_group->iconUuid().isNull() &&
!m_database->metadata()->containsCustomIcon(m_group->iconUuid())) {
m_group->setIcon(Entry::DefaultIconNumber);
}
m_group = 0; m_group = 0;
m_database = 0;
Q_EMIT editFinished(false); Q_EMIT editFinished(false);
} }

View File

@ -52,6 +52,7 @@ private:
QWidget* const m_editGroupWidgetMain; QWidget* const m_editGroupWidgetMain;
EditWidgetIcons* const m_editGroupWidgetIcons; EditWidgetIcons* const m_editGroupWidgetIcons;
Group* m_group; Group* m_group;
Database* m_database;
Q_DISABLE_COPY(EditGroupWidget) Q_DISABLE_COPY(EditGroupWidget)
}; };

View File

@ -62,31 +62,42 @@ EditWidgetIcons::~EditWidgetIcons()
IconStruct EditWidgetIcons::save() IconStruct EditWidgetIcons::save()
{ {
Q_ASSERT(m_database);
Q_ASSERT(!m_currentUuid.isNull());
IconStruct iconStruct; IconStruct iconStruct;
if (m_ui->defaultIconsRadio->isChecked()) { if (m_ui->defaultIconsRadio->isChecked()) {
QModelIndex index = m_ui->defaultIconsView->currentIndex(); QModelIndex index = m_ui->defaultIconsView->currentIndex();
if (index.isValid()) { if (index.isValid()) {
iconStruct.number = index.row(); iconStruct.number = index.row();
} }
else {
Q_ASSERT(false);
}
} }
else { else {
QModelIndex index = m_ui->customIconsView->currentIndex(); QModelIndex index = m_ui->customIconsView->currentIndex();
if (index.isValid()) { if (index.isValid()) {
iconStruct.uuid = m_customIconModel->uuidFromIndex(m_ui->customIconsView->currentIndex()); iconStruct.uuid = m_customIconModel->uuidFromIndex(m_ui->customIconsView->currentIndex());
} }
else {
iconStruct.number = -1;
}
} }
m_database = 0;
m_currentUuid = Uuid();
return iconStruct; return iconStruct;
} }
void EditWidgetIcons::load(Uuid currentUuid, Database* database, IconStruct iconStruct) void EditWidgetIcons::load(Uuid currentUuid, Database* database, IconStruct iconStruct)
{ {
Q_ASSERT(database);
Q_ASSERT(!currentUuid.isNull());
m_database = database; m_database = database;
m_currentUuid = currentUuid; m_currentUuid = currentUuid;
if (database) {
this->setEnabled(true);
m_customIconModel->setIcons(database->metadata()->customIcons(), m_customIconModel->setIcons(database->metadata()->customIcons(),
database->metadata()->customIconsOrder()); database->metadata()->customIconsOrder());
@ -108,10 +119,6 @@ void EditWidgetIcons::load(Uuid currentUuid, Database* database, IconStruct icon
} }
} }
} }
else {
this->setEnabled(false);
}
}
void EditWidgetIcons::addCustomIcon() void EditWidgetIcons::addCustomIcon()
{ {