mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 07:19:42 -05:00
Convert iconCount() and expiredIconIndex() to constants.
This commit is contained in:
parent
e144f7c85a
commit
baa5a74ba0
@ -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()
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user