12 #include "KDChartLeveyJenningsAxis_p.h"
22 #include "KDChartPainterSaver_p.h"
25 #include <KDABLibFakes>
44 auto *cd = qobject_cast<LeveyJenningsDiagram *>(
d->mDiagram);
48 auto *cd = qobject_cast<LeveyJenningsDiagram *>(
diagram);
53 void LeveyJenningsAxis::init()
57 const QStringList
labels = QStringList() << tr(
"-3sd") << tr(
"-2sd") << tr(
"mean")
58 << tr(
"+2sd") << tr(
"+3sd");
82 if (
type !=
d->type) {
86 if (qobject_cast<const LeveyJenningsDiagram *>(
d->diagram()) && qobject_cast<const LeveyJenningsCoordinatePlane *>(
d->diagram()->coordinatePlane())) {
87 color = qobject_cast<const LeveyJenningsCoordinatePlane *>(
d->diagram()->coordinatePlane())->gridAttributes().gridPen(
type).color();
119 Q_ASSERT_X(
d->diagram(),
"LeveyJenningsAxis::paint",
120 "Function call not allowed: The axis is not assigned to any diagram.");
123 Q_ASSERT_X(plane,
"LeveyJenningsAxis::paint",
124 "Bad function call: PaintContext::coodinatePlane() NOT a levey jennings plane.");
128 if (!
d->diagram()->model())
145 : diag->calculatedMeanValue();
147 : diag->calculatedStandardDeviation();
149 const bool drawLabels = labelTA.
isVisible();
155 const QObject *referenceArea = plane->parent();
157 const QVector<qreal> values = QVector<qreal>() << (meanValue - 3 * standardDeviation)
158 << (meanValue - 2 * standardDeviation)
160 << (meanValue + 2 * standardDeviation)
161 << (meanValue + 3 * standardDeviation);
163 Q_ASSERT_X(values.count() <=
labels().count(),
"LeveyJenningsAxis::paintAsOrdinate",
"Need to have at least 5 labels");
171 QPainter *
const painter = context->
painter();
172 const PainterSaver ps(painter);
173 painter->setRenderHint(QPainter::Antialiasing,
true);
174 painter->setClipping(
false);
178 for (
int i = 0; i < values.count(); ++i) {
179 const QPointF labelPos = plane->translate(QPointF(0.0, values.at(i)));
182 const QSize size = labelItem.
sizeHint();
184 labelItem.
setGeometry(QRectF(QPointF(xPos, labelPos.y() - size.height() / 2.0), size).toRect());
187 if (values.at(i) > diag->expectedMeanValue() + 4 * diag->expectedStandardDeviation())
190 if (values.at(i) < diag->expectedMeanValue() - 4 * diag->expectedStandardDeviation())
193 labelItem.
paint(painter);
202 setLabels(QStringList() << QString::fromLatin1(
" "));
208 const QObject *referenceArea = plane->
parent();
211 const bool drawLabels = labelTA.
isVisible();
216 const QPair<QDateTime, QDateTime> range = diag->timeRange();
218 QPainter *
const painter = context->
painter();
219 const PainterSaver ps(painter);
220 painter->setRenderHint(QPainter::Antialiasing,
true);
221 painter->setClipping(
false);
228 QSize origSize = labelItem.
sizeHint();
229 if (range.first.secsTo(range.second) < 86400)
238 labelItem.
setGeometry(QRectF(QPointF(
geometry().left() - origSize.width() / 2.0, yPos), size).toRect());
239 labelItem.
paint(painter);
247 if (range.first.secsTo(range.second) < 86400)
255 labelItem2.
setGeometry(QRectF(QPointF(
geometry().right() - size.width() + origSize.width() / 2.0, yPos), size).toRect());
256 labelItem2.
paint(painter);
@ MeasureOrientationMinimum
virtual const QString customizedLabel(const QString &label) const
Reimplement this method if you want to adjust axis labels before they are printed.
const AbstractDiagram * diagram() const
void setLabels(const QStringList &list)
Use this to specify your own set of strings, to be used as axis labels.
QStringList labels() const
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for axis labels.
TextAttributes textAttributes() const
Returns the text attributes to be used for axis labels.
AbstractDiagram defines the interface for diagram classes.
virtual bool isOrdinate() const
void paintCtx(PaintContext *) override
virtual bool isAbscissa() const
virtual Position position() const
QRect geometry() const override
~LeveyJenningsAxis() override
Qt::DateFormat dateFormat() const
void setDateFormat(Qt::DateFormat format)
void paintCtx(PaintContext *) override
LeveyJenningsGridAttributes::GridType type() const
void setType(LeveyJenningsGridAttributes::GridType type)
virtual void paintAsAbscissa(PaintContext *)
bool compare(const LeveyJenningsAxis *other) const
LeveyJenningsAxis(LeveyJenningsDiagram *diagram=nullptr)
virtual void paintAsOrdinate(PaintContext *)
Levey Jennings coordinate plane This is actually nothing real more than a plain cartesian coordinate ...
LeveyDiagram defines a Levey Jennings chart.
Stores information about painting diagrams.
AbstractCoordinatePlane * coordinatePlane() const
QPainter * painter() const
static QPen scalePen(const QPen &pen)
A set of text attributes.
void setPen(const QPen &pen)
QSize sizeHint() const override
void paint(QPainter *) override
void setText(const QString &text)
void setGeometry(const QRect &r) override