Convert iconCount() and expiredIconIndex() to constants.

This commit is contained in:
Felix Geyer 2012-06-29 15:22:43 +02:00
parent e144f7c85a
commit baa5a74ba0
7 changed files with 19 additions and 26 deletions

View File

@ -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()

View File

@ -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();

View File

@ -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);

View File

@ -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());

View File

@ -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();

View File

@ -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();

View File

@ -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;