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

View File

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

View File

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

View File

@ -62,54 +62,61 @@ EditWidgetIcons::~EditWidgetIcons()
IconStruct EditWidgetIcons::save()
{
Q_ASSERT(m_database);
Q_ASSERT(!m_currentUuid.isNull());
IconStruct iconStruct;
if (m_ui->defaultIconsRadio->isChecked()) {
QModelIndex index = m_ui->defaultIconsView->currentIndex();
if (index.isValid()) {
iconStruct.number = index.row();
}
else {
Q_ASSERT(false);
}
}
else {
QModelIndex index = m_ui->customIconsView->currentIndex();
if (index.isValid()) {
iconStruct.uuid = m_customIconModel->uuidFromIndex(m_ui->customIconsView->currentIndex());
}
else {
iconStruct.number = -1;
}
}
m_database = 0;
m_currentUuid = Uuid();
return iconStruct;
}
void EditWidgetIcons::load(Uuid currentUuid, Database* database, IconStruct iconStruct)
{
Q_ASSERT(database);
Q_ASSERT(!currentUuid.isNull());
m_database = database;
m_currentUuid = currentUuid;
if (database) {
this->setEnabled(true);
m_customIconModel->setIcons(database->metadata()->customIcons(),
database->metadata()->customIconsOrder());
m_customIconModel->setIcons(database->metadata()->customIcons(),
database->metadata()->customIconsOrder());
Uuid iconUuid = iconStruct.uuid;
if (iconUuid.isNull()) {
int iconNumber = iconStruct.number;
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0));
m_ui->defaultIconsRadio->setChecked(true);
}
else {
QModelIndex index = m_customIconModel->indexFromUuid(iconUuid);
if (index.isValid()) {
m_ui->customIconsView->setCurrentIndex(index);
m_ui->customIconsRadio->setChecked(true);
}
else {
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0));
m_ui->defaultIconsRadio->setChecked(true);
}
}
Uuid iconUuid = iconStruct.uuid;
if (iconUuid.isNull()) {
int iconNumber = iconStruct.number;
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0));
m_ui->defaultIconsRadio->setChecked(true);
}
else {
this->setEnabled(false);
QModelIndex index = m_customIconModel->indexFromUuid(iconUuid);
if (index.isValid()) {
m_ui->customIconsView->setCurrentIndex(index);
m_ui->customIconsRadio->setChecked(true);
}
else {
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0));
m_ui->defaultIconsRadio->setChecked(true);
}
}
}