diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 44a8d4395..937d586e6 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -81,32 +81,26 @@ void VContainer::setData(const VContainer &data) { case(GObject::Arc): { - VArc *arc = new VArc(*data.GeometricObject(i.key())); - Q_ASSERT(arc != 0); - UpdateGObject(i.key(), arc); + CopyGObject(data, i.key()); break; } case(GObject::Point): { - VPointF *point = new VPointF(*data.GeometricObject(i.key())); - Q_ASSERT(point != 0); - UpdateGObject(i.key(), point); + CopyGObject(data, i.key()); break; } case(GObject::Spline): { - VSpline *spl = new VSpline(*data.GeometricObject(i.key())); - Q_ASSERT(spl != 0); - UpdateGObject(i.key(), spl); + CopyGObject(data, i.key()); break; } case(GObject::SplinePath): { - VSplinePath *path = new VSplinePath(*data.GeometricObject(i.key())); - Q_ASSERT(path != 0); - UpdateGObject(i.key(), path); + CopyGObject(data, i.key()); break; } + default: + qWarning()<<"Don't know how copy this type."; } } standartTable = *data.DataStandartTable(); diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index da8e1b40d..49a1bfb58 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -61,6 +61,13 @@ public: */ VContainer(const VContainer &data); ~VContainer(); + template + void CopyGObject(const VContainer &data, const qint64 &id) + { + T *obj = new T(*data.GeometricObject(id)); + Q_ASSERT(obj != 0); + UpdateGObject(id, obj); + } /** * @brief setData copy data from container * @param data container @@ -79,7 +86,6 @@ public: throw VExceptionBadId(tr("Can't find object"), id); } T obj = dynamic_cast(gObj); - //T obj = qobject_cast(gObj); Q_ASSERT(obj != 0); return obj; }