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

List:       kde-commits
Subject:    koffice/kchart
From:       Inge Wallin <inge () lysator ! liu ! se>
Date:       2006-03-02 21:57:40
Message-ID: 1141336660.100145.9609.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 515160 by ingwa:

Implement combined bars and lines charts.  

Thanks Karl-Heinz Zimmer for the code.



 M  +2 -2      kchartSubTypeChartPage.cc  
 M  +10 -4     kchart_params.cc  
 M  +9 -37     kchart_params.h  
 M  +30 -4     kchart_part.cc  


--- trunk/koffice/kchart/kchartSubTypeChartPage.cc #515159:515160
@@ -257,7 +257,7 @@
         }
     }
 
-    m_numLines->setValue( m_params->barlinesNumLines() );
+    m_numLines->setValue( m_params->barNumLines() );
 
     slotChangeSubType( m_params->barChartSubType() );
 }
@@ -292,7 +292,7 @@
     }
 
     // FIXME: Error controls.
-    m_params->setBarlinesNumLines( m_numLines->value() );
+    m_params->setBarNumLines( m_numLines->value() );
 }
 
 KChartLineSubTypeChartPage::KChartLineSubTypeChartPage( KChartParams* params,
--- trunk/koffice/kchart/kchart_params.cc #515159:515160
@@ -50,12 +50,12 @@
       m_part( _part )
 {
     // Default values for subtypes.
-    m_barlinesChartSubType = BarlinesNormal;
-    m_barlinesNumLines     = 1;
-
     m_firstRowAsLabel = false;
     m_firstColAsLabel = false;
 
+    // Default values for OpenDocument extensions.
+    m_barNumLines     = 0;
+
     m_dcop = 0;
     //dcopObject(); // build it
 }
@@ -67,6 +67,9 @@
 }
 
 
+// ----------------------------------------------------------------
+
+
 QString KChartParams::chartTypeToString( ChartType _type) const
 {
 #if 0
@@ -554,7 +557,7 @@
 	break;
 
     case Bar:
-        switch( m_barlinesChartSubType ) {
+        switch( barChartSubType() ) {
         case BarStacked:
             plotAreaStyle.addProperty( "chart:stacked", "true" );
             break;
@@ -563,6 +566,8 @@
             break;
         case BarNormal:
             break;
+	case BarMultiRows:
+	    break;
         }
         plotAreaStyle.addProperty( "chart:vertical", "false" ); // #### always?
         plotAreaStyle.addProperty( "chart:lines-used", 0 ); // #### for now
@@ -618,6 +623,7 @@
                                   KDChartAxisParams::AxisPos axisPos, const char* axisName ) const
 {
     bodyWriter->startElement( "chart:axis" );
+
     bodyWriter->addAttribute( "chart:dimension", axisName );
     bodyWriter->addAttribute( "chart:name", QCString( "primary-" ) + axisName );
 
--- trunk/koffice/kchart/kchart_params.h #515159:515160
@@ -53,10 +53,6 @@
 	Polar      = KDChartParams::Polar,
 	BoxWhisker = KDChartParams::BoxWhisker
 
-#if 0
-	// Only in KChart
-	BarLines
-#endif
     } ChartType;
 
     // Data direction
@@ -70,14 +66,10 @@
     ~KChartParams();
 
     // Reimplementation of selected KDChartParams methods
-    // FIXME: Enhance for BarLines
     ChartType  chartType() const            { return m_chartType; }
     void       setChartType( ChartType _type ) {
 	m_chartType = _type;
-#if 0
-	if ( _type != BarLines )
-#endif
-	    KDChartParams::setChartType( (KDChartParams::ChartType) _type );
+	KDChartParams::setChartType( (KDChartParams::ChartType) _type );
     }
 
     // Data in rows or columns.
@@ -96,42 +88,19 @@
     void       setFirstColAsLabel( bool _val );
 
     // ----------------------------------------------------------------
-    // BARLINES CHART-SPECIFIC
+    // BAR CHART EXTENSIONS TO SUPPORT OPENDOCUMENT
 
-    enum BarlinesChartSubType {
-	BarlinesNormal,
-	BarlinesStacked,
-	BarlinesPercent
-    };
-
-
 public slots:
-    void setBarlinesChartSubType( BarlinesChartSubType _barlinesChartSubType ) {
-	m_barlinesChartSubType = _barlinesChartSubType;
-	emit changed();
-    }
 
-    BarlinesChartSubType barlinesChartSubType() const {
-	return m_barlinesChartSubType;
-    }
-
-    void setBarlinesNumLines( int _numLines ) {
-	m_barlinesNumLines = _numLines;
+    void setBarNumLines( int _numLines ) {
+	m_barNumLines = _numLines;
 	emit changed();
     }
 
-    int barlinesNumLines() const {
-	return m_barlinesNumLines;
+    int barNumLines() const {
+	return m_barNumLines;
     }
 
-
-    static QString barlinesChartSubTypeToString( BarlinesChartSubType type );
-    static BarChartSubType stringToBarlinesChartSubType( const QString& string );
-
- private:
-    BarlinesChartSubType  m_barlinesChartSubType;
-    int                   m_barlinesNumLines;
-
     // ----------------------------------------------------------------
 
  public:
@@ -167,6 +136,9 @@
     bool           m_firstRowAsLabel;
     bool           m_firstColAsLabel;
 
+    // Extensions to support OpenDocument
+    int            m_barNumLines; // Number of lines in a bar chart.
+
     DCOPObject    *m_dcop;
 };
 
--- trunk/koffice/kchart/kchart_part.cc #515159:515160
@@ -396,8 +396,9 @@
 //
 void KChartPart::createDisplayData()
 {
-    int  rowOffset = 0;
-    int  colOffset = 0;
+    int  rowOffset   = 0;
+    int  colOffset   = 0;
+    int  numDatasets = 0;
 
     if ( m_params->firstRowAsLabel() )
 	rowOffset++;
@@ -413,8 +414,10 @@
     if (m_params->dataDirection() == KChartParams::DataRows) {
 	// Data is handled in rows.  This is the way KDChart works also.
 
-	m_displayData.expand( m_currentData.usedRows() - rowOffset,
+	numDatasets = m_currentData.usedRows() - rowOffset;
+	m_displayData.expand( numDatasets, 
 			      m_currentData.usedCols() - colOffset );
+
 	for (uint row = rowOffset; row < m_currentData.usedRows(); row++) {
 	    for (uint col = colOffset; col < m_currentData.usedCols(); col++) {
 		if ( m_currentData.cellContent( row, col,
@@ -433,7 +436,8 @@
 	// everything since KDChart wants its data in rows.
 
 	// Resize displayData so that the transposed data has room.
-	m_displayData.expand( m_currentData.usedCols() - colOffset,
+	numDatasets = m_currentData.usedCols() - colOffset;
+	m_displayData.expand( numDatasets,
 			      m_currentData.usedRows() - rowOffset );
 
 	// Copy data and transpose it.
@@ -450,6 +454,28 @@
 	}
     }
 
+    if ( m_params->chartType() == KChartParams::Bar
+	 && m_params->barNumLines() > 0 ) {
+
+        // Specify that we want to have an additional chart.
+        m_params->setAdditionalChartType( KDChartParams::Line );
+
+        const int numBarDatasets = numDatasets - m_params->barNumLines();
+
+        // assign the datasets to the charts: DataEntry, from, to, chart#
+        m_params->setChartSourceMode( KDChartParams::DataEntry,
+                                      0, numBarDatasets - 1,
+                                      0 ); // The bar chart
+        m_params->setChartSourceMode( KDChartParams::DataEntry,
+                                      numBarDatasets, numDatasets - 1,
+                                      1 ); // The line chart
+    } 
+    else {
+	// Otherwise we don't want any extra chart.
+        m_params->setAdditionalChartType( KDChartParams::NoType );
+    }
+
+
     // If this is a HiLo chart, we need to manually create the correct
     // values.  This is not done by KDChart.
     //
[prev in list] [next in list] [prev in thread] [next in thread] 

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