#include <KDChartCartesianAxis.h>
Inheritance diagram for KDChart::CartesianAxis:
For being useful, axes need to be assigned to a diagram, see AbstractCartesianDiagram::addAxis and AbstractCartesianDiagram::takeAxis.
Definition at line 48 of file KDChartCartesianAxis.h.
Public Types | |
enum | Position { Bottom, Top, Right, Left } |
Public Member Functions | |
void | alignToReferencePoint (const RelativePosition &position) |
BackgroundAttributes | backgroundAttributes () const |
virtual int | bottomOverlap (bool doNotRecalculate=false) const |
This is called at layout time by KDChart:AutoSpacerLayoutItem::sizeHint(). | |
CartesianAxis (AbstractCartesianDiagram *diagram=0) | |
C'tor of the class for cartesian axes. | |
bool | compare (const AbstractAreaBase *other) const |
Returns true if both areas have the same settings. | |
bool | compare (const AbstractAxis *other) const |
Returns true if both axes have the same settings. | |
bool | compare (const CartesianAxis *other) const |
Returns true if both axes have the same settings. | |
virtual void | connectSignals () |
Wireing the signal/slot connections. | |
const AbstractCoordinatePlane * | coordinatePlane () const |
Convenience function, returns the coordinate plane, in which this axis is used. | |
void | createObserver (AbstractDiagram *diagram) |
virtual const QString | customizedLabel (const QString &label) const |
Implement this method if you want to adjust axis labels before they are printed. | |
void | deleteObserver (AbstractDiagram *diagram) |
const AbstractDiagram * | diagram () const |
virtual Qt::Orientations | expandingDirections () const |
pure virtual in QLayoutItem | |
FrameAttributes | frameAttributes () const |
virtual QRect | geometry () const |
pure virtual in QLayoutItem | |
void | getFrameLeadings (int &left, int &top, int &right, int &bottom) const |
bool | hasDefaultTitleTextAttributes () const |
virtual bool | isAbscissa () const |
virtual bool | isEmpty () const |
pure virtual in QLayoutItem | |
virtual bool | isOrdinate () const |
QStringList | labels () const |
Returns a list of strings, that are used as axis labels, as set via setLabels. | |
virtual void | layoutPlanes () |
virtual int | leftOverlap (bool doNotRecalculate=false) const |
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint(). | |
virtual QSize | maximumSize () const |
pure virtual in QLayoutItem | |
virtual QSize | minimumSize () const |
pure virtual in QLayoutItem | |
bool | observedBy (AbstractDiagram *diagram) const |
virtual void | paint (QPainter *) |
reimpl | |
virtual void | paintAll (QPainter &painter) |
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invoked automatically. | |
virtual void | paintBackground (QPainter &painter, const QRect &rectangle) |
virtual void | paintCtx (PaintContext *) |
reimpl | |
virtual void | paintFrame (QPainter &painter, const QRect &rectangle) |
virtual void | paintIntoRect (QPainter &painter, const QRect &rect) |
Draws the background and frame, then calls paint(). | |
QLayout * | parentLayout () |
virtual const Position | position () const |
void | removeFromParentLayout () |
void | resetTitleTextAttributes () |
Reset the title text attributes to the built-in default:. | |
virtual int | rightOverlap (bool doNotRecalculate=false) const |
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint(). | |
void | setBackgroundAttributes (const BackgroundAttributes &a) |
void | setFrameAttributes (const FrameAttributes &a) |
virtual void | setGeometry (const QRect &r) |
pure virtual in QLayoutItem | |
void | setLabels (const QStringList &list) |
Use this to specify your own set of strings, to be used as axis labels. | |
void | setParentLayout (QLayout *lay) |
virtual void | setParentWidget (QWidget *widget) |
Inform the item about its widget: This enables the item, to trigger that widget's update, whenever the size of the item's contents has changed. | |
virtual void | setPosition (Position p) |
void | setShortLabels (const QStringList &list) |
Use this to specify your own set of strings, to be used as axis labels, in case the normal labels are too long. | |
void | setTextAttributes (const TextAttributes &a) |
Use this to specify the text attributes to be used for axis labels. | |
void | setTitleText (const QString &text) |
void | setTitleTextAttributes (const TextAttributes &a) |
QStringList | shortLabels () const |
Returns a list of strings, that are used as axis labels, as set via setShortLabels. | |
virtual QSize | sizeHint () const |
pure virtual in QLayoutItem | |
virtual void | sizeHintChanged () const |
Report changed size hint: ask the parent widget to recalculate the layout. | |
TextAttributes | textAttributes () const |
Returns the text attributes to be used for axis labels. | |
int | tickLength (bool subUnitTicks=false) const |
QString | titleText () const |
TextAttributes | titleTextAttributes () const |
Returns the text attributes that will be used for displaying the title text. | |
virtual int | topOverlap (bool doNotRecalculate=false) const |
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint(). | |
~CartesianAxis () | |
Static Public Member Functions | |
void | paintBackgroundAttributes (QPainter &painter, const QRect &rectangle, const KDChart::BackgroundAttributes &attributes) |
void | paintFrameAttributes (QPainter &painter, const QRect &rectangle, const KDChart::FrameAttributes &attributes) |
Public Attributes | |
public | Q_SLOTS: void update() |
protected | Q_SLOTS: virtual void delayedInit() |
Protected Member Functions | |
virtual QRect | areaGeometry () const |
QRect | innerRect () const |
virtual void | positionHasChanged () |
Protected Attributes | |
Q_SIGNALS | __pad0__: void positionChanged( AbstractArea * ) |
QWidget * | mParent |
QLayout * | mParentLayout |
|
Definition at line 56 of file KDChartCartesianAxis.h.
|
|
C'tor of the class for cartesian axes.
Definition at line 51 of file KDChartCartesianAxis.cpp.
00052 : AbstractAxis ( new Private( diagram, this ), diagram ) 00053 { 00054 init(); 00055 } |
|
Definition at line 57 of file KDChartCartesianAxis.cpp. References d, and KDChart::AbstractCartesianDiagram::takeAxis().
00058 { 00059 // when we remove the first axis it will unregister itself and 00060 // propagate the next one to the primary, thus the while loop 00061 while ( d->mDiagram ) { 00062 AbstractCartesianDiagram *cd = qobject_cast<AbstractCartesianDiagram*>( d->mDiagram ); 00063 cd->takeAxis( this ); 00064 } 00065 Q_FOREACH( AbstractDiagram *diagram, d->secondaryDiagrams ) { 00066 AbstractCartesianDiagram *cd = qobject_cast<AbstractCartesianDiagram*>( diagram ); 00067 cd->takeAxis( this ); 00068 } 00069 } |
|
Definition at line 90 of file KDChartAbstractAreaBase.cpp.
00091 { 00092 Q_UNUSED( position ); 00093 // PENDING(kalle) FIXME 00094 qWarning( "Sorry, not implemented: void AbstractAreaBase::alignToReferencePoint( const RelativePosition& position )" ); 00095 } |
|
Implements KDChart::AbstractAreaBase. Definition at line 150 of file KDChartAbstractArea.cpp. Referenced by KDChart::CartesianCoordinatePlane::drawingArea(), KDChart::PolarCoordinatePlane::layoutDiagrams(), paint(), KDChart::AbstractArea::paintAll(), and paintCtx().
00151 { 00152 return geometry(); 00153 } |
|
Definition at line 112 of file KDChartAbstractAreaBase.cpp. References d. Referenced by updateCommonBrush().
00113 { 00114 return d->backgroundAttributes; 00115 } |
|
This is called at layout time by KDChart:AutoSpacerLayoutItem::sizeHint(). The method triggers AbstractArea::sizeHint() to find out the amount of overlap at the bottom edge of the area.
Definition at line 101 of file KDChartAbstractArea.cpp. References d. Referenced by KDChart::AutoSpacerLayoutItem::sizeHint().
|
|
Returns true if both areas have the same settings.
Definition at line 75 of file KDChartAbstractAreaBase.cpp.
00076 { 00077 if( other == this ) return true; 00078 if( ! other ){ 00079 //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer"; 00080 return false; 00081 } 00082 /* 00083 qDebug() << "AbstractAreaBase:" << (frameAttributes() == other->frameAttributes()) 00084 << (backgroundAttributes() == other->backgroundAttributes()) << "\n"; 00085 */ 00086 return (frameAttributes() == other->frameAttributes()) && 00087 (backgroundAttributes() == other->backgroundAttributes()); 00088 } |
|
Returns true if both axes have the same settings.
Definition at line 142 of file KDChartAbstractAxis.cpp.
00143 { 00144 if( other == this ) return true; 00145 if( ! other ){ 00146 //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer"; 00147 return false; 00148 } 00149 /* 00150 qDebug() << (textAttributes() == other->textAttributes()); 00151 qDebug() << (labels() == other->labels()); 00152 qDebug() << (shortLabels() == other->shortLabels()); 00153 */ 00154 return ( static_cast<const AbstractAreaBase*>(this)->compare( other ) ) && 00155 (textAttributes() == other->textAttributes()) && 00156 (labels() == other->labels()) && 00157 (shortLabels() == other->shortLabels()); 00158 } |
|
Returns true if both axes have the same settings.
Definition at line 77 of file KDChartCartesianAxis.cpp.
00078 { 00079 if( other == this ) return true; 00080 if( ! other ){ 00081 //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer"; 00082 return false; 00083 } 00084 /* 00085 qDebug() << (position() == other->position()); 00086 qDebug() << (titleText() == other->titleText()); 00087 qDebug() << (titleTextAttributes() == other->titleTextAttributes()); 00088 */ 00089 return ( static_cast<const AbstractAxis*>(this)->compare( other ) ) && 00090 ( position() == other->position() ) && 00091 ( titleText() == other->titleText() ) && 00092 ( titleTextAttributes() == other->titleTextAttributes() ); 00093 } |
|
Wireing the signal/slot connections. This method gets called automatically, each time, when you assign the axis to a diagram, either by passing a diagram* to the c'tor, or by calling the diagram's setAxis method, resp. If overwriting this method in derived classes, make sure to call this base method AbstractAxis::connectSignals(), so your axis gets connected to the diagram's built-in signals.
Definition at line 211 of file KDChartAbstractAxis.cpp. References d. Referenced by KDChart::AbstractAxis::createObserver().
00212 { 00213 if( d->observer ){ 00214 connect( d->observer, SIGNAL( diagramDataChanged( AbstractDiagram *) ), 00215 this, SLOT( update() ) ); 00216 } 00217 } |
|
Convenience function, returns the coordinate plane, in which this axis is used. If the axis is not used in a coordinate plane, the return value is Zero. Definition at line 312 of file KDChartAbstractAxis.cpp. References d.
|
|
Definition at line 177 of file KDChartAbstractAxis.cpp. References KDChart::AbstractAxis::connectSignals(), and d. Referenced by KDChart::AbstractCartesianDiagram::addAxis().
00178 { 00179 if( d->setDiagram( diagram ) ) 00180 connectSignals(); 00181 } |
|
Implement this method if you want to adjust axis labels before they are printed. KD Chart is calling this method immediately before drawing the text, this means: What you return here will be drawn without further modifications.
Definition at line 161 of file KDChartAbstractAxis.cpp. Referenced by maximumSize(), and paintCtx().
00162 {
00163 return label;
00164 }
|
|
Definition at line 193 of file KDChartAbstractAxis.cpp. References d. Referenced by KDChart::AbstractCartesianDiagram::takeAxis(), and KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram().
00194 { 00195 d->unsetDiagram( diagram ); 00196 } |
|
Definition at line 319 of file KDChartAbstractAxis.cpp. References d.
00320 { 00321 return d->diagram(); 00322 } |
|
pure virtual in QLayoutItem
Definition at line 960 of file KDChartCartesianAxis.cpp. References Bottom, Left, position(), Right, and Top.
00961 { 00962 Qt::Orientations ret; 00963 switch ( position() ) 00964 { 00965 case Bottom: 00966 case Top: 00967 ret = Qt::Horizontal; 00968 break; 00969 case Left: 00970 case Right: 00971 ret = Qt::Vertical; 00972 break; 00973 default: 00974 Q_ASSERT( false ); // all positions need to be handeld 00975 break; 00976 }; 00977 return ret; 00978 } |
|
Definition at line 102 of file KDChartAbstractAreaBase.cpp. References d. Referenced by KDChart::Legend::clone(), and updateCommonBrush().
00103 { 00104 return d->frameAttributes; 00105 } |
|
pure virtual in QLayoutItem
Implements KDChart::AbstractAxis. Definition at line 1197 of file KDChartCartesianAxis.cpp. References d. Referenced by paintCtx().
01198 { 01199 return d->geometry; 01200 } |
|
Definition at line 204 of file KDChartAbstractAreaBase.cpp. References d. Referenced by KDChart::AbstractAreaBase::innerRect(), and KDChart::AbstractAreaWidget::paintAll().
00205 { 00206 if( d && d->frameAttributes.isVisible() ){ 00207 const int padding = qMax( d->frameAttributes.padding(), 0 ); 00208 left = padding; 00209 top = padding; 00210 right = padding; 00211 bottom = padding; 00212 }else{ 00213 left = 0; 00214 top = 0; 00215 right = 0; 00216 bottom = 0; 00217 } 00218 } |
|
Definition at line 133 of file KDChartCartesianAxis.cpp. References d. Referenced by titleTextAttributes().
00134 { 00135 return d->useDefaultTextAttributes; 00136 } |
|
Definition at line 220 of file KDChartAbstractAreaBase.cpp. References KDChart::AbstractAreaBase::areaGeometry(), and KDChart::AbstractAreaBase::getFrameLeadings(). Referenced by KDChart::TextArea::paintAll(), and KDChart::AbstractArea::paintAll().
00221 { 00222 int left; 00223 int top; 00224 int right; 00225 int bottom; 00226 getFrameLeadings( left, top, right, bottom ); 00227 return 00228 QRect( QPoint(0,0), areaGeometry().size() ) 00229 .adjusted( left, top, -right, -bottom ); 00230 } |
|
Definition at line 164 of file KDChartCartesianAxis.cpp. References Bottom, position(), and Top. Referenced by paintCtx(), and tickLength().
|
|
pure virtual in QLayoutItem
Definition at line 955 of file KDChartCartesianAxis.cpp.
00956 { 00957 return false; // if the axis exists, it has some (perhaps default) content 00958 } |
|
Definition at line 169 of file KDChartCartesianAxis.cpp. References Left, position(), and Right. Referenced by paintCtx().
|
|
Returns a list of strings, that are used as axis labels, as set via setLabels.
Definition at line 273 of file KDChartAbstractAxis.cpp. References d. Referenced by maximumSize(), and paintCtx().
00274 { 00275 return d->hardLabels; 00276 } |
|
Definition at line 150 of file KDChartCartesianAxis.cpp. References d, and KDChart::AbstractCoordinatePlane::layoutPlanes(). Referenced by resetTitleTextAttributes(), setPosition(), setTitleText(), and setTitleTextAttributes().
00151 { 00152 //qDebug() << "CartesianAxis::layoutPlanes()"; 00153 if( ! d->diagram() || ! d->diagram()->coordinatePlane() ) { 00154 //qDebug() << "CartesianAxis::layoutPlanes(): Sorry, found no plane."; 00155 return; 00156 } 00157 AbstractCoordinatePlane* plane = d->diagram()->coordinatePlane(); 00158 if( plane ){ 00159 plane->layoutPlanes(); 00160 //qDebug() << "CartesianAxis::layoutPlanes() OK"; 00161 } 00162 } |
|
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint(). The method triggers AbstractArea::sizeHint() to find out the amount of overlap at the left edge of the area.
Definition at line 77 of file KDChartAbstractArea.cpp. References d. Referenced by KDChart::AutoSpacerLayoutItem::sizeHint().
|
|
pure virtual in QLayoutItem
Definition at line 1007 of file KDChartCartesianAxis.cpp. References Bottom, calculateOverlap(), KDChart::AbstractAxis::customizedLabel(), d, KDChart::AbstractCoordinatePlane::gridDimensionsList(), KDChart::TextAttributes::isVisible(), KDChart::AbstractAxis::labels(), Left, KDChart::AbstractCoordinatePlane::parent(), position(), KDChart::TextLayoutItem::realFont(), referenceDiagramIsBarDiagram(), Right, KDChart::TextLayoutItem::setText(), KDChart::TextLayoutItem::sizeHint(), KDChart::AbstractAxis::textAttributes(), tickLength(), titleText(), and Top. Referenced by minimumSize(), and sizeHint().
01008 { 01009 QSize result; 01010 if ( !d->diagram() ) 01011 return result; 01012 01013 const TextAttributes labelTA = textAttributes(); 01014 const bool drawLabels = labelTA.isVisible(); 01015 01016 const TextAttributes titleTA( d->titleTextAttributesWithAdjustedRotation() ); 01017 const bool drawTitle = titleTA.isVisible() && ! titleText().isEmpty(); 01018 01019 AbstractCoordinatePlane* plane = d->diagram()->coordinatePlane(); 01020 //qDebug() << this<<"::maximumSize() uses plane geometry" << plane->geometry(); 01021 QObject* refArea = plane->parent(); 01022 TextLayoutItem labelItem( QString::null, labelTA, refArea, 01023 KDChartEnums::MeasureOrientationMinimum, Qt::AlignLeft ); 01024 TextLayoutItem titleItem( titleText(), titleTA, refArea, 01025 KDChartEnums::MeasureOrientationMinimum, Qt::AlignHCenter | Qt::AlignVCenter ); 01026 const qreal labelGap = 01027 drawLabels 01028 ? (QFontMetricsF( labelItem.realFont() ).height() / 3.0) 01029 : 0.0; 01030 const qreal titleGap = 01031 drawTitle 01032 ? (QFontMetricsF( titleItem.realFont() ).height() / 3.0) 01033 : 0.0; 01034 01035 switch ( position() ) 01036 { 01037 case Bottom: 01038 case Top: { 01039 const bool isBarDiagram = referenceDiagramIsBarDiagram(d->diagram()); 01040 int leftOverlap = 0; 01041 int rightOverlap = 0; 01042 01043 qreal w = 10.0; 01044 qreal h = 0.0; 01045 if( drawLabels ){ 01046 // if there're no label strings, we take the biggest needed number as height 01047 if ( labels().count() ){ 01048 // find the longest label text: 01049 const int first=0; 01050 const int last=labels().count()-1; 01051 for ( int i = first; i <= last; ++i ) 01052 { 01053 labelItem.setText( customizedLabel(labels()[ i ]) ); 01054 const QSize siz = labelItem.sizeHint(); 01055 h = qMax( h, static_cast<qreal>(siz.height()) ); 01056 calculateOverlap( i, first, last, siz.width(), isBarDiagram, 01057 leftOverlap, rightOverlap ); 01058 01059 } 01060 }else{ 01061 QStringList headerLabels = d->diagram()->itemRowLabels(); 01062 const int headerLabelsCount = headerLabels.count(); 01063 if( headerLabelsCount ){ 01064 const int first=0; 01065 const int last=headerLabelsCount-1; 01066 for ( int i = first; i <= last; ++i ) 01067 { 01068 labelItem.setText( customizedLabel(headerLabels[ i ]) ); 01069 const QSize siz = labelItem.sizeHint(); 01070 h = qMax( h, static_cast<qreal>(siz.height()) ); 01071 calculateOverlap( i, first, last, siz.width(), isBarDiagram, 01072 leftOverlap, rightOverlap ); 01073 } 01074 }else{ 01075 labelItem.setText( 01076 customizedLabel( 01077 QString::number( plane->gridDimensionsList().first().end, 'f', 0 ))); 01078 const QSize siz = labelItem.sizeHint(); 01079 h = siz.height(); 01080 calculateOverlap( 0, 0, 0, siz.width(), isBarDiagram, 01081 leftOverlap, rightOverlap ); 01082 } 01083 } 01084 // we leave a little gap between axis labels and bottom (or top, resp.) side of axis 01085 h += labelGap; 01086 } 01087 // space for a possible title: 01088 if ( drawTitle ) { 01089 // we add the title height and leave a little gap between axis labels and axis title 01090 h += titleItem.sizeHint().height() + titleGap; 01091 w = titleItem.sizeHint().width() + 2.0; 01092 } 01093 // space for the ticks 01094 h += qAbs( tickLength() ) * 3.0; 01095 result = QSize ( static_cast<int>( w ), static_cast<int>( h ) ); 01096 01097 01098 // If necessary adjust the widths 01099 // of the left (or right, resp.) side neighboring columns: 01100 d->amountOfLeftOverlap = leftOverlap; 01101 d->amountOfRightOverlap = rightOverlap; 01102 /* Unused code for a push-model: 01103 if( leftOverlap || rightOverlap ){ 01104 QTimer::singleShot(200, const_cast<CartesianAxis*>(this), 01105 SLOT(adjustLeftRightGridColumnWidths())); 01106 } 01107 */ 01108 } 01109 break; 01110 case Left: 01111 case Right: { 01112 int topOverlap = 0; 01113 int bottomOverlap = 0; 01114 01115 qreal w = 0.0; 01116 qreal h = 10.0; 01117 if( drawLabels ){ 01118 // if there're no label strings, we take the biggest needed number as width 01119 if ( labels().count() == 0 ) 01120 { 01121 labelItem.setText( 01122 customizedLabel( 01123 QString::number( plane->gridDimensionsList().last().end, 'f', 0 ))); 01124 const QSize siz = labelItem.sizeHint(); 01125 w = siz.width(); 01126 calculateOverlap( 0, 0, 0, siz.height(), false,// bar diagram flag is ignored for Ordinates 01127 topOverlap, bottomOverlap ); 01128 }else{ 01129 // find the longest label text: 01130 const int first=0; 01131 const int last=labels().count()-1; 01132 for ( int i = first; i <= last; ++i ) 01133 { 01134 labelItem.setText( customizedLabel(labels()[ i ]) ); 01135 const QSize siz = labelItem.sizeHint(); 01136 qreal lw = siz.width(); 01137 w = qMax( w, lw ); 01138 calculateOverlap( 0, 0, 0, siz.height(), false,// bar diagram flag is ignored for Ordinates 01139 topOverlap, bottomOverlap ); 01140 } 01141 } 01142 // we leave a little gap between axis labels and left (or right, resp.) side of axis 01143 w += labelGap; 01144 } 01145 // space for a possible title: 01146 if ( drawTitle ) { 01147 // we add the title height and leave a little gap between axis labels and axis title 01148 w += titleItem.sizeHint().width() + titleGap; 01149 h = titleItem.sizeHint().height() + 2.0; 01150 //qDebug() << "left/right axis title item size-hint:" << titleItem.sizeHint(); 01151 } 01152 // space for the ticks 01153 w += qAbs( tickLength() ) * 3.0; 01154 01155 result = QSize ( static_cast<int>( w ), static_cast<int>( h ) ); 01156 //qDebug() << "left/right axis width:" << result << " w:" << w; 01157 01158 01159 // If necessary adjust the heights 01160 // of the top (or bottom, resp.) side neighboring rows: 01161 d->amountOfTopOverlap = topOverlap; 01162 d->amountOfBottomOverlap = bottomOverlap; 01163 /* Unused code for a push-model: 01164 if( topOverlap || bottomOverlap ){ 01165 QTimer::singleShot(200, const_cast<CartesianAxis*>(this), 01166 SLOT(adjustTopBottomGridRowHeights())); 01167 } 01168 */ 01169 } 01170 break; 01171 default: 01172 Q_ASSERT( false ); // all positions need to be handled 01173 break; 01174 }; 01175 //qDebug() << "*******************" << result; 01176 //result=QSize(0,0); 01177 return result; 01178 } |
|
pure virtual in QLayoutItem
Definition at line 1180 of file KDChartCartesianAxis.cpp. References maximumSize().
01181 { 01182 return maximumSize(); 01183 } |
|
Definition at line 324 of file KDChartAbstractAxis.cpp. References d.
00325 { 00326 return d->hasDiagram( diagram ); 00327 } |
|
reimpl
Implements KDChart::AbstractLayoutItem. Definition at line 193 of file KDChartCartesianAxis.cpp. References KDChart::AbstractArea::areaGeometry(), d, paintCtx(), KDChart::PaintContext::setCoordinatePlane(), KDChart::PaintContext::setPainter(), and KDChart::PaintContext::setRectangle().
00194 { 00195 if( ! d->diagram() || ! d->diagram()->coordinatePlane() ) return; 00196 PaintContext ctx; 00197 ctx.setPainter ( painter ); 00198 ctx.setCoordinatePlane( d->diagram()->coordinatePlane() ); 00199 const QRect rect( areaGeometry() ); 00200 00201 //qDebug() << "CartesianAxis::paint( QPainter* painter ) " << " areaGeometry()():" << rect << " sizeHint():" << sizeHint(); 00202 00203 ctx.setRectangle( 00204 QRectF ( 00205 //QPointF(0, 0), 00206 QPointF(rect.left(), rect.top()), 00207 QSizeF(rect.width(), rect.height() ) ) ); 00208 // enabling clipping so that we're not drawing outside 00209 QRegion clipRegion( rect.adjusted( -1, -1, 1, 1 ) ); 00210 painter->save(); 00211 painter->setClipRegion( clipRegion ); 00212 paintCtx( &ctx ); 00213 painter->restore(); 00214 //qDebug() << "KDChart::CartesianAxis::paint() done."; 00215 } |
|
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invoked automatically.
Reimplemented from KDChart::AbstractLayoutItem. Definition at line 123 of file KDChartAbstractArea.cpp. References KDChart::AbstractArea::areaGeometry(), d, KDChart::AbstractAreaBase::innerRect(), KDChart::AbstractLayoutItem::paint(), KDChart::AbstractAreaBase::paintBackground(), and KDChart::AbstractAreaBase::paintFrame(). Referenced by KDChart::AbstractArea::paintIntoRect().
00124 { 00125 // Paint the background and frame 00126 const QRect overlappingArea( geometry().adjusted( 00127 -d->amountOfLeftOverlap, 00128 -d->amountOfTopOverlap, 00129 d->amountOfRightOverlap, 00130 d->amountOfBottomOverlap ) ); 00131 paintBackground( painter, overlappingArea ); 00132 paintFrame( painter, overlappingArea ); 00133 00134 // temporarily adjust the widget size, to be sure all content gets calculated 00135 // to fit into the inner rectangle 00136 const QRect oldGeometry( areaGeometry() ); 00137 QRect inner( innerRect() ); 00138 inner.moveTo( 00139 oldGeometry.left() + inner.left(), 00140 oldGeometry.top() + inner.top() ); 00141 const bool needAdjustGeometry = oldGeometry != inner; 00142 if( needAdjustGeometry ) 00143 setGeometry( inner ); 00144 paint( &painter ); 00145 if( needAdjustGeometry ) 00146 setGeometry( oldGeometry ); 00147 //qDebug() << "AbstractAreaWidget::paintAll() done."; 00148 } |
|
Definition at line 188 of file KDChartAbstractAreaBase.cpp. References d, and KDChart::AbstractAreaBase::paintBackgroundAttributes(). Referenced by KDChart::TextArea::paintAll(), KDChart::AbstractAreaWidget::paintAll(), and KDChart::AbstractArea::paintAll().
00189 { 00190 Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintBackground()", 00191 "Private class was not initialized!" ); 00192 paintBackgroundAttributes( painter, rect, d->backgroundAttributes ); 00193 } |
|
Definition at line 119 of file KDChartAbstractAreaBase.cpp. References KDChart::BackgroundAttributes::brush(), KDChart::BackgroundAttributes::isVisible(), KDChart::BackgroundAttributes::pixmap(), and KDChart::BackgroundAttributes::pixmapMode(). Referenced by KDChart::AbstractAreaBase::paintBackground().
00121 { 00122 if( !attributes.isVisible() ) return; 00123 00124 /* first draw the brush (may contain a pixmap)*/ 00125 if( Qt::NoBrush != attributes.brush().style() ) { 00126 KDChart::PainterSaver painterSaver( &painter ); 00127 painter.setPen( Qt::NoPen ); 00128 const QPointF newTopLeft( painter.deviceMatrix().map( rect.topLeft() ) ); 00129 painter.setBrushOrigin( newTopLeft ); 00130 painter.setBrush( attributes.brush() ); 00131 painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) ); 00132 } 00133 /* next draw the backPixmap over the brush */ 00134 if( !attributes.pixmap().isNull() && 00135 attributes.pixmapMode() != BackgroundAttributes::BackgroundPixmapModeNone ) { 00136 QPointF ol = rect.topLeft(); 00137 if( BackgroundAttributes::BackgroundPixmapModeCentered == attributes.pixmapMode() ) 00138 { 00139 ol.setX( rect.center().x() - attributes.pixmap().width() / 2 ); 00140 ol.setY( rect.center().y() - attributes.pixmap().height()/ 2 ); 00141 painter.drawPixmap( ol, attributes.pixmap() ); 00142 } else { 00143 QMatrix m; 00144 double zW = (double)rect.width() / (double)attributes.pixmap().width(); 00145 double zH = (double)rect.height() / (double)attributes.pixmap().height(); 00146 switch( attributes.pixmapMode() ) { 00147 case BackgroundAttributes::BackgroundPixmapModeScaled: 00148 { 00149 double z; 00150 z = qMin( zW, zH ); 00151 m.scale( z, z ); 00152 } 00153 break; 00154 case BackgroundAttributes::BackgroundPixmapModeStretched: 00155 m.scale( zW, zH ); 00156 break; 00157 default: 00158 ; // Cannot happen, previously checked 00159 } 00160 QPixmap pm = attributes.pixmap().transformed( m ); 00161 ol.setX( rect.center().x() - pm.width() / 2 ); 00162 ol.setY( rect.center().y() - pm.height()/ 2 ); 00163 painter.drawPixmap( ol, pm ); 00164 } 00165 } 00166 } |
|
reimpl
Reimplemented from KDChart::AbstractLayoutItem. Definition at line 370 of file KDChartCartesianAxis.cpp. References KDChart::AbstractArea::areaGeometry(), Bottom, KDChart::DataDimension::calcMode, calculateNextLabel(), KDChart::PaintContext::coordinatePlane(), KDChart::AbstractAxis::customizedLabel(), d, KDChart::DataDimensionsList, KDChart::DataDimension::distance(), KDChart::DataDimension::end, KDChart::TextLayoutItem::geometry(), geometry(), KDChart::AbstractCoordinatePlane::gridDimensionsList(), KDChart::TextLayoutItem::intersects(), isAbscissa(), KDChart::DataDimension::isCalculated, isOrdinate(), KDChart::TextAttributes::isVisible(), KDChart::AbstractAxis::labels(), Left, KDChart::TextLayoutItem::paint(), KDChart::PaintContext::painter(), KDChart::AbstractCoordinatePlane::parent(), position(), KDChart::TextLayoutItem::realFont(), referenceDiagramIsBarDiagram(), Right, KDChart::TextLayoutItem::setGeometry(), KDChart::TextLayoutItem::setText(), KDChart::AbstractAxis::shortLabels(), KDChart::TextLayoutItem::sizeHint(), KDChart::DataDimension::start, KDChart::DataDimension::stepWidth, KDChart::DataDimension::subStepWidth, KDChart::TextLayoutItem::text(), KDChart::AbstractAxis::textAttributes(), tickLength(), titleText(), Top, and KDChart::CartesianCoordinatePlane::translate(). Referenced by paint().
00371 { 00372 00373 Q_ASSERT_X ( d->diagram(), "CartesianAxis::paint", 00374 "Function call not allowed: The axis is not assigned to any diagram." ); 00375 00376 CartesianCoordinatePlane* plane = dynamic_cast<CartesianCoordinatePlane*>(context->coordinatePlane()); 00377 Q_ASSERT_X ( plane, "CartesianAxis::paint", 00378 "Bad function call: PaintContext::coodinatePlane() NOT a cartesian plane." ); 00379 00380 // note: Not having any data model assigned is no bug 00381 // but we can not draw an axis then either. 00382 if( ! d->diagram()->model() ) 00383 return; 00384 00385 00386 /* 00387 * let us paint the labels at a 00388 * smaller resolution 00389 * Same mini pixel value as for 00390 * Cartesian Grid 00391 */ 00392 //const qreal MinimumPixelsBetweenRulers = 1.0; 00393 DataDimensionsList dimensions( plane->gridDimensionsList() ); 00394 //qDebug("CartesianAxis::paintCtx() gets DataDimensionsList.first(): start: %f end: %f stepWidth: %f", dimensions.first().start, dimensions.first().end, dimensions.first().stepWidth); 00395 00396 // test for programming errors: critical 00397 Q_ASSERT_X ( dimensions.count() == 2, "CartesianAxis::paint", 00398 "Error: plane->gridDimensionsList() did not return exactly two dimensions." ); 00399 DataDimension dimX = 00400 AbstractGrid::adjustedLowerUpperRange( dimensions.first(), true, true ); 00401 const DataDimension dimY = 00402 AbstractGrid::adjustedLowerUpperRange( dimensions.last(), true, true ); 00403 const DataDimension& dim = (isAbscissa() ? dimX : dimY); 00404 00405 /* 00406 if(isAbscissa()) 00407 qDebug() << " " << "Abscissa:" << dimX.start <<".."<<dimX.end <<" step"<<dimX.stepWidth; 00408 else 00409 qDebug() << " " << "Ordinate:" << dimY.start <<".."<<dimY.end <<" step"<<dimY.stepWidth; 00410 */ 00411 00412 00413 /* 00414 * let us paint the labels at a 00415 * smaller resolution 00416 * Same mini pixel value as for 00417 * Cartesian Grid 00418 */ 00419 const qreal MinimumPixelsBetweenRulers = qMin( dimX.stepWidth, dimY.stepWidth );//1.0; 00420 00421 // preparations: 00422 // - calculate the range that will be displayed: 00423 const qreal absRange = qAbs( dim.distance() ); 00424 00425 qreal numberOfUnitRulers; 00426 if ( isAbscissa() ) { 00427 if( dimX.isCalculated ) 00428 numberOfUnitRulers = absRange / qAbs( dimX.stepWidth ) + 1.0; 00429 else 00430 numberOfUnitRulers = d->diagram()->model()->rowCount() - 1.0; 00431 }else{ 00432 numberOfUnitRulers = absRange / qAbs( dimY.stepWidth ) + 1.0; 00433 00434 } 00435 00436 // qDebug() << "absRange" << absRange << "dimY.stepWidth:" << dimY.stepWidth << "numberOfUnitRulers:" << numberOfUnitRulers; 00437 00438 qreal numberOfSubUnitRulers; 00439 if ( isAbscissa() ){ 00440 if( dimX.isCalculated ) 00441 numberOfSubUnitRulers = absRange / qAbs( dimX.subStepWidth ) + 1.0; 00442 else 00443 numberOfSubUnitRulers = dimX.subStepWidth>0 ? absRange / qAbs( dimX.subStepWidth ) + 1.0 : 0.0; 00444 }else{ 00445 numberOfSubUnitRulers = absRange / qAbs( dimY.subStepWidth ) + 1.0; 00446 } 00447 00448 // - calculate the absolute range in screen pixels: 00449 const QPointF p1 = plane->translate( QPointF(dimX.start, dimY.start) ); 00450 const QPointF p2 = plane->translate( QPointF(dimX.end, dimY.end) ); 00451 00452 double screenRange; 00453 if ( isAbscissa() ) 00454 { 00455 screenRange = qAbs ( p1.x() - p2.x() ); 00456 } else { 00457 screenRange = qAbs ( p1.y() - p2.y() ); 00458 } 00459 00460 const bool useItemCountLabels = isAbscissa() && ! dimX.isCalculated; 00461 //qDebug() << "CartesianAxis::paintCtx useItemCountLabels "<< useItemCountLabels; 00462 00463 //qDebug() << "isAbscissa():" << isAbscissa() << " dimX.isCalculated:" << dimX.isCalculated << " dimX.stepWidth: "<<dimX.stepWidth; 00464 //FIXME(khz): Remove this code, and do the calculation in the grid calc function 00465 if( isAbscissa() && ! dimX.isCalculated ){ 00466 // dont ignore the users settings 00467 dimX.stepWidth = dimX.stepWidth ? dimX.stepWidth : 1.0; 00468 //qDebug() << "screenRange / numberOfUnitRulers <= MinimumPixelsBetweenRulers" << screenRange <<"/" << numberOfUnitRulers <<"<=" << MinimumPixelsBetweenRulers; 00469 while( screenRange / numberOfUnitRulers <= MinimumPixelsBetweenRulers ){ 00470 dimX.stepWidth *= 10.0; 00471 dimX.subStepWidth *= 10.0; 00472 numberOfUnitRulers = qAbs( dimX.distance() / dimX.stepWidth ); 00473 } 00474 } 00475 00476 const bool drawUnitRulers = screenRange / ( numberOfUnitRulers / dimX.stepWidth ) > MinimumPixelsBetweenRulers; 00477 const bool drawSubUnitRulers = 00478 (numberOfSubUnitRulers != 0.0) && 00479 (screenRange / numberOfSubUnitRulers > MinimumPixelsBetweenRulers); 00480 00481 const TextAttributes labelTA = textAttributes(); 00482 const bool drawLabels = labelTA.isVisible(); 00483 00484 // - find the reference point at which to start drawing and the increment (line distance); 00485 QPointF rulerRef; 00486 const QRect areaGeoRect( areaGeometry() ); 00487 const QRect geoRect( geometry() ); 00488 QRectF rulerRect; 00489 double rulerWidth; 00490 double rulerHeight; 00491 00492 QPainter* ptr = context->painter(); 00493 00494 //for debugging: if( isAbscissa() )ptr->drawRect(areaGeoRect.adjusted(0,0,-1,-1)); 00495 //qDebug() << " " << (isAbscissa() ? "Abscissa":"Ordinate") << "axis painting with geometry" << areaGeoRect; 00496 00497 // FIXME references are of course different for all locations: 00498 rulerWidth = areaGeoRect.width(); 00499 rulerHeight = areaGeoRect.height(); 00500 switch( position() ) 00501 { 00502 case Top: 00503 rulerRef.setX( areaGeoRect.topLeft().x() ); 00504 rulerRef.setY( areaGeoRect.topLeft().y() + rulerHeight ); 00505 break; 00506 case Bottom: 00507 rulerRef.setX( areaGeoRect.bottomLeft().x() ); 00508 rulerRef.setY( areaGeoRect.bottomLeft().y() - rulerHeight ); 00509 break; 00510 case Right: 00511 rulerRef.setX( areaGeoRect.bottomRight().x() - rulerWidth ); 00512 rulerRef.setY( areaGeoRect.bottomRight().y() ); 00513 break; 00514 case Left: 00515 rulerRef.setX( areaGeoRect.bottomLeft().x() + rulerWidth ); 00516 rulerRef.setY( areaGeoRect.bottomLeft().y() ); 00517 break; 00518 } 00519 00520 // set up the lines to paint: 00521 00522 // set up a map of integer positions, 00523 00524 // - starting with the fourth 00525 // - the the halfs 00526 // - then the tens 00527 // this will override all halfs and fourth that hit a higher-order ruler 00528 // MAKE SURE TO START AT (0, 0)! 00529 00530 // set up a reference point, a step vector and a unit vector for the drawing: 00531 00532 const qreal minValueY = dimY.start; 00533 const qreal maxValueY = dimY.end; 00534 const qreal minValueX = dimX.start; 00535 const qreal maxValueX = dimX.end; 00536 const bool isLogarithmicX = (dimX.calcMode == AbstractCoordinatePlane::Logarithmic ); 00537 const bool isLogarithmicY = (dimY.calcMode == AbstractCoordinatePlane::Logarithmic ); 00538 //#define AXES_PAINTING_DEBUG 1 00539 #ifdef AXES_PAINTING_DEBUG 00540 qDebug() << "CartesianAxis::paint: reference values:" << endl 00541 << "-- range x/y: " << dimX.distance() << "/" << dimY.distance() << endl 00542 << "-- absRange: " << absRange << endl 00543 << "-- numberOfUnitRulers: " << numberOfUnitRulers << endl 00544 << "-- screenRange: " << screenRange << endl 00545 << "-- drawUnitRulers: " << drawUnitRulers << endl 00546 << "-- drawLabels: " << drawLabels << endl 00547 << "-- ruler reference point:: " << rulerRef << endl 00548 << "-- minValueX: " << minValueX << " maxValueX: " << maxValueX << endl 00549 << "-- minValueY: " << minValueY << " maxValueY: " << maxValueY << endl 00550 ; 00551 #endif 00552 00553 ptr->setPen ( Qt::black ); 00554 00555 const QObject* referenceArea = plane->parent(); 00556 00557 // that QVector contains all drawn x-ticks (so no subticks are drawn there also) 00558 QVector< int > drawnXTicks; 00559 // and that does the same for the y-ticks 00560 QVector< int > drawnYTicks; 00561 00562 /* 00563 * Find out if it is a bar diagram 00564 * bar diagrams display their data per column 00565 * we need to handle the last label another way 00566 * 1 - Last label == QString null ( Header Labels ) 00567 * 2 - Display labels and ticks in the middle of the column 00568 */ 00569 00570 const bool isBarDiagram = referenceDiagramIsBarDiagram(d->diagram()); 00571 00572 // this draws the unit rulers 00573 if ( drawUnitRulers ) { 00574 const int hardLabelsCount = labels().count(); 00575 const int shortLabelsCount = shortLabels().count(); 00576 bool useShortLabels = false; 00577 00578 00579 bool useConfiguredStepsLabels = false; 00580 QStringList headerLabels; 00581 if( useItemCountLabels ){ 00582 //qDebug() << (isOrdinate() ? "is Ordinate" : "is Abscissa"); 00583 headerLabels = 00584 isOrdinate() 00585 ? d->diagram()->datasetLabels() 00586 : d->diagram()->itemRowLabels(); 00587 // check if configured stepWidth 00588 useConfiguredStepsLabels = isAbscissa() && 00589 dimX.stepWidth && 00590 (( (headerLabels.count() - 1)/ dimX.stepWidth ) != numberOfUnitRulers); 00591 if( useConfiguredStepsLabels ) { 00592 numberOfUnitRulers = ( headerLabels.count() - 1 )/ dimX.stepWidth; 00593 // we need to register data values for the steps 00594 // in case it is configured by the user 00595 QStringList configuredStepsLabels; 00596 double value = headerLabels.first().toDouble(); 00597 configuredStepsLabels << QString::number( value ); 00598 for ( int i = 0; i < numberOfUnitRulers; i++ ) { 00599 value += dimX.stepWidth; 00600 configuredStepsLabels.append( QString::number( value ) ); 00601 } 00602 headerLabels = configuredStepsLabels; 00603 } 00604 00605 if ( isBarDiagram ) 00606 headerLabels.append( QString::null ); 00607 } 00608 00609 00610 const int headerLabelsCount = headerLabels.count(); 00611 //qDebug() << "headerLabelsCount" << headerLabelsCount; 00612 00613 TextLayoutItem* labelItem = 00614 drawLabels 00615 ? new TextLayoutItem( QString::number( minValueY ), 00616 labelTA, 00617 referenceArea, 00618 KDChartEnums::MeasureOrientationMinimum, 00619 Qt::AlignLeft ) 00620 : 0; 00621 TextLayoutItem* labelItem2 = 00622 drawLabels 00623 ? new TextLayoutItem( QString::number( minValueY ), 00624 labelTA, 00625 referenceArea, 00626 KDChartEnums::MeasureOrientationMinimum, 00627 Qt::AlignLeft ) 00628 : 0; 00629 const QFontMetricsF met( 00630 drawLabels 00631 ? labelItem->realFont() 00632 : QFontMetricsF( QApplication::font() ) ); 00633 const qreal halfFontHeight = met.height() * 0.5; 00634 00635 if ( isAbscissa() ) { 00636 // If we have a labels list AND a short labels list, we first find out, 00637 // if there is enough space for the labels: if not, use the short labels. 00638 if( drawLabels && hardLabelsCount > 0 && shortLabelsCount > 0 ){ 00639 bool labelsAreOverlapping = false; 00640 int iLabel = 0; 00641 qreal i = minValueX; 00642 while ( i < maxValueX && !labelsAreOverlapping ) 00643 { 00644 if ( dimX.stepWidth != 1.0 && ! dim.isCalculated ) 00645 { 00646 labelItem->setText( customizedLabel(QString::number( i, 'f', 0 )) ); 00647 labelItem2->setText( customizedLabel(QString::number( i + dimX.stepWidth, 'f', 0 )) ); 00648 } else { 00649 00650 int index = iLabel; 00651 labelItem->setText( customizedLabel(labels()[ index < hardLabelsCount ? index : 0 ]) ); 00652 labelItem2->setText( customizedLabel(labels()[ index < hardLabelsCount - 1 ? index + 1 : 0]) ); 00653 } 00654 QPointF firstPos( i, 0.0 ); 00655 firstPos = plane->translate( firstPos ); 00656 00657 QPointF secondPos( i + dimX.stepWidth, 0.0 ); 00658 secondPos = plane->translate( secondPos ); 00659 00660 labelsAreOverlapping = labelItem->intersects( *labelItem2, firstPos, secondPos ); 00661 if ( iLabel++ > hardLabelsCount - 1 ) 00662 iLabel = 0; 00663 if ( isLogarithmicX ) 00664 i *= 10.0; 00665 else 00666 i += dimX.stepWidth; 00667 00668 } 00669 00670 useShortLabels = labelsAreOverlapping; 00671 } 00672 00673 qreal labelDiff = dimX.stepWidth; 00674 //qDebug() << "labelDiff " << labelDiff; 00675 if ( drawLabels ) 00676 { 00677 00678 qreal i = minValueX; 00679 int iLabel = 0; 00680 const int precision = ( QString::number( labelDiff ).section( QLatin1Char('.'), 1, 2 ) ).length(); 00681 00682 while ( i + labelDiff < maxValueX ) 00683 { 00684 00685 //qDebug() << "drawLabels" << drawLabels << " hardLabelsCount" << hardLabelsCount 00686 // << " dimX.stepWidth" << dimX.stepWidth << " dim.isCalculated" << dim.isCalculated; 00687 if ( !drawLabels || hardLabelsCount < 1 || ( dimX.stepWidth != 1.0 && ! dim.isCalculated ) ) 00688 { 00689 // Check intersects for the header label - we need to pass the full string 00690 // here and not only the i value. 00691 if( useConfiguredStepsLabels ){ 00692 labelItem->setText( customizedLabel(headerLabels[ iLabel ]) ); 00693 labelItem2->setText(customizedLabel(headerLabels[ iLabel+1 ]) ); 00694 }else{ 00695 //qDebug() << "i + labelDiff " << i + labelDiff; 00696 labelItem->setText( customizedLabel(headerLabelsCount ? headerLabels[static_cast<int>(i)] 00697 : QString::number( i, 'f', precision )) ); 00698 // qDebug() << "1 - labelItem->text() " << labelItem->text(); 00699 //qDebug() << "labelDiff" << labelDiff 00700 // << " index" << i+labelDiff << " count" << headerLabelsCount; 00701 labelItem2->setText( customizedLabel(headerLabelsCount ? headerLabels[static_cast<int>(i+labelDiff)] 00702 : QString::number( i + labelDiff, 'f', precision )) ); 00703 //qDebug() << "2 - labelItem->text() " << labelItem->text(); 00704 //qDebug() << "labelItem2->text() " << labelItem2->text(); 00705 } 00706 } else { 00707 const int idx = (iLabel < hardLabelsCount ) ? iLabel : 0; 00708 const int idx2= (iLabel < hardLabelsCount - 1) ? iLabel + 1 : 0; 00709 labelItem->setText( customizedLabel( 00710 useShortLabels ? shortLabels()[ idx ] : labels()[ idx ]) ); 00711 labelItem2->setText( customizedLabel( 00712 useShortLabels ? shortLabels()[ idx2] : labels()[ idx2]) ); 00713 } 00714 00715 QPointF firstPos( i, 0.0 ); 00716 firstPos = plane->translate( firstPos ); 00717 00718 QPointF secondPos( i + labelDiff, 0.0 ); 00719 secondPos = plane->translate( secondPos ); 00720 00721 00722 if ( labelItem->intersects( *labelItem2, firstPos, secondPos ) ) 00723 { 00724 i = minValueX; 00725 labelDiff += labelDiff; 00726 iLabel = 0; 00727 } 00728 else 00729 { 00730 i += labelDiff; 00731 } 00732 00733 ++iLabel; 00734 if ( (iLabel > hardLabelsCount - 1) && !useConfiguredStepsLabels ) 00735 { 00736 iLabel = 0; 00737 } 00738 } 00739 } 00740 00741 int idxLabel = 0; 00742 qreal iLabelF = minValueX; 00743 qreal i = minValueX; 00744 qreal labelStep = 0.0; 00745 //qDebug() << "dimX.stepWidth:" << dimX.stepWidth; 00746 //dimX.stepWidth = 0.5; 00747 while( i <= maxValueX ) { 00748 // Line charts: we want the first tick to begin at 0.0 not at 0.5 otherwise labels and 00749 // values does not fit each others 00750 QPointF topPoint ( i + ( isBarDiagram ? 0.5 : 0.0 ), 0.0 ); 00751 QPointF bottomPoint ( topPoint ); 00752 topPoint = plane->translate( topPoint ); 00753 bottomPoint = plane->translate( bottomPoint ); 00754 topPoint.setY( rulerRef.y() + tickLength() ); 00755 bottomPoint.setY( rulerRef.y() ); 00756 00757 const qreal translatedValue = topPoint.x(); 00758 const bool bIsVisibleLabel = 00759 ( translatedValue >= geoRect.left() && translatedValue <= geoRect.right() ); 00760 00761 //Dont paint more ticks than we need 00762 //when diagram type is Bar 00763 bool painttick = true; 00764 if ( isBarDiagram && i == maxValueX ) 00765 painttick = false; 00766 00767 if ( bIsVisibleLabel && painttick ) 00768 ptr->drawLine( topPoint, bottomPoint ); 00769 00770 drawnXTicks.append( static_cast<int>( topPoint.x() ) ); 00771 if( drawLabels ) { 00772 if( bIsVisibleLabel ){ 00773 if ( isLogarithmicX ) 00774 labelItem->setText( customizedLabel(QString::number( i, 'f', 0 )) ); 00775 /* We dont need that 00776 * it causes header labels to be skipped even if there is enough 00777 * space for them to displayed. 00778 * Commenting for now - I need to test more in details - Let me know if I am wrong here. 00779 */ 00780 /* 00781 else if( (dimX.stepWidth != 1.0) && ! dimX.isCalculated ) { 00782 labelItem->setText( customizedLabel(QString::number( i, 'f', 0 )) ); 00783 } 00784 */ 00785 else { 00786 labelItem->setText( 00787 customizedLabel( 00788 hardLabelsCount 00789 ? ( useShortLabels ? shortLabels()[ idxLabel ] : labels()[ idxLabel ] ) 00790 : ( headerLabelsCount ? headerLabels[ idxLabel ] : QString::number( iLabelF )))); 00791 } 00792 // No need to call labelItem->setParentWidget(), since we are using 00793 // the layout item temporarily only. 00794 if( labelStep <= 0 ) { 00795 const QSize size( labelItem->sizeHint() ); 00796 labelItem->setGeometry( 00797 QRect( 00798 QPoint( 00799 static_cast<int>( topPoint.x() - size.width() / 2 ), 00800 static_cast<int>( topPoint.y() + 00801 ( position() == Bottom 00802 ? halfFontHeight 00803 : ((halfFontHeight + size.height()) * -1.0) ) ) ), 00804 size ) ); 00805 00806 bool origClipping = ptr->hasClipping(); 00807 00808 QRect labelGeo = labelItem->geometry(); 00809 // if our item would only half fit, we disable clipping for that one 00810 if( labelGeo.left() < geoRect.left() && labelGeo.right() > geoRect.left() ) 00811 ptr->setClipping( false ); 00812 if( labelGeo.left() < geoRect.right() && labelGeo.right() > geoRect.right() ) 00813 ptr->setClipping( false ); 00814 00815 labelItem->setGeometry( labelGeo ); 00816 00817 labelStep = labelDiff - dimX.stepWidth; 00818 labelItem->paint( ptr ); 00819 00820 // do not call customizedLabel() again: 00821 labelItem2->setText( labelItem->text() ); 00822 00823 // maybe enable clipping afterwards 00824 ptr->setClipping( origClipping ); 00825 } else { 00826 labelStep -= dimX.stepWidth; 00827 } 00828 } 00829 00830 if( hardLabelsCount ) { 00831 if( idxLabel >= hardLabelsCount -1 ) 00832 idxLabel = 0; 00833 else 00834 ++idxLabel; 00835 } else if( headerLabelsCount ) { 00836 if( idxLabel >= headerLabelsCount - 1 ) { 00837 idxLabel = 0; 00838 }else 00839 ++idxLabel; 00840 } else { 00841 iLabelF += dimX.stepWidth; 00842 } 00843 } 00844 if ( isLogarithmicX ) 00845 i *= 10.0; 00846 else 00847 i += dimX.stepWidth; 00848 } 00849 } else { 00850 const double maxLimit = maxValueY; 00851 const double steg = dimY.stepWidth; 00852 int maxLabelsWidth = 0; 00853 qreal labelValue; 00854 if( drawLabels && position() == Right ){ 00855 // Find the widest label, so we to know how much we need to right-shift 00856 // our labels, to get them drawn right aligned: 00857 labelValue = minValueY; 00858 while ( labelValue <= maxLimit ) { 00859 labelItem->setText( customizedLabel(QString::number( labelValue )) ); 00860 maxLabelsWidth = qMax( maxLabelsWidth, labelItem->sizeHint().width() ); 00861 00862 calculateNextLabel( labelValue, steg, isLogarithmicY ); 00863 } 00864 } 00865 00866 bool origClipping = ptr->hasClipping(); 00867 ptr->setClipping( false ); 00868 labelValue = minValueY; 00869 qreal step = steg; 00870 bool nextLabel = false; 00871 //qDebug("minValueY: %f maxLimit: %f steg: %f", minValueY, maxLimit, steg); 00872 00873 // first calculate the steps depending on labels colision 00874 while ( labelValue <= maxLimit ) { 00875 QPointF leftPoint = plane->translate( QPointF( 0, labelValue ) ); 00876 const qreal translatedValue = leftPoint.y(); 00877 //qDebug() << "geoRect:" << geoRect << " geoRect.top()" << geoRect.top() 00878 //<< "geoRect.bottom()" << geoRect.bottom() << " translatedValue:" << translatedValue; 00879 if( translatedValue > geoRect.top() && translatedValue <= geoRect.bottom() ){ 00880 if ( drawLabels ) { 00881 labelItem->setText( customizedLabel(QString::number( labelValue )) ); 00882 labelItem2->setText( customizedLabel(QString::number( labelValue + step )) ); 00883 QPointF nextPoint = plane->translate( QPointF( 0, labelValue + step ) ); 00884 if ( labelItem->intersects( *labelItem2, leftPoint, nextPoint ) ) 00885 { 00886 step += steg; 00887 nextLabel = false; 00888 }else{ 00889 nextLabel = true; 00890 } 00891 } 00892 }else{ 00893 nextLabel = true; 00894 } 00895 00896 if ( nextLabel || isLogarithmicY ) 00897 calculateNextLabel( labelValue, step, isLogarithmicY ); 00898 else 00899 labelValue = minValueY; 00900 } 00901 00902 // Second - Paint the labels 00903 labelValue = minValueY; 00904 //qDebug() << "axis labels starting at" << labelValue << "step width" << step; 00905 while ( labelValue <= maxLimit ) { 00906 //qDebug() << "value now" << labelValue; 00907 labelItem->setText( customizedLabel(QString::number( labelValue )) ); 00908 QPointF leftPoint = plane->translate( QPointF( 0, labelValue ) ); 00909 QPointF rightPoint ( 0.0, labelValue ); 00910 rightPoint = plane->translate( rightPoint ); 00911 leftPoint.setX( rulerRef.x() + tickLength() ); 00912 rightPoint.setX( rulerRef.x() ); 00913 00914 const qreal translatedValue = rightPoint.y(); 00915 const bool bIsVisibleLabel = 00916 ( translatedValue >= geoRect.top() && translatedValue <= geoRect.bottom() ); 00917 00918 if( bIsVisibleLabel ){ 00919 ptr->drawLine( leftPoint, rightPoint ); 00920 drawnYTicks.append( static_cast<int>( leftPoint.y() ) ); 00921 const QSize labelSize( labelItem->sizeHint() ); 00922 leftPoint.setX( leftPoint.x() ); 00923 const int x = 00924 static_cast<int>( leftPoint.x() + met.height() * ( position() == Left ? -0.5 : 0.5) ) 00925 - ( position() == Left ? labelSize.width() : (labelSize.width() - maxLabelsWidth) ); 00926 const int y = 00927 static_cast<int>( leftPoint.y() - ( met.ascent() + met.descent() ) * 0.6 ); 00928 labelItem->setGeometry( QRect( QPoint( x, y ), labelSize ) ); 00929 labelItem->paint( ptr ); 00930 } 00931 00932 calculateNextLabel( labelValue, step, isLogarithmicY ); 00933 } 00934 00935 ptr->setClipping( origClipping ); 00936 } 00937 delete labelItem; 00938 delete labelItem2; 00939 } 00940 00941 // this draws the subunit rulers 00942 if ( drawSubUnitRulers ) { 00943 d->drawSubUnitRulers( ptr, plane, dim, rulerRef, isAbscissa() ? drawnXTicks : drawnYTicks ); 00944 } 00945 00946 if( ! titleText().isEmpty() ){ 00947 d->drawTitleText( ptr, plane, areaGeoRect ); 00948 } 00949 00950 //qDebug() << "KDChart::CartesianAxis::paintCtx() done."; 00951 } |
|
Definition at line 196 of file KDChartAbstractAreaBase.cpp. References d, and KDChart::AbstractAreaBase::paintFrameAttributes(). Referenced by KDChart::TextArea::paintAll(), KDChart::AbstractAreaWidget::paintAll(), and KDChart::AbstractArea::paintAll().
00197 { 00198 Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintFrame()", 00199 "Private class was not initialized!" ); 00200 paintFrameAttributes( painter, rect, d->frameAttributes ); 00201 } |
|
Definition at line 169 of file KDChartAbstractAreaBase.cpp. References KDChart::FrameAttributes::isVisible(), and KDChart::FrameAttributes::pen(). Referenced by KDChart::AbstractAreaBase::paintFrame().
00171 { 00172 00173 if( !attributes.isVisible() ) return; 00174 00175 // Note: We set the brush to NoBrush explicitely here. 00176 // Otherwise we might get a filled rectangle, so any 00177 // previously drawn background would be overwritten by that area. 00178 00179 const QPen oldPen( painter.pen() ); 00180 const QBrush oldBrush( painter.brush() ); 00181 painter.setPen( attributes.pen() ); 00182 painter.setBrush( Qt::NoBrush ); 00183 painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) ); 00184 painter.setBrush( oldBrush ); 00185 painter.setPen( oldPen ); 00186 } |
|
Draws the background and frame, then calls paint(). In most cases there is no need to overwrite this method in a derived class, but you would overwrite AbstractLayoutItem::paint() instead. Definition at line 111 of file KDChartAbstractArea.cpp. References KDChart::AbstractArea::paintAll().
00112 { 00113 const QRect oldGeometry( geometry() ); 00114 if( oldGeometry != rect ) 00115 setGeometry( rect ); 00116 painter.translate( rect.left(), rect.top() ); 00117 paintAll( painter ); 00118 painter.translate( -rect.left(), -rect.top() ); 00119 if( oldGeometry != rect ) 00120 setGeometry( oldGeometry ); 00121 } |
|
Definition at line 74 of file KDChartLayoutItems.h.
00075 { 00076 return mParentLayout; 00077 } |
|
Definition at line 145 of file KDChartCartesianAxis.cpp. References d. Referenced by expandingDirections(), isAbscissa(), isOrdinate(), maximumSize(), paintCtx(), and tickLength().
00146 { 00147 return d->position; 00148 } |
|
Reimplemented from KDChart::AbstractAreaBase. Definition at line 155 of file KDChartAbstractArea.cpp.
00156 {
00157 emit positionChanged( this );
00158 }
|
|
Definition at line 78 of file KDChartLayoutItems.h. Referenced by KDChart::Chart::takeCoordinatePlane().
00079 { 00080 if( mParentLayout ){ 00081 if( widget() ) 00082 mParentLayout->removeWidget( widget() ); 00083 else 00084 mParentLayout->removeItem( this ); 00085 } 00086 } |
|
Reset the title text attributes to the built-in default:. Same font and pen as AbstractAxis::textAttributes() and 1.5 times their size. Definition at line 127 of file KDChartCartesianAxis.cpp. References d, and layoutPlanes().
00128 { 00129 d->useDefaultTextAttributes = true; 00130 layoutPlanes(); 00131 } |
|
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint(). The method triggers AbstractArea::sizeHint() to find out the amount of overlap at the right edge of the area.
Definition at line 85 of file KDChartAbstractArea.cpp. References d. Referenced by KDChart::AutoSpacerLayoutItem::sizeHint().
|
|
Definition at line 107 of file KDChartAbstractAreaBase.cpp. References d.
00108 { 00109 d->backgroundAttributes = a; 00110 } |
|
Definition at line 97 of file KDChartAbstractAreaBase.cpp. References d. Referenced by KDChart::Legend::clone().
00098 { 00099 d->frameAttributes = a; 00100 } |
|
pure virtual in QLayoutItem
Implements KDChart::AbstractAxis. Definition at line 1190 of file KDChartCartesianAxis.cpp. References d.
01191 { 01192 // qDebug() << "KDChart::CartesianAxis::setGeometry(" << r << ") called" 01193 // << (isAbscissa() ? "for Abscissa":"for Ordinate") << "axis"; 01194 d->geometry = r; 01195 } |
|
Use this to specify your own set of strings, to be used as axis labels. Labels specified via setLabels take precedence: If a non-empty list is passed, KD Chart will use these strings as axis labels, instead of calculating them. If you a smaller number of strings than the number of labels drawn at this axis, KD Chart will iterate over the list, repeating the strings, until all labels are drawn. As an example you could specify the seven days of the week as abscissa labels, which would be repeatedly used then. By passing an empty QStringList you can reset the default behaviour.
Definition at line 263 of file KDChartAbstractAxis.cpp. References d.
00264 { 00265 d->hardLabels = list; 00266 } |
|
Definition at line 70 of file KDChartLayoutItems.h.
00071 { 00072 mParentLayout = lay; 00073 } |
|
Inform the item about its widget: This enables the item, to trigger that widget's update, whenever the size of the item's contents has changed. Thus, you need to call setParentWidget on every item, that has a non-fixed size. Definition at line 64 of file KDChartLayoutItems.cpp. References KDChart::AbstractLayoutItem::mParent. Referenced by KDChart::Legend::buildLegend(), and KDChart::AbstractCartesianDiagram::takeAxis().
00065 { 00066 mParent = widget; 00067 } |
|
Definition at line 139 of file KDChartCartesianAxis.cpp. References d, and layoutPlanes().
00140 { 00141 d->position = p; 00142 layoutPlanes(); 00143 } |
|
Use this to specify your own set of strings, to be used as axis labels, in case the normal labels are too long.
Definition at line 289 of file KDChartAbstractAxis.cpp. References d.
00290 { 00291 d->hardShortLabels = list; 00292 } |
|
Use this to specify the text attributes to be used for axis labels. By default, the reference area will be set at painting time. It will be the then-valid coordinate plane's parent widget, so normally, it will be the KDChart::Chart. Thus the labels of all of your axes in all of your diagrams within that Chart will be drawn in same font size, by default.
Definition at line 231 of file KDChartAbstractAxis.cpp. References d.
00232 { 00233 d->textAttributes = a; 00234 } |
|
Definition at line 96 of file KDChartCartesianAxis.cpp. References d, and layoutPlanes().
00097 { 00098 //FIXME(khz): Call update al all places where axis internals are changed! 00099 d->titleText = text; 00100 layoutPlanes(); 00101 } |
|
Definition at line 108 of file KDChartCartesianAxis.cpp. References d, and layoutPlanes().
00109 { 00110 d->titleTextAttributes = a; 00111 d->useDefaultTextAttributes = false; 00112 layoutPlanes(); 00113 } |
|
Returns a list of strings, that are used as axis labels, as set via setShortLabels.
Definition at line 302 of file KDChartAbstractAxis.cpp. References d. Referenced by paintCtx().
00303 { 00304 return d->hardShortLabels; 00305 } |
|
pure virtual in QLayoutItem
Definition at line 1185 of file KDChartCartesianAxis.cpp. References maximumSize().
01186 { 01187 return maximumSize(); 01188 } |
|
Report changed size hint: ask the parent widget to recalculate the layout.
Definition at line 86 of file KDChartLayoutItems.cpp. Referenced by KDChart::TextLayoutItem::sizeHint().
00087 { 00088 // This is exactly like what QWidget::updateGeometry does. 00089 // qDebug("KDChart::AbstractLayoutItem::sizeHintChanged() called"); 00090 if( mParent ) { 00091 if ( mParent->layout() ) 00092 mParent->layout()->invalidate(); 00093 else 00094 QApplication::postEvent( mParent, new QEvent( QEvent::LayoutRequest ) ); 00095 } 00096 } |
|
Returns the text attributes to be used for axis labels.
Definition at line 241 of file KDChartAbstractAxis.cpp. References d. Referenced by maximumSize(), paintCtx(), and titleTextAttributes().
00242 { 00243 return d->textAttributes; 00244 } |
|
Definition at line 1202 of file KDChartCartesianAxis.cpp. References isAbscissa(), Left, position(), and Top. Referenced by maximumSize(), and paintCtx().
01203 { 01204 int result = 0; 01205 01206 if ( isAbscissa() ) { 01207 result = position() == Top ? -4 : 3; 01208 } else { 01209 result = position() == Left ? -4 : 3; 01210 } 01211 01212 if ( subUnitTicks ) 01213 result = result < 0 ? result + 1 : result - 1; 01214 01215 return result; 01216 } |
|
Definition at line 103 of file KDChartCartesianAxis.cpp. References d. Referenced by maximumSize(), and paintCtx().
00104 { 00105 return d->titleText; 00106 } |
|
Returns the text attributes that will be used for displaying the title text. This is either the text attributes as specified by setTitleTextAttributes, or (if setTitleTextAttributes() was not called) the default text attributes. Definition at line 115 of file KDChartCartesianAxis.cpp. References d, KDChart::TextAttributes::fontSize(), hasDefaultTitleTextAttributes(), KDChart::TextAttributes::setFontSize(), KDChart::Measure::setValue(), KDChart::AbstractAxis::textAttributes(), and KDChart::Measure::value().
00116 { 00117 if( hasDefaultTitleTextAttributes() ){ 00118 TextAttributes ta( textAttributes() ); 00119 Measure me( ta.fontSize() ); 00120 me.setValue( me.value() * 1.5 ); 00121 ta.setFontSize( me ); 00122 return ta; 00123 } 00124 return d->titleTextAttributes; 00125 } |
|
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint(). The method triggers AbstractArea::sizeHint() to find out the amount of overlap at the top edge of the area.
Definition at line 93 of file KDChartAbstractArea.cpp. References d. Referenced by KDChart::AutoSpacerLayoutItem::sizeHint().
|
|
Reimplemented in KDChart::AbstractCoordinatePlane. Definition at line 141 of file KDChartAbstractArea.h. |
|
Definition at line 88 of file KDChartLayoutItems.h. Referenced by KDChart::AbstractLayoutItem::setParentWidget(). |
|
Definition at line 89 of file KDChartLayoutItems.h. |
|
Definition at line 129 of file KDChartAbstractAxis.h. |
|
Definition at line 126 of file KDChartAbstractAxis.h. |