KPlotting 5.109.0
kplotwidget.h
1/* -*- C++ -*-
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2003 Jason Harris <kstars@30doradus.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KPLOTWIDGET_H
9#define KPLOTWIDGET_H
10
11#include <kplotting_export.h>
12
13#include <QFrame>
14#include <QList>
15
16class KPlotAxis;
17class KPlotObject;
18class KPlotPoint;
19
67class KPLOTTING_EXPORT KPlotWidget : public QFrame
68{
69 Q_OBJECT
70 Q_PROPERTY(int leftPadding READ leftPadding)
71 Q_PROPERTY(int rightPadding READ rightPadding)
72 Q_PROPERTY(int topPadding READ topPadding)
73 Q_PROPERTY(int bottomPadding READ bottomPadding)
74 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
75 Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
76 Q_PROPERTY(QColor gridColor READ gridColor WRITE setGridColor)
77 Q_PROPERTY(bool grid READ isGridShown WRITE setShowGrid)
78 Q_PROPERTY(bool objectToolTip READ isObjectToolTipShown WRITE setObjectToolTipShown)
79public:
84 explicit KPlotWidget(QWidget *parent = nullptr);
85
89 ~KPlotWidget() override;
90
94 enum Axis {
95 LeftAxis = 0,
99 };
100
104 QSize minimumSizeHint() const override;
105
109 QSize sizeHint() const override;
110
118 void setLimits(double x1, double x2, double y1, double y2);
119
141 void setSecondaryLimits(double x1, double x2, double y1, double y2);
142
149
155 QRectF dataRect() const;
156
163 QRectF secondaryDataRect() const;
164
169 QRect pixRect() const;
170
177
183 void addPlotObjects(const QList<KPlotObject *> &objects);
184
188 QList<KPlotObject *> plotObjects() const;
189
195 void setAutoDeletePlotObjects(bool autoDelete);
196
202
208
213 void resetPlot();
214
225
231 QColor backgroundColor() const;
232
239 QColor foregroundColor() const;
240
246 QColor gridColor() const;
247
252 void setBackgroundColor(const QColor &bg);
253
258 void setForegroundColor(const QColor &fg);
259
264 void setGridColor(const QColor &gc);
265
270 bool isGridShown() const;
271
277
282 bool antialiasing() const;
283
288 void setAntialiasing(bool b);
289
297 int leftPadding() const;
298
305 int rightPadding() const;
306
313 int topPadding() const;
314
321 int bottomPadding() const;
322
327 void setLeftPadding(int padding);
328
333 void setRightPadding(int padding);
334
339 void setTopPadding(int padding);
340
345 void setBottomPadding(int padding);
346
352
360 QPointF mapToWidget(const QPointF &p) const;
361
373 void maskRect(const QRectF &r, float value = 1.0f);
374
386 void maskAlongLine(const QPointF &p1, const QPointF &p2, float value = 1.0f);
387
400 void placeLabel(QPainter *painter, KPlotPoint *pp);
401
407
412 const KPlotAxis *axis(Axis type) const;
413
414public Q_SLOTS:
420 void setShowGrid(bool show);
421
427 void setObjectToolTipShown(bool show);
428
429protected:
433 bool event(QEvent *) override;
434
438 void paintEvent(QPaintEvent *) override;
439
443 void resizeEvent(QResizeEvent *) override;
444
451 virtual void drawAxes(QPainter *p);
452
458
464 QList<KPlotPoint *> pointsUnderPoint(const QPoint &p) const;
465
466private:
467 class Private;
468 Private *const d;
469
470 Q_DISABLE_COPY(KPlotWidget)
471};
472
473#endif
Axis for KPlotWidget.
Definition kplotaxis.h:25
Encapsulates a data set to be plotted in a KPlotWidget.
Definition kplotobject.h:41
Encapsulates a point in the plot.
Definition kplotpoint.h:28
Generic data plotting widget.
Definition kplotwidget.h:68
void setAutoDeletePlotObjects(bool autoDelete)
Enables auto-deletion of plot objects if autoDelete is true; otherwise auto-deletion is disabled.
void maskRect(const QRectF &r, float value=1.0f)
Indicate that object labels should try to avoid the given rectangle in the plot.
QRectF secondaryDataRect() const
KPlotWidget(QWidget *parent=nullptr)
Constructor.
bool isObjectToolTipShown() const
void resizeEvent(QResizeEvent *) override
The resize event handler, called when the widget is resized.
QList< KPlotObject * > plotObjects() const
void resetPlot()
Clear the object list, reset the data limits, and remove axis labels If auto-delete was not disabled,...
void setPixRect()
Synchronize the PixRect with the current widget size and padding settings.
void maskAlongLine(const QPointF &p1, const QPointF &p2, float value=1.0f)
Indicate that object labels should try to avoid the line joining the two given points (in pixel coord...
void setSecondaryLimits(double x1, double x2, double y1, double y2)
Reset the secondary data limits, which control the values displayed along the top and right axes.
int bottomPadding() const
~KPlotWidget() override
Destructor.
int leftPadding() const
void setRightPadding(int padding)
Set the number of pixels to the right of the plot area.
void setBackgroundColor(const QColor &bg)
Set the background color.
QColor foregroundColor() const
QRectF dataRect() const
QSize sizeHint() const override
bool event(QEvent *) override
Generic event handler.
int topPadding() const
void paintEvent(QPaintEvent *) override
The paint event handler, executed when update() or repaint() is called.
QPointF mapToWidget(const QPointF &p) const
Map a coordinate.
KPlotAxis * axis(Axis type)
void setObjectToolTipShown(bool show)
Toggle the display of a tooltip for point objects.
void setShowGrid(bool show)
Toggle whether grid lines are drawn at major tickmarks.
QList< KPlotPoint * > pointsUnderPoint(const QPoint &p) const
void placeLabel(QPainter *painter, KPlotPoint *pp)
Place an object label optimally in the plot.
const KPlotAxis * axis(Axis type) const
QSize minimumSizeHint() const override
void setForegroundColor(const QColor &fg)
Set the foreground color.
QColor gridColor() const
int rightPadding() const
void replacePlotObject(int i, KPlotObject *o)
Replace an item in the KPlotObject list.
void setLimits(double x1, double x2, double y1, double y2)
Set new data limits for the plot.
void addPlotObject(KPlotObject *object)
Add an item to the list of KPlotObjects to be plotted.
void setLeftPadding(int padding)
Set the number of pixels to the left of the plot area.
virtual void drawAxes(QPainter *p)
Draws the plot axes and axis labels.
void setGridColor(const QColor &gc)
Set the grid color.
void setAntialiasing(bool b)
Toggle antialiased drawing.
void resetPlotMask()
Reset the mask used for non-overlapping labels so that all regions of the plot area are considered em...
QRect pixRect() const
QColor backgroundColor() const
Axis
The four types of plot axes.
Definition kplotwidget.h:94
@ BottomAxis
the bottom axis
Definition kplotwidget.h:96
@ TopAxis
the top axis
Definition kplotwidget.h:98
@ RightAxis
the right axis
Definition kplotwidget.h:97
void setDefaultPaddings()
Revert all four padding values to -1, so that they will be automatically determined.
void setBottomPadding(int padding)
Set the number of pixels below the plot area.
void addPlotObjects(const QList< KPlotObject * > &objects)
Add more than one KPlotObject at one time.
bool isGridShown() const
void clearSecondaryLimits()
Unset the secondary limits, so the top and right axes show the same tickmarks as the bottom and left ...
bool antialiasing() const
void setTopPadding(int padding)
Set the number of pixels above the plot area.
void removeAllPlotObjects()
Removes all plot objects that were added to the widget.