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

List:       kde-commits
Subject:    koffice/karbon
From:       Jan Hambrecht <jaham () gmx ! net>
Date:       2008-11-26 23:35:33
Message-ID: 1227742533.016679.21527.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 889513 by jaham:

fix crash in style preview by using refcounting on the
shape background and shape border which is previewed
(reported by Zagge)



 M  +3 -3      plugins/dockers/KarbonStyleDocker.cpp  
 M  +2 -2      plugins/dockers/KarbonStyleDocker.h  
 M  +27 -3     ui/widgets/KarbonStylePreview.cpp  
 M  +3 -3      ui/widgets/KarbonStylePreview.h  


--- trunk/koffice/karbon/plugins/dockers/KarbonStyleDocker.cpp #889512:889513
@@ -159,7 +159,7 @@
     return m_preview->strokeIsSelected();
 }
 
-void KarbonStyleDocker::updateStyle( const KoShapeBorderModel * stroke, const KoShapeBackground * fill )
+void KarbonStyleDocker::updateStyle( KoShapeBorderModel * stroke, KoShapeBackground * fill )
 {
     KoCanvasResourceProvider * provider = m_canvas->resourceProvider();
     int activeStyle = provider->resource( Karbon::ActiveStyle ).toInt();
@@ -167,7 +167,7 @@
     QColor qColor;
     if( activeStyle == Karbon::Foreground )
     {
-        const KoLineBorder * border = dynamic_cast<const KoLineBorder*>( stroke );
+        KoLineBorder * border = dynamic_cast<KoLineBorder*>( stroke );
         if( border )
             qColor = border->color();
         else
@@ -175,7 +175,7 @@
     }
     else
     {
-        const KoColorBackground * background = dynamic_cast<const KoColorBackground*>( fill );
+        KoColorBackground * background = dynamic_cast<KoColorBackground*>( fill );
         if( background )
             qColor = background->color();
         else
--- trunk/koffice/karbon/plugins/dockers/KarbonStyleDocker.h #889512:889513
@@ -46,8 +46,8 @@
     /// Returns if the stroke mode is active
     bool strokeIsSelected() const;
     
-    /// Sets the shape border ans fill to display
-    void updateStyle( const KoShapeBorderModel * stroke, const KoShapeBackground * fill );
+    /// Sets the shape border and fill to display
+    void updateStyle( KoShapeBorderModel * stroke, KoShapeBackground * fill );
 
 private slots:
     void fillSelected();
--- trunk/koffice/karbon/ui/widgets/KarbonStylePreview.cpp #889512:889513
@@ -57,6 +57,10 @@
 
 KarbonStylePreview::~KarbonStylePreview()
 {
+    if( m_background && ! m_background->removeUser() )
+        delete m_background;
+    if( m_stroke && ! m_stroke->removeUser() )
+        delete m_stroke;
 }
 
 void KarbonStylePreview::paintEvent( QPaintEvent* event )
@@ -139,10 +143,30 @@
     return false;
 }
 
-void KarbonStylePreview::update( const KoShapeBorderModel * stroke, const KoShapeBackground * fill )
+void KarbonStylePreview::update( KoShapeBorderModel * stroke, KoShapeBackground * fill )
 {
-    m_background = fill;
-    m_stroke = stroke;
+    if( fill != m_background )
+    {
+        if( m_background && ! m_background->removeUser() )
+            delete m_background;
+        
+        m_background = fill;
+        
+        if( m_background )
+            m_background->addUser();
+    }
+    
+    if( stroke != m_stroke )
+    {
+        if( m_stroke && ! m_stroke->removeUser() )
+            delete m_stroke;
+        
+        m_stroke = stroke;
+        
+        if( m_stroke )
+            m_stroke->addUser();
+    }
+    
     QFrame::update();
 }
 
--- trunk/koffice/karbon/ui/widgets/KarbonStylePreview.h #889512:889513
@@ -55,7 +55,7 @@
      * @param stroke the stroke to preview
      * @param fill the fill to preview
      */
-    void update( const KoShapeBorderModel * stroke, const KoShapeBackground * fill );
+    void update( KoShapeBorderModel * stroke, KoShapeBackground * fill );
 
     virtual bool eventFilter( QObject* object, QEvent* event );
 
@@ -82,8 +82,8 @@
     void drawStroke( QPainter & painter, const KoShapeBorderModel* );
 
     bool m_strokeWidget; ///< shows if stroke or fill is selected
-    const KoShapeBackground * m_background; ///< the fill to preview
-    const KoShapeBorderModel * m_stroke; ///< the stroke to preview
+    KoShapeBackground * m_background; ///< the fill to preview
+    KoShapeBorderModel * m_stroke; ///< the stroke to preview
     QRectF m_strokeRect;
     QRectF m_fillRect;
     KoCheckerBoardPainter m_checkerPainter;
[prev in list] [next in list] [prev in thread] [next in thread] 

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