Commit 5d74215f authored by Thomas Zander's avatar Thomas Zander

Replace addUser/removeUser with ref/deref

This makes sure we follow the Qt APIs and be more consistent and
compatible.

svn path=/trunk/koffice/; revision=1072430
parent 1e7a32f7
......@@ -98,12 +98,12 @@ QRectF KoFilterEffectStack::clipRectForBoundingRect(const QRectF &boundingRect)
return QRectF(x, y, w, h);
}
void KoFilterEffectStack::addUser()
bool KoFilterEffectStack::ref()
{
d->refCount.ref();
return d->refCount.ref();
}
bool KoFilterEffectStack::removeUser()
bool KoFilterEffectStack::deref()
{
return d->refCount.deref();
}
......
......@@ -89,10 +89,16 @@ public:
/// Returns the clipping rectangle for the given bounding rect
QRectF clipRectForBoundingRect(const QRectF &boundingRect) const;
/// Increase reference counter
void addUser();
/// Decrease reference counter
bool removeUser();
/**
* 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 reference counter
int useCount() const;
......
......@@ -106,13 +106,13 @@ KoShapePrivate::~KoShapePrivate()
}
delete userData;
delete appData;
if (border && ! border->removeUser())
if (border && !border->deref())
delete border;
if (shadow && ! shadow->removeUser())
if (shadow && !shadow->deref())
delete shadow;
if (fill && ! fill->removeUser())
if (fill && !fill->deref())
delete fill;
if (filterEffectStack && ! filterEffectStack->removeUser())
if (filterEffectStack && !filterEffectStack->deref())
delete filterEffectStack;
qDeleteAll(eventActions);
}
......@@ -673,14 +673,14 @@ QSet<KoEventAction *> KoShape::eventActions() const
return d->eventActions;
}
void KoShape::setBackground(KoShapeBackground * fill)
void KoShape::setBackground(KoShapeBackground *fill)
{
Q_D(KoShape);
if (d->fill)
d->fill->removeUser();
d->fill->deref();
d->fill = fill;
if (d->fill)
d->fill->addUser();
d->fill->ref();
d->shapeChanged(BackgroundChanged);
notifyChanged();
}
......@@ -824,10 +824,10 @@ void KoShape::setBorder(KoShapeBorderModel *border)
{
Q_D(KoShape);
if (border)
border->addUser();
border->ref();
d->updateBorder();
if (d->border)
d->border->removeUser();
d->border->deref();
d->border = border;
d->updateBorder();
d->shapeChanged(BorderChanged);
......@@ -838,10 +838,10 @@ void KoShape::setShadow(KoShapeShadow * shadow)
{
Q_D(KoShape);
if (d->shadow)
d->shadow->removeUser();
d->shadow->deref();
d->shadow = shadow;
if (d->shadow) {
d->shadow->addUser();
d->shadow->ref();
// TODO update changed area
}
d->shapeChanged(ShadowChanged);
......@@ -969,15 +969,15 @@ void KoShape::loadStyle(const KoXmlElement & element, KoShapeLoadingContext &con
styleStack.setTypeProperties("graphic");
}
if(d->fill && !d->fill->removeUser()) {
if(d->fill && !d->fill->deref()) {
delete d->fill;
d->fill = 0;
}
if(d->border && !d->border->removeUser()) {
if(d->border && !d->border->deref()) {
delete d->border;
d->border = 0;
}
if(d->shadow && !d->shadow->removeUser()) {
if(d->shadow && !d->shadow->deref()) {
delete d->shadow;
d->shadow = 0;
}
......@@ -1463,10 +1463,10 @@ void KoShape::setFilterEffectStack(KoFilterEffectStack * filterEffectStack)
{
Q_D(KoShape);
if (d->filterEffectStack)
d->filterEffectStack->removeUser();
d->filterEffectStack->deref();
d->filterEffectStack = filterEffectStack;
if (d->filterEffectStack) {
d->filterEffectStack->addUser();
d->filterEffectStack->ref();
}
notifyChanged();
}
......
......@@ -44,13 +44,13 @@ bool KoShapeBackground::hasTransparency()
return false;
}
void KoShapeBackground::addUser()
bool KoShapeBackground::ref()
{
Q_D(KoShapeBackground);
d->refCount.ref();
return d->refCount.ref();
}
bool KoShapeBackground::removeUser()
bool KoShapeBackground::deref()
{
Q_D(KoShapeBackground);
return d->refCount.deref();
......
......@@ -57,11 +57,17 @@ public:
/// load background from odf styles
virtual bool loadStyle(KoOdfLoadingContext &context, const QSizeF &shapeSize) = 0;
/// refcounting
void addUser();
/// decrements the usecount. Returns true if the new value is non-zero, false otherwise.
bool removeUser();
/// refcounting
/**
* 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:
......
......@@ -43,12 +43,12 @@ KoInsets KoShapeBorderModel::borderInsets(const KoShape *shape)
return insets;
}
void KoShapeBorderModel::addUser()
bool KoShapeBorderModel::ref()
{
d->refCount.ref();
return d->refCount.ref();
}
bool KoShapeBorderModel::removeUser()
bool KoShapeBorderModel::deref()
{
return d->refCount.deref();
}
......
......@@ -94,11 +94,17 @@ public:
*/
virtual void paintBorder(KoShape *shape, QPainter &painter, const KoViewConverter &converter, const QColor & color ) = 0;
/// refcounting
void addUser();
/// refcounting
bool removeUser();
/// refcounting
/**
* 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;
private:
......
......@@ -124,29 +124,28 @@ bool KoShapeGroup::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &
void KoShapeGroup::shapeChanged(ChangeType type, KoShape *shape)
{
Q_UNUSED(shape);
switch( type )
switch (type) {
case KoShape::BorderChanged:
{
case KoShape::BorderChanged:
{
KoShapeBorderModel * stroke = border();
if( stroke ) {
if( stroke->removeUser() )
delete stroke;
setBorder(0);
}
break;
KoShapeBorderModel *stroke = border();
if (stroke) {
if (stroke->deref())
delete stroke;
setBorder(0);
}
case KoShape::ShadowChanged:
{
KoShapeShadow * shade = shadow();
if( shade ) {
if( shade->removeUser() )
delete shade;
setShadow(0);
}
break;
break;
}
case KoShape::ShadowChanged:
{
KoShapeShadow *shade = shadow();
if (shade) {
if (shade->deref())
delete shade;
setShadow(0);
}
default:
break;
break;
}
default:
break;
}
}
......@@ -151,12 +151,12 @@ void KoShapeShadow::insets(const KoShape *shape, KoInsets &insets)
insets.bottom = (d->offset.y() > 0.0) ? d->offset.y() : 0.0;
}
void KoShapeShadow::addUser()
bool KoShapeShadow::ref()
{
d->refCount.ref();
return d->refCount.ref();
}
bool KoShapeShadow::removeUser()
bool KoShapeShadow::deref()
{
return d->refCount.deref();
}
......
......@@ -80,11 +80,17 @@ public:
/// Returns the insets of the shadow
void insets(const KoShape *shape, KoInsets &insets);
/// Increase reference counter
void addUser();
/// Decrease reference counter
bool removeUser();
/// Return reference counter
/**
* 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;
private:
......
......@@ -31,11 +31,11 @@ public:
}
~Private() {
foreach(KoShapeBackground* fill, oldFills) {
if (fill && ! fill->removeUser())
if (fill && !fill->deref())
delete fill;
}
foreach(KoShapeBackground* fill, newFills) {
if (fill && ! fill->removeUser())
if (fill && !fill->deref())
delete fill;
}
}
......@@ -43,14 +43,14 @@ public:
void addOldFill( KoShapeBackground * oldFill )
{
if (oldFill)
oldFill->addUser();
oldFill->ref();
oldFills.append(oldFill);
}
void addNewFill( KoShapeBackground * newFill )
{
if (newFill)
newFill->addUser();
newFill->ref();
newFills.append(newFill);
}
......
......@@ -31,7 +31,7 @@ public:
~Private()
{
foreach(KoShapeBorderModel* border, oldBorders) {
if (border && ! border->removeUser())
if (border && !border->deref())
delete border;
}
}
......@@ -39,14 +39,14 @@ public:
void addOldBorder( KoShapeBorderModel * oldBorder )
{
if (oldBorder)
oldBorder->addUser();
oldBorder->ref();
oldBorders.append(oldBorder);
}
void addNewBorder( KoShapeBorderModel * newBorder )
{
if (newBorder)
newBorder->addUser();
newBorder->ref();
newBorders.append(newBorder);
}
......
......@@ -29,7 +29,7 @@ public:
Private() {}
~Private() {
foreach(KoShapeShadow* shadow, oldShadows) {
if (shadow && ! shadow->removeUser())
if (shadow && !shadow->deref())
delete shadow;
}
}
......@@ -37,14 +37,14 @@ public:
void addOldShadow( KoShapeShadow * oldShadow )
{
if (oldShadow)
oldShadow->addUser();
oldShadow->ref();
oldShadows.append(oldShadow);
}
void addNewShadow( KoShapeShadow * newShadow )
{
if (newShadow)
newShadow->addUser();
newShadow->ref();
newShadows.append(newShadow);
}
......
......@@ -35,7 +35,7 @@ public:
Edge edges[4];
QRectF bounds;
int refCount;
QAtomicInt refCount;
};
KoTextBlockBorderData::KoTextBlockBorderData(const QRectF &paragRect)
......@@ -196,14 +196,14 @@ void KoTextBlockBorderData::setEdge(Side side, const QTextBlockFormat &bf,
d->edges[side] = edge;
}
void KoTextBlockBorderData::addUser()
bool KoTextBlockBorderData::ref()
{
d->refCount++;
d->refCount.ref();
}
int KoTextBlockBorderData::removeUser()
bool KoTextBlockBorderData::deref()
{
return --d->refCount;
return d->refCount.deref();
}
int KoTextBlockBorderData::useCount() const
......
......@@ -62,11 +62,17 @@ public:
~KoTextBlockBorderData();
/// refcounting
void addUser();
/// refcounting
int removeUser();
/// refcounting
/**
* 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;
/**
......
......@@ -25,7 +25,7 @@ class KoTextBlockData::Private
public:
Private() : counterWidth(0), counterSpacing(0), counterIndex(1), border(0) {}
~Private() {
if (border && border->removeUser() == 0)
if (border && !border->deref())
delete border;
}
qreal counterWidth;
......@@ -60,11 +60,11 @@ qreal KoTextBlockData::counterWidth() const
void KoTextBlockData::setBorder(KoTextBlockBorderData *border)
{
if (d->border && d->border->removeUser() == 0)
if (d->border && !d->border->deref())
delete d->border;
d->border = border;
if (d->border)
d->border->addUser();
d->border->ref();
}
void KoTextBlockData::setCounterWidth(qreal width)
......
......@@ -57,9 +57,9 @@ StylePreview::StylePreview(QWidget * parent)
StylePreview::~StylePreview()
{
if (m_background && ! m_background->removeUser())
if (m_background && !m_background->deref())
delete m_background;
if (m_stroke && ! m_stroke->removeUser())
if (m_stroke && !m_stroke->deref())
delete m_stroke;
}
......@@ -137,23 +137,23 @@ bool StylePreview::eventFilter(QObject *, QEvent *event)
void StylePreview::update(KoShapeBorderModel * stroke, KoShapeBackground * fill)
{
if (fill != m_background) {
if (m_background && ! m_background->removeUser())
if (m_background && !m_background->deref())
delete m_background;
m_background = fill;
if (m_background)
m_background->addUser();
m_background->ref();
}
if (stroke != m_stroke) {
if (m_stroke && ! m_stroke->removeUser())
if (m_stroke && !m_stroke->deref())
delete m_stroke;
m_stroke = stroke;
if (m_stroke)
m_stroke->addUser();
m_stroke->ref();
}
QFrame::update();
......
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