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

Make KoShapeBackground implicitly sharable

parent 38713473
......@@ -20,6 +20,7 @@
#include "KoColorBackground.h"
#include "KoColorBackground_p.h"
#include "KoShapeSavingContext.h"
#include "KisSharedDescendent.h"
#include <KoOdfGraphicStyles.h>
#include <KoOdfLoadingContext.h>
#include <KoXmlNS.h>
......@@ -29,17 +30,17 @@
#include <QPainter>
KoColorBackground::KoColorBackground()
: KoShapeBackground(*(new KoColorBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoColorBackgroundPrivate()))
{
}
KoColorBackground::KoColorBackground(KoShapeBackgroundPrivate &dd)
: KoShapeBackground(dd)
KoColorBackground::KoColorBackground(KisSharedDescendent<KoShapeBackgroundPrivate> &dd)
: KoShapeBackground(dd)
{
}
KoColorBackground::KoColorBackground(const QColor &color, Qt::BrushStyle style)
: KoShapeBackground(*(new KoColorBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoColorBackgroundPrivate()))
{
SHARED_D(KoColorBackground);
if (style < Qt::SolidPattern || style >= Qt::LinearGradientPattern)
......
......@@ -59,10 +59,9 @@ public:
// reimplemented from KoShapeBackground
bool loadStyle(KoOdfLoadingContext & context, const QSizeF &shapeSize) override;
protected:
KoColorBackground(KoShapeBackgroundPrivate &dd);
KoColorBackground(KisSharedDescendent<KoShapeBackgroundPrivate> &dd);
private:
// Q_DECLARE_PRIVATE(KoColorBackground)
// Q_DISABLE_COPY(KoColorBackground)
SHARED_DECLARE_PRIVATE(KoColorBackground)
};
#endif // KOCOLORBACKGROUND_H
......@@ -44,7 +44,7 @@ public:
};
KoGradientBackground::KoGradientBackground(QGradient * gradient, const QTransform &matrix)
: KoShapeBackground(*(new KoGradientBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoGradientBackgroundPrivate()))
{
SHARED_D(KoGradientBackground);
d->gradient = gradient;
......@@ -53,7 +53,7 @@ KoGradientBackground::KoGradientBackground(QGradient * gradient, const QTransfor
}
KoGradientBackground::KoGradientBackground(const QGradient & gradient, const QTransform &matrix)
: KoShapeBackground(*(new KoGradientBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoGradientBackgroundPrivate()))
{
SHARED_D(KoGradientBackground);
d->gradient = KoFlake::cloneGradient(&gradient);
......
......@@ -70,10 +70,8 @@ public:
void fillStyle(KoGenStyle &style, KoShapeSavingContext &context) override;
/// reimplemented from KoShapeBackground
bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) override;
private:
// Q_DECLARE_PRIVATE(KoGradientBackground)
// Q_DISABLE_COPY(KoGradientBackground)
SHARED_DECLARE_PRIVATE(KoGradientBackground)
};
#endif // KOGRADIENTBACKGROUND_H
......@@ -54,13 +54,13 @@ public:
};
KoHatchBackground::KoHatchBackground()
: KoColorBackground(*(new KoHatchBackgroundPrivate()))
: KoColorBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoHatchBackgroundPrivate()))
{
}
void KoHatchBackground::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &context, const QPainterPath &fillPath) const
{
Q_D(const KoHatchBackground);
CONST_SHARED_D(KoHatchBackground);
if (d->color.isValid()) {
// paint background color if set by using the color background
KoColorBackground::paint(painter, converter, context, fillPath);
......@@ -127,7 +127,7 @@ void KoHatchBackground::paint(QPainter &painter, const KoViewConverter &converte
void KoHatchBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &context)
{
Q_D(KoHatchBackground);
SHARED_D(KoHatchBackground);
KoGenStyle::Type type = style.type();
KoGenStyle::PropertyType propertyType = (type == KoGenStyle::GraphicStyle || type == KoGenStyle::GraphicAutoStyle ||
......@@ -145,7 +145,7 @@ void KoHatchBackground::fillStyle(KoGenStyle &style, KoShapeSavingContext &conte
QString KoHatchBackground::saveHatchStyle(KoShapeSavingContext &context) const
{
Q_D(const KoHatchBackground);
CONST_SHARED_D(KoHatchBackground);
KoGenStyle hatchStyle(KoGenStyle::HatchStyle /*no family name*/);
hatchStyle.addAttribute("draw:display-name", d->name);
hatchStyle.addAttribute("draw:color", d->lineColor.name());
......@@ -172,7 +172,7 @@ QString KoHatchBackground::saveHatchStyle(KoShapeSavingContext &context) const
bool KoHatchBackground::loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize)
{
// <draw:hatch draw:name="hatchStyle3" draw:color="#000000" draw:display-name="#000000 Vertical" draw:distance="0.102cm" draw:rotation="900" draw:style="single"/>
Q_D(KoHatchBackground);
SHARED_D(KoHatchBackground);
Q_UNUSED(shapeSize);
KoStyleStack &styleStack = context.styleStack();
......
......@@ -51,8 +51,8 @@ public:
private:
QString saveHatchStyle(KoShapeSavingContext &context) const;
Q_DECLARE_PRIVATE(KoHatchBackground)
Q_DISABLE_COPY(KoHatchBackground)
private:
SHARED_DECLARE_PRIVATE(KoHatchBackground)
};
#endif /* KOHATCHBACKGROUND_H */
......@@ -65,7 +65,7 @@ public:
KoOdfGradientBackground::KoOdfGradientBackground()
: KoShapeBackground(*(new KoOdfGradientBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoOdfGradientBackgroundPrivate()))
{
}
......
......@@ -57,10 +57,8 @@ private:
private:
void debug() const;
private:
// Q_DECLARE_PRIVATE(KoOdfGradientBackground)
Q_DISABLE_COPY(KoOdfGradientBackground)
SHARED_DECLARE_PRIVATE(KoOdfGradientBackground)
};
#endif
......@@ -133,7 +133,7 @@ public:
KoPatternBackground::KoPatternBackground(KoImageCollection *imageCollection)
: KoShapeBackground(*(new KoPatternBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoPatternBackgroundPrivate()))
{
SHARED_D(KoPatternBackground);
d->imageCollection = imageCollection;
......
......@@ -121,8 +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_DISABLE_COPY(KoPatternBackground)
SHARED_DECLARE_PRIVATE(KoPatternBackground)
};
#endif // KOPATTERNBACKGROUND_H
......@@ -29,21 +29,20 @@ KoShapeBackgroundPrivate::~KoShapeBackgroundPrivate()
{
}
KoShapeBackground::KoShapeBackground(KoShapeBackgroundPrivate &dd)
:d_ptr(&dd)
KoShapeBackground::KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate> &dd)
: d_ptr(&dd)
{
}
KoShapeBackground::KoShapeBackground()
: d_ptr(new KoShapeBackgroundPrivate())
: d_ptr(KisSharedDescendent<KoShapeBackgroundPrivate>::pointerOf(KoShapeBackgroundPrivate()))
{
}
KoShapeBackground::~KoShapeBackground()
{
delete d_ptr;
}
bool KoShapeBackground::hasTransparency() const
......
......@@ -25,6 +25,8 @@
#include <QtGlobal>
#include <QSharedDataPointer>
#include <KisSharedDescendent.h>
class QSizeF;
class QPainter;
class QPainterPath;
......@@ -35,9 +37,6 @@ 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
......@@ -70,12 +69,10 @@ public:
virtual explicit operator bool() const { return true; }
protected:
KoShapeBackground(KoShapeBackgroundPrivate &);
QSharedDataPointer<KoShapeBackgroundPrivate> d_ptr;
KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate> &);
QSharedDataPointer<KisSharedDescendent<KoShapeBackgroundPrivate> > d_ptr;
private:
// Q_DECLARE_PRIVATE(KoShapeBackground)
SHARED_DECLARE_PRIVATE(KoShapeBackground)
};
#endif // KOSHAPEBACKGROUND_H
......@@ -20,9 +20,7 @@
#ifndef KoShapeBackgroundPrivate_H
#define KoShapeBackgroundPrivate_H
#include <QSharedData>
class KoShapeBackgroundPrivate : public QSharedData
class KoShapeBackgroundPrivate
{
public:
KoShapeBackgroundPrivate();
......
......@@ -48,7 +48,7 @@ public:
};
KoVectorPatternBackground::KoVectorPatternBackground()
: KoShapeBackground(*(new KoVectorPatternBackgroundPrivate()))
: KoShapeBackground(KisSharedDescendent<KoShapeBackgroundPrivate>::of(KoVectorPatternBackgroundPrivate()))
{
}
......
......@@ -59,10 +59,8 @@ public:
bool hasTransparency() const override;
void fillStyle(KoGenStyle &style, KoShapeSavingContext &context) override;
bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) override;
private:
// Q_DECLARE_PRIVATE(KoVectorPatternBackground)
Q_DISABLE_COPY(KoVectorPatternBackground)
SHARED_DECLARE_PRIVATE(KoVectorPatternBackground)
};
#endif // KOVECTORPATTERNBACKGROUND_H
......@@ -46,8 +46,12 @@
* Replace all `Q_D()` macros that get const d-pointers with `CONST_SHARED_D(YourClass)`.
*/
#define CONST_SHARED_D(Class) const Class##Private *const d = reinterpret_cast<const Class##Private *>(d_ptr.constData()->constData())
#define SHARED_D(Class) Class##Private *const d = reinterpret_cast<Class##Private *>(d_ptr.data()->data())
#define SHARED_DECLARE_PRIVATE(Class) \
inline const Class##Private *d_func() const { return reinterpret_cast<const Class##Private *>(d_ptr.constData()->constData()); } \
inline Class##Private *d_func() { return reinterpret_cast<Class##Private *>(d_ptr.data()->data()); } \
inline const Class##Private *const_d_func() const { return d_func(); }
#define CONST_SHARED_D(Class) const Class##Private *const d = const_d_func()
#define SHARED_D(Class) Class##Private *const d = d_func()
template<typename T>
class KisSharedDescendent : public KisDescendent<T>, public QSharedData
......
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