Not quite correct. You should serialise the group into the byte array, not assign it.
For example let's assume you have an item CanvasItem which has properties such as its coordinates (x and y), dimensions (w and h) name (name) and colour (c). To serialise it, you could for example create such a function for it:
ds << "CanvasItem" << item.x << item.y << item.w << item.h << item.name << item.c;
return ds;
}
QDataStream & operator<<(QDataStream &ds, CanvasItem &item){
ds << "CanvasItem" << item.x << item.y << item.w << item.h << item.name << item.c;
return ds;
}
To copy to clipboard, switch view to plain text mode
You can then provide a function for deserialisation too:
ds >> type;
if(type!="CanvasItem"){
qDebug("Not a canvas item");
return;
}
ds >> item.x >> item.y >> item.w >> item.h >> item.name >> item.c;
}
QDataStream & operator>>(QDataStream &ds, CanvasItem &item){
QString type;
ds >> type;
if(type!="CanvasItem"){
qDebug("Not a canvas item");
return;
}
ds >> item.x >> item.y >> item.w >> item.h >> item.name >> item.c;
}
To copy to clipboard, switch view to plain text mode
Serialisation is a way to turn an object into its "text" or binary (stream in general) representation which can then be stored somewhere (for example piped through network). Deserialisation is something opposite -- creates objects out of their serial representation.
Then you'll be able to fill your QMimeData object:
CanvasItem *item;
//...
ds << *item;
mime->setData("Canvas Group",&ba);
clipboard->setMimeData(mime,mode);
CanvasItem *item;
//...
QByteArray ba;
QDataStream ds(&ba);
ds << *item;
QMimeData *mime = new QMimeData;
mime->setData("Canvas Group",&ba);
clipboard->setMimeData(mime,mode);
To copy to clipboard, switch view to plain text mode
Of course you can do the same with the group. Serialise the whole group by providing some header from the group and then serialising all its elements (and maybe also provide some footer).
Bookmarks