24 #include <KDChartWidget_p.h> 39 #include <KDABLibFakes> 45 Widget::Private::Private(
Widget * qq )
50 m_cartPlane( &m_chart ),
51 m_polPlane( &m_chart ),
58 layout.addWidget( &m_chart );
61 Widget::Private::~Private() {}
77 QWidget(parent), _d( new Private( this ) )
98 if ( ! checkDatasetWidth( 1 ) )
101 QStandardItemModel & model =
d->m_model;
103 justifyModelSize( data.size(), column + 1 );
105 for (
int i = 0; i < data.size(); ++i )
107 const QModelIndex index = model.index( i, column );
108 model.setData( index, QVariant( data[i] ), Qt::DisplayRole );
110 if ( ! title.isEmpty() )
111 model.setHeaderData( column, Qt::Horizontal, QVariant( title ) );
116 if ( ! checkDatasetWidth( 2 ))
119 QStandardItemModel & model =
d->m_model;
121 justifyModelSize( data.size(), (column + 1) * 2 );
123 for (
int i = 0; i < data.size(); ++i )
125 QModelIndex index = model.index( i, column * 2 );
126 model.setData( index, QVariant( data[i].first ), Qt::DisplayRole );
128 index = model.index( i, column * 2 + 1 );
129 model.setData( index, QVariant( data[i].second ), Qt::DisplayRole );
131 if ( ! title.isEmpty() ) {
132 model.setHeaderData( column, Qt::Horizontal, QVariant( title ) );
138 if ( ! checkDatasetWidth( 1 ) )
141 QStandardItemModel & model =
d->m_model;
143 justifyModelSize( row + 1, column + 1 );
145 const QModelIndex index = model.index( row, column );
146 model.setData( index, QVariant( data ), Qt::DisplayRole );
151 if ( ! checkDatasetWidth( 2 ))
154 QStandardItemModel & model =
d->m_model;
156 justifyModelSize( row + 1, (column + 1) * 2 );
158 QModelIndex index = model.index( row, column * 2 );
159 model.setData( index, QVariant( data.first ), Qt::DisplayRole );
161 index = model.index( row, column * 2 + 1 );
162 model.setData( index, QVariant( data.second ), Qt::DisplayRole );
171 d->usedDatasetWidth = 0;
179 d->m_chart.setGlobalLeading( left, top, right, bottom );
187 d->m_chart.setGlobalLeadingLeft( leading );
195 return d->m_chart.globalLeadingLeft();
203 d->m_chart.setGlobalLeadingTop( leading );
211 return d->m_chart.globalLeadingTop();
219 d->m_chart.setGlobalLeadingRight( leading );
227 return d->m_chart.globalLeadingRight();
235 d->m_chart.setGlobalLeadingBottom( leading );
243 return d->m_chart.globalLeadingBottom();
251 return d->m_chart.headerFooter();
259 return d->m_chart.headerFooters();
273 d->m_chart.addHeaderFooter( newHeader );
282 d->m_chart.addHeaderFooter( header );
288 d->m_chart.replaceHeaderFooter( header, oldHeader );
293 d->m_chart.takeHeaderFooter( header );
301 return d->m_chart.legend();
309 return d->m_chart.legends();
319 d->m_chart.addLegend( legend );
328 legend->setParent( &
d->m_chart );
329 d->m_chart.addLegend( legend );
335 legend->setParent( &
d->m_chart );
336 d->m_chart.replaceLegend( legend, oldLegend );
341 d->m_chart.takeLegend( legend );
347 qDebug() <<
"diagram(): coordinatePlane() was NULL";
379 return d->m_chart.coordinatePlane();
399 if ( chartType != oldType ) {
400 if ( chartType !=
NoType ) {
404 d->m_chart.takeCoordinatePlane( &
d->m_polPlane );
405 d->m_chart.addCoordinatePlane( &
d->m_cartPlane );
407 d->m_chart.replaceCoordinatePlane( &
d->m_cartPlane );
413 d->m_chart.takeCoordinatePlane( &
d->m_cartPlane );
414 d->m_chart.addCoordinatePlane( &
d->m_polPlane );
416 d->m_chart.replaceCoordinatePlane( &
d->m_polPlane );
420 switch ( chartType ) {
428 diag =
new Plotter( &
d->m_chart, &
d->m_cartPlane );
442 if ( diag != NULL ) {
450 newDiag->addAxis ( axis );
454 Q_FOREACH(
Legend* l,
d->m_chart.legends() ) {
466 if ( chartType !=
NoType ) {
467 if ( chartType != oldType || chartSubType !=
subType() )
469 d->m_chart.resize( size() );
473 template<
class DiagramType,
class Subtype >
476 if ( DiagramType *dia = qobject_cast< DiagramType * >( _dia ) ) {
506 Q_ASSERT_X (
false,
"Widget::setSubType",
"Sub-type not supported!" );
518 if ( qobject_cast< BarDiagram* >( dia ) )
520 else if ( qobject_cast< LineDiagram* >( dia ) )
522 else if ( qobject_cast< Plotter* >( dia ) )
524 else if ( qobject_cast< PieDiagram* >( dia ) )
526 else if ( qobject_cast< PolarDiagram* >( dia ) )
528 else if ( qobject_cast< RingDiagram* >( dia ) )
549 #define TEST_SUB_TYPE(DIAGRAM, INTERNALSUBTYPE, SUBTYPE) \ 551 if ( DIAGRAM && DIAGRAM->type() == INTERNALSUBTYPE ) \ 583 "Widget::subType",
"Chart type not supported!" );
593 bool Widget::checkDatasetWidth(
int width )
595 if ( width ==
diagram()->datasetDimension() )
597 d->usedDatasetWidth = width;
600 qDebug() <<
"The current diagram type doesn't support this data dimension.";
614 void Widget::justifyModelSize(
int rows,
int columns )
616 QAbstractItemModel & model =
d->m_model;
617 const int currentRows = model.rowCount();
618 const int currentCols = model.columnCount();
620 if ( currentCols < columns )
621 if ( ! model.insertColumns( currentCols, columns - currentCols ))
622 qDebug() <<
"justifyModelSize: could not increase model size.";
623 if ( currentRows < rows )
624 if ( ! model.insertRows( currentRows, rows - currentRows ))
625 qDebug() <<
"justifyModelSize: could not increase model size.";
627 Q_ASSERT( model.rowCount() >= rows );
628 Q_ASSERT( model.columnCount() >= columns );
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
void setDiagram(KDChart::AbstractDiagram *newDiagram)
A convenience method doing the same as replaceDiagram( newDiagram, 0 );.
void setPosition(Position position)
Specify the position of a non-floating legend.
PolarDiagram defines a common polar diagram.
BarDiagram defines a common bar diagram.
Plotter defines a diagram type plotting two-dimensional data.
virtual void replaceDiagram(AbstractDiagram *diagram, AbstractDiagram *oldDiagram=0)
Replaces the old diagram, or appends the diagram, it there is none yet.
AbstractDiagram defines the interface for diagram classes.
void setText(const QString &text)
The class for cartesian axes.
AbstractDiagram * diagram()
Legend defines the interface for the legend drawing class.
LineDiagram defines a common line diagram.
virtual KDChart::CartesianAxisList axes() const
#define KDAB_SET_OBJECT_NAME(x)
void setModel(QAbstractItemModel *model) override
Associate a model with the diagram.
Base class for diagrams based on a cartesian coordianate system.
Defines a position, using compass terminology.
PieDiagram defines a common pie diagram.
virtual void takeAxis(CartesianAxis *axis)
Removes the axis from the diagram, without deleting it.
RingDiagram defines a common ring diagram.