Commit 776c2eaa authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Create branch work/363582-stable-xmi from master @ df0d4542

- Arguments of functions saveToXMI1 and save1 are changed from
    QDomDocument& doc, QDomElement& elem
  to
    QXmlStreamWriter& writer
- Basic load/save are working but more testing is needed.
  In particular, drag, cut/copy/paste, and undo/redo need testing.
- Unit tests are adapted and are passed.

CCBUG: 363582
parent df0d4542
......@@ -39,6 +39,7 @@
#include <QDomDocument>
#include <QPixmap>
#include <QTextStream>
#include <QXmlStreamWriter>
/**
* Constructor.
......@@ -118,20 +119,21 @@ UMLDragData::~UMLDragData()
*/
void UMLDragData::setUMLDataClip1(UMLObjectList& objects)
{
QDomDocument domDoc;
QDomElement xmiclip = domDoc.createElement(QLatin1String("xmiclip"));
domDoc.appendChild(xmiclip);
QDomElement objectsTag = domDoc.createElement(QLatin1String("umlobjects"));
xmiclip.appendChild(objectsTag);
QString xmiClip;
QXmlStreamWriter stream(&xmiClip);
stream.writeStartElement(QLatin1String("xmiclip"));
stream.writeStartElement(QLatin1String("umlobjects"));
UMLObjectListIt object_it(objects);
UMLObject* obj = 0;
while (object_it.hasNext()) {
obj = object_it.next();
obj->saveToXMI1(domDoc, objectsTag);
obj->saveToXMI1(stream);
}
setData(QLatin1String("application/x-uml-clip1"), domDoc.toString().toUtf8());
stream.writeEndElement(); // umlobjects
stream.writeEndElement(); // xmiclip
setData(QLatin1String("application/x-uml-clip1"), xmiClip.toUtf8());
}
/**
......@@ -140,27 +142,28 @@ void UMLDragData::setUMLDataClip1(UMLObjectList& objects)
*/
void UMLDragData::setUMLDataClip2(UMLObjectList& objects, UMLViewList& diagrams)
{
QDomDocument domDoc;
QDomElement xmiclip = domDoc.createElement(QLatin1String("xmiclip"));
domDoc.appendChild(xmiclip);
QDomElement objectsTag = domDoc.createElement(QLatin1String("umlobjects"));
xmiclip.appendChild(objectsTag);
QString xmiClip;
QXmlStreamWriter stream(&xmiClip);
stream.writeStartElement(QLatin1String("xmiclip"));
stream.writeStartElement(QLatin1String("umlobjects"));
UMLObjectListIt object_it(objects);
UMLObject* obj = 0;
while (object_it.hasNext()) {
obj = object_it.next();
obj->saveToXMI1(domDoc, objectsTag);
obj->saveToXMI1(stream);
}
QDomElement viewsTag = domDoc.createElement(QLatin1String("umlviews"));
xmiclip.appendChild(viewsTag);
stream.writeEndElement(); // umlobjects
stream.writeStartElement(QLatin1String("umlviews"));
foreach(UMLView* view, diagrams) {
view->umlScene()->saveToXMI1(domDoc, viewsTag);
view->umlScene()->saveToXMI1(stream);
}
setData(QLatin1String("application/x-uml-clip2"), domDoc.toString().toUtf8());
stream.writeEndElement(); // umlviews
stream.writeEndElement(); // xmiclip
setData(QLatin1String("application/x-uml-clip2"), xmiClip.toUtf8());
}
/**
......@@ -169,18 +172,18 @@ void UMLDragData::setUMLDataClip2(UMLObjectList& objects, UMLViewList& diagrams)
*/
void UMLDragData::setUMLDataClip3(UMLListViewItemList& umlListViewItems)
{
QDomDocument domDoc;
QDomElement xmiclip = domDoc.createElement(QLatin1String("xmiclip"));
domDoc.appendChild(xmiclip);
QDomElement itemsTag = domDoc.createElement(QLatin1String("umllistviewitems"));
xmiclip.appendChild(itemsTag);
QString xmiClip;
QXmlStreamWriter stream(&xmiClip);
stream.writeStartElement(QLatin1String("xmiclip"));
stream.writeStartElement(QLatin1String("umllistviewitems"));
foreach(UMLListViewItem* item, umlListViewItems) {
item->saveToXMI1(domDoc, itemsTag);
item->saveToXMI1(stream);
}
setData(QLatin1String("application/x-uml-clip3"), domDoc.toString().toUtf8());
stream.writeEndElement(); // umllistviewitems
stream.writeEndElement(); // xmiclip
setData(QLatin1String("application/x-uml-clip3"), xmiClip.toUtf8());
}
/**
......@@ -189,36 +192,39 @@ void UMLDragData::setUMLDataClip3(UMLListViewItemList& umlListViewItems)
* between only selected widgets will be copied and also
* its respective ListView Items
*/
void UMLDragData::setUMLDataClip4(UMLObjectList& objects, UMLWidgetList& widgets, AssociationWidgetList& associations,
void UMLDragData::setUMLDataClip4(UMLObjectList& objects,
UMLWidgetList& widgets,
AssociationWidgetList& associations,
QPixmap& pngImage, UMLScene *scene)
{
QDomDocument domDoc;
QDomElement xmiclip = domDoc.createElement(QLatin1String("xmiclip"));
xmiclip.setAttribute(QLatin1String("diagramtype"), scene->type());
xmiclip.setAttribute(QLatin1String("diagramid"), Uml::ID::toString(scene->ID()));
domDoc.appendChild(xmiclip);
QDomElement objectsTag = domDoc.createElement(QLatin1String("umlobjects"));
xmiclip.appendChild(objectsTag);
QString xmiClip;
QXmlStreamWriter stream(&xmiClip);
stream.writeStartElement(QLatin1String("xmiclip"));
stream.writeAttribute(QLatin1String("diagramtype"), QString::number(scene->type()));
stream.writeAttribute(QLatin1String("diagramid"), Uml::ID::toString(scene->ID()));
stream.writeStartElement(QLatin1String("umlobjects"));
foreach (UMLObject* obj, objects) {
obj->saveToXMI1(domDoc, objectsTag);
obj->saveToXMI1(stream);
}
QDomElement widgetsTag = domDoc.createElement(QLatin1String("widgets"));
xmiclip.appendChild(widgetsTag);
stream.writeEndElement(); // umlobjects
stream.writeStartElement(QLatin1String("widgets"));
foreach (UMLWidget* widget, widgets) {
widget->saveToXMI1(domDoc, widgetsTag);
widget->saveToXMI1(stream);
}
QDomElement associationWidgetsTag = domDoc.createElement(QLatin1String("associations"));
xmiclip.appendChild(associationWidgetsTag);
stream.writeEndElement(); // widgets
stream.writeStartElement(QLatin1String("associations"));
foreach (AssociationWidget* association, associations) {
association->saveToXMI1(domDoc, associationWidgetsTag);
association->saveToXMI1(stream);
}
setData(QLatin1String("application/x-uml-clip4"), domDoc.toString().toUtf8());
stream.writeEndElement(); // associations
stream.writeEndElement(); // xmiclip
setData(QLatin1String("application/x-uml-clip4"), xmiClip.toUtf8());
QImage img = pngImage.toImage();
int l_size = img.byteCount();
......@@ -236,17 +242,18 @@ void UMLDragData::setUMLDataClip4(UMLObjectList& objects, UMLWidgetList& widgets
*/
void UMLDragData::setUMLDataClip5(UMLObjectList& objects)
{
QDomDocument domDoc;
QDomElement xmiclip = domDoc.createElement(QLatin1String("xmiclip"));
domDoc.appendChild(xmiclip);
QDomElement objectsTag = domDoc.createElement(QLatin1String("umlobjects"));
xmiclip.appendChild(objectsTag);
QString xmiClip;
QXmlStreamWriter stream(&xmiClip);
stream.writeStartElement(QLatin1String("xmiclip"));
stream.writeStartElement(QLatin1String("umlobjects"));
foreach (UMLObject* obj, objects) {
obj->saveToXMI1(domDoc, objectsTag);
obj->saveToXMI1(stream);
}
setData(QLatin1String("application/x-uml-clip5"), domDoc.toString().toUtf8());
stream.writeEndElement(); // umlobjects
stream.writeEndElement(); // xmiclip
setData(QLatin1String("application/x-uml-clip5"), xmiClip.toUtf8());
}
/**
......
......@@ -11,12 +11,14 @@
#include "cmdremovediagram.h"
#include "basictypes.h"
#include "debug_utils.h"
#include "uml.h"
#include "umldoc.h"
#include "umlscene.h"
#include "umlview.h"
#include <KLocalizedString>
#include <QXmlStreamWriter>
namespace Uml
{
......@@ -37,12 +39,20 @@ namespace Uml
setText(msg);
// Save diagram XMI for undo
QDomDocument doc;
QDomElement container = doc.createElement(QLatin1String("diagram"));
scene->saveToXMI1(doc, container);
// The first child element contains the diagram XMI
m_element = container.firstChild().toElement();
QString xmi;
QXmlStreamWriter stream(&xmi);
stream.writeStartElement(QLatin1String("diagram"));
scene->saveToXMI1(stream);
stream.writeEndElement(); // diagram
QString error;
int line;
QDomDocument domDoc;
if (domDoc.setContent(xmi, &error, &line)) {
// The first child element contains the diagram XMI
m_element = domDoc.firstChild().firstChild().toElement(); // CHECK was: container
} else {
uWarning() << "Cannot set content: " << error << " line:" << line;
}
}
CmdRemoveDiagram::~CmdRemoveDiagram()
......
......@@ -12,6 +12,7 @@
// app includes
#include "associationwidget.h"
#include "debug_utils.h"
#include "model_utils.h"
#include "uml.h"
#include "umlscene.h"
......@@ -19,6 +20,7 @@
// kde includes
#include <KLocalizedString>
#include <QXmlStreamWriter>
namespace Uml
{
......@@ -33,9 +35,19 @@ namespace Uml
addWidgetToScene(widget);
QDomDocument doc;
m_element = doc.createElement(QLatin1String("widget"));
widget->saveToXMI1(doc, m_element);
QString xmi;
QXmlStreamWriter stream(&xmi);
stream.writeStartElement(QLatin1String("widget"));
widget->saveToXMI1(stream);
stream.writeEndElement(); // widget
QString error;
int line;
QDomDocument domDoc;
if (domDoc.setContent(xmi, &error, &line)) {
m_element = domDoc.firstChild().firstChild().toElement();
} else {
uWarning() << "Cannot set content:" << error << " line:" << line;
}
}
/**
......@@ -48,9 +60,19 @@ namespace Uml
addWidgetToScene(widget);
QDomDocument doc;
m_element = doc.createElement(QLatin1String("widget"));
widget->saveToXMI1(doc, m_element);
QString xmi;
QXmlStreamWriter stream(&xmi);
stream.writeStartElement(QLatin1String("widget"));
widget->saveToXMI1(stream);
stream.writeEndElement(); // widget
QString error;
int line;
QDomDocument domDoc;
if (domDoc.setContent(xmi, &error, &line)) {
m_element = domDoc.firstChild().firstChild().toElement();
} else {
uWarning() << "Cannot set content:" << error << " line:" << line;
}
}
/**
......
......@@ -12,6 +12,7 @@
// app includes
#include "associationwidget.h"
#include "debug_utils.h"
#include "umlscene.h"
#include "umlwidget.h"
......@@ -28,18 +29,45 @@ namespace Uml
{
setText(i18n("Remove widget : %1", widget->name()));
// save "child" elements
foreach(QGraphicsItem* item, widget->childItems()) {
UMLWidget* child = dynamic_cast<UMLWidget*>(item);
if (child != nullptr) {
QDomDocument doc;
m_children.append(doc.createElement(QLatin1String("child")));
child->saveToXMI1(doc, m_children.back());
uIgnoreZeroPointer(child);
QString xmi;
QXmlStreamWriter kidStream(&xmi);
kidStream.writeStartElement(QLatin1String("child"));
child->saveToXMI1(kidStream);
kidStream.writeEndElement(); // child
QString error;
int line;
QDomDocument domDoc;
if (domDoc.setContent(xmi, &error, &line)) {
QDomElement domElem = domDoc.firstChild().firstChild().toElement();
if (domElem.isNull())
uWarning() << "child QDomElement is null";
else
m_children.append(domElem);
} else {
uWarning() << "Cannot set content:" << error << " line:" << line;
}
}
// save "widget" element
QString xmi;
QXmlStreamWriter stream(&xmi);
stream.writeStartElement(QLatin1String("widget"));
widget->saveToXMI1(stream);
stream.writeEndElement(); // widget
QString error;
int line;
QDomDocument doc;
m_element = doc.createElement(QLatin1String("widget"));
widget->saveToXMI1(doc, m_element);
if (doc.setContent(xmi, &error, &line)) {
m_element = doc.firstChild().firstChild().toElement();
if (m_element.isNull())
uWarning() << "widget QDomElement is null";
} else {
uWarning() << "Cannot set content:" << error << " line:" << line;
}
}
/**
......@@ -50,9 +78,22 @@ namespace Uml
{
setText(i18n("Remove widget : %1", widget->name()));
// save "widget" element
QString xmi;
QXmlStreamWriter stream(&xmi);
stream.writeStartElement(QLatin1String("widget"));
widget->saveToXMI1(stream);
stream.writeEndElement(); // widget
QString error;
int line;
QDomDocument doc;
m_element = doc.createElement(QLatin1String("widget"));
widget->saveToXMI1(doc, m_element);
if (doc.setContent(xmi, &error, &line)) {
m_element = doc.firstChild().firstChild().toElement();
if (m_element.isNull())
uWarning() << "widget QDomElement is null";
} else {
uWarning() << "Cannot set content:" << error << " line:" << line;
}
}
/**
......
......@@ -30,6 +30,7 @@
// qt includes
#include <QList>
#include <QRegExp>
#include <QXmlStreamWriter>
/**
* Constructor.
......@@ -710,7 +711,7 @@ void ClassifierCodeDocument::loadClassFieldsFromXMI(QDomElement & elem)
/**
* Save the XMI representation of this object.
*/
void ClassifierCodeDocument::saveToXMI1 (QDomDocument & doc, QDomElement & root)
void ClassifierCodeDocument::saveToXMI1(QXmlStreamWriter& writer)
{
#if 0
// avoid the creation of primitive data type
......@@ -723,11 +724,11 @@ void ClassifierCodeDocument::saveToXMI1 (QDomDocument & doc, QDomElement & root)
return;
}
#endif
QDomElement docElement = doc.createElement(QLatin1String("classifiercodedocument"));
writer.writeStartElement(QLatin1String("classifiercodedocument"));
setAttributesOnNode(doc, docElement);
setAttributesOnNode(writer);
root.appendChild(docElement);
writer.writeEndElement();
}
/**
......@@ -746,22 +747,22 @@ void ClassifierCodeDocument::loadFromXMI1 (QDomElement & root)
* Set attributes of the node that represents this class
* in the XMI document.
*/
void ClassifierCodeDocument::setAttributesOnNode (QDomDocument & doc, QDomElement & docElement)
void ClassifierCodeDocument::setAttributesOnNode (QXmlStreamWriter& writer)
{
// do super-class first
CodeDocument::setAttributesOnNode(doc, docElement);
CodeDocument::setAttributesOnNode(writer);
// cache local attributes/fields
docElement.setAttribute(QLatin1String("parent_class"), Uml::ID::toString(getParentClassifier()->id()));
writer.writeAttribute(QLatin1String("parent_class"), Uml::ID::toString(getParentClassifier()->id()));
// (code) class fields
// which we will store in its own separate child node block
QDomElement fieldsElement = doc.createElement(QLatin1String("classfields"));
writer.writeStartElement(QLatin1String("classfields"));
CodeClassFieldList::Iterator it = m_classfieldVector.begin();
CodeClassFieldList::Iterator end = m_classfieldVector.end();
for (; it!= end; ++it)
(*it)->saveToXMI1(doc, fieldsElement);
docElement.appendChild(fieldsElement);
(*it)->saveToXMI1(writer);
writer.writeEndElement();
}
/**
......
......@@ -80,14 +80,14 @@ public:
virtual void updateContent() = 0;
virtual void saveToXMI1(QDomDocument &doc, QDomElement &root);
virtual void saveToXMI1(QXmlStreamWriter& writer);
virtual void loadFromXMI1(QDomElement &root);
protected:
void loadClassFieldsFromXMI(QDomElement &childElem);
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement);
virtual void setAttributesOnNode(QXmlStreamWriter& writer);
virtual void setAttributesFromNode(QDomElement &element);
TextBlock * findCodeClassFieldTextBlockByTag(const QString &tag);
......
......@@ -13,6 +13,7 @@
#include "codeaccessormethod.h"
// qt/kde includes
#include <QXmlStreamWriter>
// local includes
#include "codeclassfield.h"
......@@ -107,27 +108,27 @@ void CodeAccessorMethod::loadFromXMI1(QDomElement & root)
/**
* Save the XMI representation of this object.
*/
void CodeAccessorMethod::saveToXMI1(QDomDocument & doc, QDomElement & root)
void CodeAccessorMethod::saveToXMI1(QXmlStreamWriter& writer)
{
QDomElement docElement = doc.createElement(QLatin1String("codeaccessormethod"));
writer.writeStartElement(QLatin1String("codeaccessormethod"));
setAttributesOnNode(doc, docElement);
setAttributesOnNode(writer);
root.appendChild(docElement);
writer.writeEndElement();
}
/**
* Set attributes of the node that represents this class
* in the XMI document.
*/
void CodeAccessorMethod::setAttributesOnNode(QDomDocument & doc, QDomElement & elem)
void CodeAccessorMethod::setAttributesOnNode(QXmlStreamWriter& writer)
{
// set super-class attributes
CodeMethodBlock::setAttributesOnNode(doc, elem);
CodeMethodBlock::setAttributesOnNode(writer);
// set local class attributes
elem.setAttribute(QLatin1String("accessType"), getType());
elem.setAttribute(QLatin1String("classfield_id"), getParentClassField()->ID());
writer.writeAttribute(QLatin1String("accessType"), QString::number(getType()));
writer.writeAttribute(QLatin1String("classfield_id"), getParentClassField()->ID());
}
/**
......
......@@ -16,6 +16,7 @@
#include <QString>
class CodeClassField;
class QXmlStreamWriter;
class CodeAccessorMethod : public CodeMethodBlock
{
......@@ -46,7 +47,7 @@ public:
virtual void updateContent() = 0;
virtual void saveToXMI1(QDomDocument & doc, QDomElement & root);
virtual void saveToXMI1(QXmlStreamWriter& writer);
virtual void loadFromXMI1(QDomElement & root);
virtual void setAttributesFromObject(TextBlock * obj);
......@@ -55,7 +56,7 @@ protected:
virtual void release();
virtual void setAttributesOnNode(QDomDocument & doc, QDomElement & blockElement);
virtual void setAttributesOnNode(QXmlStreamWriter& writer);
virtual void setAttributesFromNode(QDomElement & element);
......
......@@ -61,12 +61,12 @@ CodeBlock::ContentType CodeBlock::contentType() const
* @param doc the xmi document
* @param root the starting point to append
*/
void CodeBlock::saveToXMI1(QDomDocument & doc, QDomElement & root)
void CodeBlock::saveToXMI1(QXmlStreamWriter& writer)
{
QDomElement blockElement = doc.createElement(QLatin1String("codeblock"));
writer.writeStartElement(QLatin1String("codeblock"));
// set attributes
setAttributesOnNode(doc, blockElement);
root.appendChild(blockElement);
setAttributesOnNode(writer);
writer.writeEndElement();
}
/**
......@@ -75,13 +75,13 @@ void CodeBlock::saveToXMI1(QDomDocument & doc, QDomElement & root)
* @param doc the xmi document
* @param blockElement the xmi element holding the attributes
*/
void CodeBlock::setAttributesOnNode(QDomDocument & doc, QDomElement & blockElement)
void CodeBlock::setAttributesOnNode(QXmlStreamWriter& writer)
{
// call super-class
TextBlock::setAttributesOnNode(doc, blockElement);
TextBlock::setAttributesOnNode(writer);
// local attributes
if (m_contentType != AutoGenerated)
blockElement.setAttribute(QLatin1String("contentType"), contentType());
writer.writeAttribute(QLatin1String("contentType"), QString::number(contentType()));
}
/**
......
......@@ -37,7 +37,7 @@ public:
static QString enumToString(const ContentType& val);
virtual void saveToXMI1(QDomDocument & doc, QDomElement & root);
virtual void saveToXMI1(QXmlStreamWriter& writer);
virtual void loadFromXMI1(QDomElement & root);
virtual void setAttributesFromObject(TextBlock * obj);
......@@ -46,7 +46,7 @@ public:
protected:
virtual void setAttributesOnNode(QDomDocument & doc, QDomElement & blockElement);
virtual void setAttributesOnNode(QXmlStreamWriter& writer);
virtual void setAttributesFromNode(QDomElement & element);
private:
......
......@@ -17,6 +17,9 @@
#include "codegenfactory.h"
#include "debug_utils.h"
// qt/kde includes
#include <QXmlStreamWriter>
/**
* Basic Constructor
*/
......@@ -52,30 +55,30 @@ CodeComment * CodeBlockWithComments::getComment () const
/**