Issue #77 Move definition of Mixin::Index::apply

This commit is contained in:
Mat Sutcliffe
2020-10-29 22:41:00 +00:00
parent 371c1f4f7c
commit 4cc1c7e0a9
2 changed files with 27 additions and 23 deletions

View File

@@ -53,7 +53,7 @@ namespace BlackMisc
//! Update by variant map //! Update by variant map
//! \return number of values changed, with skipEqualValues equal values will not be changed //! \return number of values changed, with skipEqualValues equal values will not be changed
CPropertyIndexList apply(const CPropertyIndexVariantMap &indexMap, bool skipEqualValues = false); CPropertyIndexList apply(const CPropertyIndexVariantMap &indexMap, bool skipEqualValues = false); // impl in propertyindexvariantmap.h
//! Set property by index //! Set property by index
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
@@ -114,28 +114,6 @@ namespace BlackMisc
using ::BlackMisc::Mixin::Index<DERIVED>::equalsPropertyByIndex; using ::BlackMisc::Mixin::Index<DERIVED>::equalsPropertyByIndex;
// *INDENT-ON* // *INDENT-ON*
template <class Derived>
CPropertyIndexList Index<Derived>::apply(const BlackMisc::CPropertyIndexVariantMap &indexMap, bool skipEqualValues)
{
if (indexMap.isEmpty()) return {};
CPropertyIndexList changed;
const auto &map = indexMap.map();
for (auto it = map.begin(); it != map.end(); ++it)
{
const CVariant value = it.value();
const CPropertyIndex index = it.key();
if (skipEqualValues)
{
const bool equal = derived()->equalsPropertyByIndex(value, index);
if (equal) { continue; }
}
derived()->setPropertyByIndex(index, value);
changed.push_back(index);
}
return changed;
}
template <class Derived> template <class Derived>
void Index<Derived>::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) void Index<Derived>::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{ {

View File

@@ -14,6 +14,7 @@
#include "blackmisc/blackmiscexport.h" #include "blackmisc/blackmiscexport.h"
#include "blackmisc/mixin/mixincompare.h" #include "blackmisc/mixin/mixincompare.h"
#include "blackmisc/mixin/mixindbus.h" #include "blackmisc/mixin/mixindbus.h"
#include "blackmisc/mixin/mixinindex.h"
#include "blackmisc/inheritancetraits.h" #include "blackmisc/inheritancetraits.h"
#include "blackmisc/predicates.h" #include "blackmisc/predicates.h"
#include "blackmisc/propertyindex.h" #include "blackmisc/propertyindex.h"
@@ -139,6 +140,31 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::DataStreamByMetaClass::unmarshalFromDataStream //! \copydoc BlackMisc::Mixin::DataStreamByMetaClass::unmarshalFromDataStream
void unmarshalFromDataStream(QDataStream &stream); void unmarshalFromDataStream(QDataStream &stream);
}; };
namespace Mixin
{
template <class Derived>
CPropertyIndexList Index<Derived>::apply(const BlackMisc::CPropertyIndexVariantMap &indexMap, bool skipEqualValues)
{
if (indexMap.isEmpty()) return {};
CPropertyIndexList changed;
const auto &map = indexMap.map();
for (auto it = map.begin(); it != map.end(); ++it)
{
const CVariant value = it.value();
const CPropertyIndex index = it.key();
if (skipEqualValues)
{
const bool equal = derived()->equalsPropertyByIndex(value, index);
if (equal) { continue; }
}
derived()->setPropertyByIndex(index, value);
changed.push_back(index);
}
return changed;
}
}
} // ns } // ns
Q_DECLARE_METATYPE(BlackMisc::CPropertyIndexVariantMap) Q_DECLARE_METATYPE(BlackMisc::CPropertyIndexVariantMap)