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

List:       kde-commits
Subject:    koffice/plugins/chartshape/kdchart/src
From:       Johannes Simon <johannes.simon () gmail ! com>
Date:       2010-10-16 14:23:14
Message-ID: 20101016142314.5B946AC896 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1186464 by jsimon:

Implement different ways to specify marker size in KD Chart so that we can use a \
relative-to-diagram-size bubble size for bubble charts.

 M  +26 -3     KDChartAbstractDiagram.cpp  
 M  +2 -0      KDChartAbstractDiagram_p.h  
 M  +1 -0      KDChartBarDiagram.cpp  
 M  +1 -0      KDChartLineDiagram.cpp  
 M  +12 -0     KDChartMarkerAttributes.cpp  
 M  +27 -0     KDChartMarkerAttributes.h  
 M  +2 -1      KDChartPieDiagram.cpp  
 M  +1 -0      KDChartPlotter.cpp  
 M  +2 -1      KDChartPolarDiagram.cpp  
 M  +2 -1      KDChartRadarDiagram.cpp  
 M  +2 -1      KDChartRingDiagram.cpp  


--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartAbstractDiagram.cpp \
#1186463:1186464 @@ -558,9 +558,32 @@
     if ( !ma.isVisible() ) return;
 
     const PainterSaver painterSaver( painter );
-    // the size of the marker - unscaled
-    const QSizeF maSize( ma.markerSize().width() / painter->matrix().m11(), 
-                         ma.markerSize().height() / painter->matrix().m22() );
+
+    QSizeF maSize = ma.markerSize();
+    const qreal diagramWidth = d->diagramSize.width();
+    const qreal diagramHeight = d->diagramSize.height();
+
+    switch( ma.markerSizeMode() ) {
+    case MarkerAttributes::AbsoluteSize:
+        // Unscaled, i.e. without the painter's "zoom"
+        maSize.rwidth()  /= painter->matrix().m11();
+        maSize.rheight() /= painter->matrix().m22();
+        break;
+    case MarkerAttributes::AbsoluteSizeScaled:
+        // Keep maSize as is. It is specified directly in pixels and desired
+        // to be effected by the painter's "zoom".
+        break;
+    case MarkerAttributes::RelativeToDiagramWidth:
+        maSize *= diagramWidth;
+        break;
+    case MarkerAttributes::RelativeToDiagramHeight:
+        maSize *= diagramHeight;
+        break;
+    case MarkerAttributes::RelativeToDiagramWidthHeightMin:
+        maSize *= qMin( diagramWidth, diagramHeight );
+        break;
+    }
+
     QBrush indexBrush( brush( index ) );
     QPen indexPen( ma.pen() );
     if ( ma.markerColor().isValid() )
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartAbstractDiagram_p.h \
#1186463:1186464 @@ -500,6 +500,8 @@
         mutable QPair<QPointF,QPointF> databoundaries;
         mutable bool databoundariesDirty;
         ReverseMapper reverseMapper;
+        /// The size of the diagram set by AbstractDiagram::resize()
+        QSizeF diagramSize;
 
         QMap< Qt::Orientation, QString > unitSuffix;
         QMap< Qt::Orientation, QString > unitPrefix;
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartBarDiagram.cpp \
#1186463:1186464 @@ -400,6 +400,7 @@
 
 void BarDiagram::resize( const QSizeF& size )
 {
+    d->diagramSize = size;
     d->compressor.setResolution( static_cast< int >( size.width() * \
                coordinatePlane()->zoomFactorX() ),
                                  static_cast< int >( size.height() * \
coordinatePlane()->zoomFactorY() ) );  setDataBoundariesDirty();
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartLineDiagram.cpp \
#1186463:1186464 @@ -453,6 +453,7 @@
 
 void LineDiagram::resize ( const QSizeF& size )
 {
+    d->diagramSize = size;
     d->compressor.setResolution( static_cast<int>( size.width() * \
                coordinatePlane()->zoomFactorX() ),
                                  static_cast<int>( size.height() * \
coordinatePlane()->zoomFactorY() ) );  setDataBoundariesDirty();
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartMarkerAttributes.cpp \
#1186463:1186464 @@ -42,6 +42,7 @@
     bool threeD;
     QMap<uint,MarkerStyle> markerStylesMap;
     MarkerStyle markerStyle;
+    MarkerSizeMode markerSizeMode;
     QSizeF markerSize;
     QColor markerColor;
     QPen markerPen;
@@ -51,6 +52,7 @@
     : visible( false ),
       threeD( false ),
       markerStyle( MarkerSquare ),
+      markerSizeMode( AbsoluteSize ),
       markerSize( 10, 10 ),
       markerPen( Qt::black )
 {
@@ -155,6 +157,16 @@
     return d->markerSize;
 }
 
+void MarkerAttributes::setMarkerSizeMode( MarkerSizeMode mode )
+{
+    d->markerSizeMode = mode;
+}
+
+MarkerAttributes::MarkerSizeMode MarkerAttributes::markerSizeMode() const
+{
+    return d->markerSizeMode;
+}
+
 void MarkerAttributes::setMarkerColor( const QColor& color )
 {
     d->markerColor = color;
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartMarkerAttributes.h \
#1186463:1186464 @@ -56,6 +56,19 @@
                            MarkerFastCross = 7,
                            NoMarker = 8 };
 
+        enum MarkerSizeMode {
+            /// the marker size is directly specified in pixels
+            AbsoluteSize = 0,
+            /// the marker size is specified in pixels, but scaled by the
+            /// painter's zoom level
+            AbsoluteSizeScaled = 1,
+            /// the marker size is relative to the diagram's width
+            RelativeToDiagramWidth  = 2,
+            /// the marker size is relative to the diagram's height
+            RelativeToDiagramHeight = 3,
+            /// the marker size is relative to the diagram's min(width, height)
+            RelativeToDiagramWidthHeightMin = 4 };
+
         void setVisible( bool visible );
         bool isVisible() const;
 
@@ -79,6 +92,20 @@
         void setMarkerSize( const QSizeF& size );
         QSizeF markerSize() const;
 
+        /**
+         * With this method you can change the way the actual marker size is
+         * calculated.
+         *
+         * By default, the marker size is absolute (equiv. to @a mode = \
AbsoluteSize) +         * and specifies the size in pixels.
+         *
+         * In any other case, the size specified will be relative to what is
+         * specified in @a mode, e.g. the diagram's width. A marker width or
+         * height of 1.0 is then 100% of the diagram's width.
+         */
+        void setMarkerSizeMode( MarkerSizeMode mode );
+        MarkerSizeMode markerSizeMode() const;
+
         void setMarkerColor( const QColor& color );
         QColor markerColor() const;
 
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartPieDiagram.cpp \
#1186463:1186464 @@ -108,8 +108,9 @@
 {
 }
 
-void PieDiagram::resize ( const QSizeF& )
+void PieDiagram::resize ( const QSizeF& size )
 {
+    d->diagramSize = size;
 }
 
 static QRectF buildReferenceRect( const PolarCoordinatePlane* plane )
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartPlotter.cpp #1186463:1186464
@@ -371,6 +371,7 @@
 
 void Plotter::resize ( const QSizeF& size )
 {
+    d->diagramSize = size;
     d->setCompressorResolution( size, coordinatePlane() );
     setDataBoundariesDirty();
 }
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartPolarDiagram.cpp \
#1186463:1186464 @@ -232,8 +232,9 @@
     }
 }
 
-void PolarDiagram::resize ( const QSizeF& )
+void PolarDiagram::resize ( const QSizeF& size )
 {
+    d->diagramSize = size;
 }
 
 /*virtual*/
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartRadarDiagram.cpp \
#1186463:1186464 @@ -263,8 +263,9 @@
     }
 }
 
-void RadarDiagram::resize ( const QSizeF& )
+void RadarDiagram::resize ( const QSizeF& size )
 {
+    d->diagramSize = size;
 }
 
 /*virtual*/
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartRingDiagram.cpp \
#1186463:1186464 @@ -295,8 +295,9 @@
     }
 }
 
-void RingDiagram::resize( const QSizeF& )
+void RingDiagram::resize( const QSizeF& size )
 {
+    d->diagramSize = size;
 }
 
 /**


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

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