32#ifndef _QX_NESTED_MODEL_H_
33#define _QX_NESTED_MODEL_H_
70template <
class T,
class M>
83template <
class T,
class M >
86template <
class T,
bool bIsQObject >
90 static std::shared_ptr<T>
clone(T & t)
91 { std::shared_ptr<T> p = std::make_shared<T>(); (* p) = t;
return p; }
102 static std::shared_ptr<T>
clone(T & t)
112 QVariant value = pDataMember->
toVariant(& t2);
119template <
class T,
class M,
bool bIsTypeVoid >
123template <
class T,
class M>
127template <
class T,
class M >
139 static_assert(
is_valid,
"is_valid");
146 pModel->beginInsertRows(idxParent, 0, 0);
149 if (! pDataMemberId) {
qAssert(
false); pModel->endInsertRows();
return pModel; }
150 QVariant value = pDataMemberId->
toVariant(& t);
152 { idx--; value = QVariant(
static_cast<qlonglong
>(idx)); }
154 pListOfItems->
insert(0, key, ptr);
155 pModel->endInsertRows();
161 if (! pModel) {
qAssert(
false);
return; }
163 if (! pListOfItems || (pListOfItems->
count() <= 0)) {
return; }
170template <
class T,
class M >
186 static_assert(
is_valid,
"is_valid");
189 long lCount =
static_cast<long>(type_generic_container::size(t));
190 if (lCount <= 0) {
return pModel; }
192 pModel->beginInsertRows(idxParent, 0, (lCount - 1));
193 for (
typename T::iterator it = t.begin(); it != t.end(); ++it)
194 {
insertItem(pModel, (* it), iCurrRow); iCurrRow++; }
195 pModel->endInsertRows();
199 template <
typename U>
202 if (! pModel) {
qAssert(
false);
return false; }
209 if (! pDataMemberId) {
qAssert(
false);
return false; }
210 QVariant value = pDataMemberId->
toVariant(& item);
212 { idx--; value = QVariant(
static_cast<qlonglong
>(idx)); }
214 pListOfItems->
insert(iRow, key, ptr);
220 if (! pModel) {
qAssert(
false);
return; }
221 type_generic_container::clear(t);
224 for (
long l = 0; l < pListOfItems->
count(); l++)
227 type_item item = type_generic_container::createItem();
230 QVariant vKey = QVariant(
static_cast<qlonglong
>(l));
232 type_generic_container::insertItem(t, item);
238 template <
typename U>
242 template <
typename U,
bool bIsPointer >
249 template <
typename U1,
typename U2>
256 template <
typename U1,
typename U2>
263#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
264 template <
typename U1,
typename U2>
265 struct insertItem_Helper<QPair<U1, U2>, false>
271 template <
typename U1,
typename U2>
272 struct insertItem_Helper<const QPair<U1, U2>, false>
274 static inline bool insert(
qx::IxModel * pModel,
const QPair<U1, U2> & item,
int iRow)
279 template <
typename U>
282 enum { is_same_type = std::is_same<qx::model_view::detail::QxNestedModel_Container<T, M>::type_data, U>::value };
289template <
class T,
class M >
307 M * pModelType = NULL; Q_UNUSED(pModelType);
310 if (pModel) { pModel->
clear(); }
qAssert(pModel != NULL);
316template <
class T,
class M >
325 {
return type_model_view_3::create(pParent, idxParent, t); }
328 { type_model_view_3::synchronize(pModel, t); }
337namespace model_view {
350template <
class T,
class M>
352{ Q_UNUSED(pModelType);
static_assert((std::is_base_of<qx::IxModel, M>::value || std::is_same<M, void>::value),
"(std::is_base_of<qx::IxModel, M>::value || std::is_same<M, void>::value)");
return qx::model_view::detail::QxNestedModel<T, M>::create(pParent, idxParent, t); }
Interface to manage Qt model/view architecture with classes registered into QxOrm context (Qt widgets...
Clone all classes registered into QxOrm context using QxOrm library serialization engine.
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...
All classes registered into QxOrm context can be used with Qt model/view architecture (Qt widgets and...
qx::IxClass : common interface for all classes registered into QxOrm context
IxDataMemberX * getDataMemberX() const
qx::IxDataMember : common interface for all class properties registered into QxOrm context
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)=0
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context) const =0
qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOr...
virtual long count_WithDaoStrategy() const =0
virtual IxDataMember * get_WithDaoStrategy(long lIndex) const =0
qx::IxModel : interface to manage Qt model/view architecture with classes registered into QxOrm conte...
Q_INVOKABLE void clear(bool bUpdateColumns=false)
IxCollection * getCollection() const
long m_lManualInsertIndex
Index to insert manually items to the collection.
void setParentModel(IxModel *pParent)
IxDataMember * m_pDataMemberId
Primary key (property id) defined into QxOrm context.
bool insert(const Key &key, const Value &value)
Add element 'value' at the end of the list indexed by 'key'.
long count() const
Return the number of items in the list (same as 'size()')
const_reference_value getByIndex(long index) const
Return the item at index position 'index'.
qx::QxModel<T, B> : all classes registered into QxOrm context can be used with Qt model/view architec...
qx::trait::get_primary_key< T >::type type_primary_key
std::shared_ptr< T > type_ptr
static T * getSingleton()
qx::trait::construct_ptr<T>::get(T & t, bool bReset = false) : instantiate (or reset) a new pointer,...
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
qx::trait::get_base_class<T>::type : retrieve base class of type T registered into QxOrm context and ...
Register all primitive and useful types of stl, boost and Qt libraries using QX_REGISTER_CLASS_NAME(T...
qx::IxModel * create_nested_model(qx::IxModel *pParent, const QModelIndex &idxParent, T &t)
qx::model_view::create_nested_model is used by QxEntityEditor to manage complex data structure to wor...
T * clone_to_nude_ptr(const T &obj)
qx::clone_to_nude_ptr(const T & obj) : return a nude pointer (be careful with memory leak) of a new i...
std::shared_ptr< T > clone(const T &obj)
qx::clone(const T & obj) : return a boost smart-pointer (std::shared_ptr<T>) of a new instance of typ...
qx::trait::is_container<T>::value : return true if T is a container from stl, boost,...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
qx::trait::is_smart_ptr<T>::value : return true if T is a smart-pointer of boost, Qt or QxOrm librari...
qx::trait::is_valid_primary_key<T>(const T & t) : return true if t can be a valid primary key to be i...
qx_bool from_variant(const QVariant &v, T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
void sync_nested_model(qx::IxModel *pModel, T &t)
qx::IxModel * create_nested_model_with_type(qx::IxModel *pParent, const QModelIndex &idxParent, T &t, M *pModelType)
bool is_valid_primary_key(const T &t)
Root namespace for all QxOrm library features.
static bool insert(qx::IxModel *pModel, U &item, int iRow)
static bool insert(qx::IxModel *pModel, const std::pair< U1, U2 > &item, int iRow)
static bool insert(qx::IxModel *pModel, std::pair< U1, U2 > &item, int iRow)
static bool insert(qx::IxModel *pModel, U &item, int iRow)
qx::QxModel< type_data >::type_ptr type_ptr
static qx::IxModel * create(qx::IxModel *pParent, const QModelIndex &idxParent, T &t)
static bool insertItem(qx::IxModel *pModel, U &item, int iRow)
qx::trait::generic_container< T > type_generic_container
qx::QxModel< type_data >::type_primary_key type_primary_key
type_generic_container::type_value_qx type_data
type_generic_container::type_item type_item
static void synchronize(qx::IxModel *pModel, T &t)
static bool insert(qx::IxModel *pModel, U &item, int iRow)
qx::QxModel< type_data >::type_collection type_collection
static qx::IxModel * newModel(qx::IxModel *pParent)
static qx::IxModel * newModel(qx::IxModel *pParent)
qx::QxModel< T >::type_collection type_collection
static qx::IxModel * create(qx::IxModel *pParent, const QModelIndex &idxParent, T &t)
qx::QxModel< T >::type_primary_key type_primary_key
static void synchronize(qx::IxModel *pModel, T &t)
qx::QxModel< T >::type_ptr type_ptr
static void synchronize(T &t1, T &t2)
static std::shared_ptr< T > clone(T &t)
static void synchronize(T &t1, T &t2)
static std::shared_ptr< T > clone(T &t)
static qx::IxModel * create_Helper(qx::IxModel *pParent, const QModelIndex &idxParent, U &u)
static qx::IxModel * create_NullHelper(qx::IxModel *pParent, const QModelIndex &idxParent)
static qx::IxModel * create(qx::IxModel *pParent, const QModelIndex &idxParent, T &t)
static void synchronize(qx::IxModel *pModel, T &t)
static void synchronize(qx::IxModel *pModel, T &t)
std::conditional< qx::trait::is_smart_ptr< T >::value, qx::model_view::detail::QxNestedModel_Ptr< T, M >, type_model_view_1 >::type type_model_view_2
std::conditional< std::is_pointer< T >::value, qx::model_view::detail::QxNestedModel_Ptr< T, M >, qx::model_view::detail::QxNestedModel_Generic< T, M > >::type type_model_view_1
static qx::IxModel * create(qx::IxModel *pParent, const QModelIndex &idxParent, T &t)
std::conditional< qx::trait::is_container< T >::value, qx::model_view::detail::QxNestedModel_Container< T, M >, type_model_view_2 >::type type_model_view_3
static void get(T &t, bool bReset=false)
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
qx::trait::is_smart_ptr<T>::value : return true if T is a smart-pointer of boost, Qt or QxOrm librari...