mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Caf: Added specialization for PdmPointer<T>.
Preparations for PtrArrayField. Made isEqual use QVariant::value<T>()
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -39,9 +40,10 @@ public:
|
||||
/// Check equality between QVariants that carries a Field Value.
|
||||
/// The == operator will normally work, but does not support custom types in the QVariant
|
||||
/// See http://qt-project.org/doc/qt-4.8/qvariant.html#operator-eq-eq-64
|
||||
/// Using the == between the real types is more safe.
|
||||
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
|
||||
{
|
||||
return variantValue == variantValue2;
|
||||
return variantValue.value<T>() == variantValue2.value<T>();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,6 +73,31 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
/// Partial specialization for caf::PdmPointer<T>
|
||||
/// Used internally to avoid havning to declare everything Q_DECLARE_METATYPE()
|
||||
/// User must use PdmPtrField or PdmChildField
|
||||
//==================================================================================================
|
||||
template <typename T>
|
||||
class PdmValueFieldSpecialization<PdmPointer<T> >
|
||||
{
|
||||
public:
|
||||
static QVariant convert(const PdmPointer<T>& value)
|
||||
{
|
||||
return QVariant::fromValue(PdmPointer<PdmObjectHandle>(value.rawPtr()));
|
||||
}
|
||||
|
||||
static void setFromVariant(const QVariant& variantValue, caf::PdmPointer<T>& value)
|
||||
{
|
||||
value.setRawPtr(variantValue.value<PdmPointer<PdmObjectHandle> >().rawPtr());
|
||||
}
|
||||
|
||||
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
|
||||
{
|
||||
return variantValue.value<PdmPointer<PdmObjectHandle> >() == variantValue2.value<PdmPointer<PdmObjectHandle> >() ;
|
||||
}
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Partial specialization for std::vector
|
||||
//==================================================================================================
|
||||
@@ -108,6 +135,7 @@ public:
|
||||
|
||||
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
|
||||
{
|
||||
assert(false); // Not sure this actually works JJS
|
||||
return variantValue == variantValue2;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
|
||||
static bool isDataElementEqual(const QVariant& variantValue, const QVariant& variantValue2)
|
||||
{
|
||||
return variantValue.value<T>() == variantValue2.value<T>();
|
||||
return PdmValueFieldSpecialization<T>::isEqual(variantValue, variantValue2);
|
||||
}
|
||||
|
||||
/// Methods to get a list of options for a field, specialized for AppEnum
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
|
||||
static bool isDataElementEqual(const QVariant& variantValue, const QVariant& variantValue2)
|
||||
{
|
||||
return variantValue.value<T>() == variantValue2.value<T>();
|
||||
return PdmValueFieldSpecialization<T>::isEqual(variantValue, variantValue2);
|
||||
}
|
||||
|
||||
/// Methods to get a list of options for a field, specialized for AppEnum
|
||||
|
||||
Reference in New Issue
Block a user