24 #include "KDChartAbstractCoordinatePlane_p.h" 29 #include <KDABLibFakes> 31 #include <QGridLayout> 32 #include <QRubberBand> 33 #include <QMouseEvent> 34 #include <QtCore/qmath.h> 40 AbstractCoordinatePlane::Private::Private()
44 , referenceCoordinatePlane( 0 )
45 , enableCornerSpacers( true )
46 , enableRubberBandZooming( false )
65 void AbstractCoordinatePlane::init()
70 Qt::QueuedConnection );
78 d->diagrams.append( diagram );
79 diagram->setParent(
d->parent );
83 connect( diagram, SIGNAL( modelsChanged() ),
this, SLOT(
layoutPlanes() ) );
84 connect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
update()) );
85 connect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
relayout()) );
95 if ( diagram && oldDiagram_ != diagram ) {
97 if (
d->diagrams.count() ) {
99 oldDiagram =
d->diagrams.first();
100 if ( oldDiagram == diagram )
116 const int idx =
d->diagrams.indexOf( diagram );
118 d->diagrams.removeAt( idx );
119 diagram->setParent( 0 );
121 disconnect( diagram, SIGNAL( modelsChanged() ),
this, SLOT(
layoutPlanes() ) );
122 disconnect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
update()) );
123 disconnect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
relayout()) );
132 if (
d->diagrams.isEmpty() )
136 return d->diagrams.first();
149 qCopy(
d->diagrams.begin(),
d->diagrams.end(), std::back_inserter( list ) );
159 d->gridAttributes = a;
165 return d->gridAttributes;
170 return d->grid->updateData(
this );
175 d->grid->setNeedRecalculate();
180 d->referenceCoordinatePlane = plane;
185 return d->referenceCoordinatePlane;
213 return Qt::Vertical | Qt::Horizontal;
220 return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
225 return QSize(60, 60);
237 if (
d->geometry != r ) {
273 d->enableRubberBandZooming = enable;
275 if ( !enable &&
d->rubberBand != 0 )
277 delete d->rubberBand;
284 return d->enableRubberBandZooming;
289 if (
d->enableCornerSpacers == enable )
return;
291 d->enableCornerSpacers = enable;
297 return d->enableCornerSpacers;
302 if ( event->button() == Qt::LeftButton )
304 if (
d->enableRubberBandZooming &&
d->rubberBand == 0 )
305 d->rubberBand =
new QRubberBand( QRubberBand::Rectangle, qobject_cast< QWidget* >(
parent() ) );
307 if (
d->rubberBand != 0 )
309 d->rubberBandOrigin =
event->pos();
310 d->rubberBand->setGeometry( QRect( event->pos(), QSize() ) );
311 d->rubberBand->show();
316 else if ( event->button() == Qt::RightButton )
318 if (
d->enableRubberBandZooming && !
d->rubberBandZoomConfigHistory.isEmpty() )
336 a->mousePressEvent( event );
342 if ( event->button() == Qt::RightButton )
350 a->mouseDoubleClickEvent( event );
356 if (
d->rubberBand != 0 )
362 const qreal rubberWidth =
static_cast< qreal
>(
d->rubberBand->width() );
363 const qreal rubberHeight =
static_cast< qreal
>(
d->rubberBand->height() );
365 if ( rubberWidth > 0.0 && rubberHeight > 0.0 )
368 const qreal centerX = qFloor(
d->rubberBand->geometry().width() / 2.0 +
d->rubberBand->geometry().x() );
369 const qreal centerY = qCeil(
d->rubberBand->geometry().height() / 2.0 +
d->rubberBand->geometry().y() );
371 const qreal rubberCenterX =
static_cast< qreal
>( centerX -
geometry().x() );
372 const qreal rubberCenterY =
static_cast< qreal
>( centerY -
geometry().y() );
375 const qreal myWidth =
static_cast< qreal
>(
geometry().width() );
376 const qreal myHeight =
static_cast< qreal
>(
geometry().height() );
383 const qreal newZoomFactorX =
zoomFactorX() * myWidth / rubberWidth;
384 const qreal newZoomFactorY =
zoomFactorY() * myHeight / rubberHeight;
387 const QPointF newZoomCenter( newCenterX, newCenterY );
394 d->rubberBand->parentWidget()->update();
395 delete d->rubberBand;
403 a->mouseReleaseEvent( event );
409 if (
d->rubberBand != 0 )
411 const QRect normalized = QRect(
d->rubberBandOrigin, event->pos() ).normalized();
412 d->rubberBand->setGeometry( normalized &
geometry() );
419 a->mouseMoveEvent( event );
423 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE) 428 return d->isVisiblePoint(
this, point );
437 #if !defined(QT_NO_DEBUG_STREAM) 442 stream <<
"DataDimension(" 443 <<
" start=" << r.
start void needUpdate()
Emitted when plane needs to update its drawings.
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane, TernaryCoordinatePlane.
QSize minimumSize() const override
pure virtual in QLayoutItem
virtual AbstractCoordinatePlane * sharedAxisMasterPlane(QPainter *p=0)
virtual void takeDiagram(AbstractDiagram *diagram)
Removes the diagram from the plane, without deleting it.
bool isEmpty() const override
pure virtual in QLayoutItem
An area in the chart with a background, a frame, etc.
void setParent(Chart *parent)
Called internally by KDChart::Chart.
bool isRubberBandZoomingEnabled() const
QRect geometry() const override
pure virtual in QLayoutItem
void internal_geometryChanged(QRect, QRect)
A chart with one or more diagrams.
ZoomParameters stores the center and the factor of zooming internally.
virtual void layoutDiagrams()=0
Distribute the available space among the diagrams and axes.
void needRelayout()
Emitted when plane needs to trigger the Chart's layouting.
Definition of global enums.
void relayout()
Calling relayout() on the plane triggers the global KDChart::Chart::slotRelayout() ...
void layoutPlanes()
Calling layoutPlanes() on the plane triggers the global KDChart::Chart::slotLayoutPlanes() ...
void destroyedCoordinatePlane(AbstractCoordinatePlane *)
Emitted when this coordinate plane is destroyed.
void setGlobalGridAttributes(const GridAttributes &)
Set the grid attributes to be used by this coordinate plane.
virtual void mouseMoveEvent(QMouseEvent *event)
KDChartEnums::GranularitySequence sequence
virtual QPointF zoomCenter() const
void update()
Calling update() on the plane triggers the global KDChart::Chart::update()
virtual void replaceDiagram(AbstractDiagram *diagram, AbstractDiagram *oldDiagram=0)
Replaces the old diagram, or appends the diagram, it there is none yet.
~AbstractCoordinatePlane() override
AbstractDiagram defines the interface for diagram classes.
virtual void setZoomFactorX(qreal factor)
Sets the zoom factor in horizontal direction, that is applied to all coordinate transformations.
const QPointF center() const
static QString granularitySequenceToString(GranularitySequence sequence)
Converts the specified granularity sequence enum to a string representation.
AbstractDiagram * diagram()
QSize sizeHint() const override
pure virtual in QLayoutItem
void setReferenceCoordinatePlane(AbstractCoordinatePlane *plane)
Set another coordinate plane to be used as the reference plane for this one.
void geometryChanged(QRect, QRect)
Emitted after the geometry of the Coordinate Plane has been changed.
virtual void mouseReleaseEvent(QMouseEvent *event)
const bool isVisiblePoint(const QPointF &point) const
Tests, if a point is visible on the coordinate plane.
void setRubberBandZoomingEnabled(bool enable)
Enables or disables zooming with a rubber band using the mouse.
virtual void setZoomFactorY(qreal factor)
Sets the zoom factor in vertical direction, that is applied to all coordinate transformations.
virtual void setCoordinatePlane(AbstractCoordinatePlane *plane)
Set the coordinate plane associated with the diagram.
AbstractCoordinatePlane * referenceCoordinatePlane() const
There are two ways, in which planes can be caused to interact, in where they are put layouting wise: ...
virtual qreal zoomFactorY() const
QSize maximumSize() const override
pure virtual in QLayoutItem
A set of attributes controlling the appearance of grids.
DataDimensionsList gridDimensionsList()
Returns the dimensions used for drawing the grid lines.
void setCornerSpacersEnabled(bool enable)
Enables or disables the use of spacers in the plane corners.
bool isCornerSpacersEnabled() const
GridAttributes globalGridAttributes() const
virtual void mouseDoubleClickEvent(QMouseEvent *event)
QDebug operator<<(QDebug stream, const DataDimension &r)
Qt::Orientations expandingDirections() const override
pure virtual in QLayoutItem
AbstractCoordinatePlane::AxesCalcMode calcMode
AbstractDiagramList diagrams()
virtual void addDiagram(AbstractDiagram *diagram)
Adds a diagram to this coordinate plane.
Helper class for one dimension of data, e.g.
void setGeometry(const QRect &r) override
pure virtual in QLayoutItem
virtual void setZoomCenter(const QPointF ¢er)
Set the point (in value coordinates) to be used as the center point in zoom operations.
void needLayoutPlanes()
Emitted when plane needs to trigger the Chart's layouting of the coord.
void setGridNeedsRecalculate()
Used by the chart to clear the cached grid data.
virtual qreal zoomFactorX() const
virtual void mousePressEvent(QMouseEvent *event)