diff --git a/src/blackmisc/propertyindex.cpp b/src/blackmisc/propertyindex.cpp index ceac5e172..ab98a962a 100644 --- a/src/blackmisc/propertyindex.cpp +++ b/src/blackmisc/propertyindex.cpp @@ -114,4 +114,11 @@ namespace BlackMisc return list; } + void CPropertyIndex::prepend(int newLeftIndex) + { + QList newList = indexList(); + newList.prepend(newLeftIndex); + this->setIndexStringByList(newList); + } + } // namespace diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 8a5840054..8ccc07db9 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -90,6 +90,9 @@ namespace BlackMisc //! Index list QList 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 CastType frontCasted() const { diff --git a/src/blackmisc/propertyindexvariantmap.cpp b/src/blackmisc/propertyindexvariantmap.cpp index 4239be2d6..1b169e4a1 100644 --- a/src/blackmisc/propertyindexvariantmap.cpp +++ b/src/blackmisc/propertyindexvariantmap.cpp @@ -138,6 +138,18 @@ namespace BlackMisc this->addValue(index, QString(str)); } + void CPropertyIndexVariantMap::prependIndex(int index) + { + QMap 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 */ diff --git a/src/blackmisc/propertyindexvariantmap.h b/src/blackmisc/propertyindexvariantmap.h index 8ee1846a7..c08cf862d 100644 --- a/src/blackmisc/propertyindexvariantmap.h +++ b/src/blackmisc/propertyindexvariantmap.h @@ -61,6 +61,9 @@ namespace BlackMisc //! Add a value as non CVariant template 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(); }