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 6d455bc1 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Wrap KoShapeBackground in QPointer

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.

BUG: 321714
parent 490e71c7
......@@ -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"
......
......@@ -135,9 +135,9 @@ void KisToolShape::addShape(KoShape* shape)
break;
case KisPainter::FillStylePattern:
if (imageCollection) {
KoPatternBackground* fill = new KoPatternBackground(imageCollection);
QPointer<KoPatternBackground> fill = new KoPatternBackground(imageCollection);
fill->setPattern(currentPattern()->image());
shape->setBackground(fill);
shape->setBackground(fill.data());
} else {
shape->setBackground(0);
}
......@@ -147,8 +147,8 @@ 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);
shape->setBackground(gradientFill);
QPointer<KoGradientBackground> gradientFill = new KoGradientBackground(gradient);
shape->setBackground(gradientFill.data());
}
break;
case KisPainter::FillStyleNone:
......
......@@ -727,10 +727,8 @@ void KoConnectionShape::shapeChanged(ChangeType type, KoShape *shape)
case BackgroundChanged:
{
// connection shape should not have a background
KoShapeBackground *fill = background();
QPointer<KoShapeBackground> fill = background();
if (fill) {
if (fill->deref())
delete fill;
setBackground(0);
}
return;
......
......@@ -210,9 +210,9 @@ void KoOdfWorkaround::fixPresentationPlaceholder(KoShape *shape)
}
}
KoColorBackground *KoOdfWorkaround::fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context)
QPointer<KoColorBackground> KoOdfWorkaround::fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context)
{
KoColorBackground *colorBackground = 0;
QPointer<KoColorBackground> colorBackground = 0;
KoOdfLoadingContext &odfContext = context.odfLoadingContext();
if (odfContext.generatorType() == KoOdfLoadingContext::OpenOffice) {
const KoPathShape *pathShape = dynamic_cast<const KoPathShape*>(shape);
......
......@@ -26,6 +26,8 @@
#include "KoTextShapeDataBase.h"
#include <qnamespace.h>
#include <QPointer>
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 QPointer<KoColorBackground> fixBackgroundColor(const KoShape *shape, KoShapeLoadingContext &context);
/**
* Old versions of ooimpress does not set the placeholder for shapes that should have it set
......
......@@ -128,8 +128,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 +1004,15 @@ KoShapeAnchor *KoShape::anchor() const
return d->anchor;
}
void KoShape::setBackground(KoShapeBackground *fill)
void KoShape::setBackground(QPointer<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
QPointer<KoShapeBackground> KoShape::background() const
{
Q_D(const KoShape);
return d->fill;
......@@ -1278,7 +1272,7 @@ QString KoShape::saveStyle(KoGenStyle &style, KoShapeSavingContext &context) con
if (s)
s->fillStyle(style, context);
KoShapeBackground *bg = background();
QPointer<KoShapeBackground> bg = background();
if (bg) {
bg->fillStyle(style, context);
}
......@@ -1385,10 +1379,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 = 0;
if (d->stroke && !d->stroke->deref()) {
delete d->stroke;
d->stroke = 0;
......@@ -1571,10 +1562,10 @@ bool KoShape::loadOdfAttributes(const KoXmlElement &element, KoShapeLoadingConte
return true;
}
KoShapeBackground *KoShape::loadOdfFill(KoShapeLoadingContext &context) const
QPointer<KoShapeBackground> KoShape::loadOdfFill(KoShapeLoadingContext &context) const
{
QString fill = KoShapePrivate::getStyleProperty("fill", context);
KoShapeBackground *bg = 0;
QPointer<KoShapeBackground> bg = 0;
if (fill == "solid") {
bg = new KoColorBackground();
}
......
......@@ -27,6 +27,7 @@
#include "KoFlake.h"
#include "KoConnectionPoint.h"
#include <QPointer>
#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(QPointer<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;
QPointer<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;
QPointer<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 <QPointer>
class QSizeF;
class QPainter;
class QPainterPath;
......@@ -37,8 +40,9 @@ class KoViewConverter;
* Derived classes are used to paint the background of
* a shape within a given painter path.
*/
class FLAKE_EXPORT KoShapeBackground
class FLAKE_EXPORT KoShapeBackground : public QObject // For use with QPointer
{
Q_OBJECT
public:
KoShapeBackground();
virtual ~KoShapeBackground();
......@@ -59,25 +63,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.
QPointer<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(QPointer<KoShapeBackground> oldFill)
{
if (oldFill)
oldFill->ref();
oldFills.append(oldFill);
}
void addNewFill(KoShapeBackground * newFill)
void addNewFill(QPointer<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<QPointer<KoShapeBackground> > oldFills;
QList<QPointer<KoShapeBackground> > newFills;
};
KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, KoShapeBackground * fill,
KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, QPointer<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, QPointer<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<QPointer<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 (QPointer<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<QPointer<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<QPointer<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 <QPointer>
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, QPointer<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, QPointer<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<QPointer<KoShapeBackground> > &fills, KUndo2Command *parent = 0);
virtual ~KoShapeBackgroundCommand();
/// redo the command
......
......@@ -541,7 +541,7 @@ void SvgParser::applyFillStyle(KoShape *shape)
SvgGradientHelper *gradient = findGradient(gc->fillId);
if (gradient) {
// great, we have a gradient fill
KoGradientBackground *bg = 0;
QPointer<KoGradientBackground> bg = 0;
if (gradient->gradientUnits() == SvgGradientHelper::ObjectBoundingBox) {
bg = new KoGradientBackground(*gradient->gradient());
bg->setTransform(gradient->transform());
......@@ -552,7 +552,7 @@ void SvgParser::applyFillStyle(KoShape *shape)
QTransform invShapematrix = shape->transformation().inverted();
bg->setTransform(gradient->transform() * gc->matrix * invShapematrix);
}
shape->setBackground(bg);
shape->setBackground(bg.data());
} else {
// try to find referenced pattern
SvgPatternHelper *pattern = findPattern(gc->fillId);
......@@ -592,7 +592,7 @@ void SvgParser::applyFillStyle(KoShape *shape)
qDeleteAll(patternContent);
if (!image.isNull()) {
KoPatternBackground *bg = new KoPatternBackground(imageCollection);
QPointer<KoPatternBackground> bg = new KoPatternBackground(imageCollection);
bg->setPattern(image);
QPointF refPoint = shape->documentToShape(pattern->position(objectBound));
......@@ -624,7 +624,7 @@ void SvgParser::applyFillStyle(KoShape *shape)
qreal offsetY = 100.0 * (refPoint.y() - fy * tileSize.height()) / tileSize.height();
bg->setReferencePointOffset(QPointF(offsetX, offsetY));
shape->setBackground(bg);
shape->setBackground(bg.data());
}
} else {
// no referenced fill found, use fallback color
......@@ -1267,7 +1267,7 @@ KoShape * SvgParser::createShapeFromElement(const KoXmlElement &element, SvgLoad
delete oldStroke;
// reset fill
KoShapeBackground *oldFill = shape->background();
QPointer<KoShapeBackground> oldFill = shape->background();
shape->setBackground(0);
delete oldFill;
......@@ -1312,7 +1312,7 @@ KoShape * SvgParser::createShape(const QString &shapeID)
delete oldStroke;
// reset fill
KoShapeBackground *oldFill = shape->background();
QPointer<KoShapeBackground> oldFill = shape->background();
shape->setBackground(0);
delete oldFill;
......
......@@ -74,18 +74,18 @@ void SvgStyleWriter::saveSvgFill(KoShape *shape, SvgSavingContext &context)
}
QBrush fill(Qt::NoBrush);
KoColorBackground * cbg = dynamic_cast<KoColorBackground*>(shape->background());
QPointer<KoColorBackground> cbg = dynamic_cast<KoColorBackground*>(shape->background().data());
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());
QPointer<KoGradientBackground> gbg = dynamic_cast<KoGradientBackground*>(shape->background().data());
if (gbg) {
QString gradientId = saveSvgGradient(gbg->gradient(), gbg->transform(), context);
context.shapeWriter().addAttribute("fill", "url(#" + gradientId + ")");
}
KoPatternBackground * pbg = dynamic_cast<KoPatternBackground*>(shape->background());
QPointer<KoPatternBackground> pbg = dynamic_cast<KoPatternBackground*>(shape->background().data());
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(QPointer<KoPatternBackground> pattern, KoShape *shape, SvgSavingContext &context)
{
const QString uid = context.createUID("pattern");
......
......@@ -31,6 +31,7 @@
#include "flake_export.h"
#include <QGradient>
#include <QPointer>
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(QPointer<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));
QPointer<KoShapeBackground> whiteFill = new KoColorBackground(QColor(Qt::white));
QPointer<KoShapeBackground> blackFill = new KoColorBackground(QColor(Qt::black));
QPointer<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();
QPointer<KoShapeBackground> bg = background();
if( bg )
bg->fillStyle( style, paContext );
}
......
......@@ -114,7 +114,7 @@ void KoPABackgroundToolWidget::setBackgroundImage()
i18nc( "(qtundo-format)", "Change slide background image") :
i18nc( "(qtundo-format)", "Change page background image");
KUndo2Command * cmd = new KUndo2Command(commandTitle);
KoPatternBackground * bg = new KoPatternBackground( collection );
QPointer<KoPatternBackground> bg = new KoPatternBackground( collection );
bg->setPattern( image );
QSizeF imageSize = bg->patternOriginalSize();
QSizeF pageSize = m_tool->view()->activePage()->size();
......@@ -134,7 +134,7 @@ void KoPABackgroundToolWidget::setBackgroundImage()
}
bg->setRepeat( repeat );
new KoShapeBackgroundCommand( page, bg, cmd );
new KoShapeBackgroundCommand( page, bg.data(), cmd );
m_tool->canvas()->addCommand( cmd );
}
}
......
......@@ -246,14 +246,14 @@ KoFillConfigWidget::KoFillConfigWidget(QWidget *parent)
KoAbstractResourceServerAdapter *gradientResourceAdapter = new KoResourceServerAdapter<KoAbstractGradient>(serverProvider->gradientServer(), this);
d->gradientAction = new KoResourcePopupAction(gradientResourceAdapter, d->colorButton);
d->gradientAction->setToolTip(i18n("Change the filling color"));
connect(d->gradientAction, SIGNAL(resourceSelected(KoShapeBackground*)), this, SLOT(gradientChanged(KoShapeBackground*)));
connect(d->gradientAction, SIGNAL(resourceSelected(QPointer<KoShapeBackground> )), this, SLOT(gradientChanged(QPointer<KoShapeBackground> )));
connect(d->colorButton, SIGNAL(iconSizeChanged()), d->gradientAction, SLOT(updateIcon()));
// Pattern selector
KoAbstractResourceServerAdapter *patternResourceAdapter = new KoResourceServerAdapter<KoPattern>(serverProvider->patternServer(), this);
d->patternAction = new KoResourcePopupAction(patternResourceAdapter, d->colorButton);
d->patternAction->setToolTip(i18n("Change the filling color"));
connect(d->patternAction, SIGNAL(resourceSelected(KoShapeBackground*)), this, SLOT(patternChanged(KoShapeBackground*)));
connect(d->patternAction, SIGNAL(resourceSelected(QPointer<KoShapeBackground> )), this, SLOT(patternChanged(QPointer<KoShapeBackground> )));
connect(d->colorButton, SIGNAL(iconSizeChanged()), d->patternAction, SLOT(updateIcon()));
// Spacer
......@@ -338,7 +338,7 @@ void KoFillConfigWidget::colorChanged()
return;
}
KoShapeBackground *fill = new KoColorBackground(d->colorAction->currentColor());
QPointer<KoShapeBackground> fill = new KoColorBackground(d->colorAction->currentColor());
QList<KoShape*> selectedShapes = selection->selectedShapes();
if (selectedShapes.isEmpty()) {
......@@ -356,7 +356,7 @@ void KoFillConfigWidget::colorChanged()
canvasController->canvas()->addCommand(firstCommand);
}
void KoFillConfigWidget::gradientChanged(KoShapeBackground* background)
void KoFillConfigWidget::gradientChanged(QPointer<KoShapeBackground> background)
{
KoCanvasController *canvasController = KoToolManager::instance()->activeCanvasController();
KoSelection *selection = canvasController->canvas()->shapeManager()->selection();
......@@ -370,7 +370,7 @@ void KoFillConfigWidget::gradientChanged(KoShapeBackground* background)
return;
}
KoGradientBackground *gradientBackground = dynamic_cast<KoGradientBackground*>(background);
QPointer<KoGradientBackground> gradientBackground = dynamic_cast<KoGradientBackground*>(background.data());
if (! gradientBackground) {
return;
}
......@@ -380,7 +380,7 @@ void KoFillConfigWidget::gradientChanged(KoShapeBackground* background)
KUndo2Command *firstCommand = 0;
foreach (KoShape *shape, selectedShapes) {
KoShapeBackground *fill = applyFillGradientStops(shape, newStops);
QPointer<KoShapeBackground> fill = applyFillGradientStops(shape, newStops);
if (! fill) {
continue;
}
......@@ -393,7 +393,7 @@ void KoFillConfigWidget::gradientChanged(KoShapeBackground* background)
canvasController->canvas()->addCommand(firstCommand);
}
void KoFillConfigWidget::patternChanged(KoShapeBackground* background)
void KoFillConfigWidget::patternChanged(QPointer<KoShapeBackground> background)
{
KoCanvasController *canvasController = KoToolManager::instance()->activeCanvasController();
KoSelection *selection = canvasController->canvas()->shapeManager()->selection();
......@@ -402,7 +402,7 @@ void KoFillConfigWidget::patternChanged(KoShapeBackground* background)
return;
}
KoPatternBackground *patternBackground = dynamic_cast<KoPatternBackground*>(background);
QPointer<KoPatternBackground> patternBackground = dynamic_cast<KoPatternBackground*>(background.data());
if (! patternBackground) {
return;
}
......@@ -414,9 +414,9 @@ void KoFillConfigWidget::patternChanged(KoShapeBackground* background)
KoImageCollection *imageCollection = canvasController->canvas()->shapeController()->resourceManager()->imageCollection();
if (imageCollection) {
KoPatternBackground *fill = new KoPatternBackground(imageCollection);
QPointer<KoPatternBackground> fill = new KoPatternBackground(imageCollection);
fill->setPattern(patternBackground->pattern());
canvasController->canvas()->addCommand(new KoShapeBackgroundCommand(selectedShapes, fill));
canvasController->canvas()->addCommand(new KoShapeBackgroundCommand(selectedShapes, fill.data()));
}
}
......@@ -454,7 +454,7 @@ void KoFillConfigWidget::updateWidget(KoShape *shape)
shape->waitUntilReady(zoomHandler, false);
d->colorButton->setEnabled(true);
KoShapeBackground *background = shape->background();
QPointer<KoShapeBackground> background = shape->background();
if (! background) {
// No Fill
d->group->button(KoFillConfigWidget::None)->setChecked(true);
......@@ -464,9 +464,9 @@ void KoFillConfigWidget::updateWidget(KoShape *shape)
return;
}
KoColorBackground *colorBackground = dynamic_cast<KoColorBackground*>(background);
KoGradientBackground *gradientBackground = dynamic_cast<KoGradientBackground*>(background);
KoPatternBackground *patternBackground = dynamic_cast<KoPatternBackground*>(background);