12 #include "KDChartBarDiagram_p.h"
16 #include "KDChartPainterSaver_p.h"
23 #include <KDABLibFakes>
25 #include "KDChartNormalBarDiagram_p.h"
26 #include "KDChartNormalLyingBarDiagram_p.h"
27 #include "KDChartPercentBarDiagram_p.h"
28 #include "KDChartPercentLyingBarDiagram_p.h"
29 #include "KDChartStackedBarDiagram_p.h"
30 #include "KDChartStackedLyingBarDiagram_p.h"
34 BarDiagram::Private::Private()
38 BarDiagram::Private::~Private()
41 delete stackedDiagram;
42 delete percentDiagram;
43 delete normalLyingDiagram;
44 delete stackedLyingDiagram;
45 delete percentLyingDiagram;
48 void BarDiagram::Private::setOrientationAndType(Qt::Orientation o,
BarDiagram::BarType type)
50 if (orientation == o && implementor->type() == type) {
53 auto *barDia = qobject_cast<BarDiagram *>(diagram);
57 if (orientation == Qt::Vertical) {
60 implementor = normalDiagram;
63 implementor = stackedDiagram;
66 implementor = percentDiagram;
69 Q_ASSERT_X(
false,
"BarDiagram::setType",
"unknown diagram subtype");
74 implementor = normalLyingDiagram;
77 implementor = stackedLyingDiagram;
80 implementor = percentLyingDiagram;
83 Q_ASSERT_X(
false,
"BarDiagram::setType",
"unknown diagram subtype");
87 Q_ASSERT(implementor->type() == type);
91 barDia->setDataBoundariesDirty();
92 Q_EMIT barDia->layoutChanged(barDia);
93 Q_EMIT barDia->propertiesChanged();
104 void BarDiagram::init()
106 d->normalDiagram =
new NormalBarDiagram(
this);
107 d->stackedDiagram =
new StackedBarDiagram(
this);
108 d->percentDiagram =
new PercentBarDiagram(
this);
109 d->normalLyingDiagram =
new NormalLyingBarDiagram(
this);
110 d->stackedLyingDiagram =
new StackedLyingBarDiagram(
this);
111 d->percentLyingDiagram =
new PercentLyingBarDiagram(
this);
112 d->implementor =
d->normalDiagram;
125 auto *newDiagram =
new BarDiagram(
new Private(*
d));
126 newDiagram->setType(
type());
150 d->setOrientationAndType(
d->orientation,
type);
158 return d->implementor->type();
166 d->setOrientationAndType(
orientation,
d->implementor->type());
174 return d->orientation;
201 d->attributesModel->mapFromSource(index),
202 QVariant::fromValue(ba),
231 return d->attributesModel->data(
232 d->attributesModel->mapFromSource(index),
265 d->attributesModel->setData(
266 d->attributesModel->mapFromSource(index),
267 QVariant::fromValue(threeDAttrs),
297 return d->attributesModel->data(
298 d->attributesModel->mapFromSource(index),
319 d->compressor.setResolution(
static_cast<int>(this->size().width() *
coordinatePlane()->zoomFactorX()),
320 static_cast<int>(this->size().height() *
coordinatePlane()->zoomFactorY()));
323 return QPair<QPointF, QPointF>(QPointF(0, 0), QPointF(0, 0));
330 return d->implementor->calculateDataBoundaries();
335 QPainter painter(viewport());
348 const PainterSaver p(ctx->
painter());
349 if (model()->rowCount(rootIndex()) == 0 || model()->columnCount(rootIndex()) == 0)
367 d->implementor->paint(ctx);
374 d->compressor.setResolution(
static_cast<int>(size.width() *
coordinatePlane()->zoomFactorX()),
377 QAbstractItemView::resize(size.toSize());
380 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && defined(Q_COMPILER_MANGLES_RETURN_TYPE)
389 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && defined(Q_COMPILER_MANGLES_RETURN_TYPE)
Base class for diagrams based on a cartesian coordianate system.
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane,...
virtual AbstractCoordinatePlane * sharedAxisMasterPlane(QPainter *p=nullptr)
virtual AttributesModel * attributesModel() const
virtual bool checkInvariants(bool justReturnTheStatus=false) const
void layoutChanged(AbstractDiagram *)
QModelIndex attributesModelRootIndex() const
returns a QModelIndex pointing into the AttributesModel that corresponds to the root index of the dia...
const QPair< QPointF, QPointF > dataBoundaries() const
Return the bottom left and top right data point, that the diagram will display (unless the grid adjus...
AbstractCoordinatePlane * coordinatePlane() const
void setDataBoundariesDirty() const
static bool isBoundariesValid(const QRectF &r)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override
Set of attributes for changing the appearance of bar charts.
BarDiagram defines a common bar diagram.
void setThreeDBarAttributes(const ThreeDBarAttributes &a)
ThreeDBarAttributes threeDBarAttributes() const
BarDiagram(QWidget *parent=nullptr, CartesianCoordinatePlane *plane=nullptr)
int numberOfAbscissaSegments() const override
BarAttributes barAttributes() const
const QPair< QPointF, QPointF > calculateDataBoundaries() const override
bool compare(const BarDiagram *other) const
void paintEvent(QPaintEvent *) override
void resizeEvent(QResizeEvent *) override
Qt::Orientation orientation() const
virtual BarDiagram * clone() const
void setBarAttributes(const BarAttributes &a)
void paint(PaintContext *paintContext) override
int numberOfOrdinateSegments() const override
void setOrientation(Qt::Orientation orientation)
void resize(const QSizeF &area) override
void setType(const BarType type)
qreal threeDItemDepth(const QModelIndex &index) const override
Cartesian coordinate plane.
Stores information about painting diagrams.
void setPainter(QPainter *painter)
void setCoordinatePlane(AbstractCoordinatePlane *plane)
void setRectangle(const QRectF &rect)
AbstractCoordinatePlane * coordinatePlane() const
QPainter * painter() const
A set of 3D bar attributes.
@ ThreeDBarAttributesRole