Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 1bd83f16 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Wrap KoShapeBackground in QSharedPointer

This patch wraps KoShapeBackground in a QPointer instead of doing manual
refcounting. Bug 321714 shows, imo, that the manual refcounting is
fragile and sometimes breaks. I don't remember why we weren't supposed
to use QPointer (other than that it gets a little ugly with subclassing),
but it seems a good fit here.

There are other classes that do manual refcounting, and I think those
should be converted, too -- but in another patch.
parent f71c5820
......@@ -19,8 +19,9 @@
#include "kis_shape_selection_model.h"
#include "kis_debug.h"
#include "KoShapeContainer.h"
#include "KoShapeManager.h"
#include <KoShapeContainer.h>
#include <KoShapeBackground.h>
#include <KoShapeManager.h>
#include "kis_shape_selection.h"
#include "kis_selection.h"
......@@ -68,7 +69,7 @@ void KisShapeSelectionModel::add(KoShape *child)
return;
child->setStroke(0);
child->setBackground(0);
child->setBackground( QSharedPointer<KoShapeBackground>(0));
m_shapeMap.insert(child, child->boundingRect());
m_shapeSelection->shapeManager()->addShape(child);
......
......@@ -128,18 +128,18 @@ void KisToolShape::addShape(KoShape* shape)
KoImageCollection* imageCollection = canvas()->shapeController()->resourceManager()->imageCollection();
switch(fillStyle()) {
case KisPainter::FillStyleForegroundColor:
shape->setBackground(new KoColorBackground(currentFgColor().toQColor()));
shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(currentFgColor().toQColor())));
break;
case KisPainter::FillStyleBackgroundColor:
shape->setBackground(new KoColorBackground(currentBgColor().toQColor()));
shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(currentBgColor().toQColor())));
break;
case KisPainter::FillStylePattern:
if (imageCollection) {
KoPatternBackground* fill = new KoPatternBackground(imageCollection);
QSharedPointer<KoPatternBackground> fill(new KoPatternBackground(imageCollection));
fill->setPattern(currentPattern()->image());
shape->setBackground(fill);
} else {
shape->setBackground(0);
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
}
break;
case KisPainter::FillStyleGradient:
......@@ -147,13 +147,13 @@ void KisToolShape::addShape(KoShape* shape)
QLinearGradient *gradient = new QLinearGradient(QPointF(0, 0), QPointF(1, 1));
gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
gradient->setStops(currentGradient()->toQGradient()->stops());
KoGradientBackground* gradientFill = new KoGradientBackground(gradient);
QSharedPointer<KoGradientBackground> gradientFill(new KoGradientBackground(gradient));
shape->setBackground(gradientFill);
}
break;
case KisPainter::FillStyleNone:
default:
shape->setBackground(0);
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
break;
}
KUndo2Command * cmd = canvas()->shapeController()->addShape(shape);
......
......@@ -300,7 +300,7 @@ void KisFloatingMessage::removeMessage()
deleteLater();
}
void KisFloatingMessage::updateOpacity(int value)
void KisFloatingMessage::updateOpacity(int /*value*/)
{
setWindowOpacity(OSD_WINDOW_OPACITY - 0.1);
}
......@@ -727,11 +727,9 @@ void KoConnectionShape::shapeChanged(ChangeType type, KoShape *shape)
case BackgroundChanged:
{
// connection shape should not have a background
KoShapeBackground *fill = background();
QSharedPointer<KoShapeBackground> fill = background();
if (fill) {
if (fill->deref())
delete fill;
setBackground(0);
setBackground(QSharedPointer<KoShapeBackground>(0));
}
return;
}
......
......@@ -210,9 +210,9 @@ void KoOdfWorkaround::fixPresentationPlaceholder(KoShape *shape)
}
}
KoColorBackground *KoOdfWorkaround::fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context)
QSharedPointer<KoColorBackground> KoOdfWorkaround::fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context)
{
KoColorBackground *colorBackground = 0;
QSharedPointer<KoColorBackground> colorBackground;
KoOdfLoadingContext &odfContext = context.odfLoadingContext();
if (odfContext.generatorType() == KoOdfLoadingContext::OpenOffice) {
const KoPathShape *pathShape = dynamic_cast<const KoPathShape*>(shape);
......@@ -221,9 +221,9 @@ KoColorBackground *KoOdfWorkaround::fixBackgroundColor(const KoShape *shape, KoS
KoStyleStack &styleStack = odfContext.styleStack();
const QString color(styleStack.property(KoXmlNS::draw, "fill-color"));
if (color.isEmpty()) {
colorBackground = new KoColorBackground(QColor(153, 204, 255));
colorBackground = QSharedPointer<KoColorBackground>(new KoColorBackground(QColor(153, 204, 255)));
} else {
colorBackground = new KoColorBackground(color);
colorBackground = QSharedPointer<KoColorBackground>(new KoColorBackground(color));
}
}
}
......
......@@ -26,6 +26,8 @@
#include "KoTextShapeDataBase.h"
#include <qnamespace.h>
#include <QSharedPointer>
class KoXmlElement;
class KoShape;
class KoShapeLoadingContext;
......@@ -71,7 +73,7 @@ namespace KoOdfWorkaround
FLAKE_EXPORT QColor fixMissingFillColor(const KoXmlElement &element, KoShapeLoadingContext &context);
FLAKE_EXPORT bool fixMissingStyle_DisplayLabel(const KoXmlElement &element, KoShapeLoadingContext &context);
FLAKE_EXPORT KoColorBackground *fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context);
FLAKE_EXPORT QSharedPointer<KoColorBackground> fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context);
/**
* Old versions of ooimpress does not set the placeholder for shapes that should have it set
......
......@@ -83,7 +83,6 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
userData(0),
appData(0),
stroke(0),
fill(0),
shadow(0),
clipPath(0),
filterEffectStack(0),
......@@ -128,8 +127,6 @@ KoShapePrivate::~KoShapePrivate()
delete stroke;
if (shadow && !shadow->deref())
delete shadow;
if (fill && !fill->deref())
delete fill;
if (filterEffectStack && !filterEffectStack->deref())
delete filterEffectStack;
delete clipPath;
......@@ -1006,19 +1003,15 @@ KoShapeAnchor *KoShape::anchor() const
return d->anchor;
}
void KoShape::setBackground(KoShapeBackground *fill)
void KoShape::setBackground(QSharedPointer<KoShapeBackground> fill)
{
Q_D(KoShape);
if (d->fill)
d->fill->deref();
d->fill = fill;
if (d->fill)
d->fill->ref();
d->shapeChanged(BackgroundChanged);
notifyChanged();
}
KoShapeBackground *KoShape::background() const
QSharedPointer<KoShapeBackground> KoShape::background() const
{
Q_D(const KoShape);
return d->fill;
......@@ -1278,7 +1271,7 @@ QString KoShape::saveStyle(KoGenStyle &style, KoShapeSavingContext &context) con
if (s)
s->fillStyle(style, context);
KoShapeBackground *bg = background();
QSharedPointer<KoShapeBackground> bg = background();
if (bg) {
bg->fillStyle(style, context);
}
......@@ -1385,10 +1378,7 @@ void KoShape::loadStyle(const KoXmlElement &element, KoShapeLoadingContext &cont
KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
styleStack.setTypeProperties("graphic");
if (d->fill && !d->fill->deref()) {
delete d->fill;
d->fill = 0;
}
d->fill.clear();
if (d->stroke && !d->stroke->deref()) {
delete d->stroke;
d->stroke = 0;
......@@ -1571,15 +1561,15 @@ bool KoShape::loadOdfAttributes(const KoXmlElement &element, KoShapeLoadingConte
return true;
}
KoShapeBackground *KoShape::loadOdfFill(KoShapeLoadingContext &context) const
QSharedPointer<KoShapeBackground> KoShape::loadOdfFill(KoShapeLoadingContext &context) const
{
QString fill = KoShapePrivate::getStyleProperty("fill", context);
KoShapeBackground *bg = 0;
QSharedPointer<KoShapeBackground> bg;
if (fill == "solid") {
bg = new KoColorBackground();
bg = QSharedPointer<KoShapeBackground>(new KoColorBackground());
}
else if (fill == "hatch") {
bg = new KoHatchBackground();
bg = QSharedPointer<KoShapeBackground>(new KoHatchBackground());
}
else if (fill == "gradient") {
QString styleName = KoShapePrivate::getStyleProperty("fill-gradient-name", context);
......@@ -1589,26 +1579,25 @@ KoShapeBackground *KoShape::loadOdfFill(KoShapeLoadingContext &context) const
style = e->attributeNS(KoXmlNS::draw, "style", QString());
}
if ((style == "rectangular") || (style == "square")) {
bg = new KoOdfGradientBackground();
bg = QSharedPointer<KoShapeBackground>(new KoOdfGradientBackground());
} else {
QGradient *gradient = new QLinearGradient();
gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
bg = new KoGradientBackground(gradient);
bg = QSharedPointer<KoShapeBackground>(new KoGradientBackground(gradient));
}
} else if (fill == "bitmap") {
bg = new KoPatternBackground(context.imageCollection());
bg = QSharedPointer<KoShapeBackground>(new KoPatternBackground(context.imageCollection()));
#ifndef NWORKAROUND_ODF_BUGS
} else if (fill.isEmpty()) {
bg = KoOdfWorkaround::fixBackgroundColor(this, context);
bg = QSharedPointer<KoShapeBackground>(KoOdfWorkaround::fixBackgroundColor(this, context));
return bg;
#endif
} else {
return 0;
return QSharedPointer<KoShapeBackground>(0);
}
if (!bg->loadStyle(context.odfLoadingContext(), size())) {
delete bg;
return 0;
return QSharedPointer<KoShapeBackground>(0);
}
return bg;
......
......@@ -27,6 +27,7 @@
#include "KoFlake.h"
#include "KoConnectionPoint.h"
#include <QSharedPointer>
#include <QTransform>
#include <QVector>
#include <QSet>
......@@ -484,7 +485,7 @@ public:
* if it is transparent or not.
* @param background the new shape background.
*/
void setBackground(KoShapeBackground *background);
void setBackground(QSharedPointer<KoShapeBackground> background);
/**
* return the brush used to paint te background of this shape with.
......@@ -493,7 +494,7 @@ public:
* will be able to tell if its transparent or not.
* @return the background-brush
*/
KoShapeBackground *background() const;
QSharedPointer<KoShapeBackground> background() const;
/**
* Returns true if there is some transparency, false if the shape is fully opaque.
......@@ -1163,7 +1164,7 @@ protected:
KoShapeStrokeModel *loadOdfStroke(const KoXmlElement &element, KoShapeLoadingContext &context) const;
/// Loads the shadow style
KoShapeBackground *loadOdfFill(KoShapeLoadingContext &context) const;
QSharedPointer<KoShapeBackground> loadOdfFill(KoShapeLoadingContext &context) const;
/// Loads the connection points
void loadOdfGluePoints(const KoXmlElement &element, KoShapeLoadingContext &context);
......
......@@ -18,10 +18,10 @@
*/
#include "KoShapeBackground.h"
#include "KoShapeBackground_p.h"
KoShapeBackgroundPrivate::KoShapeBackgroundPrivate()
: refCount(0)
{
}
......@@ -34,6 +34,8 @@ KoShapeBackground::KoShapeBackground(KoShapeBackgroundPrivate &dd)
{
}
KoShapeBackground::KoShapeBackground()
: d_ptr(new KoShapeBackgroundPrivate())
{
......@@ -48,21 +50,3 @@ bool KoShapeBackground::hasTransparency() const
{
return false;
}
bool KoShapeBackground::ref()
{
Q_D(KoShapeBackground);
return d->refCount.ref();
}
bool KoShapeBackground::deref()
{
Q_D(KoShapeBackground);
return d->refCount.deref();
}
int KoShapeBackground::useCount() const
{
Q_D(const KoShapeBackground);
return d->refCount;
}
......@@ -22,6 +22,9 @@
#include "flake_export.h"
#include <QObject>
#include <QSharedPointer>
class QSizeF;
class QPainter;
class QPainterPath;
......@@ -59,25 +62,13 @@ public:
/// load background from odf styles
virtual bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) = 0;
/**
* Increments the use-value.
* Returns true if the new value is non-zero, false otherwise.
*/
bool ref();
/**
* Decrements the use-value.
* Returns true if the new value is non-zero, false otherwise.
*/
bool deref();
/// Return the usage count
int useCount() const;
protected:
KoShapeBackground(KoShapeBackgroundPrivate &);
KoShapeBackgroundPrivate *d_ptr;
private:
Q_DECLARE_PRIVATE(KoShapeBackground)
};
#endif // KOSHAPEBACKGROUND_H
......@@ -20,14 +20,11 @@
#ifndef KoShapeBackgroundPrivate_H
#define KoShapeBackgroundPrivate_H
#include <QAtomicInt>
class KoShapeBackgroundPrivate
{
public:
KoShapeBackgroundPrivate();
virtual ~KoShapeBackgroundPrivate();
QAtomicInt refCount;
};
#endif
......@@ -69,7 +69,7 @@ public:
KoShapeUserData *userData;
KoShapeApplicationData *appData;
KoShapeStrokeModel *stroke; ///< points to a stroke, or 0 if there is no stroke
KoShapeBackground * fill; ///< Stands for the background color / fill etc.
QSharedPointer<KoShapeBackground> fill; ///< Stands for the background color / fill etc.
QList<KoShape*> dependees; ///< list of shape dependent on this shape
KoShapeShadow * shadow; ///< the current shape shadow
KoClipPath * clipPath; ///< the current clip path
......
......@@ -30,36 +30,26 @@ public:
Private() {
}
~Private() {
foreach(KoShapeBackground* fill, oldFills) {
if (fill && !fill->deref())
delete fill;
}
foreach(KoShapeBackground* fill, newFills) {
if (fill && !fill->deref())
delete fill;
}
oldFills.clear();
newFills.clear();
}
void addOldFill(KoShapeBackground * oldFill)
void addOldFill(QSharedPointer<KoShapeBackground> oldFill)
{
if (oldFill)
oldFill->ref();
oldFills.append(oldFill);
}
void addNewFill(KoShapeBackground * newFill)
void addNewFill(QSharedPointer<KoShapeBackground> newFill)
{
if (newFill)
newFill->ref();
newFills.append(newFill);
}
QList<KoShape*> shapes; ///< the shapes to set background for
QList<KoShapeBackground*> oldFills;
QList<KoShapeBackground*> newFills;
QList<QSharedPointer<KoShapeBackground> > oldFills;
QList<QSharedPointer<KoShapeBackground> > newFills;
};
KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, KoShapeBackground * fill,
KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, QSharedPointer<KoShapeBackground> fill,
KUndo2Command *parent)
: KUndo2Command(parent)
, d(new Private())
......@@ -73,7 +63,7 @@ KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes
setText(i18nc("(qtundo-format)", "Set background"));
}
KoShapeBackgroundCommand::KoShapeBackgroundCommand(KoShape * shape, KoShapeBackground * fill, KUndo2Command *parent)
KoShapeBackgroundCommand::KoShapeBackgroundCommand(KoShape * shape, QSharedPointer<KoShapeBackground> fill, KUndo2Command *parent)
: KUndo2Command(parent)
, d(new Private())
{
......@@ -84,7 +74,7 @@ KoShapeBackgroundCommand::KoShapeBackgroundCommand(KoShape * shape, KoShapeBackg
setText(i18nc("(qtundo-format)", "Set background"));
}
KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, const QList<KoShapeBackground*> &fills, KUndo2Command *parent)
KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, const QList<QSharedPointer<KoShapeBackground> > &fills, KUndo2Command *parent)
: KUndo2Command(parent)
, d(new Private())
{
......@@ -92,7 +82,7 @@ KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes
foreach(KoShape *shape, d->shapes) {
d->addOldFill(shape->background());
}
foreach (KoShapeBackground * fill, fills) {
foreach (QSharedPointer<KoShapeBackground> fill, fills) {
d->addNewFill(fill);
}
......@@ -102,7 +92,7 @@ KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes
void KoShapeBackgroundCommand::redo()
{
KUndo2Command::redo();
QList<KoShapeBackground*>::iterator brushIt = d->newFills.begin();
QList<QSharedPointer<KoShapeBackground> >::iterator brushIt = d->newFills.begin();
foreach(KoShape *shape, d->shapes) {
shape->setBackground(*brushIt);
shape->update();
......@@ -113,7 +103,7 @@ void KoShapeBackgroundCommand::redo()
void KoShapeBackgroundCommand::undo()
{
KUndo2Command::undo();
QList<KoShapeBackground*>::iterator brushIt = d->oldFills.begin();
QList<QSharedPointer<KoShapeBackground> >::iterator brushIt = d->oldFills.begin();
foreach(KoShape *shape, d->shapes) {
shape->setBackground(*brushIt);
shape->update();
......
......@@ -26,6 +26,7 @@
#include <kundo2command.h>
#include <QList>
#include <QBrush>
#include <QSharedPointer>
class KoShape;
class KoShapeBackground;
......@@ -40,7 +41,7 @@ public:
* @param fill the new shape background
* @param parent the parent command used for macro commands
*/
KoShapeBackgroundCommand(const QList<KoShape*> &shapes, KoShapeBackground *fill, KUndo2Command *parent = 0);
KoShapeBackgroundCommand(const QList<KoShape*> &shapes, QSharedPointer<KoShapeBackground> fill, KUndo2Command *parent = 0);
/**
* Command to set a new shape background.
......@@ -48,7 +49,7 @@ public:
* @param fill the new shape background
* @param parent the parent command used for macro commands
*/
KoShapeBackgroundCommand(KoShape *shape, KoShapeBackground *fill, KUndo2Command *parent = 0);
KoShapeBackgroundCommand(KoShape *shape, QSharedPointer<KoShapeBackground> fill, KUndo2Command *parent = 0);
/**
* Command to set new shape backgrounds.
......@@ -56,7 +57,7 @@ public:
* @param fills the new backgrounds, one for each shape
* @param parent the parent command used for macro commands
*/
KoShapeBackgroundCommand(const QList<KoShape*> &shapes, const QList<KoShapeBackground*> &fills, KUndo2Command *parent = 0);
KoShapeBackgroundCommand(const QList<KoShape*> &shapes, const QList<QSharedPointer<KoShapeBackground> > &fills, KUndo2Command *parent = 0);
virtual ~KoShapeBackgroundCommand();
/// redo the command
......
......@@ -533,21 +533,21 @@ void SvgParser::applyFillStyle(KoShape *shape)
return;
if (gc->fillType == SvgGraphicsContext::None) {
shape->setBackground(0);
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
} else if (gc->fillType == SvgGraphicsContext::Solid) {
shape->setBackground(new KoColorBackground(gc->fillColor));
shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(gc->fillColor)));
} else if (gc->fillType == SvgGraphicsContext::Complex) {
// try to find referenced gradient
SvgGradientHelper *gradient = findGradient(gc->fillId);
if (gradient) {
// great, we have a gradient fill
KoGradientBackground *bg = 0;
QSharedPointer<KoGradientBackground> bg;
if (gradient->gradientUnits() == SvgGradientHelper::ObjectBoundingBox) {
bg = new KoGradientBackground(*gradient->gradient());
bg = QSharedPointer<KoGradientBackground>(new KoGradientBackground(*gradient->gradient()));
bg->setTransform(gradient->transform());
} else {
QGradient *convertedGradient = SvgGradientHelper::convertGradient(gradient->gradient(), shape->size());
bg = new KoGradientBackground(*convertedGradient);
bg = QSharedPointer<KoGradientBackground>(new KoGradientBackground(convertedGradient));
delete convertedGradient;
QTransform invShapematrix = shape->transformation().inverted();
bg->setTransform(gradient->transform() * gc->matrix * invShapematrix);
......@@ -592,7 +592,7 @@ void SvgParser::applyFillStyle(KoShape *shape)
qDeleteAll(patternContent);
if (!image.isNull()) {
KoPatternBackground *bg = new KoPatternBackground(imageCollection);
QSharedPointer<KoPatternBackground> bg(new KoPatternBackground(imageCollection));
bg->setPattern(image);
QPointF refPoint = shape->documentToShape(pattern->position(objectBound));
......@@ -628,7 +628,7 @@ void SvgParser::applyFillStyle(KoShape *shape)
}
} else {
// no referenced fill found, use fallback color
shape->setBackground(new KoColorBackground(gc->fillColor));
shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(gc->fillColor)));
}
}
}
......@@ -1267,9 +1267,7 @@ KoShape * SvgParser::createShapeFromElement(const KoXmlElement &element, SvgLoad
delete oldStroke;
// reset fill
KoShapeBackground *oldFill = shape->background();
shape->setBackground(0);
delete oldFill;
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
if (!svgShape->loadSvg(element, context)) {
delete shape;
......@@ -1312,9 +1310,7 @@ KoShape * SvgParser::createShape(const QString &shapeID)
delete oldStroke;
// reset fill
KoShapeBackground *oldFill = shape->background();
shape->setBackground(0);
delete oldFill;
shape->setBackground(QSharedPointer<KoShapeBackground>(0));
return shape;
}
......
......@@ -74,18 +74,18 @@ void SvgStyleWriter::saveSvgFill(KoShape *shape, SvgSavingContext &context)
}
QBrush fill(Qt::NoBrush);
KoColorBackground * cbg = dynamic_cast<KoColorBackground*>(shape->background());
QSharedPointer<KoColorBackground> cbg = qSharedPointerDynamicCast<KoColorBackground>(shape->background());
if (cbg) {
context.shapeWriter().addAttribute("fill", cbg->color().name());
if (cbg->color().alphaF() < 1.0)
context.shapeWriter().addAttribute("fill-opacity", cbg->color().alphaF());
}
KoGradientBackground * gbg = dynamic_cast<KoGradientBackground*>(shape->background());
QSharedPointer<KoGradientBackground> gbg = qSharedPointerDynamicCast<KoGradientBackground>(shape->background());
if (gbg) {
QString gradientId = saveSvgGradient(gbg->gradient(), gbg->transform(), context);
context.shapeWriter().addAttribute("fill", "url(#" + gradientId + ")");
}
KoPatternBackground * pbg = dynamic_cast<KoPatternBackground*>(shape->background());
QSharedPointer<KoPatternBackground> pbg = qSharedPointerDynamicCast<KoPatternBackground>(shape->background());
if (pbg) {
const QString patternId = saveSvgPattern(pbg, shape, context);
context.shapeWriter().addAttribute("fill", "url(#" + patternId + ")");
......@@ -284,7 +284,7 @@ QString SvgStyleWriter::saveSvgGradient(const QGradient *gradient, const QTransf
return uid;
}
QString SvgStyleWriter::saveSvgPattern(KoPatternBackground *pattern, KoShape *shape, SvgSavingContext &context)
QString SvgStyleWriter::saveSvgPattern(QSharedPointer<KoPatternBackground> pattern, KoShape *shape, SvgSavingContext &context)
{
const QString uid = context.createUID("pattern");
......
......@@ -31,6 +31,7 @@
#include "flake_export.h"
#include <QGradient>
#include <QSharedPointer>
class SvgSavingContext;
class KoShape;
......@@ -58,7 +59,7 @@ protected:
/// Saves gradient
static QString saveSvgGradient(const QGradient *gradient, const QTransform &gradientTransform, SvgSavingContext &context);
/// Saves pattern
static QString saveSvgPattern(KoPatternBackground *pattern, KoShape *shape, SvgSavingContext &context);
static QString saveSvgPattern(QSharedPointer<KoPatternBackground> pattern, KoShape *shape, SvgSavingContext &context);
};
#endif // SVGSTYLEWRITER_H
......@@ -27,13 +27,12 @@
void TestShapeBackgroundCommand::refCounting()
{
MockShape * shape1 = new MockShape();
KoShapeBackground * whiteFill = new KoColorBackground(QColor(Qt::white));
KoShapeBackground * blackFill = new KoColorBackground(QColor(Qt::black));
KoShapeBackground * redFill = new KoColorBackground(QColor(Qt::red));
QSharedPointer<KoShapeBackground> whiteFill(new KoColorBackground(QColor(Qt::white)));
QSharedPointer<KoShapeBackground> blackFill(new KoColorBackground(QColor(Qt::black)));
QSharedPointer<KoShapeBackground> redFill (new KoColorBackground(QColor(Qt::red)));
shape1->setBackground(whiteFill);
QVERIFY(shape1->background() == whiteFill);
QCOMPARE(whiteFill->useCount(), 1);
// old fill is white, new fill is black
KUndo2Command *cmd1 = new KoShapeBackgroundCommand(shape1, blackFill);
......
......@@ -135,7 +135,7 @@ QString KoPAPageBase::saveOdfPageStyle( KoPASavingContext &paContext ) const
void KoPAPageBase::saveOdfPageStyleData( KoGenStyle &style, KoPASavingContext &paContext ) const
{
KoShapeBackground * bg = background();
QSharedPointer<KoShapeBackground> bg = background();
if( bg )
bg->fillStyle( style, paContext );
}
......
......@@ -882,7 +882,7 @@ void KoPAView::insertPage()
KoPAPageBase * page = 0;
if ( viewMode()->masterMode() ) {
KoPAMasterPage * masterPage = d->doc->newMasterPage();
masterPage->setBackground( new KoColorBackground( Qt::white ) );
masterPage->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(Qt::white)));
// use the layout of the current active page for the new page