#include <KDChartWidget.h>
Inheritance diagram for KDChart::Widget:
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. | |
BarDiagram * | barDiagram () |
If the current diagram is a BarDiagram, it is returnd; otherwise 0 is returned. | |
AbstractCoordinatePlane * | coordinatePlane () |
Returns a pointer to the current coordinate plane. | |
AbstractDiagram * | diagram () |
Returns a pointer to the current diagram. | |
HeaderFooter * | firstHeaderFooter () |
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). | |
Legend * | legend () |
Returns the first of all legends. | |
LineDiagram * | lineDiagram () |
If the current diagram is a LineDiagram, it is returnd; otherwise 0 is returned. | |
PieDiagram * | pieDiagram () |
If the current diagram is a PieDiagram, it is returnd; otherwise 0 is returned. | |
PolarDiagram * | polarDiagram () |
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. | |
RingDiagram * | ringDiagram () |
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 |
|
Definition at line 203 of file KDChartWidget.h.
|
|
Sub type values, matching the values defines for the respective Diagram classes.
Definition at line 209 of file KDChartWidget.h.
|
|
Standard Qt-style Constructor. Creates a new widget with all data initialized empty.
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 } |
|
Destructor.
Definition at line 93 of file KDChartWidget.cpp.
00094 {
00095 delete _d; _d = 0;
00096 }
|
|
Adds an existing header / footer object.
Definition at line 286 of file KDChartWidget.cpp. References d, and KDChart::HeaderFooter::setParent().
|
|
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 } |
|
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 } |
|
Adds an empty legend on the given position.
Definition at line 322 of file KDChartWidget.cpp. References d, diagram(), and KDChart::Legend::setPosition().
|
|
Returns a list with all headers.
Definition at line 264 of file KDChartWidget.cpp. References d.
00265 { 00266 return d->m_chart.headerFooters(); 00267 } |
|
Returns a list with all legends.
Definition at line 314 of file KDChartWidget.cpp. References d.
00315 { 00316 return d->m_chart.legends(); 00317 } |
|
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 } |
|
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 } |
|
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 } |
|
Returns the first of all headers.
Definition at line 256 of file KDChartWidget.cpp. References d.
00257 { 00258 return d->m_chart.headerFooter(); 00259 } |
|
Returns the bottom leading (border).
Definition at line 248 of file KDChartWidget.cpp. References d.
00249 { 00250 return d->m_chart.globalLeadingBottom(); 00251 } |
|
Returns the left leading (border).
Definition at line 200 of file KDChartWidget.cpp. References d.
00201 { 00202 return d->m_chart.globalLeadingLeft(); 00203 } |
|
Returns the right leading (border).
Definition at line 232 of file KDChartWidget.cpp. References d.
00233 { 00234 return d->m_chart.globalLeadingRight(); 00235 } |
|
Returns the top leading (border).
Definition at line 216 of file KDChartWidget.cpp. References d.
00217 { 00218 return d->m_chart.globalLeadingTop(); 00219 } |
|
Returns the first of all legends.
Definition at line 306 of file KDChartWidget.cpp. References d.
00307 { 00308 return d->m_chart.legend(); 00309 } |
|
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 } |
|
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 } |
|
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 } |
|
Replaces the old header (or footer, resp.), or appends the new header or footer, it there is none yet.
Definition at line 292 of file KDChartWidget.cpp. References d, and KDChart::HeaderFooter::setParent().
|
|
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 } |
|
Resets all data.
Definition at line 175 of file KDChartWidget.cpp. References d.
|
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
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 } |
|
Sets the bottom leading (border).
Definition at line 240 of file KDChartWidget.cpp. References d.
00241 { 00242 d->m_chart.setGlobalLeadingBottom( leading ); 00243 } |
|
Sets the left leading (border).
Definition at line 192 of file KDChartWidget.cpp. References d.
00193 { 00194 d->m_chart.setGlobalLeadingLeft( leading ); 00195 } |
|
Sets the right leading (border).
Definition at line 224 of file KDChartWidget.cpp. References d.
00225 { 00226 d->m_chart.setGlobalLeadingRight( leading ); 00227 } |
|
Sets the top leading (border).
Definition at line 208 of file KDChartWidget.cpp. References d.
00209 { 00210 d->m_chart.setGlobalLeadingTop( leading ); 00211 } |
|
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.
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 } |
|
Returns the sub-type of the chart.
|
|
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.
Definition at line 298 of file KDChartWidget.cpp. References d.
00299 { 00300 d->m_chart.takeHeaderFooter( header ); 00301 } |
|
Definition at line 346 of file KDChartWidget.cpp. References d.
00347 { 00348 d->m_chart.takeLegend( legend ); 00349 } |
|
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 } |
|
Definition at line 96 of file KDChartWidget.h. |
|
Definition at line 216 of file KDChartWidget.h. |
|
Definition at line 96 of file KDChartWidget.h. |
|
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 } |
|
Definition at line 96 of file KDChartWidget.h. |