#include <KDChartChart>
Inheritance diagram for KDChart::Chart:
The Chart class represents a drawing consisting of one or more diagrams and various optional elements such as legends, axes, text boxes, headers or footers. It takes ownership of all these elements when they are assigned to it. Each diagram is associated with a coordinate plane, of which the chart can have more than one. The coordinate planes (and thus the associated diagrams) can be layed out in various ways.
The Chart class makes heavy use of the Qt Interview framework for model/view programming, and thus requires data to be presented to it in a QAbstractItemModel compatible way. For many simple charts, especially if the visualized data is static, KDChart::Widget provides an abstracted interface, that hides the complexity of Interview to a large extent.
Definition at line 72 of file KDChartChart.h.
Public Member Functions | |
void | addCoordinatePlane (AbstractCoordinatePlane *plane) |
Adds a coordinate plane to the chart. | |
void | addHeaderFooter (HeaderFooter *headerFooter) |
Adds a header or a footer to the chart. | |
void | addLegend (Legend *legend) |
Add the given legend to the chart. | |
BackgroundAttributes | backgroundAttributes () const |
Chart (QWidget *parent=0) | |
AbstractCoordinatePlane * | coordinatePlane () |
Each chart must have at least one coordinate plane. | |
QLayout * | coordinatePlaneLayout () |
CoordinatePlaneList | coordinatePlanes () |
The list of coordinate planes. | |
FrameAttributes | frameAttributes () const |
int | globalLeadingBottom () const |
The padding between the start of the widget and the start of the area that is used for drawing at the bottom. | |
int | globalLeadingLeft () const |
The padding between the start of the widget and the start of the area that is used for drawing on the left. | |
int | globalLeadingRight () const |
The padding between the start of the widget and the start of the area that is used for drawing on the right. | |
int | globalLeadingTop () const |
The padding between the start of the widget and the start of the area that is used for drawing at the top. | |
HeaderFooter * | headerFooter () |
The first header or footer of the chart. | |
HeaderFooterList | headerFooters () |
The list of headers and footers associated with the chart. | |
Legend * | legend () |
The first legend of the chart or 0 if there was none added to the chart. | |
LegendList | legends () |
The list of all legends associated with the chart. | |
void | paint (QPainter *painter, const QRect &target) |
Paints all the contents of the chart. | |
void | reLayoutFloatingLegends () |
void | replaceCoordinatePlane (AbstractCoordinatePlane *plane, AbstractCoordinatePlane *oldPlane=0) |
Replaces the old coordinate plane, or appends the plane, it there is none yet. | |
void | replaceHeaderFooter (HeaderFooter *headerFooter, HeaderFooter *oldHeaderFooter=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) |
Replaces the old legend, or appends the new legend, it there is none yet. | |
void | setBackgroundAttributes (const BackgroundAttributes &a) |
Specify the background attributes to be used, by default there is no background. | |
void | setCoordinatePlaneLayout (QLayout *layout) |
void | setFrameAttributes (const FrameAttributes &a) |
Specify the frame attributes to be used, by default is it a thin black line. | |
void | setGlobalLeading (int left, int top, int right, int bottom) |
Set the padding between the margin of the widget and the area that the contents are drawn into. | |
void | setGlobalLeadingBottom (int leading) |
Set the padding between the start of the widget and the start of the area that is used for drawing on the bottom. | |
void | setGlobalLeadingLeft (int leading) |
Set the padding between the start of the widget and the start of the area that is used for drawing on the left. | |
void | setGlobalLeadingRight (int leading) |
Set the padding between the start of the widget and the start of the area that is used for drawing on the right. | |
void | setGlobalLeadingTop (int leading) |
Set the padding between the start of the widget and the start of the area that is used for drawing at the top. | |
void | takeCoordinatePlane (AbstractCoordinatePlane *plane) |
Removes the coordinate plane from the chart, without deleting it. | |
void | takeHeaderFooter (HeaderFooter *headerFooter) |
Removes the header (or footer, resp.) from the chart, without deleting it. | |
void | takeLegend (Legend *legend) |
Removes the legend from the chart, without deleting it. | |
~Chart () | |
Public Attributes | |
Q_SIGNALS | __pad0__: void propertiesChanged() |
Protected Member Functions | |
void | mousePressEvent (QMouseEvent *event) |
reimp | |
void | paintEvent (QPaintEvent *event) |
Draws the background and frame, then calls paint(). | |
void | resizeEvent (QResizeEvent *event) |
Adjusts the internal layout when the chart is resized. |
|
Definition at line 781 of file KDChartChart.cpp. References addCoordinatePlane(), setFrameAttributes(), KDChart::FrameAttributes::setPadding(), KDChart::FrameAttributes::setPen(), and KDChart::FrameAttributes::setVisible().
00782 : QWidget ( parent ) 00783 , _d( new Private( this ) ) 00784 { 00785 #if defined KDAB_EVAL 00786 EvalDialog::checkEvalLicense( "KD Chart" ); 00787 #endif 00788 00789 FrameAttributes frameAttrs; 00790 frameAttrs.setVisible( true ); 00791 frameAttrs.setPen( QPen( Qt::black ) ); 00792 frameAttrs.setPadding( 1 ); 00793 setFrameAttributes( frameAttrs ); 00794 00795 addCoordinatePlane( new CartesianCoordinatePlane ( this ) ); 00796 } |
|
Definition at line 798 of file KDChartChart.cpp.
00799 {
00800 delete _d;
00801 }
|
|
Adds a coordinate plane to the chart. The chart takes ownership.
Definition at line 846 of file KDChartChart.cpp. References d, and KDChart::AbstractCoordinatePlane::setParent(). Referenced by Chart(), and replaceCoordinatePlane().
00847 { 00848 connect( plane, SIGNAL( destroyedCoordinatePlane( AbstractCoordinatePlane* ) ), 00849 d, SLOT( slotUnregisterDestroyedPlane( AbstractCoordinatePlane* ) ) ); 00850 connect( plane, SIGNAL( needUpdate() ), this, SLOT( update() ) ); 00851 connect( plane, SIGNAL( needRelayout() ), d, SLOT( slotRelayout() ) ) ; 00852 connect( plane, SIGNAL( needLayoutPlanes() ), d, SLOT( slotLayoutPlanes() ) ) ; 00853 connect( plane, SIGNAL( propertiesChanged() ),this, SIGNAL( propertiesChanged() ) ); 00854 d->coordinatePlanes.append( plane ); 00855 plane->setParent( this ); 00856 d->slotLayoutPlanes(); 00857 } |
|
Adds a header or a footer to the chart. The chart takes ownership.
Definition at line 1036 of file KDChartChart.cpp. References d, and KDChart::HeaderFooter::setParent(). Referenced by replaceHeaderFooter().
01037 { 01038 d->headerFooters.append( headerFooter ); 01039 headerFooter->setParent( this ); 01040 connect( headerFooter, SIGNAL( destroyedHeaderFooter( HeaderFooter* ) ), 01041 d, SLOT( slotUnregisterDestroyedHeaderFooter( HeaderFooter* ) ) ); 01042 connect( headerFooter, SIGNAL( positionChanged( HeaderFooter* ) ), 01043 d, SLOT( slotRelayout() ) ); 01044 d->slotRelayout(); 01045 } |
|
Add the given legend to the chart. The chart takes ownership.
Definition at line 1089 of file KDChartChart.cpp. References d, KDChart::TextAttributes::fontSize(), KDChart::TextAttributes::setFontSize(), KDChart::Legend::setReferenceArea(), KDChart::Measure::setRelativeMode(), KDChart::Legend::setTextAttributes(), KDChart::Legend::setTitleTextAttributes(), KDChart::Measure::setValue(), KDChart::Legend::setVisible(), KDChart::Legend::textAttributes(), and KDChart::Legend::titleTextAttributes(). Referenced by replaceLegend().
01090 { 01091 if( ! legend ) return; 01092 01093 //qDebug() << "adding the legend"; 01094 d->legends.append( legend ); 01095 legend->setParent( this ); 01096 01097 TextAttributes textAttrs( legend->textAttributes() ); 01098 01099 KDChart::Measure measure( textAttrs.fontSize() ); 01100 measure.setRelativeMode( this, KDChartEnums::MeasureOrientationMinimum ); 01101 measure.setValue( 20 ); 01102 textAttrs.setFontSize( measure ); 01103 legend->setTextAttributes( textAttrs ); 01104 01105 textAttrs = legend->titleTextAttributes(); 01106 measure.setRelativeMode( this, KDChartEnums::MeasureOrientationMinimum ); 01107 measure.setValue( 24 ); 01108 textAttrs.setFontSize( measure ); 01109 01110 legend->setTitleTextAttributes( textAttrs ); 01111 01112 legend->setReferenceArea( this ); 01113 01114 /* 01115 future: Use relative sizes for the markers too! 01116 01117 const uint nMA = Legend::datasetCount(); 01118 for( uint iMA = 0; iMA < nMA; ++iMA ){ 01119 MarkerAttributes ma( legend->markerAttributes( iMA ) ); 01120 ma.setMarkerSize( ... ) 01121 legend->setMarkerAttributes( iMA, ma ) 01122 } 01123 */ 01124 01125 connect( legend, SIGNAL( destroyedLegend( Legend* ) ), 01126 d, SLOT( slotUnregisterDestroyedLegend( Legend* ) ) ); 01127 connect( legend, SIGNAL( positionChanged( AbstractAreaWidget* ) ), 01128 d, SLOT( slotLayoutPlanes() ) ); //slotRelayout() ) ); 01129 connect( legend, SIGNAL( propertiesChanged() ),this, SIGNAL( propertiesChanged() ) ); 01130 legend->setVisible( true ); 01131 d->slotRelayout(); 01132 } |
|
Definition at line 820 of file KDChartChart.cpp. References d.
00821 { 00822 return d->backgroundAttributes; 00823 } |
|
Each chart must have at least one coordinate plane. Initially a default CartesianCoordinatePlane is created. Use replaceCoordinatePlane() to replace it with a different one, such as a PolarCoordinatePlane.
Definition at line 830 of file KDChartChart.cpp. References d.
|
|
Definition at line 825 of file KDChartChart.cpp. References d.
00826 { 00827 return d->planesLayout; 00828 } |
|
The list of coordinate planes.
Definition at line 841 of file KDChartChart.cpp. References KDChart::CoordinatePlaneList, and d.
00842 { 00843 return d->coordinatePlanes; 00844 } |
|
Definition at line 810 of file KDChartChart.cpp. References d.
00811 { 00812 return d->frameAttributes; 00813 } |
|
The padding between the start of the widget and the start of the area that is used for drawing at the bottom.
Definition at line 935 of file KDChartChart.cpp. References d.
00936 { 00937 return d->globalLeadingBottom; 00938 } |
|
The padding between the start of the widget and the start of the area that is used for drawing on the left.
Definition at line 902 of file KDChartChart.cpp. References d.
00903 { 00904 return d->globalLeadingLeft; 00905 } |
|
The padding between the start of the widget and the start of the area that is used for drawing on the right.
Definition at line 924 of file KDChartChart.cpp. References d.
00925 { 00926 return d->globalLeadingRight; 00927 } |
|
The padding between the start of the widget and the start of the area that is used for drawing at the top.
Definition at line 913 of file KDChartChart.cpp. References d.
00914 { 00915 return d->globalLeadingTop; 00916 } |
|
The first header or footer of the chart. By default there is none.
Definition at line 1074 of file KDChartChart.cpp. References d.
|
|
The list of headers and footers associated with the chart.
Definition at line 1083 of file KDChartChart.cpp. References d, and KDChart::HeaderFooterList.
01084 { 01085 return d->headerFooters; 01086 } |
|
The first legend of the chart or 0 if there was none added to the chart.
Definition at line 1161 of file KDChartChart.cpp. References d. Referenced by paint(), and reLayoutFloatingLegends().
|
|
The list of all legends associated with the chart.
Definition at line 1171 of file KDChartChart.cpp. References d, and KDChart::LegendList.
01172 { 01173 return d->legends; 01174 } |
|
reimp
Definition at line 1177 of file KDChartChart.cpp. References d, KDChart::AbstractCoordinatePlane::diagram(), KDChart::AbstractCoordinatePlane::diagrams(), KDChart::AbstractCoordinatePlane::geometry(), and KDChart::AbstractCoordinatePlane::mousePressEvent().
01178 { 01179 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ) { 01180 if ( plane->geometry().contains( event->pos() ) ) { 01181 if ( plane->diagrams().size() > 0 ) { 01182 QPoint pos = plane->diagram()->mapFromGlobal( event->globalPos() ); 01183 QMouseEvent ev( QEvent::MouseButtonPress, pos, event->globalPos(), 01184 event->button(), event->buttons(), 01185 event->modifiers() ); 01186 plane->mousePressEvent( &ev ); 01187 } 01188 } 01189 } 01190 } |
|
Paints all the contents of the chart. Use this method, to make KDChart draw into your QPainter.
Definition at line 940 of file KDChartChart.cpp. References d, legend(), and KDChart::AbstractAreaWidget::paintIntoRect().
00941 { 00942 if( target.isEmpty() || !painter ) return; 00943 //qDebug() << "Chart::paint( ..," << target << ")"; 00944 00945 GlobalMeasureScaling::instance()->setFactors( 00946 static_cast<qreal>(target.width()) / 00947 static_cast<qreal>(geometry().size().width()), 00948 static_cast<qreal>(target.height()) / 00949 static_cast<qreal>(geometry().size().height()) ); 00950 00951 if( target.size() != d->currentLayoutSize ){ 00952 d->resizeLayout( target.size() ); 00953 } 00954 const QPoint translation = target.topLeft(); 00955 painter->translate( translation ); 00956 00957 d->paintAll( painter ); 00958 00959 // for debugging: 00960 //painter->setPen(QPen(Qt::blue, 8)); 00961 //painter->drawRect(target.adjusted(12,12,-12,-12)); 00962 00963 KDAB_FOREACH( Legend *legend, d->legends ) { 00964 const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide); 00965 if ( !hidden ) { 00966 //qDebug() << "painting legend at " << legend->geometry(); 00967 legend->paintIntoRect( *painter, legend->geometry() ); 00968 //testing: 00969 //legend->paintIntoRect( *painter, legend->geometry().adjusted(-100,0,-100,0) ); 00970 } 00971 } 00972 00973 painter->translate( -translation.x(), -translation.y() ); 00974 00975 GlobalMeasureScaling::instance()->resetFactors(); 00976 00977 //qDebug() << "KDChart::Chart::paint() done.\n"; 00978 } |
|
Draws the background and frame, then calls paint(). In most cases there is no need to override this method in a derived class, but if you do, do not forget to call paint().
Definition at line 1022 of file KDChartChart.cpp. References d, and reLayoutFloatingLegends().
01023 { 01024 QPainter painter( this ); 01025 01026 if( size() != d->currentLayoutSize ){ 01027 d->resizeLayout( size() ); 01028 reLayoutFloatingLegends(); 01029 } 01030 01031 //FIXME(khz): Paint the background/frame too! 01032 // (can we derive Chart from AreaWidget ??) 01033 d->paintAll( &painter ); 01034 } |
|
Definition at line 990 of file KDChartChart.cpp. References KDChart::RelativePosition::alignment(), KDChart::RelativePosition::calculatedPoint(), d, KDChart::Legend::floatingPosition(), KDChart::Position::isFloating(), legend(), KDChart::Legend::position(), and KDChart::Legend::sizeHint(). Referenced by paintEvent(), and resizeEvent().
00991 { 00992 KDAB_FOREACH( Legend *legend, d->legends ) { 00993 const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide); 00994 if ( legend->position().isFloating() && !hidden ){ 00995 // resize the legend 00996 const QSize legendSize( legend->sizeHint() ); 00997 legend->setGeometry( QRect( legend->geometry().topLeft(), legendSize ) ); 00998 // find the legends corner point (reference point plus any paddings) 00999 const RelativePosition relPos( legend->floatingPosition() ); 01000 QPointF pt( relPos.calculatedPoint( size() ) ); 01001 qDebug() << pt; 01002 // calculate the legend's top left point 01003 const Qt::Alignment alignTopLeft = Qt::AlignBottom | Qt::AlignLeft; 01004 if( (relPos.alignment() & alignTopLeft) != alignTopLeft ){ 01005 if( relPos.alignment() & Qt::AlignRight ) 01006 pt.rx() -= legendSize.width(); 01007 else if( relPos.alignment() & Qt::AlignHCenter ) 01008 pt.rx() -= 0.5 * legendSize.width(); 01009 01010 if( relPos.alignment() & Qt::AlignBottom ) 01011 pt.ry() -= legendSize.height(); 01012 else if( relPos.alignment() & Qt::AlignVCenter ) 01013 pt.ry() -= 0.5 * legendSize.height(); 01014 } 01015 qDebug() << pt << endl; 01016 legend->move( static_cast<int>(pt.x()), static_cast<int>(pt.y()) ); 01017 } 01018 } 01019 } |
|
Replaces the old coordinate plane, or appends the plane, it there is none yet.
Definition at line 859 of file KDChartChart.cpp. References addCoordinatePlane(), d, and takeCoordinatePlane().
00861 { 00862 if( plane && oldPlane_ != plane ){ 00863 AbstractCoordinatePlane* oldPlane = oldPlane_; 00864 if( d->coordinatePlanes.count() ){ 00865 if( ! oldPlane ) 00866 oldPlane = d->coordinatePlanes.first(); 00867 takeCoordinatePlane( oldPlane ); 00868 } 00869 delete oldPlane; 00870 addCoordinatePlane( plane ); 00871 } 00872 } |
|
Replaces the old header (or footer, resp.), or appends the new header or footer, it there is none yet.
Definition at line 1047 of file KDChartChart.cpp. References addHeaderFooter(), d, and takeHeaderFooter().
01049 { 01050 if( headerFooter && oldHeaderFooter_ != headerFooter ){ 01051 HeaderFooter* oldHeaderFooter = oldHeaderFooter_; 01052 if( d->headerFooters.count() ){ 01053 if( ! oldHeaderFooter ) 01054 oldHeaderFooter = d->headerFooters.first(); 01055 takeHeaderFooter( oldHeaderFooter ); 01056 } 01057 delete oldHeaderFooter; 01058 addHeaderFooter( headerFooter ); 01059 } 01060 } |
|
Replaces the old legend, or appends the new legend, it there is none yet.
Definition at line 1135 of file KDChartChart.cpp. References addLegend(), d, and takeLegend().
01136 { 01137 if( legend && oldLegend_ != legend ){ 01138 Legend* oldLegend = oldLegend_; 01139 if( d->legends.count() ){ 01140 if( ! oldLegend ) 01141 oldLegend = d->legends.first(); 01142 takeLegend( oldLegend ); 01143 } 01144 delete oldLegend; 01145 addLegend( legend ); 01146 } 01147 } |
|
Adjusts the internal layout when the chart is resized.
Definition at line 980 of file KDChartChart.cpp. References d, reLayoutFloatingLegends(), and KDChart::AbstractCoordinatePlane::setGridNeedsRecalculate().
00981 { 00982 d->resizeLayout( size() ); 00983 KDAB_FOREACH( AbstractCoordinatePlane* plane, d->coordinatePlanes ){ 00984 plane->setGridNeedsRecalculate(); 00985 } 00986 reLayoutFloatingLegends(); 00987 } |
|
Specify the background attributes to be used, by default there is no background. To set a light blue background, you could do something like this:
Definition at line 815 of file KDChartChart.cpp. References d.
00816 { 00817 d->backgroundAttributes = a; 00818 } |
|
|
|
Specify the frame attributes to be used, by default is it a thin black line. To hide the frame line, you could do something like this:
Definition at line 805 of file KDChartChart.cpp. References d. Referenced by Chart().
00806 { 00807 d->frameAttributes = a; 00808 } |
|
Set the padding between the margin of the widget and the area that the contents are drawn into.
Definition at line 887 of file KDChartChart.cpp. References d, setGlobalLeadingBottom(), setGlobalLeadingLeft(), setGlobalLeadingRight(), and setGlobalLeadingTop().
00888 { 00889 setGlobalLeadingLeft( left ); 00890 setGlobalLeadingTop( top ); 00891 setGlobalLeadingRight( right ); 00892 setGlobalLeadingBottom( bottom ); 00893 d->slotRelayout(); 00894 } |
|
Set the padding between the start of the widget and the start of the area that is used for drawing on the bottom.
Definition at line 929 of file KDChartChart.cpp. References d. Referenced by setGlobalLeading().
|
|
Set the padding between the start of the widget and the start of the area that is used for drawing on the left.
Definition at line 896 of file KDChartChart.cpp. References d. Referenced by setGlobalLeading().
|
|
Set the padding between the start of the widget and the start of the area that is used for drawing on the right.
Definition at line 918 of file KDChartChart.cpp. References d. Referenced by setGlobalLeading().
|
|
Set the padding between the start of the widget and the start of the area that is used for drawing at the top.
Definition at line 907 of file KDChartChart.cpp. References d. Referenced by setGlobalLeading().
|
|
Removes the coordinate plane from the chart, without deleting it. The chart no longer owns the plane, so it is the caller's responsibility to delete the plane.
Definition at line 874 of file KDChartChart.cpp. References d, KDChart::AbstractLayoutItem::removeFromParentLayout(), and KDChart::AbstractCoordinatePlane::setParent(). Referenced by replaceCoordinatePlane().
00875 { 00876 const int idx = d->coordinatePlanes.indexOf( plane ); 00877 if( idx != -1 ){ 00878 d->coordinatePlanes.takeAt( idx ); 00879 disconnect( plane, SIGNAL( destroyedCoordinatePlane( AbstractCoordinatePlane* ) ), 00880 d, SLOT( slotUnregisterDestroyedPlane( AbstractCoordinatePlane* ) ) ); 00881 plane->removeFromParentLayout(); 00882 plane->setParent( 0 ); 00883 } 00884 d->slotLayoutPlanes(); 00885 } |
|
Removes the header (or footer, resp.) from the chart, 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 1062 of file KDChartChart.cpp. References d, and KDChart::HeaderFooter::setParent(). Referenced by replaceHeaderFooter().
01063 { 01064 const int idx = d->headerFooters.indexOf( headerFooter ); 01065 if( idx != -1 ){ 01066 d->headerFooters.takeAt( idx ); 01067 disconnect( headerFooter, SIGNAL( destroyedHeaderFooter( HeaderFooter* ) ), 01068 d, SLOT( slotUnregisterDestroyedHeaderFooter( HeaderFooter* ) ) ); 01069 headerFooter->setParent( 0 ); 01070 } 01071 d->slotRelayout(); 01072 } |
|
Removes the legend from the chart, without deleting it. The chart no longer owns the legend, so it is the caller's responsibility to delete the legend.
Definition at line 1149 of file KDChartChart.cpp. References d. Referenced by replaceLegend().
01150 { 01151 const int idx = d->legends.indexOf( legend ); 01152 if( idx != -1 ){ 01153 d->legends.takeAt( idx ); 01154 disconnect( legend, SIGNAL( destroyedLegend( Legend* ) ), 01155 d, SLOT( slotUnregisterDestroyedLegend( Legend* ) ) ); 01156 legend->setParent( 0 ); 01157 } 01158 d->slotRelayout(); 01159 } |
|
Definition at line 396 of file KDChartChart.h. |