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

List:       kde-commits
Subject:    koffice/plugins/chartshape
From:       Johannes Simon <johannes.simon () gmail ! com>
Date:       2010-10-19 21:59:49
Message-ID: 20101019215949.8715FAC899 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1187622 by jsimon:

Provide a way to paint an axis line as well as specify a pen for this axis line.

 M  +4 -4      Axis.cpp  
 M  +1 -0      Axis.h  
 M  +4 -0      PlotArea.h  
 M  +17 -0     kdchart/src/KDChartCartesianAxis.cpp  
 M  +34 -4     kdchart/src/KDChartRulerAttributes.cpp  
 M  +29 -0     kdchart/src/KDChartRulerAttributes.h  


--- trunk/koffice/plugins/chartshape/Axis.cpp #1187621:1187622
@@ -957,12 +957,11 @@
 {
     d->position = position;
 
-    // FIXME: In KChart 2.1, we will have horizontal bar diagrams.
-    // That means that e.g. LeftAxisPosition != YAxisDimension!
+    bool chartIsVertical = d->plotArea->isVertical();
     if ( position == LeftAxisPosition || position == RightAxisPosition )
-        setDimension( YAxisDimension );
+        setDimension( chartIsVertical ? XAxisDimension : YAxisDimension );
     else if ( position == TopAxisPosition || position == BottomAxisPosition )
-        setDimension( XAxisDimension );
+        setDimension( chartIsVertical ? YAxisDimension : XAxisDimension );
 
     if ( position == LeftAxisPosition )
         d->title->rotate( -90 - d->title->rotation() );
@@ -1429,6 +1428,7 @@
 
         if ( axisElement.hasAttributeNS( KoXmlNS::chart, "dimension" ) ) {
             const QString dimension = axisElement.attributeNS( KoXmlNS::chart, \
"dimension", QString() ); +            // FIXME: position and dimension should be \
handled independently  if ( dimension == "x" )
                 setPosition( BottomAxisPosition );
             else if ( dimension == "y" )
--- trunk/koffice/plugins/chartshape/Axis.h #1187621:1187622
@@ -89,6 +89,7 @@
      */
     void setCategoryDataRegion( const CellRegion &region );
 	
+    // FIXME: Make setPosition() not call setDimension()
     void setPosition( AxisPosition position );
     void setTitleText( const QString &text );
     void setShowLabels( bool show );
--- trunk/koffice/plugins/chartshape/PlotArea.h #1187621:1187622
@@ -89,6 +89,10 @@
     /**
      * Determines whether x and y axis are swapped. Default is 'false'.
      * See chart:vertical attribute in ODF v1.2, $19.63
+     *
+     * FIXME: This is exactly the opposite of what ODF defines. ODF says
+     * vertical="true" is a regular bar chart, "false" a column chart.
+     * So this specifies whether the axis is *not* swapped.
      */
     bool isVertical() const;
     int gapBetweenBars() const;
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartCartesianAxis.cpp \
#1187621:1187622 @@ -582,6 +582,8 @@
 
     // - find the reference point at which to start drawing and the increment (line \
distance);  QPointF rulerRef;
+    // Point at the other end of the axis
+    QPointF rulerRef2;
     const QRect areaGeoRect( areaGeometry() );
     const QRect geoRect( geometry() );
     QRectF rulerRect;
@@ -591,27 +593,42 @@
     //for debugging: if( isAbscissa() \
                )ptr->drawRect(areaGeoRect.adjusted(0,0,-1,-1));
     //qDebug() << "         " << (isAbscissa() ? "Abscissa":"Ordinate") << "axis \
painting with geometry" << areaGeoRect;  
+    // The "major" ruler line perpendicular to all tick mark lines
+    QLineF rulerLine;
     // FIXME references are of course different for all locations:
     switch( position() )
     {
     case Top:
         rulerRef.setX( areaGeoRect.x() );
         rulerRef.setY( areaGeoRect.y() + areaGeoRect.height() );
+        rulerRef2 = rulerRef;
+        rulerRef2.rx() += areaGeoRect.width();
         break;
     case Bottom:
         rulerRef.setX( areaGeoRect.x() );
         rulerRef.setY( areaGeoRect.y() );
+        rulerRef2 = rulerRef;
+        rulerRef2.rx() += areaGeoRect.width();
         break;
     case Right:
         rulerRef.setX( areaGeoRect.x() );
         rulerRef.setY( areaGeoRect.y() + areaGeoRect.height() );
+        rulerRef2 = rulerRef;
+        rulerRef2.ry() -= areaGeoRect.height();
         break;
     case Left:
         rulerRef.setX( areaGeoRect.x() + areaGeoRect.width() );
         rulerRef.setY( areaGeoRect.y() + areaGeoRect.height() );
+        rulerRef2 = rulerRef;
+        rulerRef2.ry() -= areaGeoRect.height();
         break;
     }
 
+    if ( rulerAttr.showRulerLine() ) {
+        ptr->setPen( rulerAttr.pen() );
+        ptr->drawLine( QLineF( rulerRef, rulerRef2 ) );
+    }
+
     // set up the lines to paint:
 
     // set up a map of integer positions,
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartRulerAttributes.cpp \
#1187621:1187622 @@ -39,10 +39,14 @@
 public:
     Private();
 private:
+    QPen pen;
     QPen tickMarkPen;
     QPen majorTickMarkPen;
     QPen minorTickMarkPen;
     
+    bool showRulerLine;
+    
+    bool tickMarkPenIsSet;
     bool majorTickMarkPenIsSet;
     bool minorTickMarkPenIsSet;
 
@@ -58,11 +62,16 @@
     : tickMarkPen( QColor( 0x00, 0x00, 0x00 ) )
     , majorTickMarkPen( QColor( 0x00, 0x00, 0x00 ) )
     , minorTickMarkPen( QColor( 0x00, 0x00, 0x00 ) )
+    , pen( Qt::black )
 {
+    pen.setCapStyle( Qt::FlatCap );
     tickMarkPen.setCapStyle( Qt::FlatCap );
     majorTickMarkPen.setCapStyle( Qt::FlatCap );
     minorTickMarkPen.setCapStyle( Qt::FlatCap );
 
+    showRulerLine = false;
+
+    tickMarkPenIsSet = false;
     majorTickMarkPenIsSet = false;
     minorTickMarkPenIsSet = false;
 
@@ -83,14 +92,35 @@
 {
 }
 
+void RulerAttributes::setPen( const QPen& pen )
+{
+        d->pen = pen;
+}
+
+QPen RulerAttributes::pen() const
+{
+        return d->pen;
+}
+
+void RulerAttributes::setShowRulerLine( bool show )
+{
+    d->showRulerLine = show;
+}
+
+bool RulerAttributes::showRulerLine() const
+{
+    return d->showRulerLine;
+}
+
 void RulerAttributes::setTickMarkPen( const QPen& pen )
 {
 	d->tickMarkPen = pen;
+    d->tickMarkPenIsSet = true;
 }
 
 QPen RulerAttributes::tickMarkPen() const
 {
-	return d->tickMarkPen;
+    return d->tickMarkPenIsSet ? d->tickMarkPen : d->pen;
 }
 
 void RulerAttributes::setMajorTickMarkPen( const QPen& pen )
@@ -106,7 +136,7 @@
 
 QPen RulerAttributes::majorTickMarkPen() const
 {
-	return d->majorTickMarkPenIsSet ? d->majorTickMarkPen : d->tickMarkPen;
+    return d->majorTickMarkPenIsSet ? d->majorTickMarkPen : tickMarkPen();
 }
 
 void RulerAttributes::setMinorTickMarkPen( const QPen& pen )
@@ -122,7 +152,7 @@
 
 QPen RulerAttributes::minorTickMarkPen() const
 {
-	return d->minorTickMarkPenIsSet ? d->minorTickMarkPen : d->tickMarkPen;
+        return d->minorTickMarkPenIsSet ? d->minorTickMarkPen : tickMarkPen();
 }
 
 void RulerAttributes::setTickMarkPen( qreal value, const QPen& pen )
@@ -139,7 +169,7 @@
 		if ( qAbs( value - it.key() ) < std::numeric_limits< float >::epsilon() )
 			return it.value();
 	}
-	return d->tickMarkPen;
+        return tickMarkPen();
 }
 
 RulerAttributes::TickMarkerPensMap RulerAttributes::tickMarkPens() const
--- trunk/koffice/plugins/chartshape/kdchart/src/KDChartRulerAttributes.h \
#1187621:1187622 @@ -33,6 +33,10 @@
 
 /**
   * @brief A set of attributes controlling the appearance of axis rulers
+  *
+  * As the naming of this class suggests, it can not be used to modify the
+  * grid of an axis, see e.g. @a CartesianCoordinatePlane::gridAttributes()
+  * instead.
   */
 class KDCHART_EXPORT RulerAttributes
 {
@@ -44,6 +48,31 @@
     ~RulerAttributes();
     
     /**
+      * Sets the pen used to draw all axis elements. This can be overwritten
+      * for individual elements using e.g. @a setTickMarkPen().
+      *
+      * The default is a cosmetic black pen.
+      */
+    void setPen( const QPen& pen );
+    QPen pen() const;
+
+    /**
+      * Use this to specify if the axis line (the one perpendicular to the
+      * tick marks, reaching from one end of the axis to the other) is to be
+      * drawn or not.
+      *
+      * By default, the ruler line is not drawn.
+      *
+      * This line is drawn exactly where the first or last grid line is drawn,
+      * for the grid that has the same line orientation as the axis that these
+      * attributes belong to.
+      *
+      * Thus, by default you will see this grid line instead if it is drawn.
+      */
+    void setShowRulerLine( bool show );
+    bool showRulerLine() const;
+    
+    /**
       * Sets the pen used to draw the tick marks
       */
     void setTickMarkPen( const QPen& pen );


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

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