[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Mon Oct 15 15:32:01 CEST 2007
SVN commit 725471 by fenton:
Update of PictureItem save/restore to use a separate node of <data>
rather than an attribute.
M +27 -8 pictureitem.cpp
M +3 -1 pictureitem.h
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.cpp #725470:725471
@@ -22,7 +22,10 @@
namespace Kst {
PictureItem::PictureItem(View *parent, const QImage &image)
- : ViewItem(parent), _image(QPixmap::fromImage(image)) {
+ : ViewItem(parent) {
+ if (!image.isNull()) {
+ _image = QPixmap::fromImage(image);
+ }
setName("Picture");
setLockAspectRatio(true);
}
@@ -34,16 +37,24 @@
void PictureItem::save(QXmlStreamWriter &xml) {
xml.writeStartElement("picture");
+ ViewItem::save(xml);
+ xml.writeStartElement("data");
QByteArray qba;
QBuffer buffer(&qba);
buffer.open(QIODevice::WriteOnly);
QImage(_image).save(&buffer, "PNG"); // writes image into ba in PNG format
- xml.writeAttribute("data", qCompress(qba).toBase64());
- ViewItem::save(xml);
+ xml.writeCharacters(qCompress(qba).toBase64());
xml.writeEndElement();
+ xml.writeEndElement();
}
+void PictureItem::setImage(const QImage &image)
+{
+ _image = QPixmap::fromImage(image);
+}
+
+
void PictureItem::paint(QPainter *painter) {
// We can do better here. Cache the scaled pixmap also.
if (!_image.isNull() && rect().isValid()) {
@@ -82,15 +93,23 @@
if (xml.isStartElement()) {
if (xml.name().toString() == "picture") {
Q_ASSERT(!rc);
- QXmlStreamAttributes attrs = xml.attributes();
- QImage loadedImage;
- QByteArray qbca = QByteArray::fromBase64(attrs.value("data").toString().toLatin1());
- loadedImage.loadFromData(qUncompress(qbca));
- rc = new PictureItem(view, loadedImage);
+ rc = new PictureItem(view);
if (parent) {
rc->setParentItem(parent);
}
// TODO add any specialized PictureItem Properties here.
+ } else if (xml.name().toString() == "data") {
+ Q_ASSERT(rc);
+ xml.readNext();
+ QImage loadedImage;
+ QByteArray qbca = QByteArray::fromBase64(xml.text().toString().toLatin1());
+ loadedImage.loadFromData(qUncompress(qbca));
+ rc->setImage(loadedImage);
+ xml.readNext();
+ if (!xml.isEndElement() || (xml.name().toString() != "data")) {
+ validTag = false;
+ }
+ xml.readNext();
} else {
Q_ASSERT(rc);
if (!rc->parse(xml, validTag) && validTag) {
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.h #725470:725471
@@ -21,12 +21,14 @@
{
Q_OBJECT
public:
- PictureItem(View *parent, const QImage &image);
+ PictureItem(View *parent, const QImage &image = QImage());
~PictureItem();
virtual void save(QXmlStreamWriter &xml);
virtual void paint(QPainter *painter);
+ void setImage(const QImage &image);
+
private:
QPixmap _image;
};
More information about the Kst
mailing list