mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
[Fwk] Use PdmValueFieldSpecialization instead of QVariant constructor
This commit is contained in:
parent
3e9e5779ab
commit
3a3d28003b
@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
namespace caf
|
||||
@ -39,15 +43,12 @@ public:
|
||||
{
|
||||
return variantValue == variantValue2;
|
||||
}
|
||||
|
||||
};
|
||||
} // End of namespace caf
|
||||
|
||||
#include "cafAppEnum.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//==================================================================================================
|
||||
/// Partial specialization for caf::AppEnum
|
||||
//==================================================================================================
|
||||
template <typename T>
|
||||
class PdmValueFieldSpecialization<caf::AppEnum<T> >
|
||||
{
|
||||
@ -67,18 +68,12 @@ public:
|
||||
{
|
||||
return variantValue == variantValue2;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//==================================================================================================
|
||||
/// Partial specialization for std::vector
|
||||
//==================================================================================================
|
||||
template <typename T>
|
||||
class PdmValueFieldSpecialization<std::vector<T> >
|
||||
{
|
||||
@ -89,10 +84,10 @@ public:
|
||||
typename std::vector<T>::const_iterator it;
|
||||
for (it = value.begin(); it != value.end() ; ++it)
|
||||
{
|
||||
returnList.push_back(QVariant::fromValue(*it));
|
||||
returnList.push_back(PdmValueFieldSpecialization<T>::convert(*it));
|
||||
}
|
||||
return returnList;
|
||||
|
||||
return returnList;
|
||||
}
|
||||
|
||||
static void setFromVariant(const QVariant& variantValue, std::vector<T>& value)
|
||||
@ -103,7 +98,10 @@ public:
|
||||
QList<QVariant> lst = variantValue.toList();
|
||||
for (int i = 0; i < lst.size(); ++i)
|
||||
{
|
||||
value.push_back(lst[i].value<T>());
|
||||
T val;
|
||||
PdmValueFieldSpecialization<T>::setFromVariant(lst[i], val);
|
||||
|
||||
value.push_back(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,7 +110,6 @@ public:
|
||||
{
|
||||
return variantValue == variantValue2;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // End of namespace caf
|
||||
|
@ -111,28 +111,13 @@ public:
|
||||
/// Convert the field value into a QVariant
|
||||
static QVariant convert(const std::vector<T>& value)
|
||||
{
|
||||
QList<QVariant> returnList;
|
||||
typename std::vector<T>::const_iterator it;
|
||||
for (it = value.begin(); it != value.end() ; ++it)
|
||||
{
|
||||
returnList.push_back(QVariant(*it));
|
||||
}
|
||||
return returnList;
|
||||
return PdmValueFieldSpecialization< std::vector<T> >::convert(value);
|
||||
}
|
||||
|
||||
/// Set the field value from a QVariant
|
||||
static void setFromVariant(const QVariant& variantValue, std::vector<T>& value)
|
||||
{
|
||||
if (variantValue.canConvert< QList<QVariant> >())
|
||||
{
|
||||
value.clear();
|
||||
QList<QVariant> lst = variantValue.toList();
|
||||
int i;
|
||||
for (i = 0; i < lst.size(); ++i)
|
||||
{
|
||||
value.push_back(lst[i].value<T>());
|
||||
}
|
||||
}
|
||||
return PdmValueFieldSpecialization< std::vector<T> >::setFromVariant(variantValue, value);
|
||||
}
|
||||
|
||||
static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2)
|
||||
|
Loading…
Reference in New Issue
Block a user