mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #618, allow to display icon when DB key is set
This commit is contained in:
@@ -34,6 +34,13 @@ namespace BlackMisc
|
||||
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)
|
||||
{
|
||||
if (candidate.isEmpty()) { return invalidDbKey(); }
|
||||
@@ -69,8 +76,8 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbIntegerKey: return CVariant::from(this->m_dbKey);
|
||||
default:
|
||||
break;
|
||||
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
||||
default: break;
|
||||
}
|
||||
return CVariant();
|
||||
}
|
||||
@@ -100,10 +107,9 @@ namespace BlackMisc
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbIntegerKey:
|
||||
return Compare::compare(this->m_dbKey, compareValue.getDbKey());
|
||||
default:
|
||||
break;
|
||||
case IndexDbIntegerKey: return Compare::compare(this->m_dbKey, compareValue.getDbKey());
|
||||
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
||||
default: break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Compare failed");
|
||||
return 0;
|
||||
@@ -113,7 +119,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (ITimestampBased::canHandleIndex(index)) { return true;}
|
||||
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
|
||||
@@ -123,6 +129,13 @@ namespace BlackMisc
|
||||
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)
|
||||
{
|
||||
QString dbKey = json.value(prefix + "id").toString();
|
||||
@@ -143,6 +156,7 @@ namespace BlackMisc
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbStringKey: return CVariant::from(this->m_dbKey);
|
||||
case IndexDatabaseIcon: return CVariant::from(this->toDatabaseIcon());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -174,8 +188,8 @@ namespace BlackMisc
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDbStringKey:
|
||||
return this->m_dbKey.compare(compareValue.getDbKey());
|
||||
case IndexDbStringKey: return this->m_dbKey.compare(compareValue.getDbKey());
|
||||
case IndexDatabaseIcon: return Compare::compare(this->hasValidDbKey(), compareValue.hasValidDbKey());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -188,7 +202,7 @@ namespace BlackMisc
|
||||
if (index.isEmpty()) { return false; }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return true;}
|
||||
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
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace BlackMisc
|
||||
//! Property index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger
|
||||
IndexDbIntegerKey = CPropertyIndex::GlobalIndexIDatastoreInteger,
|
||||
IndexDatabaseIcon
|
||||
};
|
||||
|
||||
//! Get DB key.
|
||||
@@ -52,6 +53,9 @@ namespace BlackMisc
|
||||
//! Has valid DB key
|
||||
bool hasValidDbKey() const { return m_dbKey >= 0; }
|
||||
|
||||
//! Database icon if this has valid key, otherwise empty
|
||||
const CIcon &toDatabaseIcon() const;
|
||||
|
||||
//! Invalid key
|
||||
static int invalidDbKey() { return -1; }
|
||||
|
||||
@@ -95,7 +99,8 @@ namespace BlackMisc
|
||||
//! Property index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString
|
||||
IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString,
|
||||
IndexDatabaseIcon
|
||||
};
|
||||
|
||||
//! Get DB key.
|
||||
@@ -110,6 +115,9 @@ namespace BlackMisc
|
||||
//! Has valid DB key
|
||||
bool hasValidDbKey() const { return !m_dbKey.isEmpty(); }
|
||||
|
||||
//! Database icon if this has valid key, otherwise empty
|
||||
const CIcon &toDatabaseIcon() const;
|
||||
|
||||
//! Invalid key
|
||||
static QString invalidDbKey() { return ""; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user