mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 15:15:39 +08:00
Issue #77 Move definition of Mixin::Index::apply
This commit is contained in:
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user