refs #618, allow to display icon when DB key is set

This commit is contained in:
Klaus Basan
2016-03-25 03:27:15 +01:00
parent 691ffa3417
commit bb16d5d069
2 changed files with 34 additions and 12 deletions

View File

@@ -34,6 +34,13 @@ namespace BlackMisc
this->m_dbKey = k; this->m_dbKey = k;
} }
const CIcon &IDatastoreObjectWithIntegerKey::toDatabaseIcon() const
{
static const CIcon empty;
if (this->hasValidDbKey()) { return CIconList::iconByIndex(CIcons::StandardIconDatabaseKey16); }
return empty;
}
int IDatastoreObjectWithIntegerKey::stringToDbKey(const QString &candidate) int IDatastoreObjectWithIntegerKey::stringToDbKey(const QString &candidate)
{ {
if (candidate.isEmpty()) { return invalidDbKey(); } if (candidate.isEmpty()) { return invalidDbKey(); }
@@ -69,8 +76,8 @@ namespace BlackMisc
switch (i) switch (i)
{ {
case IndexDbIntegerKey: return CVariant::from(this->m_dbKey); case IndexDbIntegerKey: return CVariant::from(this->m_dbKey);
default: case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
break; default: break;
} }
return CVariant(); return CVariant();
} }
@@ -100,10 +107,9 @@ namespace BlackMisc
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbIntegerKey: case IndexDbIntegerKey: return Compare::compare(this->m_dbKey, compareValue.getDbKey());
return Compare::compare(this->m_dbKey, compareValue.getDbKey()); case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
default: default: break;
break;
} }
Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed"); Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
return 0; return 0;
@@ -113,7 +119,7 @@ namespace BlackMisc
{ {
if (ITimestampBased::canHandleIndex(index)) { return true;} if (ITimestampBased::canHandleIndex(index)) { return true;}
int i = index.frontCasted<int>(); int i = index.frontCasted<int>();
return (i >= static_cast<int>(IndexDbIntegerKey)) && (i <= static_cast<int>(IndexDbIntegerKey)); return (i >= static_cast<int>(IndexDbIntegerKey)) && (i <= static_cast<int>(IndexDatabaseIcon));
} }
QJsonValue IDatastoreObjectWithStringKey::getDbKeyAsJsonValue() const QJsonValue IDatastoreObjectWithStringKey::getDbKeyAsJsonValue() const
@@ -123,6 +129,13 @@ namespace BlackMisc
return null; return null;
} }
const CIcon &IDatastoreObjectWithStringKey::toDatabaseIcon() const
{
static const CIcon empty;
if (this->hasValidDbKey()) { return CIconList::iconByIndex(CIcons::StandardIconDatabaseKey16); }
return empty;
}
void IDatastoreObjectWithStringKey::setKeyAndTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix) void IDatastoreObjectWithStringKey::setKeyAndTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix)
{ {
QString dbKey = json.value(prefix + "id").toString(); QString dbKey = json.value(prefix + "id").toString();
@@ -143,6 +156,7 @@ namespace BlackMisc
switch (i) switch (i)
{ {
case IndexDbStringKey: return CVariant::from(this->m_dbKey); case IndexDbStringKey: return CVariant::from(this->m_dbKey);
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
default: default:
break; break;
} }
@@ -174,8 +188,8 @@ namespace BlackMisc
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbStringKey: case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey());
return this->m_dbKey.compare(compareValue.getDbKey()); case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
default: default:
break; break;
} }
@@ -188,7 +202,7 @@ namespace BlackMisc
if (index.isEmpty()) { return false; } if (index.isEmpty()) { return false; }
if (ITimestampBased::canHandleIndex(index)) { return true;} if (ITimestampBased::canHandleIndex(index)) { return true;}
int i = index.frontCasted<int>(); int i = index.frontCasted<int>();
return (i >= static_cast<int>(IndexDbStringKey)) && (i <= static_cast<int>(IndexDbStringKey)); return (i >= static_cast<int>(IndexDbStringKey)) && (i <= static_cast<int>(IndexDatabaseIcon));
} }
} // namespace } // namespace

View File

@@ -28,7 +28,8 @@ namespace BlackMisc
//! Property index //! Property index
enum ColumnIndex enum ColumnIndex
{ {
IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger,
IndexDatabaseIcon
}; };
//! Get DB key. //! Get DB key.
@@ -52,6 +53,9 @@ namespace BlackMisc
//! Has valid DB key //! Has valid DB key
bool hasValidDbKey() const { return m_dbKey >= 0; } bool hasValidDbKey() const { return m_dbKey >= 0; }
//! Database icon if this has valid key, otherwise empty
const CIcon &toDatabaseIcon() const;
//! Invalid key //! Invalid key
static int invalidDbKey() { return -1; } static int invalidDbKey() { return -1; }
@@ -95,7 +99,8 @@ namespace BlackMisc
//! Property index //! Property index
enum ColumnIndex enum ColumnIndex
{ {
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString,
IndexDatabaseIcon
}; };
//! Get DB key. //! Get DB key.
@@ -110,6 +115,9 @@ namespace BlackMisc
//! Has valid DB key //! Has valid DB key
bool hasValidDbKey() const { return !m_dbKey.isEmpty(); } bool hasValidDbKey() const { return !m_dbKey.isEmpty(); }
//! Database icon if this has valid key, otherwise empty
const CIcon &toDatabaseIcon() const;
//! Invalid key //! Invalid key
static QString invalidDbKey() { return ""; } static QString invalidDbKey() { return ""; }