From baa5a74ba0f6b2d9b361747b1056d005b17ebe16 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Fri, 29 Jun 2012 15:22:43 +0200 Subject: [PATCH] Convert iconCount() and expiredIconIndex() to constants. --- src/core/DatabaseIcons.cpp | 28 ++++++++++------------------ src/core/DatabaseIcons.h | 5 +++-- src/format/KeePass2XmlReader.cpp | 2 +- src/gui/IconModels.cpp | 4 ++-- src/gui/entry/EntryModel.cpp | 2 +- src/gui/group/GroupModel.cpp | 2 +- tests/TestEntryModel.cpp | 2 +- 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/core/DatabaseIcons.cpp b/src/core/DatabaseIcons.cpp index 44706491b..f74200fa8 100644 --- a/src/core/DatabaseIcons.cpp +++ b/src/core/DatabaseIcons.cpp @@ -20,10 +20,12 @@ #include "core/DataPath.h" DatabaseIcons* DatabaseIcons::m_instance(Q_NULLPTR); +const int DatabaseIcons::IconCount(69); +const int DatabaseIcons::ExpiredIconIndex(45); QImage DatabaseIcons::icon(int index) { - if (index < 0 || index >= iconCount()) { + if (index < 0 || index >= IconCount) { qWarning("DatabaseIcons::icon: invalid icon index %d", index); return QImage(); } @@ -42,7 +44,7 @@ QImage DatabaseIcons::icon(int index) QPixmap DatabaseIcons::iconPixmap(int index) { - if (index < 0 || index >= iconCount()) { + if (index < 0 || index >= IconCount) { qWarning("DatabaseIcons::iconPixmap: invalid icon index %d", index); return QPixmap(); } @@ -57,19 +59,9 @@ QPixmap DatabaseIcons::iconPixmap(int index) return pixmap; } -int DatabaseIcons::iconCount() -{ - return 69; -} - -int DatabaseIcons::expiredIconIndex() -{ - return 45; -} - DatabaseIcons::DatabaseIcons() { - m_indexToName.reserve(iconCount()); + m_indexToName.reserve(IconCount); m_indexToName.append("C00_Password.png"); m_indexToName.append("C01_Package_Network.png"); m_indexToName.append("C02_MessageBox_Warning.png"); @@ -140,12 +132,12 @@ DatabaseIcons::DatabaseIcons() m_indexToName.append("C67_Certificate.png"); m_indexToName.append("C68_BlackBerry.png"); - Q_ASSERT(m_indexToName.size() == iconCount()); + Q_ASSERT(m_indexToName.size() == IconCount); - m_iconCache.reserve(iconCount()); - m_iconCache.resize(iconCount()); - m_pixmapCacheKeys.reserve(iconCount()); - m_pixmapCacheKeys.resize(iconCount()); + m_iconCache.reserve(IconCount); + m_iconCache.resize(IconCount); + m_pixmapCacheKeys.reserve(IconCount); + m_pixmapCacheKeys.resize(IconCount); } DatabaseIcons* DatabaseIcons::instance() diff --git a/src/core/DatabaseIcons.h b/src/core/DatabaseIcons.h index b7fa3e1a2..08253c577 100644 --- a/src/core/DatabaseIcons.h +++ b/src/core/DatabaseIcons.h @@ -30,11 +30,12 @@ class DatabaseIcons public: QImage icon(int index); QPixmap iconPixmap(int index); - int iconCount(); - int expiredIconIndex(); static DatabaseIcons* instance(); + static const int IconCount; + static const int ExpiredIconIndex; + private: DatabaseIcons(); diff --git a/src/format/KeePass2XmlReader.cpp b/src/format/KeePass2XmlReader.cpp index b0e540542..14f6ef330 100644 --- a/src/format/KeePass2XmlReader.cpp +++ b/src/format/KeePass2XmlReader.cpp @@ -423,7 +423,7 @@ Group* KeePass2XmlReader::parseGroup() raiseError(2); } else { - if (iconId >= databaseIcons()->iconCount()) { + if (iconId >= DatabaseIcons::IconCount) { qWarning("KeePass2XmlReader::parseGroup: icon id \"%d\" not supported", iconId); } group->setIcon(iconId); diff --git a/src/gui/IconModels.cpp b/src/gui/IconModels.cpp index 00b075e3c..c169e875b 100644 --- a/src/gui/IconModels.cpp +++ b/src/gui/IconModels.cpp @@ -27,7 +27,7 @@ DefaultIconModel::DefaultIconModel(QObject* parent) int DefaultIconModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) { - return databaseIcons()->iconCount(); + return DatabaseIcons::IconCount; } else { return 0; @@ -40,7 +40,7 @@ QVariant DefaultIconModel::data(const QModelIndex& index, int role) const return QVariant(); } - Q_ASSERT(index.row() < databaseIcons()->iconCount()); + Q_ASSERT(index.row() < DatabaseIcons::IconCount); if (role == Qt::DecorationRole) { return databaseIcons()->iconPixmap(index.row()); diff --git a/src/gui/entry/EntryModel.cpp b/src/gui/entry/EntryModel.cpp index a2327fe7b..c71e19638 100644 --- a/src/gui/entry/EntryModel.cpp +++ b/src/gui/entry/EntryModel.cpp @@ -134,7 +134,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const break; case 1: if (entry->isExpired()) { - return databaseIcons()->iconPixmap(databaseIcons()->expiredIconIndex()); + return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex); } else { return entry->iconPixmap(); diff --git a/src/gui/group/GroupModel.cpp b/src/gui/group/GroupModel.cpp index ec679cd5f..fe658621e 100644 --- a/src/gui/group/GroupModel.cpp +++ b/src/gui/group/GroupModel.cpp @@ -132,7 +132,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const } else if (role == Qt::DecorationRole) { if (group->isExpired()) { - return databaseIcons()->iconPixmap(databaseIcons()->expiredIconIndex()); + return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex); } else { return group->iconPixmap(); diff --git a/tests/TestEntryModel.cpp b/tests/TestEntryModel.cpp index 53d5bc71a..519bfbd88 100644 --- a/tests/TestEntryModel.cpp +++ b/tests/TestEntryModel.cpp @@ -193,7 +193,7 @@ void TestEntryModel::testDefaultIconModel() DefaultIconModel* model = new DefaultIconModel(this); ModelTest* modelTest = new ModelTest(model, this); - QCOMPARE(model->rowCount(), databaseIcons()->iconCount()); + QCOMPARE(model->rowCount(), DatabaseIcons::IconCount); delete modelTest; delete model;