libkpl  5.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 <tille@uni-freiburg.de>, (C) 2017
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 
21 class QPointF;
22 class QPrinter;
23 class QString;
24 class QTransform;
25 class FrameItem;
26 
34 class Q_DECL_EXPORT KplScene : public QGraphicsScene
35 {
36  Q_OBJECT
37 public:
43  KplScene(const QSizeF& size = QSizeF(21, 14.8), QObject* parent = 0);
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", const QString& yText = "y",
132  const QString& header = "", double relSize = 1, int colX = 0,
133  int colY = 1, int colErr = 2, bool errorBars = false,
141  bool readPlo(const QUrl& url, QWidget* window = 0);
162  static bool readPlo(const QUrl& url, QList<QGraphicsItem*>& list,
163  QWidget* window = 0, unsigned colorFrame = 0,
164  unsigned colorGrid = 0, unsigned colorData = 0,
166  double x0 = 4, double y0 = 3, double width = 15,
167  double height = 10,
169  int colX = 0, int colY = 0, int colErr = 0,
170  bool errorBars = false);
180  bool savePlo(const QUrl& url, bool absolute = true, char format = 'g',
181  int precision = 6) const;
192  static bool savePlo(const QUrl& url, const QList<QGraphicsItem*>& list,
193  bool absolute = true, char format = 'g',
194  int precision = 6);
202  bool savePS(const QUrl& url = QUrl(), bool landscape = false,
203  bool boundingBox = true);
205  inline const QSizeF size() const { return m_size; };
207  void setDashOffsets() const;
212  void setProperties(QGraphicsItem* item) const;
217  void setSize(const QSizeF& size);
223  QPointF steps(int z = -1) const;
228  void updatePos(QGraphicsItem* item);
229 
230 signals:
237  void mouseMoved(const QPointF& pos, const FrameItem* frame);
243  void mousePressed(const QPointF& pos, Qt::MouseButtons buttons);
248  void positionChanged(QGraphicsItem* item);
253  void previewCreated(const QString& filename);
254 
255 protected:
261  FrameItem* frame(int z = -1) const;
267  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e);
272  virtual void mousePressEvent(QGraphicsSceneMouseEvent* e);
273  double m_sx, m_sy;
274  QTransform m_matrix, m_inv;
275  QSizeF m_size;
276 };
277 
278 #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.
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.
KplScene(const QSizeF &size=QSizeF(21, 14.8), QObject *parent=0)
Constructor.
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.
static bool framelike(int type)
Checks if type of an item is that of a FrameItem or an item inheriting from FrameItem.
const QTransform & matrix() const
Returns matrix for transformation from cm to pixel units.
Definition: kplscene.h:89
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.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e)
Emits signal mouseMoved to indicate actual position and the frame item under the mouse cursor.
void print(QPrinter *printer)
Prints plot.
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:205
static bool readPlo(const QUrl &url, QList< QGraphicsItem * > &list, QWidget *window=0, 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.
QList< QGraphicsItem * > items(Qt::SortOrder order) const
Returns ordered list of items.
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", const QString &yText="y", const QString &header="", 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 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.
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=0)
Reads plot file, initializes items and adds them to the scene.
~KplScene()
Destructor.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *e)
Emits signal mousePressed to indicate actual position and pressed button.