Template CopyGObject.

--HG--
branch : feature
This commit is contained in:
dismine 2013-12-31 10:08:14 +02:00
parent 6669a0a15a
commit a9dfc45f99
2 changed files with 13 additions and 13 deletions

View File

@ -81,32 +81,26 @@ void VContainer::setData(const VContainer &data)
{ {
case(GObject::Arc): case(GObject::Arc):
{ {
VArc *arc = new VArc(*data.GeometricObject<const VArc *>(i.key())); CopyGObject<VArc>(data, i.key());
Q_ASSERT(arc != 0);
UpdateGObject(i.key(), arc);
break; break;
} }
case(GObject::Point): case(GObject::Point):
{ {
VPointF *point = new VPointF(*data.GeometricObject<const VPointF *>(i.key())); CopyGObject<VPointF>(data, i.key());
Q_ASSERT(point != 0);
UpdateGObject(i.key(), point);
break; break;
} }
case(GObject::Spline): case(GObject::Spline):
{ {
VSpline *spl = new VSpline(*data.GeometricObject<const VSpline *>(i.key())); CopyGObject<VSpline>(data, i.key());
Q_ASSERT(spl != 0);
UpdateGObject(i.key(), spl);
break; break;
} }
case(GObject::SplinePath): case(GObject::SplinePath):
{ {
VSplinePath *path = new VSplinePath(*data.GeometricObject<const VSplinePath *>(i.key())); CopyGObject<VSplinePath>(data, i.key());
Q_ASSERT(path != 0);
UpdateGObject(i.key(), path);
break; break;
} }
default:
qWarning()<<"Don't know how copy this type.";
} }
} }
standartTable = *data.DataStandartTable(); standartTable = *data.DataStandartTable();

View File

@ -61,6 +61,13 @@ public:
*/ */
VContainer(const VContainer &data); VContainer(const VContainer &data);
~VContainer(); ~VContainer();
template <typename T>
void CopyGObject(const VContainer &data, const qint64 &id)
{
T *obj = new T(*data.GeometricObject<const T *>(id));
Q_ASSERT(obj != 0);
UpdateGObject(id, obj);
}
/** /**
* @brief setData copy data from container * @brief setData copy data from container
* @param data container * @param data container
@ -79,7 +86,6 @@ public:
throw VExceptionBadId(tr("Can't find object"), id); throw VExceptionBadId(tr("Can't find object"), id);
} }
T obj = dynamic_cast<T>(gObj); T obj = dynamic_cast<T>(gObj);
//T obj = qobject_cast<T>(gObj);
Q_ASSERT(obj != 0); Q_ASSERT(obj != 0);
return obj; return obj;
} }