Thanks, but propably description of my problem is wrong.
I`ve 3 elems. For eg. QGraphicsPathItems. Because of, that objects are grouped/ungrouped so I need to have that objects in one group.
So I create QGraphicsItemGroup object. Now, this group contains 3 objects (QGraphicsPathItems).
Storing to DB.
Group is stored to dataStream like below:
ds << childItems().count();
{
GraphicType typeChild = (GraphicType)item->type();
switch(typeChild)
{
case eShapeElem:
{
ShapeElem* shapeElem = qgraphicsitem_cast<ShapeElem*>(item);
ds << shapeElem;
//of course proper operators were created
// QDataStream &operator<<(QDataStream&, const ShapeElem*);
// QDataStream &operator>>(QDataStream&, ShapeElem*);
break;
}
.. other types
}
}
QDataStream ds;
ds << childItems().count();
BOOST_FOREACH(QGraphicsItem* item, childItems())
{
GraphicType typeChild = (GraphicType)item->type();
switch(typeChild)
{
case eShapeElem:
{
ShapeElem* shapeElem = qgraphicsitem_cast<ShapeElem*>(item);
ds << shapeElem;
//of course proper operators were created
// QDataStream &operator<<(QDataStream&, const ShapeElem*);
// QDataStream &operator>>(QDataStream&, ShapeElem*);
break;
}
.. other types
}
}
To copy to clipboard, switch view to plain text mode
Group is read from dataStream like below:
int countChildren;
ds >> countChildren;
for(int iIdx = 0; iIdx < countChildren....) {
ds >> typeChild;
switch(typeChild)
{
case eShapeElem:
{
item = new ShapeElem();
dataStream >> (ShapeElem*)item;
lstRetrivedChildren.add(item);
break;
}
}
}
addToGroup(item);
int countChildren;
QDataStream ds;
ds >> countChildren;
for(int iIdx = 0; iIdx < countChildren....) {
ds >> typeChild;
switch(typeChild)
{
case eShapeElem:
{
item = new ShapeElem();
dataStream >> (ShapeElem*)item;
lstRetrivedChildren.add(item);
break;
}
}
}
BOOST_FOREACH(QGraphicsItem* item, lstRetrivedChildren)
addToGroup(item);
To copy to clipboard, switch view to plain text mode
Storing ShapeElem to stream:
ds << (qint32)type();
ds << path();
QDataStream ds;
ds << (qint32)type();
ds << path();
To copy to clipboard, switch view to plain text mode
Reading ShapeElem from stream:
ds >> path;
setPath(path);
QPainterPath path;
QDataStream ds;
ds >> path;
setPath(path);
To copy to clipboard, switch view to plain text mode
If I don`t save path(rect or other) of children, How I create them after load file?
Thanks!
Bookmarks