Fix problem with updating objects inside vcontainer.
--HG-- branch : feature
This commit is contained in:
parent
f78c122cb0
commit
89a2323944
|
@ -249,22 +249,6 @@ void VContainer::UpdateId(quint32 newId)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief UpdateObject update object in container
|
||||
* @param id id of existing object
|
||||
* @param point object
|
||||
*/
|
||||
template <typename val>
|
||||
void VContainer::UpdateObject(const quint32 &id, val point)
|
||||
{
|
||||
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
||||
SCASSERT(point.isNull() == false)
|
||||
point->setId(id);
|
||||
d->gObjects.insert(id, point);
|
||||
UpdateId(id);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Clear clear data in container. Id will be 0.
|
||||
|
@ -497,27 +481,6 @@ quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
|
|||
return id;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief UpdateGObject update GObject by id
|
||||
* @param id id of existing GObject
|
||||
* @param obj object
|
||||
*/
|
||||
void VContainer::UpdateGObject(quint32 id, VGObject* obj)
|
||||
{
|
||||
SCASSERT(obj != nullptr)
|
||||
QSharedPointer<VGObject> pointer(obj);
|
||||
UpdateGObject(id, pointer);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VContainer::UpdateGObject(quint32 id, const QSharedPointer<VGObject> &obj)
|
||||
{
|
||||
SCASSERT(not obj.isNull())
|
||||
UpdateObject(id, obj);
|
||||
uniqueNames.insert(obj->name());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VContainer::UpdatePiece(quint32 id, const VPiece &detail)
|
||||
{
|
||||
|
|
|
@ -160,8 +160,10 @@ public:
|
|||
void RemoveVariable(const QString& name);
|
||||
void RemovePiece(quint32 id);
|
||||
|
||||
void UpdateGObject(quint32 id, VGObject* obj);
|
||||
void UpdateGObject(quint32 id, const QSharedPointer<VGObject> &obj);
|
||||
template <class T>
|
||||
void UpdateGObject(quint32 id, T* obj);
|
||||
template <class T>
|
||||
void UpdateGObject(quint32 id, const QSharedPointer<T> &obj);
|
||||
void UpdatePiece(quint32 id, const VPiece &detail);
|
||||
void UpdatePiecePath(quint32 id, const VPiecePath &path);
|
||||
|
||||
|
@ -221,8 +223,8 @@ private:
|
|||
// cppcheck-suppress functionStatic
|
||||
const val GetObject(const QHash<key, val> &obj, key id) const;
|
||||
|
||||
template <typename val>
|
||||
void UpdateObject(const quint32 &id, val point);
|
||||
template <typename T>
|
||||
void UpdateObject(const quint32 &id, const QSharedPointer<T> &point);
|
||||
|
||||
template <typename key, typename val>
|
||||
static quint32 AddObject(QHash<key, val> &obj, val value);
|
||||
|
@ -312,14 +314,23 @@ void VContainer::AddVariable(const QString& name, const QSharedPointer<T> &var)
|
|||
{
|
||||
if (d->variables.value(name)->GetType() == var->GetType())
|
||||
{
|
||||
d->variables[name].clear();
|
||||
QSharedPointer<T> v = qSharedPointerDynamicCast<T>(d->variables.value(name));
|
||||
if (v.isNull())
|
||||
{
|
||||
throw VExceptionBadId(tr("Can't cast object."), name);
|
||||
}
|
||||
*v = *var;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw VExceptionBadId(tr("Can't find object. Type mismatch."), name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
d->variables.insert(name, var);
|
||||
}
|
||||
|
||||
uniqueNames.insert(name);
|
||||
}
|
||||
|
||||
|
@ -329,4 +340,54 @@ uint VContainer::qHash( const QSharedPointer<T> &p )
|
|||
{
|
||||
return qHash( p.data() );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief UpdateGObject update GObject by id
|
||||
* @param id id of existing GObject
|
||||
* @param obj object
|
||||
*/
|
||||
template <class T>
|
||||
void VContainer::UpdateGObject(quint32 id, T* obj)
|
||||
{
|
||||
SCASSERT(obj != nullptr)
|
||||
UpdateGObject(id, QSharedPointer<T>(obj));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
void VContainer::UpdateGObject(quint32 id, const QSharedPointer<T> &obj)
|
||||
{
|
||||
SCASSERT(not obj.isNull())
|
||||
UpdateObject(id, obj);
|
||||
uniqueNames.insert(obj->name());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief UpdateObject update object in container
|
||||
* @param id id of existing object
|
||||
* @param point object
|
||||
*/
|
||||
template <typename T>
|
||||
void VContainer::UpdateObject(const quint32 &id, const QSharedPointer<T> &point)
|
||||
{
|
||||
Q_ASSERT_X(id != NULL_ID, Q_FUNC_INFO, "id == 0"); //-V654 //-V712
|
||||
SCASSERT(point.isNull() == false)
|
||||
point->setId(id);
|
||||
if (d->gObjects.contains(id))
|
||||
{
|
||||
QSharedPointer<T> obj = qSharedPointerDynamicCast<T>(d->gObjects.value(id));
|
||||
if (obj.isNull())
|
||||
{
|
||||
throw VExceptionBadId(tr("Can't cast object"), id);
|
||||
}
|
||||
*obj = *point;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->gObjects.insert(id, point);
|
||||
}
|
||||
UpdateId(id);
|
||||
}
|
||||
#endif // VCONTAINER_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user