refs #369, prepend function for properties

This commit is contained in:
Klaus Basan
2015-02-02 17:43:55 +01:00
parent cec59c5d72
commit 8e8f9e4804
4 changed files with 25 additions and 0 deletions

View File

@@ -114,4 +114,11 @@ namespace BlackMisc
return list;
}
void CPropertyIndex::prepend(int newLeftIndex)
{
QList<int> newList = indexList();
newList.prepend(newLeftIndex);
this->setIndexStringByList(newList);
}
} // namespace

View File

@@ -90,6 +90,9 @@ namespace BlackMisc
//! Index list
QList<int> indexList() const;
//! Shif existing indexes to right and insert given index at front
void prepend(int newLeftIndex);
//! First element casted to given type, usually then PropertIndex enum
template<class CastType> CastType frontCasted() const
{

View File

@@ -138,6 +138,18 @@ namespace BlackMisc
this->addValue(index, QString(str));
}
void CPropertyIndexVariantMap::prependIndex(int index)
{
QMap<CPropertyIndex, CVariant> newMap;
for (const CPropertyIndex &pi : this->indexes())
{
CPropertyIndex newPi(pi);
newPi.prepend(index);
newMap.insert(newPi, this->m_values[pi]);
}
this->m_values = newMap;
}
/*
* Indexes
*/

View File

@@ -61,6 +61,9 @@ namespace BlackMisc
//! Add a value as non CVariant
template<class T> void addValue(const CPropertyIndex &index, const T &value) { this->m_values.insert(index, CVariant::fromValue(value)); }
//! Prepend index to all property indexes
void prependIndex(int index);
//! Is empty?
bool isEmpty() const { return this->m_values.isEmpty(); }