[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    flake patches for review (1/3)
From:       Thomas Zander <zander () kde ! org>
Date:       2010-01-09 14:00:06
Message-ID: 201001091500.06770.zander () kde ! org
[Download RAW message or body]

Please find attached some patches I'd like to submit for review.

ps. I'd appreciate if the mailinglist would accept mails bigger than 40Kb. Its 
rather trivial to reach that level. Hence my 3 mails...
-- 
Thomas Zander

["0001-Replace-addUser-removeUser-with-ref-deref.patch" (text/x-patch)]

From 99f5b6bf13661a91e1a086144606b63a302986cd Mon Sep 17 00:00:00 2001
From: Thomas Zander <zander@kde.org>
Date: Sat, 9 Jan 2010 11:41:02 +0100
Subject: [PATCH 1/6] Replace addUser/removeUser with ref/deref

This makes sure we follow the Qt APIs and be more consistent and
compatible.
---
 .../filterEffectTool/FilterStackSetCommand.cpp     |   10 ++--
 karbon/ui/widgets/KarbonSmallStylePreview.cpp      |   26 ++++++------
 libs/flake/KoFilterEffectStack.cpp                 |    6 +-
 libs/flake/KoFilterEffectStack.h                   |   14 +++++--
 libs/flake/KoShape.cpp                             |   32 ++++++++--------
 libs/flake/KoShapeBackground.cpp                   |    6 +-
 libs/flake/KoShapeBackground.h                     |   16 +++++--
 libs/flake/KoShapeBorderModel.cpp                  |    6 +-
 libs/flake/KoShapeBorderModel.h                    |   16 +++++--
 libs/flake/KoShapeGroup.cpp                        |   41 ++++++++++----------
 libs/flake/KoShapeShadow.cpp                       |    6 +-
 libs/flake/KoShapeShadow.h                         |   16 +++++--
 libs/flake/commands/KoShapeBackgroundCommand.cpp   |    8 ++--
 libs/flake/commands/KoShapeBorderCommand.cpp       |    6 +-
 libs/flake/commands/KoShapeShadowCommand.cpp       |    6 +-
 libs/kotext/KoTextBlockBorderData.cpp              |   10 ++--
 libs/kotext/KoTextBlockBorderData.h                |   16 +++++--
 libs/kotext/KoTextBlockData.cpp                    |    6 +-
 plugins/dockers/styledocker/StylePreview.cpp       |   12 +++---
 19 files changed, 144 insertions(+), 115 deletions(-)

diff --git a/karbon/plugins/tools/filterEffectTool/FilterStackSetCommand.cpp \
b/karbon/plugins/tools/filterEffectTool/FilterStackSetCommand.cpp index \
                23e0114..8fe26bf 100644
--- a/karbon/plugins/tools/filterEffectTool/FilterStackSetCommand.cpp
+++ b/karbon/plugins/tools/filterEffectTool/FilterStackSetCommand.cpp
@@ -29,18 +29,18 @@ FilterStackSetCommand::FilterStackSetCommand(KoFilterEffectStack \
*newStack, KoSh  Q_ASSERT(m_shape);
     m_oldFilterStack = m_shape->filterEffectStack();
     if (m_newFilterStack)
-        m_newFilterStack->addUser();
+        m_newFilterStack->ref();
     if (m_oldFilterStack)
-        m_oldFilterStack->addUser();
-    
+        m_oldFilterStack->ref();
+
     setText(i18n("Set filter stack"));
 }
 
 FilterStackSetCommand::~FilterStackSetCommand()
 {
-    if (m_newFilterStack && ! m_newFilterStack->removeUser())
+    if (m_newFilterStack && !m_newFilterStack->deref())
         delete m_newFilterStack;
-    if (m_oldFilterStack && ! m_oldFilterStack->removeUser())
+    if (m_oldFilterStack && !m_oldFilterStack->deref())
         delete m_oldFilterStack;
 }
 
diff --git a/karbon/ui/widgets/KarbonSmallStylePreview.cpp \
b/karbon/ui/widgets/KarbonSmallStylePreview.cpp index 073b807..09836f9 100644
--- a/karbon/ui/widgets/KarbonSmallStylePreview.cpp
+++ b/karbon/ui/widgets/KarbonSmallStylePreview.cpp
@@ -57,24 +57,24 @@ public:
         setCursor( Qt::PointingHandCursor );
         setToolTip( i18n("Press to apply fill to selection" ) );
     }
-    
+
     virtual ~KarbonFillStyleWidget()
     {
-        if( m_fill && ! m_fill->removeUser() )
+        if (m_fill && !m_fill->deref())
             delete m_fill;
     }
-    
+
     void setFill( KoShapeBackground * fill )
     {
         if( fill != m_fill )
         {
-            if( m_fill && ! m_fill->removeUser() )
+            if (m_fill && !m_fill->deref())
                 delete m_fill;
             m_fill = fill;
-            if( m_fill )
-                m_fill->addUser();
+            if (m_fill)
+                m_fill->ref();
         }
-        
+
         update();
     }
 protected:
@@ -134,22 +134,22 @@ public:
         setCursor( Qt::PointingHandCursor );
         setToolTip( i18n("Press to apply stroke to selection" ) );
     }
-    
+
     virtual ~KarbonStrokeStyleWidget()
     {
-        if( m_stroke && ! m_stroke->removeUser() )
+        if (m_stroke && !m_stroke->deref())
             delete m_stroke;
     }
-    
+
     void setStroke( KoShapeBorderModel * stroke )
     {
         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();
+            if (m_stroke)
+                m_stroke->ref();
         }
         update();
     }
diff --git a/libs/flake/KoFilterEffectStack.cpp b/libs/flake/KoFilterEffectStack.cpp
index 3ac33f5..354ebb1 100644
--- a/libs/flake/KoFilterEffectStack.cpp
+++ b/libs/flake/KoFilterEffectStack.cpp
@@ -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();
 }
diff --git a/libs/flake/KoFilterEffectStack.h b/libs/flake/KoFilterEffectStack.h
index 69b1b80..9aad2ea 100644
--- a/libs/flake/KoFilterEffectStack.h
+++ b/libs/flake/KoFilterEffectStack.h
@@ -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;
 
diff --git a/libs/flake/KoShape.cpp b/libs/flake/KoShape.cpp
index dd63f8c..2ea65c9 100644
--- a/libs/flake/KoShape.cpp
+++ b/libs/flake/KoShape.cpp
@@ -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();
 }
diff --git a/libs/flake/KoShapeBackground.cpp b/libs/flake/KoShapeBackground.cpp
index a8b555e..158286b 100644
--- a/libs/flake/KoShapeBackground.cpp
+++ b/libs/flake/KoShapeBackground.cpp
@@ -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();
diff --git a/libs/flake/KoShapeBackground.h b/libs/flake/KoShapeBackground.h
index b3b69c1..163403f 100644
--- a/libs/flake/KoShapeBackground.h
+++ b/libs/flake/KoShapeBackground.h
@@ -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:
diff --git a/libs/flake/KoShapeBorderModel.cpp b/libs/flake/KoShapeBorderModel.cpp
index 604bafe..414c18d 100644
--- a/libs/flake/KoShapeBorderModel.cpp
+++ b/libs/flake/KoShapeBorderModel.cpp
@@ -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();
 }
diff --git a/libs/flake/KoShapeBorderModel.h b/libs/flake/KoShapeBorderModel.h
index f5380df..1b16559 100644
--- a/libs/flake/KoShapeBorderModel.h
+++ b/libs/flake/KoShapeBorderModel.h
@@ -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:
diff --git a/libs/flake/KoShapeGroup.cpp b/libs/flake/KoShapeGroup.cpp
index 6e33ebb..2661e62 100644
--- a/libs/flake/KoShapeGroup.cpp
+++ b/libs/flake/KoShapeGroup.cpp
@@ -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;
     }
 }
diff --git a/libs/flake/KoShapeShadow.cpp b/libs/flake/KoShapeShadow.cpp
index df5c597..3702872 100644
--- a/libs/flake/KoShapeShadow.cpp
+++ b/libs/flake/KoShapeShadow.cpp
@@ -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();
 }
diff --git a/libs/flake/KoShapeShadow.h b/libs/flake/KoShapeShadow.h
index d603018..43d6a5a 100644
--- a/libs/flake/KoShapeShadow.h
+++ b/libs/flake/KoShapeShadow.h
@@ -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:
diff --git a/libs/flake/commands/KoShapeBackgroundCommand.cpp \
b/libs/flake/commands/KoShapeBackgroundCommand.cpp index c7f6704..ec45928 100644
--- a/libs/flake/commands/KoShapeBackgroundCommand.cpp
+++ b/libs/flake/commands/KoShapeBackgroundCommand.cpp
@@ -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);
     }
 
diff --git a/libs/flake/commands/KoShapeBorderCommand.cpp \
b/libs/flake/commands/KoShapeBorderCommand.cpp index b03f40f..c39d55f 100644
--- a/libs/flake/commands/KoShapeBorderCommand.cpp
+++ b/libs/flake/commands/KoShapeBorderCommand.cpp
@@ -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);
     }
 
diff --git a/libs/flake/commands/KoShapeShadowCommand.cpp \
b/libs/flake/commands/KoShapeShadowCommand.cpp index 78b6e3d..fb9b45c 100644
--- a/libs/flake/commands/KoShapeShadowCommand.cpp
+++ b/libs/flake/commands/KoShapeShadowCommand.cpp
@@ -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);
     }
 
diff --git a/libs/kotext/KoTextBlockBorderData.cpp \
b/libs/kotext/KoTextBlockBorderData.cpp index 6506959..663db31 100644
--- a/libs/kotext/KoTextBlockBorderData.cpp
+++ b/libs/kotext/KoTextBlockBorderData.cpp
@@ -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
diff --git a/libs/kotext/KoTextBlockBorderData.h \
b/libs/kotext/KoTextBlockBorderData.h index 2afd72e..1170bf1 100644
--- a/libs/kotext/KoTextBlockBorderData.h
+++ b/libs/kotext/KoTextBlockBorderData.h
@@ -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;
 
     /**
diff --git a/libs/kotext/KoTextBlockData.cpp b/libs/kotext/KoTextBlockData.cpp
index bb4438d..e5649a3 100644
--- a/libs/kotext/KoTextBlockData.cpp
+++ b/libs/kotext/KoTextBlockData.cpp
@@ -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)
diff --git a/plugins/dockers/styledocker/StylePreview.cpp \
b/plugins/dockers/styledocker/StylePreview.cpp index 121a91d..2b8dbd3 100644
--- a/plugins/dockers/styledocker/StylePreview.cpp
+++ b/plugins/dockers/styledocker/StylePreview.cpp
@@ -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();
-- 
1.6.3.3


["0002-API-review-for-KoShapeShadow.patch" (text/x-patch)]

From 2280b850fbfbe33a63e6f1fc10933c20dead0bc3 Mon Sep 17 00:00:00 2001
From: Thomas Zander <zander@kde.org>
Date: Sat, 9 Jan 2010 11:57:51 +0100
Subject: [PATCH 2/6] API review for KoShapeShadow

* make 'insets' const.
* make 'insets' not pass in a KoShape; there is no way the insets
  can change based on the shape passed in.
* rename setVisibility -> setVisible so its a match with isVisible
* fix bug in insets() when the shape is invisible the insets are
  set to zero, not left untouched.
---
 libs/flake/KoPathShape.cpp                    |    2 +-
 libs/flake/KoShape.cpp                        |    6 +++---
 libs/flake/KoShapeShadow.cpp                  |   14 +++++++++-----
 libs/flake/KoShapeShadow.h                    |    7 ++++---
 libs/flake/tests/TestShapeAt.cpp              |    2 +-
 libs/flake/tests/TestShapeGroupCommand.cpp    |    2 +-
 libs/flake/tests/TestShapeShadowCommand.cpp   |    2 +-
 plugins/dockers/shadowdocker/ShadowDocker.cpp |    2 +-
 8 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/libs/flake/KoPathShape.cpp b/libs/flake/KoPathShape.cpp
index df61158..6f84471 100644
--- a/libs/flake/KoPathShape.cpp
+++ b/libs/flake/KoPathShape.cpp
@@ -379,7 +379,7 @@ QRectF KoPathShape::boundingRect() const
     }
     if (shadow()) {
         KoInsets insets;
-        shadow()->insets(this, insets);
+        shadow()->insets(insets);
         bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
     }
     if (filterEffectStack()) {
diff --git a/libs/flake/KoShape.cpp b/libs/flake/KoShape.cpp
index 2ea65c9..cb0723a 100644
--- a/libs/flake/KoShape.cpp
+++ b/libs/flake/KoShape.cpp
@@ -327,14 +327,14 @@ QRectF KoShape::boundingRect() const
     bb = transform.mapRect(bb);
     if (d->shadow) {
         KoInsets insets;
-        d->shadow->insets(this, insets);
+        d->shadow->insets(insets);
         bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
     }
     if (d->filterEffectStack) {
         QRectF clipRect = \
d->filterEffectStack->clipRectForBoundingRect(QRectF(QPointF(), mySize));  bb |= \
transform.mapRect(clipRect);  }
-    
+
     return bb;
 }
 
@@ -1156,7 +1156,7 @@ KoShapeShadow * KoShape::loadOdfShadow(const KoXmlElement & \
element, KoShapeLoad  if (! opacity.isEmpty() && opacity.right(1) == "%")
             shadowColor.setAlphaF(opacity.left(opacity.length() - 1).toFloat() / \
100.0);  shadow->setColor(shadowColor);
-        shadow->setVisibility(shadowStyle == "visible");
+        shadow->setVisible(shadowStyle == "visible");
 
         return shadow;
     }
diff --git a/libs/flake/KoShapeShadow.cpp b/libs/flake/KoShapeShadow.cpp
index 3702872..6218a1b 100644
--- a/libs/flake/KoShapeShadow.cpp
+++ b/libs/flake/KoShapeShadow.cpp
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
  * Copyright (C) 2008-2009 Jan Hambrecht <jaham@gmx.net>
+ * Copyright (C) 2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -128,7 +129,7 @@ QColor KoShapeShadow::color() const
     return d->color;
 }
 
-void KoShapeShadow::setVisibility(bool visible)
+void KoShapeShadow::setVisible(bool visible)
 {
     d->visible = visible;
 }
@@ -138,12 +139,15 @@ bool KoShapeShadow::isVisible() const
     return d->visible;
 }
 
-void KoShapeShadow::insets(const KoShape *shape, KoInsets &insets)
+void KoShapeShadow::insets(KoInsets &insets) const
 {
-    if (! d->visible)
+    if (!d->visible) {
+        insets.top = 0;
+        insets.bottom = 0;
+        insets.left = 0;
+        insets.right = 0;
         return;
-
-    Q_UNUSED(shape);
+    }
 
     insets.left = (d->offset.x() < 0.0) ? qAbs(d->offset.x()) : 0.0;
     insets.top = (d->offset.y() < 0.0) ? qAbs(d->offset.y()) : 0.0;
diff --git a/libs/flake/KoShapeShadow.h b/libs/flake/KoShapeShadow.h
index 43d6a5a..23ab9da 100644
--- a/libs/flake/KoShapeShadow.h
+++ b/libs/flake/KoShapeShadow.h
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
  * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
+ * Copyright (C) 2010 Thomas Zander <zander@kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -72,13 +73,13 @@ public:
     QColor color() const;
 
     /// Sets the shadow visibility
-    void setVisibility(bool visible);
+    void setVisible(bool visible);
 
     /// Returns if shadow is visible
     bool isVisible() const;
 
-    /// Returns the insets of the shadow
-    void insets(const KoShape *shape, KoInsets &insets);
+    /// Fills the insets oject with the space the shadow takes around a shape
+    void insets(KoInsets &insets) const;
 
     /**
      * Increments the use-value.
diff --git a/libs/flake/tests/TestShapeAt.cpp b/libs/flake/tests/TestShapeAt.cpp
index 1ffcd2c..26dbfe9 100644
--- a/libs/flake/tests/TestShapeAt.cpp
+++ b/libs/flake/tests/TestShapeAt.cpp
@@ -107,7 +107,7 @@ void TestShapeAt::testShadow()
     shadow->setOffset(QPointF(5, 9));
     shape.setShadow(shadow);
     KoInsets shadowInsets;
-    shadow->insets(&shape, shadowInsets);
+    shadow->insets(shadowInsets);
     bbox.adjust(-shadowInsets.left, -shadowInsets.top, shadowInsets.right, \
shadowInsets.bottom);  QCOMPARE(shape.boundingRect(), bbox);
 }
diff --git a/libs/flake/tests/TestShapeGroupCommand.cpp \
b/libs/flake/tests/TestShapeGroupCommand.cpp index b650b92..dc1f389 100644
--- a/libs/flake/tests/TestShapeGroupCommand.cpp
+++ b/libs/flake/tests/TestShapeGroupCommand.cpp
@@ -261,7 +261,7 @@ void TestShapeGroupCommand::testGroupStrokeShapes()
     }
     if (strokeGroup->shadow()) {
         KoInsets insets;
-        strokeGroup->shadow()->insets(strokeGroup, insets);
+        strokeGroup->shadow()->insets(insets);
         bound.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
     }
 
diff --git a/libs/flake/tests/TestShapeShadowCommand.cpp \
b/libs/flake/tests/TestShapeShadowCommand.cpp index 709c19d..a811468 100644
--- a/libs/flake/tests/TestShapeShadowCommand.cpp
+++ b/libs/flake/tests/TestShapeShadowCommand.cpp
@@ -56,7 +56,7 @@ void TestShapeShadowCommand::refCounting()
 
     // if shadow1 is deleted when deleting cmd1 this will crash
     KoInsets insets;
-    shadow1->insets(shape1,insets);
+    shadow1->insets(insets);
 
     delete cmd2;
     delete shape1;
diff --git a/plugins/dockers/shadowdocker/ShadowDocker.cpp \
b/plugins/dockers/shadowdocker/ShadowDocker.cpp index 5218930..d15b5a0 100644
--- a/plugins/dockers/shadowdocker/ShadowDocker.cpp
+++ b/plugins/dockers/shadowdocker/ShadowDocker.cpp
@@ -121,7 +121,7 @@ void ShadowDocker::shadowChanged()
         return;
 
     KoShapeShadow * newShadow = new KoShapeShadow();
-    newShadow->setVisibility( d->widget->shadowVisible() );
+    newShadow->setVisible(d->widget->shadowVisible());
     newShadow->setColor( d->widget->shadowColor() );
     newShadow->setOffset( d->widget->shadowOffset() );
     d->canvas->addCommand( new KoShapeShadowCommand( selection->selectedShapes(), \
                newShadow ) );
-- 
1.6.3.3



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic