Commit 04897836 authored by Tusooa Zhu's avatar Tusooa Zhu

Refactor out q-pointers and derived d-pointers in Flake

parent ef8ee1b4
This diff is collapsed.
......@@ -137,9 +137,15 @@ protected:
/// reimplemented
void shapeChanged(ChangeType type, KoShape *shape) override;
private:
QPointF escapeDirection(int handleId) const;
/// Populate the path list by a normal way
void normalPath(const qreal MinimumEscapeLength);
private:
Q_DECLARE_PRIVATE(KoConnectionShape)
class Private;
QSharedDataPointer<Private> d;
};
#endif
......@@ -19,16 +19,14 @@
#ifndef KOCONNECTIONSHAPEPRIVATE_P
#define KOCONNECTIONSHAPEPRIVATE_P
#include "KoParameterShape_p.h"
#include <QSharedData>
#include "KoConnectionShape.h"
class KoConnectionShapePrivate : public KoParameterShapePrivate
class KoConnectionShape::Private : public QSharedData
{
public:
explicit KoConnectionShapePrivate(KoConnectionShape *q);
explicit KoConnectionShapePrivate(const KoConnectionShapePrivate &rhs, KoConnectionShape *q);
/// Returns escape direction of given handle
QPointF escapeDirection(int handleId) const;
explicit Private();
explicit Private(const Private &rhs);
/// Checks if rays from given points into given directions intersect
bool intersects(const QPointF &p1, const QPointF &d1, const QPointF &p2, const QPointF &d2, QPointF &isect);
......@@ -36,9 +34,6 @@ public:
/// Returns perpendicular direction from given point p1 and direction d1 toward point p2
QPointF perpendicularDirection(const QPointF &p1, const QPointF &d1, const QPointF &p2);
/// Populate the path list by a normal way
void normalPath(const qreal MinimumEscapeLength);
qreal scalarProd(const QPointF &v1, const QPointF &v2) const;
qreal crossProd(const QPointF &v1, const QPointF &v2) const;
......@@ -54,7 +49,6 @@ public:
KoConnectionShape::Type connectionType;
bool forceUpdate;
bool hasCustomPath;
Q_DECLARE_PUBLIC(KoConnectionShape)
};
#endif
......@@ -26,26 +26,28 @@
#include <QPainter>
#include <FlakeDebug.h>
KoParameterShapePrivate::KoParameterShapePrivate(KoParameterShape *shape)
: KoPathShapePrivate(shape)
KoParameterShape::Private::Private()
: QSharedData()
, parametric(true)
{
}
KoParameterShapePrivate::KoParameterShapePrivate(const KoParameterShapePrivate &rhs, KoParameterShape *q)
: KoPathShapePrivate(rhs, q)
KoParameterShape::Private::Private(const Private &rhs)
: QSharedData()
, parametric(rhs.parametric)
, handles(rhs.handles)
{
}
KoParameterShape::KoParameterShape()
: KoPathShape(new KoParameterShapePrivate(this))
: KoPathShape()
, d(new Private)
{
}
KoParameterShape::KoParameterShape(KoParameterShapePrivate *dd)
: KoPathShape(dd)
KoParameterShape::KoParameterShape(const KoParameterShape &rhs)
: KoPathShape(rhs)
, d(rhs.d)
{
}
......@@ -55,7 +57,7 @@ KoParameterShape::~KoParameterShape()
void KoParameterShape::moveHandle(int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers)
{
Q_D(KoParameterShape);
if (handleId >= d->handles.size()) {
warnFlake << "handleId out of bounds";
return;
......@@ -72,7 +74,7 @@ void KoParameterShape::moveHandle(int handleId, const QPointF & point, Qt::Keybo
int KoParameterShape::handleIdAt(const QRectF & rect) const
{
Q_D(const KoParameterShape);
int handle = -1;
for (int i = 0; i < d->handles.size(); ++i) {
......@@ -86,13 +88,13 @@ int KoParameterShape::handleIdAt(const QRectF & rect) const
QPointF KoParameterShape::handlePosition(int handleId) const
{
Q_D(const KoParameterShape);
return d->handles.value(handleId);
}
void KoParameterShape::paintHandles(KisHandlePainterHelper &handlesHelper)
{
Q_D(KoParameterShape);
QList<QPointF>::const_iterator it(d->handles.constBegin());
for (; it != d->handles.constEnd(); ++it) {
......@@ -102,13 +104,13 @@ void KoParameterShape::paintHandles(KisHandlePainterHelper &handlesHelper)
void KoParameterShape::paintHandle(KisHandlePainterHelper &handlesHelper, int handleId)
{
Q_D(KoParameterShape);
handlesHelper.drawGradientHandle(d->handles[handleId]);
}
void KoParameterShape::setSize(const QSizeF &newSize)
{
Q_D(KoParameterShape);
QTransform matrix(resizeMatrix(newSize));
for (int i = 0; i < d->handles.size(); ++i) {
......@@ -120,7 +122,7 @@ void KoParameterShape::setSize(const QSizeF &newSize)
QPointF KoParameterShape::normalize()
{
Q_D(KoParameterShape);
QPointF offset(KoPathShape::normalize());
QTransform matrix;
matrix.translate(-offset.x(), -offset.y());
......@@ -134,33 +136,33 @@ QPointF KoParameterShape::normalize()
bool KoParameterShape::isParametricShape() const
{
Q_D(const KoParameterShape);
return d->parametric;
}
void KoParameterShape::setParametricShape(bool parametric)
{
Q_D(KoParameterShape);
d->parametric = parametric;
update();
}
QList<QPointF> KoParameterShape::handles() const
{
Q_D(const KoParameterShape);
return d->handles;
}
void KoParameterShape::setHandles(const QList<QPointF> &handles)
{
Q_D(KoParameterShape);
d->handles = handles;
d->shapeChanged(ParameterChanged);
shapeChangedPriv(ParameterChanged);
}
int KoParameterShape::handleCount() const
{
Q_D(const KoParameterShape);
return d->handles.count();
}
......@@ -135,7 +135,7 @@ protected:
void setHandles(const QList<QPointF> &handles);
/// constructor
KoParameterShape(KoParameterShapePrivate *);
KoParameterShape(const KoParameterShape &rhs);
/**
* @brief Updates the internal state of a KoParameterShape.
......@@ -155,8 +155,9 @@ protected:
*/
virtual void updatePath(const QSizeF &size) = 0;
protected:
Q_DECLARE_PRIVATE(KoParameterShape)
private:
class Private;
QSharedDataPointer<Private> d;
};
#endif /* KOPARAMETERSHAPE_H */
......@@ -23,18 +23,19 @@
#include "kritaflake_export.h"
#include <KoParameterShape.h>
#include "KoPathShape_p.h"
#include <QList>
#include <QPointF>
#include <QSharedData>
class KoParameterShape;
class KRITAFLAKE_EXPORT KoParameterShapePrivate : public KoPathShapePrivate
class KRITAFLAKE_EXPORT KoParameterShape::Private : public QSharedData
{
public:
explicit KoParameterShapePrivate(KoParameterShape *shape);
explicit KoParameterShapePrivate(const KoParameterShapePrivate &rhs, KoParameterShape *q);
explicit Private();
explicit Private(const KoParameterShape::Private &rhs);
virtual ~Private() = default;
bool parametric;
......
This diff is collapsed.
......@@ -475,16 +475,13 @@ public:
protected:
void notifyPointsChanged();
private:
protected:
/// constructor: to be used in cloneShape(), not in descendants!
/// \internal
/// XXX private?
KoPathShape(const KoPathShape &rhs);
protected:
/// constructor:to be used in descendant shapes
/// \internal
KoPathShape(KoPathShapePrivate *);
/// reimplemented
QString saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const override;
/// reimplemented
......@@ -515,7 +512,21 @@ protected:
QTransform resizeMatrix( const QSizeF &newSize ) const;
private:
Q_DECLARE_PRIVATE(KoPathShape)
/// close-merges specified subpath
void closeMergeSubpathPriv(KoSubpath *subpath);
/// closes specified subpath
void closeSubpathPriv(KoSubpath *subpath);
void updateLastPriv(KoPathPoint **lastPoint);
protected:
const KoSubpathList &subpaths() const;
/// XXX: refactor this using setter?
KoSubpathList &subpaths();
void map(const QTransform &matrix);
private:
class Private;
QSharedDataPointer<Private> d;
};
Q_DECLARE_METATYPE(KoPathShape*)
......
......@@ -20,14 +20,15 @@
#define KOPATHSHAPEPRIVATE_H
#include "KoPathShape.h"
#include "KoTosContainer_p.h"
#include "KoMarker.h"
class KoPathShapePrivate : public KoTosContainerPrivate
#include <QSharedData>
class KoPathShape::Private : public QSharedData
{
public:
explicit KoPathShapePrivate(KoPathShape *q);
explicit KoPathShapePrivate(const KoPathShapePrivate &rhs, KoPathShape *q);
explicit Private();
explicit Private(const Private &rhs);
QRectF handleRect(const QPointF &p, qreal radius) const;
/// Applies the viewbox transformation defined in the given element
......@@ -35,13 +36,6 @@ public:
void map(const QTransform &matrix);
void updateLast(KoPathPoint **lastPoint);
/// closes specified subpath
void closeSubpath(KoSubpath *subpath);
/// close-merges specified subpath
void closeMergeSubpath(KoSubpath *subpath);
/**
* @brief Saves the node types
*
......@@ -89,8 +83,6 @@ public:
Qt::FillRule fillRule;
Q_DECLARE_PUBLIC(KoPathShape)
KoSubpathList subpaths;
QMap<KoFlake::MarkerPosition, QExplicitlySharedDataPointer<KoMarker>> markersNew;
......
......@@ -34,13 +34,20 @@
#include "kis_debug.h"
KoSelection::KoSelection(QObject *parent)
: QObject(parent),
KoShape(new KoSelectionPrivate(this))
: QObject(parent)
, KoShape()
, d(new Private)
{
Q_D(KoSelection);
connect(&d->selectionChangedCompressor, SIGNAL(timeout()), SIGNAL(selectionChanged()));
}
KoSelection::KoSelection(const KoSelection &rhs)
: QObject()
, KoShape(rhs)
, d(rhs.d)
{
}
KoSelection::~KoSelection()
{
}
......@@ -82,7 +89,6 @@ QRectF KoSelection::boundingRect() const
void KoSelection::select(KoShape *shape)
{
Q_D(KoSelection);
KIS_SAFE_ASSERT_RECOVER_RETURN(shape != this);
KIS_SAFE_ASSERT_RECOVER_RETURN(shape);
......@@ -114,7 +120,6 @@ void KoSelection::select(KoShape *shape)
void KoSelection::deselect(KoShape *shape)
{
Q_D(KoSelection);
if (!d->selectedShapes.contains(shape))
return;
......@@ -130,7 +135,6 @@ void KoSelection::deselect(KoShape *shape)
void KoSelection::deselectAll()
{
Q_D(KoSelection);
if (d->selectedShapes.isEmpty())
return;
......@@ -148,13 +152,11 @@ void KoSelection::deselectAll()
int KoSelection::count() const
{
Q_D(const KoSelection);
return d->selectedShapes.size();
}
bool KoSelection::hitTest(const QPointF &position) const
{
Q_D(const KoSelection);
Q_FOREACH (KoShape *shape, d->selectedShapes) {
if (shape->isVisible()) continue;
......@@ -166,7 +168,6 @@ bool KoSelection::hitTest(const QPointF &position) const
const QList<KoShape*> KoSelection::selectedShapes() const
{
Q_D(const KoSelection);
return d->selectedShapes;
}
......@@ -210,7 +211,6 @@ const QList<KoShape *> KoSelection::selectedEditableShapesAndDelegates() const
bool KoSelection::isSelected(const KoShape *shape) const
{
Q_D(const KoSelection);
if (shape == this)
return true;
......@@ -224,20 +224,17 @@ bool KoSelection::isSelected(const KoShape *shape) const
KoShape *KoSelection::firstSelectedShape() const
{
Q_D(const KoSelection);
return !d->selectedShapes.isEmpty() ? d->selectedShapes.first() : 0;
}
void KoSelection::setActiveLayer(KoShapeLayer *layer)
{
Q_D(KoSelection);
d->activeLayer = layer;
emit currentLayerChanged(layer);
}
KoShapeLayer* KoSelection::activeLayer() const
{
Q_D(const KoSelection);
return d->activeLayer;
}
......
......@@ -159,7 +159,12 @@ private:
void saveOdf(KoShapeSavingContext &) const override;
bool loadOdf(const KoXmlElement &, KoShapeLoadingContext &) override;
Q_DECLARE_PRIVATE_D(KoShape::d_ptr, KoSelection)
protected:
KoSelection(const KoSelection &rhs);
private:
class Private;
QSharedDataPointer<Private> d;
};
#endif
......@@ -19,26 +19,28 @@
#ifndef KOSELECTIONPRIVATE_H
#define KOSELECTIONPRIVATE_H
#include "KoShape_p.h"
#include <QSharedData>
#include "kis_thread_safe_signal_compressor.h"
class KoShapeGroup;
class KoSelectionPrivate : public KoShapePrivate
class KoSelection::Private : public QSharedData
{
public:
explicit KoSelectionPrivate(KoSelection *parent)
: KoShapePrivate(parent),
activeLayer(0),
selectionChangedCompressor(1, KisSignalCompressor::FIRST_INACTIVE)
explicit Private()
: activeLayer(0)
, selectionChangedCompressor(1, KisSignalCompressor::FIRST_INACTIVE)
{}
explicit Private(const Private &rhs)
: activeLayer(0)
, selectionChangedCompressor(1, KisSignalCompressor::FIRST_INACTIVE)
{
}
QList<KoShape*> selectedShapes;
KoShapeLayer *activeLayer;
KisThreadSafeSignalCompressor selectionChangedCompressor;
Q_DECLARE_PUBLIC(KoSelection)
};
#endif
This diff is collapsed.
......@@ -30,6 +30,7 @@
#include <QSharedPointer>
#include <QSet>
#include <QMetaType>
#include <QSharedDataPointer>
#include <KoXmlReaderForward.h>
......@@ -49,7 +50,6 @@ class KoShapeSavingContext;
class KoShapeLoadingContext;
class KoGenStyle;
class KoShapeShadow;
class KoShapePrivate;
class KoFilterEffectStack;
class KoSnapData;
class KoClipPath;
......@@ -60,6 +60,7 @@ class KoBorder;
struct KoInsets;
class KoShapeBackground;
class KisHandlePainterHelper;
class KoShapeManager;
/**
* Base class for all flake shapes. Shapes extend this class
......@@ -1177,12 +1178,6 @@ public:
*/
void setHyperLink(const QString &hyperLink);
/**
* \internal
* Returns the private object for use within the flake lib
*/
KoShapePrivate *priv();
public:
struct KRITAFLAKE_EXPORT ShapeChangeListener {
......@@ -1191,7 +1186,6 @@ public:
private:
friend class KoShape;
friend class KoShapePrivate;
void registerShape(KoShape *shape);
void unregisterShape(KoShape *shape);
void notifyShapeChangedImpl(ChangeType type, KoShape *shape);
......@@ -1202,12 +1196,15 @@ public:
void addShapeChangeListener(ShapeChangeListener *listener);
void removeShapeChangeListener(ShapeChangeListener *listener);
protected:
QList<ShapeChangeListener *> listeners() const;
void setSizeImpl(const QSizeF &size) const;
public:
static QList<KoShape*> linearizeSubtree(const QList<KoShape*> &shapes);
protected:
/// constructor
KoShape(KoShapePrivate *);
KoShape(const KoShape &rhs);
/* ** loading saving helper methods */
/// attributes from ODF 1.1 chapter 9.2.15 Common Drawing Shape Attributes
......@@ -1294,10 +1291,21 @@ protected:
/// return the current matrix that contains the rotation/scale/position of this shape
QTransform transform() const;
KoShapePrivate *d_ptr;
private:
class Private;
QSharedDataPointer<Private> d;
protected:
/**
* Notify the shape that a change was done. To be used by inheriting shapes.
* @param type the change type
*/
void shapeChangedPriv(KoShape::ChangeType type);
private:
Q_DECLARE_PRIVATE(KoShape)
void addShapeManager(KoShapeManager *manager);
void removeShapeManager(KoShapeManager *manager);
friend class KoShapeManager;
};
Q_DECLARE_METATYPE(KoShape*)
......
......@@ -32,53 +32,39 @@
#include "kis_painting_tweaks.h"
#include "kis_assert.h"
KoShapeContainerPrivate::KoShapeContainerPrivate(KoShapeContainer *q)
: KoShapePrivate(q),
shapeInterface(q),
KoShapeContainer::Private::Private(KoShapeContainer *q)
: shapeInterface(q),
model(0)
{
}
KoShapeContainerPrivate::~KoShapeContainerPrivate()
KoShapeContainer::Private::~Private()
{
delete model;
}
KoShapeContainerPrivate::KoShapeContainerPrivate(const KoShapeContainerPrivate &rhs, KoShapeContainer *q)
: KoShapePrivate(rhs, q),
shapeInterface(q),
model(0)
KoShapeContainer::Private::Private(const KoShapeContainer::Private &rhs, KoShapeContainer *q)
: shapeInterface(q)
, model(0)
{
Q_UNUSED(rhs);
}
KoShapeContainer::KoShapeContainer(KoShapeContainerModel *model)
: KoShape(new KoShapeContainerPrivate(this))
: KoShape()
, d(new Private(this))
{
Q_D(KoShapeContainer);
d->model = model;
}
KoShapeContainer::KoShapeContainer(KoShapeContainerPrivate *dd)
: KoShape(dd)
KoShapeContainer::KoShapeContainer(const KoShapeContainer &rhs)
: KoShape(rhs)
, d(new Private(*(rhs.d.data()), this))
{
Q_D(KoShapeContainer);
// HACK ALERT: the shapes are copied inside the model,
// but we still need to connect the to the
// hierarchy here!
if (d->model) {
Q_FOREACH (KoShape *shape, d->model->shapes()) {
if (shape) { // Note: shape can be 0 because not all shapes
// implement cloneShape, e.g. the text shape.
shape->setParent(this);
}
}
}
}
KoShapeContainer::~KoShapeContainer()
{
Q_D(KoShapeContainer);
if (d->model) {
d->model->deleteOwnedShapes();
}
......@@ -94,9 +80,8 @@ void KoShapeContainer::removeShape(KoShape *shape)
shape->setParent(0);
}
int KoShapeContainer::shapeCount() const
int KoShapeContainer::shapeCount() const
{
Q_D(const KoShapeContainer);
if (d->model == 0)
return 0;
return d->model->count();
......@@ -104,7 +89,6 @@ int KoShapeContainer::shapeCount() const
void KoShapeContainer::setClipped(const KoShape *child, bool clipping)
{
Q_D(KoShapeContainer);
if (d->model == 0)
return;
d->model->setClipped(child, clipping);
......@@ -112,7 +96,6 @@ void KoShapeContainer::setClipped(const KoShape *child, bool clipping)
void KoShapeContainer::setInheritsTransform(const KoShape *shape, bool inherit)
{
Q_D(KoShapeContainer);
if (d->model == 0)
return;
d->model->setInheritsTransform(shape, inherit);
......@@ -120,7 +103,6 @@ void KoShapeContainer::setInheritsTransform(const KoShape *shape, bool inherit)
bool KoShapeContainer::inheritsTransform(const KoShape *shape) const
{
Q_D(const KoShapeContainer);
if (d->model == 0)
return false;
return d->model->inheritsTransform(shape);
......@@ -139,7 +121,6 @@ void KoShapeContainer::paint(QPainter &painter, const KoViewConverter &converter
void KoShapeContainer::shapeChanged(ChangeType type, KoShape* shape)
{
Q_UNUSED(shape);
Q_D(KoShapeContainer);
if (d->model == 0)
return;
if (!(type == RotationChanged || type == ScaleChanged || type == ShearChanged
......@@ -152,7 +133,6 @@ void KoShapeContainer::shapeChanged(ChangeType type, KoShape* shape)
bool KoShapeContainer::isClipped(const KoShape *child) const
{
Q_D(const KoShapeContainer);
if (d->model == 0) // throw exception??
return false;
return d->model->isClipped(child);
......@@ -160,7 +140,6 @@ bool KoShapeContainer::isClipped(const KoShape *child) const
void KoShapeContainer::update() const
{
Q_D(const KoShapeContainer);
KoShape::update();
if (d->model)
Q_FOREACH (KoShape *shape, d->model->shapes())
......@@ -169,7 +148,6 @@ void KoShapeContainer::update() const
QList<KoShape*> KoShapeContainer::shapes() const
{
Q_D(const KoShapeContainer);
if (d->model == 0)
return QList<KoShape*>();
......@@ -178,13 +156,32 @@ QList<KoShape*> KoShapeContainer::shapes() const
KoShapeContainerModel *KoShapeContainer::model() const
{
Q_D(const KoShapeContainer);
return d->model;
}
void KoShapeContainer::setModel(KoShapeContainerModel *model)
{
d->model = model;
}
void KoShapeContainer::setModelInit(KoShapeContainerModel *model)
{
setModel(model);
// HACK ALERT: the shapes are copied inside the model,
// but we still need to connect the to the
// hierarchy here!
if (d->model) {
Q_FOREACH (KoShape *shape, d->model->shapes()) {
if (shape) { // Note: shape can be 0 because not all shapes
// implement cloneShape, e.g. the text shape.
shape->setParent(this);
}
}
}
}
KoShapeContainer::ShapeInterface *KoShapeContainer::shapeInterface()
{
Q_D(KoShapeContainer);
return &d->shapeInterface;
}
......@@ -195,7 +192,7 @@ KoShapeContainer::ShapeInterface::ShapeInterface(KoShapeContainer *_q)
void KoShapeContainer::ShapeInterface::addShape(KoShape *shape)
{
KoShapeContainerPrivate * const d = q->d_func();
KoShapeContainer::Private * const d = q->d.data();
KIS_SAFE_ASSERT_RECOVER_RETURN(shape);
......@@ -218,7 +215,7 @@ void KoShapeContainer::ShapeInterface::addShape(KoShape *shape)
void KoShapeContainer::ShapeInterface::removeShape(KoShape *shape)
{
KoShapeContainerPrivate * const d = q->d_func();