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 e41d6a96 authored by Tusooa Zhu's avatar Tusooa Zhu 🔼

Use implicitly-shared d-pointers for KoShapeBackground heirarchy

parent b30b3b89
......@@ -41,7 +41,7 @@ KoColorBackground::KoColorBackground(KoShapeBackgroundPrivate &dd)
KoColorBackground::KoColorBackground(const QColor &color, Qt::BrushStyle style)
: KoShapeBackground(*(new KoColorBackgroundPrivate()))
{
Q_D(KoColorBackground);
SHARED_D(KoColorBackground);
if (style < Qt::SolidPattern || style >= Qt::LinearGradientPattern)
style = Qt::SolidPattern;
d->style = style;
......@@ -54,7 +54,7 @@ KoColorBackground::~KoColorBackground()
bool KoColorBackground::compareTo(const KoShapeBackground *other) const
{
Q_D(const KoColorBackground);
CONST_SHARED_D(KoColorBackground);
const KoColorBackground *bg = dynamic_cast<const KoColorBackground*>(other);
return bg && bg->color() == d->color;
......@@ -62,25 +62,25 @@ bool KoColorBackground::compareTo(const KoShapeBackground *other) const
QColor KoColorBackground::color() const
{
Q_D(const KoColorBackground);
CONST_SHARED_D(KoColorBackground);
return d->color;
}
void KoColorBackground::setColor(const QColor &color)
{
Q_D(KoColorBackground);
SHARED_D(KoColorBackground);
d->color = color;
}
Qt::BrushStyle KoColorBackground::style() const
{
Q_D(const KoColorBackground);
CONST_SHARED_D(KoColorBackground);
return d->style;
}
QBrush KoColorBackground::brush() const
{
Q_D(const KoColorBackground);
CONST_SHARED_D(KoColorBackground);
return QBrush(d->color, d->style);
}
......@@ -92,13 +92,13 @@ void KoColorBackground::paint(QPainter &painter, const KoViewConverter &/*conver
void KoColorBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
{
Q_D(KoColorBackground);
SHARED_D(KoColorBackground);
KoOdfGraphicStyles::saveOdfFillStyle(style, context.mainStyles(), QBrush(d->color, d->style));
}
bool KoColorBackground::loadStyle(KoOdfLoadingContext & context, const QSizeF &)
{
Q_D(KoColorBackground);
SHARED_D(KoColorBackground);
KoStyleStack &styleStack = context.styleStack();
if (! styleStack.hasProperty(KoXmlNS::draw, "fill"))
return false;
......
......@@ -61,8 +61,8 @@ public:
protected:
KoColorBackground(KoShapeBackgroundPrivate &dd);
private:
Q_DECLARE_PRIVATE(KoColorBackground)
Q_DISABLE_COPY(KoColorBackground)
// Q_DECLARE_PRIVATE(KoColorBackground)
// Q_DISABLE_COPY(KoColorBackground)
};
#endif // KOCOLORBACKGROUND_H
......@@ -46,7 +46,7 @@ public:
KoGradientBackground::KoGradientBackground(QGradient * gradient, const QTransform &matrix)
: KoShapeBackground(*(new KoGradientBackgroundPrivate()))
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
d->gradient = gradient;
d->matrix = matrix;
Q_ASSERT(d->gradient);
......@@ -55,7 +55,7 @@ KoGradientBackground::KoGradientBackground(QGradient * gradient, const QTransfor
KoGradientBackground::KoGradientBackground(const QGradient & gradient, const QTransform &matrix)
: KoShapeBackground(*(new KoGradientBackgroundPrivate()))
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
d->gradient = KoFlake::cloneGradient(&gradient);
d->matrix = matrix;
Q_ASSERT(d->gradient);
......@@ -63,13 +63,13 @@ KoGradientBackground::KoGradientBackground(const QGradient & gradient, const QTr
KoGradientBackground::~KoGradientBackground()
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
delete d->gradient;
}
bool KoGradientBackground::compareTo(const KoShapeBackground *other) const
{
Q_D(const KoGradientBackground);
CONST_SHARED_D(KoGradientBackground);
const KoGradientBackground *otherGradient = dynamic_cast<const KoGradientBackground*>(other);
return otherGradient &&
......@@ -79,19 +79,19 @@ bool KoGradientBackground::compareTo(const KoShapeBackground *other) const
void KoGradientBackground::setTransform(const QTransform &matrix)
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
d->matrix = matrix;
}
QTransform KoGradientBackground::transform() const
{
Q_D(const KoGradientBackground);
CONST_SHARED_D(KoGradientBackground);
return d->matrix;
}
void KoGradientBackground::setGradient(const QGradient &gradient)
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
delete d->gradient;
d->gradient = KoFlake::cloneGradient(&gradient);
......@@ -100,13 +100,13 @@ void KoGradientBackground::setGradient(const QGradient &gradient)
const QGradient * KoGradientBackground::gradient() const
{
Q_D(const KoGradientBackground);
CONST_SHARED_D(KoGradientBackground);
return d->gradient;
}
void KoGradientBackground::paint(QPainter &painter, const KoViewConverter &/*converter*/, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
{
Q_D(const KoGradientBackground);
CONST_SHARED_D(KoGradientBackground);
if (!d->gradient) return;
if (d->gradient->coordinateMode() == QGradient::ObjectBoundingMode) {
......@@ -147,7 +147,7 @@ void KoGradientBackground::paint(QPainter &painter, const KoViewConverter &/*con
void KoGradientBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
if (!d->gradient) return;
QBrush brush(*d->gradient);
brush.setTransform(d->matrix);
......@@ -156,7 +156,7 @@ void KoGradientBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &co
bool KoGradientBackground::loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize)
{
Q_D(KoGradientBackground);
SHARED_D(KoGradientBackground);
KoStyleStack &styleStack = context.styleStack();
if (! styleStack.hasProperty(KoXmlNS::draw, "fill"))
return false;
......
......@@ -72,8 +72,8 @@ public:
bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) override;
private:
Q_DECLARE_PRIVATE(KoGradientBackground)
Q_DISABLE_COPY(KoGradientBackground)
// Q_DECLARE_PRIVATE(KoGradientBackground)
// Q_DISABLE_COPY(KoGradientBackground)
};
#endif // KOGRADIENTBACKGROUND_H
......@@ -84,7 +84,7 @@ bool KoOdfGradientBackground::compareTo(const KoShapeBackground *other) const
bool KoOdfGradientBackground::loadOdf(const KoXmlElement& e)
{
Q_D(KoOdfGradientBackground);
SHARED_D(KoOdfGradientBackground);
d->style = e.attributeNS(KoXmlNS::draw, "style", QString());
//TODO: support ellipsoid here too
if ((d->style != "rectangular") && (d->style != "square")) {
......@@ -109,7 +109,7 @@ bool KoOdfGradientBackground::loadOdf(const KoXmlElement& e)
void KoOdfGradientBackground::saveOdf(KoGenStyle& styleFill, KoGenStyles& mainStyles) const
{
Q_D(const KoOdfGradientBackground);
CONST_SHARED_D(KoOdfGradientBackground);
KoGenStyle::Type type = styleFill.type();
KoGenStyle::PropertyType propertyType = (type == KoGenStyle::GraphicStyle || type == KoGenStyle::GraphicAutoStyle ||
......@@ -139,7 +139,7 @@ void KoOdfGradientBackground::saveOdf(KoGenStyle& styleFill, KoGenStyles& mainSt
void KoOdfGradientBackground::paint(QPainter& painter, const KoViewConverter &/*converter*/, KoShapePaintingContext &/*context*/, const QPainterPath& fillPath) const
{
Q_D(const KoOdfGradientBackground);
CONST_SHARED_D(KoOdfGradientBackground);
QImage buffer;
......@@ -169,7 +169,7 @@ void KoOdfGradientBackground::fillStyle(KoGenStyle& style, KoShapeSavingContext&
bool KoOdfGradientBackground::loadStyle(KoOdfLoadingContext& context, const QSizeF& shapeSize)
{
Q_UNUSED(shapeSize);
Q_D(KoOdfGradientBackground);
SHARED_D(KoOdfGradientBackground);
KoStyleStack &styleStack = context.styleStack();
if (!styleStack.hasProperty(KoXmlNS::draw, "fill")) {
......@@ -197,7 +197,7 @@ bool KoOdfGradientBackground::loadStyle(KoOdfLoadingContext& context, const QSiz
void KoOdfGradientBackground::renderSquareGradient(QImage& buffer) const
{
Q_D(const KoOdfGradientBackground);
CONST_SHARED_D(KoOdfGradientBackground);
buffer.fill(d->startColor.rgba());
QPainter painter(&buffer);
......@@ -261,7 +261,7 @@ void KoOdfGradientBackground::renderSquareGradient(QImage& buffer) const
void KoOdfGradientBackground::renderRectangleGradient(QImage& buffer) const
{
Q_D(const KoOdfGradientBackground);
CONST_SHARED_D(KoOdfGradientBackground);
buffer.fill(d->startColor.rgba());
QPainter painter(&buffer);
......@@ -377,7 +377,7 @@ void KoOdfGradientBackground::renderRectangleGradient(QImage& buffer) const
void KoOdfGradientBackground::debug() const
{
Q_D(const KoOdfGradientBackground);
CONST_SHARED_D(KoOdfGradientBackground);
debugFlake << "cx,cy: "<< d->cx << d->cy;
debugFlake << "style" << d->style;
debugFlake << "colors" << d->startColor << d->endColor;
......
......@@ -59,7 +59,7 @@ private:
void debug() const;
private:
Q_DECLARE_PRIVATE(KoOdfGradientBackground)
// Q_DECLARE_PRIVATE(KoOdfGradientBackground)
Q_DISABLE_COPY(KoOdfGradientBackground)
};
......
......@@ -135,7 +135,7 @@ public:
KoPatternBackground::KoPatternBackground(KoImageCollection *imageCollection)
: KoShapeBackground(*(new KoPatternBackgroundPrivate()))
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
d->imageCollection = imageCollection;
Q_ASSERT(d->imageCollection);
}
......@@ -152,19 +152,19 @@ bool KoPatternBackground::compareTo(const KoShapeBackground *other) const
void KoPatternBackground::setTransform(const QTransform &matrix)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
d->matrix = matrix;
}
QTransform KoPatternBackground::transform() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->matrix;
}
void KoPatternBackground::setPattern(const QImage &pattern)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
delete d->imageData;
if (d->imageCollection) {
d->imageData = d->imageCollection->createImageData(pattern);
......@@ -173,7 +173,7 @@ void KoPatternBackground::setPattern(const QImage &pattern)
void KoPatternBackground::setPattern(KoImageData *imageData)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
delete d->imageData;
d->imageData = imageData;
......@@ -181,7 +181,7 @@ void KoPatternBackground::setPattern(KoImageData *imageData)
QImage KoPatternBackground::pattern() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
if (d->imageData)
return d->imageData->image();
return QImage();
......@@ -189,37 +189,37 @@ QImage KoPatternBackground::pattern() const
void KoPatternBackground::setRepeat(PatternRepeat repeat)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
d->repeat = repeat;
}
KoPatternBackground::PatternRepeat KoPatternBackground::repeat() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->repeat;
}
KoPatternBackground::ReferencePoint KoPatternBackground::referencePoint() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->refPoint;
}
void KoPatternBackground::setReferencePoint(ReferencePoint referencePoint)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
d->refPoint = referencePoint;
}
QPointF KoPatternBackground::referencePointOffset() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->refPointOffsetPercent;
}
void KoPatternBackground::setReferencePointOffset(const QPointF &offset)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
qreal ox = qMax(qreal(0.0), qMin(qreal(100.0), offset.x()));
qreal oy = qMax(qreal(0.0), qMin(qreal(100.0), offset.y()));
......@@ -228,38 +228,38 @@ void KoPatternBackground::setReferencePointOffset(const QPointF &offset)
QPointF KoPatternBackground::tileRepeatOffset() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->tileRepeatOffsetPercent;
}
void KoPatternBackground::setTileRepeatOffset(const QPointF &offset)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
d->tileRepeatOffsetPercent = offset;
}
QSizeF KoPatternBackground::patternDisplaySize() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->targetSize();
}
void KoPatternBackground::setPatternDisplaySize(const QSizeF &size)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
d->targetImageSizePercent = QSizeF();
d->targetImageSize = size;
}
QSizeF KoPatternBackground::patternOriginalSize() const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
return d->imageData->imageSize();
}
void KoPatternBackground::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
{
Q_D(const KoPatternBackground);
CONST_SHARED_D(KoPatternBackground);
if (! d->imageData)
return;
......@@ -311,7 +311,7 @@ void KoPatternBackground::paint(QPainter &painter, const KoViewConverter &conver
void KoPatternBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
if (! d->imageData)
return;
......@@ -373,7 +373,7 @@ void KoPatternBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &con
bool KoPatternBackground::loadStyle(KoOdfLoadingContext &context, const QSizeF &)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
KoStyleStack &styleStack = context.styleStack();
if (! styleStack.hasProperty(KoXmlNS::draw, "fill"))
return false;
......@@ -477,7 +477,7 @@ bool KoPatternBackground::loadStyle(KoOdfLoadingContext &context, const QSizeF &
QRectF KoPatternBackground::patternRectFromFillSize(const QSizeF &size)
{
Q_D(KoPatternBackground);
SHARED_D(KoPatternBackground);
QRectF rect;
switch (d->repeat) {
......
......@@ -121,7 +121,7 @@ public:
/// Returns the bounding rect of the pattern image based on the given fill size
QRectF patternRectFromFillSize(const QSizeF &size);
private:
Q_DECLARE_PRIVATE(KoPatternBackground)
// Q_DECLARE_PRIVATE(KoPatternBackground)
Q_DISABLE_COPY(KoPatternBackground)
};
......
......@@ -23,6 +23,7 @@
#include "kritaflake_export.h"
#include <QtGlobal>
#include <QSharedDataPointer>
class QSizeF;
class QPainter;
......@@ -34,6 +35,9 @@ class KoShapeBackgroundPrivate;
class KoShapePaintingContext;
class KoViewConverter;
#define CONST_SHARED_D(Class) const Class##Private *d = dynamic_cast<const Class##Private *>(d_ptr.constData())
#define SHARED_D(Class) Class##Private *d = dynamic_cast<Class##Private *>(d_ptr.data())
/**
* This is the base class for shape backgrounds.
* Derived classes are used to paint the background of
......@@ -63,11 +67,13 @@ public:
/// load background from odf styles
virtual bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) = 0;
virtual explicit operator bool() const { return true; }
protected:
KoShapeBackground(KoShapeBackgroundPrivate &);
KoShapeBackgroundPrivate *d_ptr;
QSharedDataPointer<KoShapeBackgroundPrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(KoShapeBackground)
// Q_DECLARE_PRIVATE(KoShapeBackground)
};
......
......@@ -20,7 +20,9 @@
#ifndef KoShapeBackgroundPrivate_H
#define KoShapeBackgroundPrivate_H
class KoShapeBackgroundPrivate
#include <QSharedData>
class KoShapeBackgroundPrivate : public QSharedData
{
public:
KoShapeBackgroundPrivate();
......
......@@ -65,55 +65,55 @@ bool KoVectorPatternBackground::compareTo(const KoShapeBackground *other) const
void KoVectorPatternBackground::setReferenceCoordinates(KoFlake::CoordinateSystem value)
{
Q_D(KoVectorPatternBackground);
SHARED_D(KoVectorPatternBackground);
d->referenceCoordinates = value;
}
KoFlake::CoordinateSystem KoVectorPatternBackground::referenceCoordinates() const
{
Q_D(const KoVectorPatternBackground);
CONST_SHARED_D(KoVectorPatternBackground);
return d->referenceCoordinates;
}
void KoVectorPatternBackground::setContentCoordinates(KoFlake::CoordinateSystem value)
{
Q_D(KoVectorPatternBackground);
SHARED_D(KoVectorPatternBackground);
d->contentCoordinates = value;
}
KoFlake::CoordinateSystem KoVectorPatternBackground::contentCoordinates() const
{
Q_D(const KoVectorPatternBackground);
CONST_SHARED_D(KoVectorPatternBackground);
return d->contentCoordinates;
}
void KoVectorPatternBackground::setReferenceRect(const QRectF &value)
{
Q_D(KoVectorPatternBackground);
SHARED_D(KoVectorPatternBackground);
d->referenceRect = value;
}
QRectF KoVectorPatternBackground::referenceRect() const
{
Q_D(const KoVectorPatternBackground);
CONST_SHARED_D(KoVectorPatternBackground);
return d->referenceRect;
}
void KoVectorPatternBackground::setPatternTransform(const QTransform &value)
{
Q_D(KoVectorPatternBackground);
SHARED_D(KoVectorPatternBackground);
d->patternTransform = value;
}
QTransform KoVectorPatternBackground::patternTransform() const
{
Q_D(const KoVectorPatternBackground);
CONST_SHARED_D(KoVectorPatternBackground);
return d->patternTransform;
}
void KoVectorPatternBackground::setShapes(const QList<KoShape*> value)
{
Q_D(KoVectorPatternBackground);
SHARED_D(KoVectorPatternBackground);
qDeleteAll(d->shapes);
d->shapes.clear();
......@@ -122,7 +122,7 @@ void KoVectorPatternBackground::setShapes(const QList<KoShape*> value)
QList<KoShape *> KoVectorPatternBackground::shapes() const
{
Q_D(const KoVectorPatternBackground);
CONST_SHARED_D(KoVectorPatternBackground);
return d->shapes;
}
......@@ -131,7 +131,7 @@ void KoVectorPatternBackground::paint(QPainter &painter, const KoViewConverter &
Q_UNUSED(context_Unused);
Q_UNUSED(converter_Unused);
Q_D(const KoVectorPatternBackground);
CONST_SHARED_D(KoVectorPatternBackground);
const QPainterPath dstShapeOutline = fillPath;
const QRectF dstShapeBoundingBox = dstShapeOutline.boundingRect();
......
......@@ -61,7 +61,7 @@ public:
bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) override;
private:
Q_DECLARE_PRIVATE(KoVectorPatternBackground)
// Q_DECLARE_PRIVATE(KoVectorPatternBackground)
Q_DISABLE_COPY(KoVectorPatternBackground)
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment