mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-25 15:29:44 -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"
|
#include "core/DataPath.h"
|
||||||
|
|
||||||
DatabaseIcons* DatabaseIcons::m_instance(Q_NULLPTR);
|
DatabaseIcons* DatabaseIcons::m_instance(Q_NULLPTR);
|
||||||
|
const int DatabaseIcons::IconCount(69);
|
||||||
|
const int DatabaseIcons::ExpiredIconIndex(45);
|
||||||
|
|
||||||
QImage DatabaseIcons::icon(int index)
|
QImage DatabaseIcons::icon(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= iconCount()) {
|
if (index < 0 || index >= IconCount) {
|
||||||
qWarning("DatabaseIcons::icon: invalid icon index %d", index);
|
qWarning("DatabaseIcons::icon: invalid icon index %d", index);
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
@ -42,7 +44,7 @@ QImage DatabaseIcons::icon(int index)
|
|||||||
|
|
||||||
QPixmap DatabaseIcons::iconPixmap(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);
|
qWarning("DatabaseIcons::iconPixmap: invalid icon index %d", index);
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
@ -57,19 +59,9 @@ QPixmap DatabaseIcons::iconPixmap(int index)
|
|||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DatabaseIcons::iconCount()
|
|
||||||
{
|
|
||||||
return 69;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DatabaseIcons::expiredIconIndex()
|
|
||||||
{
|
|
||||||
return 45;
|
|
||||||
}
|
|
||||||
|
|
||||||
DatabaseIcons::DatabaseIcons()
|
DatabaseIcons::DatabaseIcons()
|
||||||
{
|
{
|
||||||
m_indexToName.reserve(iconCount());
|
m_indexToName.reserve(IconCount);
|
||||||
m_indexToName.append("C00_Password.png");
|
m_indexToName.append("C00_Password.png");
|
||||||
m_indexToName.append("C01_Package_Network.png");
|
m_indexToName.append("C01_Package_Network.png");
|
||||||
m_indexToName.append("C02_MessageBox_Warning.png");
|
m_indexToName.append("C02_MessageBox_Warning.png");
|
||||||
@ -140,12 +132,12 @@ DatabaseIcons::DatabaseIcons()
|
|||||||
m_indexToName.append("C67_Certificate.png");
|
m_indexToName.append("C67_Certificate.png");
|
||||||
m_indexToName.append("C68_BlackBerry.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.reserve(IconCount);
|
||||||
m_iconCache.resize(iconCount());
|
m_iconCache.resize(IconCount);
|
||||||
m_pixmapCacheKeys.reserve(iconCount());
|
m_pixmapCacheKeys.reserve(IconCount);
|
||||||
m_pixmapCacheKeys.resize(iconCount());
|
m_pixmapCacheKeys.resize(IconCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseIcons* DatabaseIcons::instance()
|
DatabaseIcons* DatabaseIcons::instance()
|
||||||
|
@ -30,11 +30,12 @@ class DatabaseIcons
|
|||||||
public:
|
public:
|
||||||
QImage icon(int index);
|
QImage icon(int index);
|
||||||
QPixmap iconPixmap(int index);
|
QPixmap iconPixmap(int index);
|
||||||
int iconCount();
|
|
||||||
int expiredIconIndex();
|
|
||||||
|
|
||||||
static DatabaseIcons* instance();
|
static DatabaseIcons* instance();
|
||||||
|
|
||||||
|
static const int IconCount;
|
||||||
|
static const int ExpiredIconIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DatabaseIcons();
|
DatabaseIcons();
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ Group* KeePass2XmlReader::parseGroup()
|
|||||||
raiseError(2);
|
raiseError(2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (iconId >= databaseIcons()->iconCount()) {
|
if (iconId >= DatabaseIcons::IconCount) {
|
||||||
qWarning("KeePass2XmlReader::parseGroup: icon id \"%d\" not supported", iconId);
|
qWarning("KeePass2XmlReader::parseGroup: icon id \"%d\" not supported", iconId);
|
||||||
}
|
}
|
||||||
group->setIcon(iconId);
|
group->setIcon(iconId);
|
||||||
|
@ -27,7 +27,7 @@ DefaultIconModel::DefaultIconModel(QObject* parent)
|
|||||||
int DefaultIconModel::rowCount(const QModelIndex& parent) const
|
int DefaultIconModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid()) {
|
if (!parent.isValid()) {
|
||||||
return databaseIcons()->iconCount();
|
return DatabaseIcons::IconCount;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -40,7 +40,7 @@ QVariant DefaultIconModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(index.row() < databaseIcons()->iconCount());
|
Q_ASSERT(index.row() < DatabaseIcons::IconCount);
|
||||||
|
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
return databaseIcons()->iconPixmap(index.row());
|
return databaseIcons()->iconPixmap(index.row());
|
||||||
|
@ -134,7 +134,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (entry->isExpired()) {
|
if (entry->isExpired()) {
|
||||||
return databaseIcons()->iconPixmap(databaseIcons()->expiredIconIndex());
|
return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return entry->iconPixmap();
|
return entry->iconPixmap();
|
||||||
|
@ -132,7 +132,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
else if (role == Qt::DecorationRole) {
|
else if (role == Qt::DecorationRole) {
|
||||||
if (group->isExpired()) {
|
if (group->isExpired()) {
|
||||||
return databaseIcons()->iconPixmap(databaseIcons()->expiredIconIndex());
|
return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return group->iconPixmap();
|
return group->iconPixmap();
|
||||||
|
@ -193,7 +193,7 @@ void TestEntryModel::testDefaultIconModel()
|
|||||||
DefaultIconModel* model = new DefaultIconModel(this);
|
DefaultIconModel* model = new DefaultIconModel(this);
|
||||||
ModelTest* modelTest = new ModelTest(model, this);
|
ModelTest* modelTest = new ModelTest(model, this);
|
||||||
|
|
||||||
QCOMPARE(model->rowCount(), databaseIcons()->iconCount());
|
QCOMPARE(model->rowCount(), DatabaseIcons::IconCount);
|
||||||
|
|
||||||
delete modelTest;
|
delete modelTest;
|
||||||
delete model;
|
delete model;
|
||||||
|
Loading…
Reference in New Issue
Block a user