[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:       2008-11-09 22:49:14
Message-ID: 1226270954.144892.23402.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 882165 by ingwa:

add lots of comments and make TODO more up to date

 M  +8 -0      TODO  
 M  +38 -27    shape/ChartConfigWidget.cpp  
 M  +41 -27    shape/ChartTool.cpp  


--- trunk/koffice/kchart/TODO #882164:882165
@@ -43,6 +43,14 @@
   + If there are several chartshapes, then the tool doesn't adapt	JOSI
     when one shape is chosen and then another.
 
+* Smaller bugs
+  + When you double click on a chart, the tool option window adapts
+    to the data in the chart (e.g. the type, etc), but if the chart
+    is selected by the default tool and then the chart tool is 
+    activated, then this is not the case.  Note that if either the 
+    legend or plot area is selected by the default tool instead of 
+    the chart shape itself, it works again.
+
 * ChartShape
   + Handle all chart types                                              ----
      - bar                                                              done
--- trunk/koffice/kchart/shape/ChartConfigWidget.cpp #882164:882165
@@ -272,16 +272,20 @@
     // Quick-access settings
     d->tableEditorDialog = new QDialog( this );
     d->tableEditor.setupUi( d->tableEditorDialog );
+    // FIXME: Why does the tableView belong to the tool option window
+    //        instead of the data editor dialog?  There is no reason
+    //        for it to even exist outside the data editor /iw
     d->tableView = new ChartTableView;
     d->tableEditor.tableViewContainer->addWidget( d->tableView );
     d->tableEditorDialog->hide();
     
-    // We need only connect one of the data direction buttons, since
-    // they are mutually exclusive.
     connect( d->tableEditor.firstRowIsLabel,    SIGNAL( toggled( bool ) ),
              this,                              SIGNAL( firstRowIsLabelChanged( bool ) ) );
     connect( d->tableEditor.firstColumnIsLabel, SIGNAL( toggled( bool ) ),
              this,                              SIGNAL( firstColumnIsLabelChanged( bool ) ) );
+
+    // We need only connect one of the data direction buttons, since
+    // they are mutually exclusive.
     connect( d->tableEditor.dataSetsInRows, SIGNAL( toggled( bool ) ),
              this,                          SLOT( ui_dataSetsInRowsChanged( bool ) ) );
     
@@ -353,21 +357,23 @@
 
 void ChartConfigWidget::open( KoShape* shape )
 {
+    // Find the selected shape and adapt the tool option window to
+    // which of the subshapes of the chart widget that was actually
+    // selected.  Then select the tab depending on which one it was.
+
+    // First see if it was the chart shape itself.
     d->shape = dynamic_cast<ChartShape*>( shape );
-    
-
-    if ( !d->shape )
-    {
+    if ( !d->shape ) {
+	// If not, try to see if it was the plot area.
         PlotArea *plotArea = dynamic_cast<PlotArea*>( shape );
-        if ( plotArea )
-        {
+        if ( plotArea ) {
             d->shape = plotArea->parent();
             d->ui.tabWidget->setCurrentIndex( 0 );
         }
-        else
-        {
+        else {
+	    // And finally try if it was the legend.
             Legend *legend = dynamic_cast<Legend*>( shape );
-            Q_ASSERT( legend ); // No shape we support
+            Q_ASSERT( legend );
             d->shape = dynamic_cast<ChartShape*>( legend->parent() );
             Q_ASSERT( d->shape );
             d->ui.tabWidget->setCurrentIndex( 2 );
@@ -376,7 +382,7 @@
 
     KoChart::ChartModel *spreadSheetModel = qobject_cast<KoChart::ChartModel*>( d->shape->model() );
     TableModel *tableModel = qobject_cast<TableModel*>( d->shape->model() );
-    d->sourceIsSpreadSheet = spreadSheetModel != 0 && tableModel == 0;
+    d->sourceIsSpreadSheet = ( spreadSheetModel != 0 && tableModel == 0 );
     kDebug() << d->sourceIsSpreadSheet;
     
     // Update the axis titles
@@ -387,16 +393,18 @@
     //d->ui.legendTitle->setText( d->shape->legend()->title() );
     
     // Fill the data table
-    if ( d->sourceIsSpreadSheet )
-    {
+    if ( d->sourceIsSpreadSheet ) {
     	d->cellRegionStringValidator = new CellRegionStringValidator( spreadSheetModel );
     	d->cellRegionDialog.labelDataRegion->setValidator( d->cellRegionStringValidator );
     	d->cellRegionDialog.xDataRegion->setValidator( d->cellRegionStringValidator );
     	d->cellRegionDialog.yDataRegion->setValidator( d->cellRegionStringValidator );
     	d->cellRegionDialog.categoryDataRegion->setValidator( d->cellRegionStringValidator );
     	
+	// If the data source is external, the editData button opens a
+	// dialog to edit the data ranges instead of the data itself.
         d->ui.editData->setText( i18n( "Data Ranges..." ) );
-        connect( d->ui.editData, SIGNAL( clicked( bool ) ), &d->cellRegionDialog, SLOT( show() ) );
+        connect( d->ui.editData,       SIGNAL( clicked( bool ) ),
+		 &d->cellRegionDialog, SLOT( show() ) );
         connect( d->cellRegionDialog.xDataRegion, SIGNAL( editingFinished() ),
                  this, SLOT( ui_dataSetXDataRegionChanged() ) );
         connect( d->cellRegionDialog.yDataRegion, SIGNAL( editingFinished() ),
@@ -410,11 +418,12 @@
         connect( d->cellRegionDialog.dataSets, SIGNAL( currentIndexChanged( int ) ),
                  this, SLOT( ui_dataSetSelectionChanged_CellRegionDialog( int ) ) );
     }
-    else
-    {
+    else {
+	// This part is run when the data source is not external,
+	// i.e. the data is handled by the chart shape itself.
         d->tableView->setModel( d->shape->model() );
         connect( d->ui.editData, SIGNAL( clicked( bool ) ),
-                 this, SLOT( slotShowTableEditor( bool ) ) );
+                 this,           SLOT( slotShowTableEditor( bool ) ) );
     }
     
     update();
@@ -469,12 +478,14 @@
         type    = AreaChartType;
         subtype = PercentChartSubtype;
     }
-    
+
+    // also known as polar chart.
     else if ( action == d->radarChartAction ) {
         type = RadarChartType;
         subtype = NoChartSubtype;
     }
-    
+
+    // also known as pie chart
     else if ( action == d->circleChartAction ) {
         type = CircleChartType;
         subtype = NoChartSubtype;
@@ -509,8 +520,7 @@
     if ( d->selectedDataSet < 0 )
         return;
     
-    if ( !b )
-    {
+    if ( !b ) {
         DataSet *dataSet = d->dataSets[ d->selectedDataSet ];
         Q_ASSERT( dataSet );
         if ( !dataSet )
@@ -705,7 +715,7 @@
         d->axes = d->shape->plotArea()->axes();
         d->dataSetAxes.clear();
     
-        if ( !d->axes.isEmpty()    ) {
+        if ( !d->axes.isEmpty() ) {
             foreach ( Axis *axis, d->axes ) {
                 d->ui.axes->addItem( axis->titleText() );
                 if ( axis->dimension() == YAxisDimension ) {
@@ -1169,10 +1179,11 @@
 
 void ChartConfigWidget::ui_dataSetCustomDataRegionChanged()
 {
-	// Only makes sense when bubble charts are implemented
-	// TODO: ui_dataSetCustomDataRegionChanged
-	return;
-	/*
+    // Only makes sense when bubble charts are implemented
+    // TODO: ui_dataSetCustomDataRegionChanged
+    return;
+
+  /*
     // Check for valid index
     if ( d->selectedDataSet_CellRegionDialog < 0 )
         return;
--- trunk/koffice/kchart/shape/ChartTool.cpp #882164:882165
@@ -159,43 +159,54 @@
     event->ignore();
 }
 
+
 void ChartTool::activate( bool )
 {
     KoShape *selectedShape = 0;
     
-    // Get the shape that the tool is working on. 
+    // Get the chart shape that the tool is working on. 
     // Let d->shape point to it.
-    KoSelection *selection = m_canvas->shapeManager()->selection();
+    KoSelection  *selection = m_canvas->shapeManager()->selection();
     foreach ( KoShape *shape, selection->selectedShapes() ) {
+
+	// Find out which type of shape that the user clicked on.
+	// We support several here, since the chart shape is comprised
+	// of several subshapes (plotarea, legend)
         d->shape = dynamic_cast<ChartShape*>( shape );
         if ( !d->shape ) {
             PlotArea *plotArea = dynamic_cast<PlotArea*>( shape );
-            if ( plotArea )
-            {
+            if ( plotArea ) {
                 selectedShape = plotArea;
                 d->shape = plotArea->parent();
             }
-            else
-            {
+            else {
                 Legend *legend = dynamic_cast<Legend*>( shape );
-                if ( legend )
-                {
+                if ( legend ) {
                     selectedShape = legend;
                     d->shape = dynamic_cast<ChartShape*>( legend->parent() );
                 }
             }
         }
         
+	// Insert the values from the selected shape (note: not only
+	// chart shape, but also plotarea or legend) into the tool
+	// option widget.
         if ( selectedShape ) {
-            foreach (QWidget *w, optionWidgets().values()) {
+            foreach ( QWidget *w, optionWidgets().values() ) {
                 KoShapeConfigWidgetBase *widget = dynamic_cast<KoShapeConfigWidgetBase*>(w);
-                Q_ASSERT(widget);
-                if (widget)
+                Q_ASSERT( widget );
+                if ( widget )
                     widget->open( selectedShape );
             }
+
+	    // We support only one selected chart at the time, so once
+	    // we found one, we don't need to search for any more
+	    // among the selected shapes.
             break;
         }
     }
+
+    // If we couldn't determine a chart shape, then there is nothing to do.
     if ( !d->shape ) { // none found
         emit done();
         return;
@@ -211,6 +222,7 @@
     d->shape = 0;
 }
 
+
 void ChartTool::updateActions()
 {
 #if 0 // Taken from DivineProportion
@@ -230,22 +242,22 @@
     widget->open( d->shape );
 
     connect( widget, SIGNAL( dataDirectionChanged( Qt::Orientation ) ),
-             this,    SLOT( setDataDirection( Qt::Orientation ) ) );
+             this,   SLOT( setDataDirection( Qt::Orientation ) ) );
     connect( widget, SIGNAL( firstRowIsLabelChanged( bool ) ),
-             this,    SLOT( setFirstRowIsLabel( bool ) ) );
+             this,   SLOT( setFirstRowIsLabel( bool ) ) );
     connect( widget, SIGNAL( firstColumnIsLabelChanged( bool ) ),
-             this,    SLOT( setFirstColumnIsLabel( bool ) ) );
+             this,   SLOT( setFirstColumnIsLabel( bool ) ) );
     
     connect( widget, SIGNAL( dataSetXDataRegionChanged( DataSet*, const QString& ) ),
-    		 this,   SLOT( setDataSetXDataRegion( DataSet*, const QString& ) ) );
+	     this,   SLOT( setDataSetXDataRegion( DataSet*, const QString& ) ) );
     connect( widget, SIGNAL( dataSetYDataRegionChanged( DataSet*, const QString& ) ),
-    		 this,   SLOT( setDataSetYDataRegion( DataSet*, const QString& ) ) );
+	     this,   SLOT( setDataSetYDataRegion( DataSet*, const QString& ) ) );
     connect( widget, SIGNAL( dataSetCustomDataRegionChanged( DataSet*, const QString& ) ),
-    		 this,   SLOT( setDataSetCustomDataRegion( DataSet*, const QString& ) ) );
+	     this,   SLOT( setDataSetCustomDataRegion( DataSet*, const QString& ) ) );
     connect( widget, SIGNAL( dataSetLabelDataRegionChanged( DataSet*, const QString& ) ),
-    		 this,   SLOT( setDataSetLabelDataRegion( DataSet*, const QString& ) ) );
+	     this,   SLOT( setDataSetLabelDataRegion( DataSet*, const QString& ) ) );
     connect( widget, SIGNAL( dataSetCategoryDataRegionChanged( DataSet*, const QString& ) ),
-    		 this,   SLOT( setDataSetCategoryDataRegion( DataSet*, const QString& ) ) );
+	     this,   SLOT( setDataSetCategoryDataRegion( DataSet*, const QString& ) ) );
     connect( widget, SIGNAL( dataSetChartTypeChanged( DataSet*, ChartType ) ),
              this,   SLOT( setDataSetChartType( DataSet*, ChartType ) ) );
     connect( widget, SIGNAL( dataSetChartSubTypeChanged( DataSet*, ChartSubtype ) ),
@@ -357,35 +369,35 @@
 void ChartTool::setDataSetXDataRegion( DataSet *dataSet, const QString &region )
 {
 	if ( !dataSet )
-		return;
+	    return;
 	dataSet->setXDataRegionString( region );
 }
 
 void ChartTool::setDataSetYDataRegion( DataSet *dataSet, const QString &region )
 {
 	if ( !dataSet )
-		return;
+	    return;
 	dataSet->setYDataRegionString( region );
 }
 
 void ChartTool::setDataSetCustomDataRegion( DataSet *dataSet, const QString &region )
 {
 	if ( !dataSet )
-		return;
+	    return;
 	dataSet->setCustomDataRegionString( region );
 }
 
 void ChartTool::setDataSetLabelDataRegion( DataSet *dataSet, const QString &region )
 {
 	if ( !dataSet )
-		return;
+	    return;
 	dataSet->setLabelDataRegionString( region );
 }
 
 void ChartTool::setDataSetCategoryDataRegion( DataSet *dataSet, const QString &region )
 {
 	if ( !dataSet )
-		return;
+	    return;
 	dataSet->setCategoryDataRegionString( region );
 }
 
@@ -592,8 +604,10 @@
 }
 
 
-void ChartTool::addAxis( AxisPosition position, const QString& title ) {
+void ChartTool::addAxis( AxisPosition position, const QString& title )
+{
     Q_ASSERT( d->shape );
+
     Axis *axis = new Axis( d->shape->plotArea() );
     axis->setPosition( position );
     axis->setTitleText( title );
@@ -625,8 +639,8 @@
 
 void ChartTool::setAxisShowGridLines( Axis *axis, bool b )
 {
-	axis->setShowMajorGrid( b );
-	axis->setShowMinorGrid( b );
+    axis->setShowMajorGrid( b );
+    axis->setShowMinorGrid( b );
     d->shape->update();
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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