From 8204f2007aa7092994405b75f31c6efcd65c3f04 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 10 May 2012 13:59:36 +0200 Subject: [PATCH] Icon model fixes. --- src/gui/EditEntryWidget.cpp | 30 +++++++++++++----------------- src/gui/EditEntryWidgetIcons.ui | 3 --- src/gui/IconModels.cpp | 18 +++++++++++++----- src/gui/IconModels.h | 3 ++- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/gui/EditEntryWidget.cpp b/src/gui/EditEntryWidget.cpp index 60c58973..a4ae78a6 100644 --- a/src/gui/EditEntryWidget.cpp +++ b/src/gui/EditEntryWidget.cpp @@ -177,7 +177,6 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupN int iconNumber = entry->iconNumber(); m_iconsUi->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0)); m_iconsUi->defaultIconsRadio->setChecked(true); - } else { QModelIndex index = m_customIconModel->indexFromUuid(iconUuid); @@ -425,16 +424,17 @@ void EditEntryWidget::addCustomIcon() if (m_metadata) { QString filename = QFileDialog::getOpenFileName( this, tr("Select Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); - QImage image(filename); - if (!image.isNull()) { - m_metadata->addCustomIcon(Uuid::random(), image.scaled(16, 16)); - m_customIconModel->setIcons(m_metadata->customIcons()); - } - else { - ; // TODO show error + if (!filename.isEmpty()) { + QImage image(filename); + if (!image.isNull()) { + m_metadata->addCustomIcon(Uuid::random(), image.scaled(16, 16)); + m_customIconModel->setIcons(m_metadata->customIcons()); + } + else { + // TODO: show error + } } } - } void EditEntryWidget::removeCustomIcon() @@ -442,12 +442,10 @@ void EditEntryWidget::removeCustomIcon() if (m_metadata) { QModelIndex index = m_iconsUi->customIconsView->currentIndex(); if (index.isValid()) { + // TODO: check if the icon is used in history items or other entries m_metadata->removeCustomIcon(m_customIconModel->uuidFromIndex(index)); m_customIconModel->setIcons(m_metadata->customIcons()); } - else { - // TODO show error - } } } @@ -455,8 +453,7 @@ void EditEntryWidget::updateIndexDefaultIcons(bool check) { if (check) { QModelIndex index = m_iconsUi->defaultIconsView->currentIndex(); - if (!index.isValid()) - { + if (!index.isValid()) { m_iconsUi->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0)); } } @@ -466,9 +463,8 @@ void EditEntryWidget::updateIndexCustomIcons(bool check) { if (check) { QModelIndex index = m_iconsUi->customIconsView->currentIndex(); - if (!index.isValid()) - { - m_iconsUi->customIconsView->setCurrentIndex(m_customIconModel->index(0, 0));; + if (!index.isValid()) { + m_iconsUi->customIconsView->setCurrentIndex(m_customIconModel->index(0, 0)); } } } diff --git a/src/gui/EditEntryWidgetIcons.ui b/src/gui/EditEntryWidgetIcons.ui index 87fdb8ec..751c973d 100644 --- a/src/gui/EditEntryWidgetIcons.ui +++ b/src/gui/EditEntryWidgetIcons.ui @@ -10,9 +10,6 @@ 300 - - Form - diff --git a/src/gui/IconModels.cpp b/src/gui/IconModels.cpp index eaf2a490..de38b114 100644 --- a/src/gui/IconModels.cpp +++ b/src/gui/IconModels.cpp @@ -26,8 +26,12 @@ DefaultIconModel::DefaultIconModel(QObject* parent) : int DefaultIconModel::rowCount(const QModelIndex& parent) const { - Q_UNUSED(parent); - return databaseIcons()->iconCount(); + if (!parent.isValid()) { + return databaseIcons()->iconCount(); + } + else { + return 0; + } } QVariant DefaultIconModel::data(const QModelIndex& index, int role) const @@ -69,8 +73,12 @@ void CustomIconModel::setIcons(QHash icons) int CustomIconModel::rowCount(const QModelIndex& parent) const { - Q_UNUSED(parent); - return m_icons.size(); + if (!parent.isValid()) { + return m_icons.size(); + } + else { + return 0; + } } QVariant CustomIconModel::data(const QModelIndex& index, int role) const @@ -98,7 +106,7 @@ QModelIndex CustomIconModel::indexFromUuid(const Uuid& uuid) const QHash::const_iterator iter; for (iter = m_uuids.constBegin(); iter != m_uuids.constEnd(); ++iter) { if (iter.value() == uuid) { - return createIndex(iter.key(), 0); + return index(iter.key(), 0); } } return QModelIndex(); diff --git a/src/gui/IconModels.h b/src/gui/IconModels.h index 7f7e1d08..edcfd7e2 100644 --- a/src/gui/IconModels.h +++ b/src/gui/IconModels.h @@ -26,6 +26,7 @@ class DefaultIconModel : public QAbstractListModel { Q_OBJECT + public: explicit DefaultIconModel(QObject* parent = 0); @@ -36,6 +37,7 @@ public: class CustomIconModel : public QAbstractListModel { Q_OBJECT + public: explicit CustomIconModel(QObject* parent = 0); @@ -48,7 +50,6 @@ public: private: QHash m_icons; QHash m_uuids; - }; #endif // KEEPASSX_ICONMODELS_H