libkpl  6.0
A Library for Graphical Presentation of Data Sets and Functions
kplscene.h
1//
2// C++ Interface: kplscene
3//
4// Description:
5//
6//
7// Author: Werner Stille <kpl@werner-stille.de>, (C) 2024
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef KPLSCENE_H
13#define KPLSCENE_H
14
15#include <QSizeF>
16#include <QGraphicsScene>
17#include <QUrl>
18#include "arrayitem.h"
19#include "frameitem.h"
20
21class QPointF;
22class QPrinter;
23class QString;
24class QTransform;
25class FrameItem;
26
34class Q_DECL_EXPORT KplScene : public QGraphicsScene
35{
36 Q_OBJECT
37public:
43 KplScene(const QSizeF& size = QSizeF(21, 14.8), QObject* parent = nullptr);
52 bool exportImage(const QUrl& url, bool boundingBox = true);
61 static bool framelike(int type);
69 void insertItem(QGraphicsItem* item, int z = -1);
75 QList<QGraphicsItem*> items(Qt::SortOrder order) const;
81 QPointF map(const QPointF& p) const;
87 QPointF mapInv(const QPointF& p) const;
89 inline const QTransform& matrix() const { return m_matrix; };
94 void print(QPrinter* printer);
123 bool readData(const QUrl& url,
125 bool autoPathHeader = false, bool autoNorm = true,
126 bool logX = false, bool logY = false, double x0 = 4,
127 double y0 = 3, double width = 15, double height = 10,
128 unsigned colorFrame = 0, unsigned colorGrid = 0,
129 unsigned colorData = 0,
131 const QString& xText = "x"_L1, const QString& yText = "y"_L1,
132 const QString& header = ""_L1, double relSize = 1,
133 int colX = 0, int colY = 1, int colErr = 2,
134 bool errorBars = false,
142 bool readPlo(const QUrl& url, QWidget* window = nullptr);
163 static bool readPlo(const QUrl& url, QList<QGraphicsItem*>& list,
164 QWidget* window = nullptr, unsigned colorFrame = 0,
165 unsigned colorGrid = 0, unsigned colorData = 0,
167 double x0 = 4, double y0 = 3, double width = 15,
168 double height = 10,
170 int colX = 0, int colY = 0, int colErr = 0,
171 bool errorBars = false);
181 bool savePlo(const QUrl& url, bool absolute = true, char format = 'g',
182 int precision = 6) const;
193 static bool savePlo(const QUrl& url, const QList<QGraphicsItem*>& list,
194 bool absolute = true, char format = 'g',
195 int precision = 6);
203 bool savePS(const QUrl& url = QUrl(), bool landscape = false,
204 bool boundingBox = true);
206 inline const QSizeF size() const { return m_size; };
208 void setDashOffsets() const;
213 void setProperties(QGraphicsItem* item) const;
218 void setSize(const QSizeF& size);
224 QPointF steps(int z = -1) const;
229 void updatePos(QGraphicsItem* item);
230
231Q_SIGNALS:
238 void mouseMoved(const QPointF& pos, const FrameItem* frame);
244 void mousePressed(const QPointF& pos, Qt::MouseButtons buttons);
249 void positionChanged(QGraphicsItem* item);
254 void previewCreated(const QString& filename);
255
256protected:
262 FrameItem* frame(int z = -1) const;
268 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e) override;
273 virtual void mousePressEvent(QGraphicsSceneMouseEvent* e) override;
274 double m_sx, m_sy;
275 QTransform m_matrix, m_inv;
276 QSizeF m_size;
277};
278
279#endif
DecimalCharacter
Decimal character.
Definition arrayitem.h:43
@ Point
Decimal point.
Definition arrayitem.h:44
Frame item class.
Definition frameitem.h:34
GridMode
Grid mode.
Definition frameitem.h:37
@ AxesWithLabels
Axes with tics and labels.
Definition frameitem.h:40
Symbol
Symbol types.
Definition kplitem.h:83
@ SolidLine
Solid line.
Definition kplitem.h:102
@ OpenCircle
Open circle.
Definition kplitem.h:101
Kpl graphics scene class.
Definition kplscene.h:35
void setSize(const QSizeF &size)
Sets scene size and transformation matrix.
bool savePlo(const QUrl &url, bool absolute=true, char format='g', int precision=6) const
Saves all plot items at URL.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override
Emits signal mouseMoved to indicate actual position and the frame item under the mouse cursor.
void mouseMoved(const QPointF &pos, const FrameItem *frame)
Emitted when mouse has moved within the plot window.
QPointF steps(int z=-1) const
Returns user unit steps for one pixel steps.
void mousePressed(const QPointF &pos, Qt::MouseButtons buttons)
Emitted when mouse button has been pressed.
void positionChanged(QGraphicsItem *item)
Emitted when position of item has changed.
void setDashOffsets() const
Sets offsets for dashed lines.
const QTransform & matrix() const
Returns matrix for transformation from cm to pixel units.
Definition kplscene.h:89
static bool framelike(int type)
Checks if type of an item is that of a FrameItem or an item inheriting from FrameItem.
bool exportImage(const QUrl &url, bool boundingBox=true)
Exports as image file.
void setProperties(QGraphicsItem *item) const
Sets item properties according to transformation matrix.
static bool savePlo(const QUrl &url, const QList< QGraphicsItem * > &list, bool absolute=true, char format='g', int precision=6)
Saves plot items of a given list at URL.
void previewCreated(const QString &filename)
Emitted after creation of a preview file to allow scheduling for cleanup.
bool readData(const QUrl &url, ArrayItem::DecimalCharacter decimalChar=ArrayItem::Point, bool autoPathHeader=false, bool autoNorm=true, bool logX=false, bool logY=false, double x0=4, double y0=3, double width=15, double height=10, unsigned colorFrame=0, unsigned colorGrid=0, unsigned colorData=0, FrameItem::GridMode gridMode=FrameItem::AxesWithLabels, const QString &xText="x"_L1, const QString &yText="y"_L1, const QString &header=""_L1, double relSize=1, int colX=0, int colY=1, int colErr=2, bool errorBars=false, KplItem::Symbol symbol=KplItem::SolidLine)
Opens a data file.
void print(QPrinter *printer)
Prints plot.
QList< QGraphicsItem * > items(Qt::SortOrder order) const
Returns ordered list of items.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *e) override
Emits signal mousePressed to indicate actual position and pressed button.
QPointF mapInv(const QPointF &p) const
Maps from pixel to cm units.
const QSizeF size() const
Returns scene size in cm units.
Definition kplscene.h:206
static bool readPlo(const QUrl &url, QList< QGraphicsItem * > &list, QWidget *window=nullptr, unsigned colorFrame=0, unsigned colorGrid=0, unsigned colorData=0, KplItem::Symbol symbol=KplItem::OpenCircle, double x0=4, double y0=3, double width=15, double height=10, FrameItem::GridMode gridMode=FrameItem::AxesWithLabels, int colX=0, int colY=0, int colErr=0, bool errorBars=false)
Reads plot file and initializes plot items.
FrameItem * frame(int z=-1) const
Finds parent item corresponding to a z value of a plot item.
bool readPlo(const QUrl &url, QWidget *window=nullptr)
Reads plot file, initializes items and adds them to the scene.
void insertItem(QGraphicsItem *item, int z=-1)
Inserts a plot item and makes it a child item of a framelike item, if a framelike item with lower z v...
QPointF map(const QPointF &p) const
Maps from cm to pixel units.
bool savePS(const QUrl &url=QUrl(), bool landscape=false, bool boundingBox=true)
Generates PostScript file.
void updatePos(QGraphicsItem *item)
Emits signal positionChanged.
KplScene(const QSizeF &size=QSizeF(21, 14.8), QObject *parent=nullptr)
Constructor.
~KplScene()
Destructor.