Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

KDChart::Widget Class Reference

#include <KDChartWidget.h>

Inheritance diagram for KDChart::Widget:

[legend]
Collaboration diagram for KDChart::Widget:
[legend]
List of all members.

Detailed Description

The KD Chart widget for usage without Model/View.

If you want to use KD Chart with Model/View, use KDChart::Chart instead.

Definition at line 63 of file KDChartWidget.h.

Public Types

enum  ChartType {
  NoType,
  Bar,
  Line,
  Pie,
  Ring,
  Polar
}
enum  SubType {
  Normal,
  Stacked,
  Percent,
  Rows
}
 Sub type values, matching the values defines for the respective Diagram classes. More...


Public Member Functions

void addHeaderFooter (HeaderFooter *header)
 Adds an existing header / footer object.

void addHeaderFooter (const QString &text, HeaderFooter::HeaderFooterType type, Position position)
 Adds a new header/footer with the given text to the position.

void addLegend (Legend *legend)
 Adds a new, already existing, legend.

void addLegend (Position position)
 Adds an empty legend on the given position.

QList< HeaderFooter * > allHeadersFooters ()
 Returns a list with all headers.

QList< Legend * > allLegends ()
 Returns a list with all legends.

BarDiagrambarDiagram ()
 If the current diagram is a BarDiagram, it is returnd; otherwise 0 is returned.

AbstractCoordinatePlanecoordinatePlane ()
 Returns a pointer to the current coordinate plane.

AbstractDiagramdiagram ()
 Returns a pointer to the current diagram.

HeaderFooterfirstHeaderFooter ()
 Returns the first of all headers.

int globalLeadingBottom () const
 Returns the bottom leading (border).

int globalLeadingLeft () const
 Returns the left leading (border).

int globalLeadingRight () const
 Returns the right leading (border).

int globalLeadingTop () const
 Returns the top leading (border).

Legendlegend ()
 Returns the first of all legends.

LineDiagramlineDiagram ()
 If the current diagram is a LineDiagram, it is returnd; otherwise 0 is returned.

PieDiagrampieDiagram ()
 If the current diagram is a PieDiagram, it is returnd; otherwise 0 is returned.

PolarDiagrampolarDiagram ()
 If the current diagram is a PolarDiagram, it is returnd; otherwise 0 is returned.

void replaceHeaderFooter (HeaderFooter *header, HeaderFooter *oldHeader=0)
 Replaces the old header (or footer, resp.), or appends the new header or footer, it there is none yet.

void replaceLegend (Legend *legend, Legend *oldLegend=0)
void resetData ()
 Resets all data.

RingDiagramringDiagram ()
 If the current diagram is a RingDiagram, it is returnd; otherwise 0 is returned.

void setDataCell (int row, int column, QPair< double, double > data)
 Sets the data for a given column using an (X, Y) QPair of doubles.

void setDataCell (int row, int column, double data)
 Sets the Y value data for a given cell.

void setDataset (int column, const QVector< QPair< double, double > > &data, const QString &title=QString())
 Sets the data in the given column using a QVector of QPairs of double for the (X, Y) values.

void setDataset (int column, const QVector< double > &data, const QString &title=QString())
 Sets the data in the given column using a QVector of double for the Y values.

void setGlobalLeadingBottom (int leading)
 Sets the bottom leading (border).

void setGlobalLeadingLeft (int leading)
 Sets the left leading (border).

void setGlobalLeadingRight (int leading)
 Sets the right leading (border).

void setGlobalLeadingTop (int leading)
 Sets the top leading (border).

void setSubType (SubType subType)
 Sets the type of the chart without changing the main type.

SubType subType () const
 Returns the sub-type of the chart.

void takeHeaderFooter (HeaderFooter *header)
 Remove the header (or footer, resp.) from the widget, without deleting it.

void takeLegend (Legend *legend)
ChartType type () const
 Returns the type of the chart.

 Widget (QWidget *parent=0)
 Standard Qt-style Constructor.

 ~Widget ()
 Destructor.


Public Attributes

public int int int bottom
public Q_SLOTS: void setGlobalLeading( int left
public int int right
public SubType subType = Normal )
public int top


Member Enumeration Documentation

enum KDChart::Widget::ChartType
 

Enumeration values:
NoType 
Bar 
Line 
Pie 
Ring 
Polar 

Definition at line 203 of file KDChartWidget.h.

00203 { NoType, Bar, Line, Pie, Ring, Polar };

enum KDChart::Widget::SubType
 

Sub type values, matching the values defines for the respective Diagram classes.

Enumeration values:
Normal 
Stacked 
Percent 
Rows 

Definition at line 209 of file KDChartWidget.h.

00209 { Normal, Stacked, Percent, Rows };


Constructor & Destructor Documentation

Widget::Widget QWidget parent = 0  )  [explicit]
 

Standard Qt-style Constructor.

Creates a new widget with all data initialized empty.

Parameters:
parent the widget parent; passed on to QWidget

Definition at line 82 of file KDChartWidget.cpp.

References Line.

00082                                 :
00083     QWidget(parent), _d( new Private( this ) )
00084 {
00085     // as default we have a cartesian coordinate plane ...
00086     // ... and a line diagram
00087     setType( Line );
00088 }

Widget::~Widget  ) 
 

Destructor.

Definition at line 93 of file KDChartWidget.cpp.

00094 {
00095     delete _d; _d = 0;
00096 }


Member Function Documentation

void Widget::addHeaderFooter HeaderFooter header  ) 
 

Adds an existing header / footer object.

See also:
replaceHeaderFooter, takeHeaderFooter

Definition at line 286 of file KDChartWidget.cpp.

References d, and KDChart::HeaderFooter::setParent().

00287 {
00288     header->setParent( &d->m_chart );
00289     d->m_chart.addHeaderFooter( header ); // we need this explicit call !
00290 }

void Widget::addHeaderFooter const QString &  text,
HeaderFooter::HeaderFooterType  type,
Position  position
 

Adds a new header/footer with the given text to the position.

Definition at line 272 of file KDChartWidget.cpp.

References d, KDChart::HeaderFooter::setPosition(), KDChart::TextLayoutItem::setText(), and KDChart::HeaderFooter::setType().

00275 {
00276     HeaderFooter* newHeader = new HeaderFooter( &d->m_chart );
00277     newHeader->setType( type );
00278     newHeader->setPosition( position );
00279     newHeader->setText( text );
00280     d->m_chart.addHeaderFooter( newHeader ); // we need this explicit call !
00281 }

void Widget::addLegend Legend legend  ) 
 

Adds a new, already existing, legend.

Definition at line 332 of file KDChartWidget.cpp.

References d, diagram(), and KDChart::Legend::setDiagram().

00333 {
00334     legend->setDiagram( diagram() );
00335     legend->setParent( &d->m_chart );
00336     d->m_chart.addLegend( legend );
00337 }

void Widget::addLegend Position  position  ) 
 

Adds an empty legend on the given position.

Definition at line 322 of file KDChartWidget.cpp.

References d, diagram(), and KDChart::Legend::setPosition().

00323 {
00324     Legend* legend = new Legend( diagram(), &d->m_chart );
00325     legend->setPosition( position );
00326     d->m_chart.addLegend( legend );
00327 }

QList< KDChart::HeaderFooter * > Widget::allHeadersFooters  ) 
 

Returns a list with all headers.

Definition at line 264 of file KDChartWidget.cpp.

References d.

00265 {
00266     return d->m_chart.headerFooters();
00267 }

QList< KDChart::Legend * > Widget::allLegends  ) 
 

Returns a list with all legends.

Definition at line 314 of file KDChartWidget.cpp.

References d.

00315 {
00316     return d->m_chart.legends();
00317 }

BarDiagram * Widget::barDiagram  ) 
 

If the current diagram is a BarDiagram, it is returnd; otherwise 0 is returned.

This function provides type-safe casting.

Definition at line 359 of file KDChartWidget.cpp.

References diagram().

00360 {
00361     return dynamic_cast<BarDiagram*>( diagram() );
00362 }

AbstractCoordinatePlane * Widget::coordinatePlane  ) 
 

Returns a pointer to the current coordinate plane.

Definition at line 380 of file KDChartWidget.cpp.

References d.

Referenced by diagram().

00381 {
00382     return d->m_chart.coordinatePlane();
00383 }

AbstractDiagram * Widget::diagram  ) 
 

Returns a pointer to the current diagram.

Definition at line 351 of file KDChartWidget.cpp.

References coordinatePlane(), and KDChart::AbstractCoordinatePlane::diagram().

Referenced by addLegend(), barDiagram(), lineDiagram(), pieDiagram(), polarDiagram(), replaceLegend(), ringDiagram(), and setSubType().

00352 {
00353     if ( coordinatePlane() == 0 )
00354         qDebug() << "diagram(): coordinatePlane() was NULL";
00355 
00356     return coordinatePlane()->diagram();
00357 }

KDChart::HeaderFooter * Widget::firstHeaderFooter  ) 
 

Returns the first of all headers.

Definition at line 256 of file KDChartWidget.cpp.

References d.

00257 {
00258     return d->m_chart.headerFooter();
00259 }

int Widget::globalLeadingBottom  )  const
 

Returns the bottom leading (border).

Definition at line 248 of file KDChartWidget.cpp.

References d.

00249 {
00250     return d->m_chart.globalLeadingBottom();
00251 }

int Widget::globalLeadingLeft  )  const
 

Returns the left leading (border).

Definition at line 200 of file KDChartWidget.cpp.

References d.

00201 {
00202     return d->m_chart.globalLeadingLeft();
00203 }

int Widget::globalLeadingRight  )  const
 

Returns the right leading (border).

Definition at line 232 of file KDChartWidget.cpp.

References d.

00233 {
00234     return d->m_chart.globalLeadingRight();
00235 }

int Widget::globalLeadingTop  )  const
 

Returns the top leading (border).

Definition at line 216 of file KDChartWidget.cpp.

References d.

00217 {
00218     return d->m_chart.globalLeadingTop();
00219 }

KDChart::Legend * Widget::legend  ) 
 

Returns the first of all legends.

Definition at line 306 of file KDChartWidget.cpp.

References d.

00307 {
00308     return d->m_chart.legend();
00309 }

LineDiagram * Widget::lineDiagram  ) 
 

If the current diagram is a LineDiagram, it is returnd; otherwise 0 is returned.

This function provides type-safe casting.

Definition at line 363 of file KDChartWidget.cpp.

References diagram().

00364 {
00365     return dynamic_cast<LineDiagram*>( diagram() );
00366 }

PieDiagram * Widget::pieDiagram  ) 
 

If the current diagram is a PieDiagram, it is returnd; otherwise 0 is returned.

This function provides type-safe casting.

Definition at line 367 of file KDChartWidget.cpp.

References diagram().

00368 {
00369     return dynamic_cast<PieDiagram*>( diagram() );
00370 }

PolarDiagram * Widget::polarDiagram  ) 
 

If the current diagram is a PolarDiagram, it is returnd; otherwise 0 is returned.

This function provides type-safe casting.

Definition at line 375 of file KDChartWidget.cpp.

References diagram().

00376 {
00377     return dynamic_cast<PolarDiagram*>( diagram() );
00378 }

void Widget::replaceHeaderFooter HeaderFooter header,
HeaderFooter oldHeader = 0
 

Replaces the old header (or footer, resp.), or appends the new header or footer, it there is none yet.

Parameters:
headerFooter The header or footer to be used instead of the old one. This parameter must not be zero, or the method will do nothing.
oldHeaderFooter The header or footer to be removed by the new one. This header or footer will be deleted automatically. If the parameter is omitted, the very first header or footer will be replaced. In case, there was no header and no footer yet, the new header or footer will just be added.
Note:
If you want to re-use the old header or footer, call takeHeaderFooter and addHeaderFooter, instead of using replaceHeaderFooter.
See also:
addHeaderFooter, takeHeaderFooter

Definition at line 292 of file KDChartWidget.cpp.

References d, and KDChart::HeaderFooter::setParent().

00293 {
00294     header->setParent( &d->m_chart );
00295     d->m_chart.replaceHeaderFooter( header, oldHeader );
00296 }

void Widget::replaceLegend Legend legend,
Legend oldLegend = 0
 

Definition at line 339 of file KDChartWidget.cpp.

References d, diagram(), and KDChart::Legend::setDiagram().

00340 {
00341     legend->setDiagram( diagram() );
00342     legend->setParent( &d->m_chart );
00343     d->m_chart.replaceLegend( legend, oldLegend );
00344 }

void Widget::resetData  ) 
 

Resets all data.

Definition at line 175 of file KDChartWidget.cpp.

References d.

00176 {
00177     d->m_model.clear();
00178     d->usedDatasetWidth = 0;
00179 }

RingDiagram * Widget::ringDiagram  ) 
 

If the current diagram is a RingDiagram, it is returnd; otherwise 0 is returned.

This function provides type-safe casting.

Definition at line 371 of file KDChartWidget.cpp.

References diagram().

00372 {
00373     return dynamic_cast<RingDiagram*>( diagram() );
00374 }

void Widget::setDataCell int  row,
int  column,
QPair< double, double >  data
 

Sets the data for a given column using an (X, Y) QPair of doubles.

Definition at line 156 of file KDChartWidget.cpp.

References d.

00157 {
00158     if ( ! checkDatasetWidth( 2 ))
00159         return;
00160 
00161     QStandardItemModel & model = d->m_model;
00162 
00163     justifyModelSize( row + 1, (column + 1) * 2 );
00164 
00165     QModelIndex index = model.index( row, column * 2 );
00166     model.setData( index, QVariant( data.first ), Qt::DisplayRole );
00167 
00168     index = model.index( row, column * 2 + 1 );
00169     model.setData( index, QVariant( data.second ), Qt::DisplayRole );
00170 }

void Widget::setDataCell int  row,
int  column,
double  data
 

Sets the Y value data for a given cell.

Definition at line 143 of file KDChartWidget.cpp.

References d.

00144 {
00145     if ( ! checkDatasetWidth( 1 ) )
00146         return;
00147 
00148     QStandardItemModel & model = d->m_model;
00149 
00150     justifyModelSize( row + 1, column + 1 );
00151 
00152     const QModelIndex index = model.index( row, column );
00153     model.setData( index, QVariant( data ), Qt::DisplayRole );
00154 }

void Widget::setDataset int  column,
const QVector< QPair< double, double > > &  data,
const QString &  title = QString()
 

Sets the data in the given column using a QVector of QPairs of double for the (X, Y) values.

Definition at line 120 of file KDChartWidget.cpp.

References d.

00121 {
00122     if ( ! checkDatasetWidth( 2 ))
00123         return;
00124 
00125     QStandardItemModel & model = d->m_model;
00126 
00127     justifyModelSize( data.size(), (column + 1) * 2 );
00128 
00129     for( int i = 0; i < data.size(); ++i )
00130     {
00131         QModelIndex index = model.index( i, column * 2 );
00132         model.setData( index, QVariant( data[i].first ), Qt::DisplayRole );
00133 
00134         index = model.index( i, column * 2 + 1 );
00135         model.setData( index, QVariant( data[i].second ), Qt::DisplayRole );
00136     }
00137     if ( ! title.isEmpty() ){
00138         model.setHeaderData( column * 2,   Qt::Horizontal, QVariant( title ) );
00139         model.setHeaderData( column * 2+1, Qt::Horizontal, QVariant( title ) );
00140     }
00141 }

void Widget::setDataset int  column,
const QVector< double > &  data,
const QString &  title = QString()
 

Sets the data in the given column using a QVector of double for the Y values.

Definition at line 102 of file KDChartWidget.cpp.

References d.

00103 {
00104     if ( ! checkDatasetWidth( 1 ) )
00105         return;
00106 
00107     QStandardItemModel & model = d->m_model;
00108 
00109     justifyModelSize( data.size(), column + 1 );
00110 
00111     for( int i = 0; i < data.size(); ++i )
00112     {
00113         const QModelIndex index = model.index( i, column );
00114         model.setData( index, QVariant( data[i] ), Qt::DisplayRole );
00115     }
00116     if ( ! title.isEmpty() )
00117         model.setHeaderData( column, Qt::Horizontal, QVariant( title ) );
00118 }

void Widget::setGlobalLeadingBottom int  leading  ) 
 

Sets the bottom leading (border).

Definition at line 240 of file KDChartWidget.cpp.

References d.

00241 {
00242     d->m_chart.setGlobalLeadingBottom( leading );
00243 }

void Widget::setGlobalLeadingLeft int  leading  ) 
 

Sets the left leading (border).

Definition at line 192 of file KDChartWidget.cpp.

References d.

00193 {
00194     d->m_chart.setGlobalLeadingLeft( leading );
00195 }

void Widget::setGlobalLeadingRight int  leading  ) 
 

Sets the right leading (border).

Definition at line 224 of file KDChartWidget.cpp.

References d.

00225 {
00226     d->m_chart.setGlobalLeadingRight( leading );
00227 }

void Widget::setGlobalLeadingTop int  leading  ) 
 

Sets the top leading (border).

Definition at line 208 of file KDChartWidget.cpp.

References d.

00209 {
00210     d->m_chart.setGlobalLeadingTop( leading );
00211 }

void Widget::setSubType SubType  subType  ) 
 

Sets the type of the chart without changing the main type.

Make sure to use a sub-type that matches the main type, so e.g. setting sub-type Rows makes sense for Bar charts only, and it will be ignored for all other chart types.

See also:
KDChartBarDiagram::BarType, KDChartLineDiagram::LineType

KDChartPieDiagram::PieType, KDChartRingDiagram::RingType

KDChartPolarDiagram::PolarType

Definition at line 462 of file KDChartWidget.cpp.

References diagram(), and SET_SUB_TYPE.

00463 {
00464     BarDiagram*  barDia  = qobject_cast< BarDiagram* >(   diagram() );
00465     LineDiagram* lineDia = qobject_cast< LineDiagram* >(  diagram() );
00466 
00467 //FIXME(khz): Add the impl for these chart types - or remove them from here:
00468 //    PieDiagram*   pieDia   = qobject_cast< PieDiagram* >(   diagram() );
00469 //    PolarDiagram* polarDia = qobject_cast< PolarDiagram* >( diagram() );
00470 //    RingDiagram*  ringDia  = qobject_cast< RingDiagram* >(  diagram() );
00471 
00472 #define SET_SUB_TYPE(DIAGRAM, SUBTYPE) \
00473 { \
00474     if( DIAGRAM ) \
00475         DIAGRAM->setType( SUBTYPE ); \
00476 }
00477     switch ( subType )
00478     {
00479         case Normal:
00480            SET_SUB_TYPE( barDia,  BarDiagram::Normal );
00481            SET_SUB_TYPE( lineDia, LineDiagram::Normal );
00482            break;
00483         case Stacked:
00484            SET_SUB_TYPE( barDia,  BarDiagram::Stacked );
00485            SET_SUB_TYPE( lineDia, LineDiagram::Stacked );
00486            break;
00487         case Percent:
00488            SET_SUB_TYPE( barDia,  BarDiagram::Percent );
00489            SET_SUB_TYPE( lineDia, LineDiagram::Percent );
00490            break;
00491         case Rows:
00492            SET_SUB_TYPE( barDia, BarDiagram::Rows );
00493            break;
00494         default:
00495            Q_ASSERT_X ( false,
00496                         "Widget::setSubType", "Sub-type not supported!" );
00497            break;
00498     }
00499 //    coordinatePlane()->show();
00500 }

SubType KDChart::Widget::subType  )  const
 

Returns the sub-type of the chart.

void Widget::takeHeaderFooter HeaderFooter header  ) 
 

Remove the header (or footer, resp.) from the widget, without deleting it.

The chart no longer owns the header or footer, so it is the caller's responsibility to delete the header or footer.

See also:
addHeaderFooter, replaceHeaderFooter

Definition at line 298 of file KDChartWidget.cpp.

References d.

00299 {
00300     d->m_chart.takeHeaderFooter( header );
00301 }

void Widget::takeLegend Legend legend  ) 
 

Definition at line 346 of file KDChartWidget.cpp.

References d.

00347 {
00348     d->m_chart.takeLegend( legend );
00349 }

Widget::ChartType Widget::type  )  const
 

Returns the type of the chart.

Definition at line 505 of file KDChartWidget.cpp.

References Bar, Line, NoType, Pie, Polar, and Ring.

00506 {
00507     // PENDING(christoph) save the type out-of-band:
00508     AbstractDiagram * const dia = const_cast<Widget*>( this )->diagram();
00509     if ( qobject_cast< BarDiagram* >( dia ) )
00510         return Bar;
00511     else if ( qobject_cast< LineDiagram* >( dia ) )
00512         return Line;
00513     else if( qobject_cast< PieDiagram* >( dia ) )
00514         return Pie;
00515     else if( qobject_cast< PolarDiagram* >( dia ) )
00516         return Polar;
00517     else if( qobject_cast< RingDiagram* >( dia ) )
00518         return Ring;
00519     else
00520         return NoType;
00521 }


Member Data Documentation

public int int int KDChart::Widget::bottom
 

Definition at line 96 of file KDChartWidget.h.

public KDChart::Widget::Q_SLOTS
 

Definition at line 216 of file KDChartWidget.h.

public int int KDChart::Widget::right
 

Definition at line 96 of file KDChartWidget.h.

Widget::SubType Widget::subType = Normal )
 

Definition at line 523 of file KDChartWidget.cpp.

00524 {
00525     // PENDING(christoph) save the type out-of-band:
00526     Widget::SubType retVal = Normal;
00527 
00528     AbstractDiagram * const dia = const_cast<Widget*>( this )->diagram();
00529     BarDiagram*  barDia  = qobject_cast< BarDiagram* >(   dia );
00530     LineDiagram* lineDia = qobject_cast< LineDiagram* >(  dia );
00531 
00532 //FIXME(khz): Add the impl for these chart types - or remove them from here:
00533 //    PieDiagram*   pieDia   = qobject_cast< PieDiagram* >(   diagram() );
00534 //    PolarDiagram* polarDia = qobject_cast< PolarDiagram* >( diagram() );
00535 //    RingDiagram*  ringDia  = qobject_cast< RingDiagram* >(  diagram() );
00536 
00537 #define TEST_SUB_TYPE(DIAGRAM, INTERNALSUBTYPE, SUBTYPE) \
00538 { \
00539     if( DIAGRAM && DIAGRAM->type() == INTERNALSUBTYPE ) \
00540         retVal = SUBTYPE; \
00541 }
00542     const Widget::ChartType mainType = type();
00543     switch ( mainType )
00544     {
00545         case Bar:
00546            TEST_SUB_TYPE( barDia, BarDiagram::Normal,  Normal );
00547            TEST_SUB_TYPE( barDia, BarDiagram::Stacked, Stacked );
00548            TEST_SUB_TYPE( barDia, BarDiagram::Percent, Percent );
00549            TEST_SUB_TYPE( barDia, BarDiagram::Rows,    Rows );
00550            break;
00551         case Line:
00552            TEST_SUB_TYPE( lineDia, LineDiagram::Normal,  Normal );
00553            TEST_SUB_TYPE( lineDia, LineDiagram::Stacked, Stacked );
00554            TEST_SUB_TYPE( lineDia, LineDiagram::Percent, Percent );
00555            break;
00556         case Pie:
00557            // no impl. yet
00558            break;
00559         case Polar:
00560            // no impl. yet
00561            break;
00562         case Ring:
00563            // no impl. yet
00564            break;
00565         default:
00566            Q_ASSERT_X ( false,
00567                         "Widget::subType", "Chart type not supported!" );
00568            break;
00569     }
00570     return retVal;
00571 }

public int KDChart::Widget::top
 

Definition at line 96 of file KDChartWidget.h.


The documentation for this class was generated from the following files:
Generated on Thu May 10 11:06:35 2007 for KD Chart 2 by doxygen 1.3.6