Here is one example how I save items in an xml project file
xmlWriter.writeStartElement("Widget");
xmlWriter.writeAttribute("id", currentProxy->accessibleName());
xmlWriter.
writeAttribute("X",
QString::number(item
->scenePos
().
x()));
xmlWriter.
writeAttribute("Y",
QString::number(item
->scenePos
().
y()));
xmlWriter.
writeAttribute("Z",
QString::number(item
->zValue
()));
xmlWriter.
writeAttribute("Width",
QString::number(progressBar
->size
().
width()));
xmlWriter.
writeAttribute("Height",
QString::number(progressBar
->size
().
height()));
xmlWriter.
writeAttribute("Min",
QString::number(progressBar
->getMin
()));
xmlWriter.
writeAttribute("Max",
QString::number(progressBar
->getMax
()));
xmlWriter.writeAttribute("Orientation", progressBar->getOrientation());
xmlWriter.writeAttribute("Color", progressBar->getColor());
xmlWriter.writeAttribute("BackgroundColor", progressBar->getBackgroundColor());
xmlWriter.
writeAttribute("BorderSize",
QString::number(progressBar
->getBorderSize
()));
xmlWriter.writeAttribute("Function", progressBar->getFunction());
xmlWriter.writeEndElement();
xmlWriter.writeStartElement("Widget");
xmlWriter.writeAttribute("id", currentProxy->accessibleName());
xmlWriter.writeAttribute("X", QString::number(item->scenePos().x()));
xmlWriter.writeAttribute("Y", QString::number(item->scenePos().y()));
xmlWriter.writeAttribute("Z", QString::number(item->zValue()));
xmlWriter.writeAttribute("Width", QString::number(progressBar->size().width()));
xmlWriter.writeAttribute("Height", QString::number(progressBar->size().height()));
xmlWriter.writeAttribute("Min", QString::number(progressBar->getMin()));
xmlWriter.writeAttribute("Max", QString::number(progressBar->getMax()));
xmlWriter.writeAttribute("Orientation", progressBar->getOrientation());
xmlWriter.writeAttribute("Color", progressBar->getColor());
xmlWriter.writeAttribute("BackgroundColor", progressBar->getBackgroundColor());
xmlWriter.writeAttribute("BorderSize", QString::number(progressBar->getBorderSize()));
xmlWriter.writeAttribute("Function", progressBar->getFunction());
xmlWriter.writeEndElement();
To copy to clipboard, switch view to plain text mode
and the code for reading it back
QStringRef xValue = attributes.value("X");
QStringRef yValue = attributes.value("Y");
QStringRef zValue = attributes.value("Z");
QStringRef heightValue = attributes.value("Height");
QStringRef widthValue = attributes.value("Width");
QStringRef minValue = attributes.value("Min");
QStringRef maxValue = attributes.value("Max");
QStringRef orientation = attributes.value("Orientation");
QStringRef color = attributes.value("Color");
QStringRef backgroundColor = attributes.value("BackgroundColor");
QStringRef borderSize = attributes.value("BorderSize");
QStringRef function = attributes.value("Function");
ExampleInstrument *exampleInstrument = new ExampleInstrument();
exampleInstrument->setMin(minValue.toString().toInt());
exampleInstrument->setMax(maxValue.toString().toInt());
exampleInstrument->setOrientation(orientation.toString());
exampleInstrument->setColor(color.toString());
exampleInstrument->setBackgroundColor(backgroundColor.toString());
exampleInstrument->setBorderSize(borderSize.toString().toInt());
exampleInstrument->setFunction(function.toString());
CdProxy *proxy = new CdProxy();
proxy->setWidget(exampleInstrument);
proxy->setPos(xValue.toString().toFloat(), yValue.toString().toFloat());
proxy->setZValue(zValue.toString().toFloat());
proxy->resize(widthValue.toString().toFloat(), heightValue.toString().toFloat());
QStringRef xValue = attributes.value("X");
QStringRef yValue = attributes.value("Y");
QStringRef zValue = attributes.value("Z");
QStringRef heightValue = attributes.value("Height");
QStringRef widthValue = attributes.value("Width");
QStringRef minValue = attributes.value("Min");
QStringRef maxValue = attributes.value("Max");
QStringRef orientation = attributes.value("Orientation");
QStringRef color = attributes.value("Color");
QStringRef backgroundColor = attributes.value("BackgroundColor");
QStringRef borderSize = attributes.value("BorderSize");
QStringRef function = attributes.value("Function");
ExampleInstrument *exampleInstrument = new ExampleInstrument();
exampleInstrument->setMin(minValue.toString().toInt());
exampleInstrument->setMax(maxValue.toString().toInt());
exampleInstrument->setOrientation(orientation.toString());
exampleInstrument->setColor(color.toString());
exampleInstrument->setBackgroundColor(backgroundColor.toString());
exampleInstrument->setBorderSize(borderSize.toString().toInt());
exampleInstrument->setFunction(function.toString());
CdProxy *proxy = new CdProxy();
proxy->setWidget(exampleInstrument);
proxy->setPos(xValue.toString().toFloat(), yValue.toString().toFloat());
proxy->setZValue(zValue.toString().toFloat());
proxy->resize(widthValue.toString().toFloat(), heightValue.toString().toFloat());
proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
To copy to clipboard, switch view to plain text mode
So what you need to do to copy items is to save the data needed and then create a new object with that data.
Bookmarks