libkpl
6.0
A Library for Graphical Presentation of Data Sets and Functions
|
Kpl graphics scene class. More...
#include <kplscene.h>
Signals | |
void | mouseMoved (const QPointF &pos, const FrameItem *frame) |
Emitted when mouse has moved within the plot window. | |
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 | previewCreated (const QString &filename) |
Emitted after creation of a preview file to allow scheduling for cleanup. | |
Public Member Functions | |
KplScene (const QSizeF &size=QSizeF(21, 14.8), QObject *parent=nullptr) | |
Constructor. | |
~KplScene () | |
Destructor. | |
bool | exportImage (const QUrl &url, bool boundingBox=true) |
Exports as image 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 value exists and the inserted item is no framelike item itself. | |
QList< QGraphicsItem * > | items (Qt::SortOrder order) const |
Returns ordered list of items. | |
QPointF | map (const QPointF &p) const |
Maps from cm to pixel units. | |
QPointF | mapInv (const QPointF &p) const |
Maps from pixel to cm units. | |
const QTransform & | matrix () const |
Returns matrix for transformation from cm to pixel units. | |
void | print (QPrinter *printer) |
Prints plot. | |
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. | |
bool | readPlo (const QUrl &url, QWidget *window=nullptr) |
Reads plot file, initializes items and adds them to the scene. | |
bool | savePlo (const QUrl &url, bool absolute=true, char format='g', int precision=6) const |
Saves all plot items at URL. | |
bool | savePS (const QUrl &url=QUrl(), bool landscape=false, bool boundingBox=true) |
Generates PostScript file. | |
const QSizeF | size () const |
Returns scene size in cm units. | |
void | setDashOffsets () const |
Sets offsets for dashed lines. | |
void | setProperties (QGraphicsItem *item) const |
Sets item properties according to transformation matrix. | |
void | setSize (const QSizeF &size) |
Sets scene size and transformation matrix. | |
QPointF | steps (int z=-1) const |
Returns user unit steps for one pixel steps. | |
void | updatePos (QGraphicsItem *item) |
Emits signal positionChanged. | |
Static Public Member Functions | |
static bool | framelike (int type) |
Checks if type of an item is that of a FrameItem or an item inheriting from FrameItem. | |
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. | |
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. | |
Protected Member Functions | |
FrameItem * | frame (int z=-1) const |
Finds parent item corresponding to a z value of a plot item. | |
virtual void | mouseMoveEvent (QGraphicsSceneMouseEvent *e) override |
Emits signal mouseMoved to indicate actual position and the frame item under the mouse cursor. | |
virtual void | mousePressEvent (QGraphicsSceneMouseEvent *e) override |
Emits signal mousePressed to indicate actual position and pressed button. | |
Protected Attributes | |
double | m_sx |
double | m_sy |
QTransform | m_matrix |
QTransform | m_inv |
QSizeF | m_size |
Kpl graphics scene class.
The methods readData, readPlo and insertItem can be used to populate the scene with plot items. The methods print and savePS allow to print and to export as PostScript file, respectively.
KplScene::KplScene | ( | const QSizeF & | size = QSizeF(21, 14.8), |
QObject * | parent = nullptr ) |
Constructor.
size | scene size in cm units. |
parent | pointer to parent QObject. |
bool KplScene::exportImage | ( | const QUrl & | url, |
bool | boundingBox = true ) |
Exports as image file.
url | URL of the file. |
boundingBox | true for calculation of bounding box. |
|
protected |
Finds parent item corresponding to a z value of a plot item.
z | z value of item, -1 for end of list. |
|
static |
Checks if type of an item is that of a FrameItem or an item inheriting from FrameItem.
type | item type as returned by the item's function type() reimplemented from QGraphicsItem::type(). |
void KplScene::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 value exists and the inserted item is no framelike item itself.
item | pointer to plot item. |
z | z value of item, -1 for appending. |
QList< QGraphicsItem * > KplScene::items | ( | Qt::SortOrder | order | ) | const |
Returns ordered list of items.
order | sort order: Qt::AscendingOrder or Qt::DescendingOrder. |
QPointF KplScene::map | ( | const QPointF & | p | ) | const |
Maps from cm to pixel units.
p | position in cm. |
QPointF KplScene::mapInv | ( | const QPointF & | p | ) | const |
Maps from pixel to cm units.
p | position in pixel units. |
|
signal |
Emitted when mouse has moved within the plot window.
pos | mouse cursor position. |
frame | pointer to frame containing pos item or 0 if pos not within a frame item. |
|
overrideprotectedvirtual |
Emits signal mouseMoved to indicate actual position and the frame item under the mouse cursor.
e | mouse event. |
|
signal |
Emitted when mouse button has been pressed.
pos | mouse cursor position. |
buttons | combination of pressed mouse buttons. |
|
overrideprotectedvirtual |
Emits signal mousePressed to indicate actual position and pressed button.
e | mouse event. |
|
signal |
Emitted when position of item has changed.
item | pointer to plot item. |
|
signal |
Emitted after creation of a preview file to allow scheduling for cleanup.
filename | full path of preview file. |
void KplScene::print | ( | QPrinter * | printer | ) |
Prints plot.
printer | pointer to printer object. |
bool KplScene::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.
In case of success, a FrameItem and a corresponding ArrayItem are constructed and added to the scene.
url | URL of the file. |
decimalChar | decimal symbol of floating point numbers used in file. |
autoPathHeader | true for setting the heading to the path of the URL. |
autoNorm | true for automatic normalization. |
logX | true for logarithmic x axis. |
logY | true for logarithmic y axis. |
x0 | left page margin in cm. |
y0 | bottom page margin in cm. |
width | width in cm.0 |
height | height in cm. |
colorFrame | color for frame and labels. |
colorGrid | color for grids and tics. |
colorData | color for data plot. |
gridMode | grid mode of frame item. |
xText | x axis text. |
yText | y axis text. |
header | header text. |
relSize | relative size of text, markers and lines. |
colX | x column index. |
colY | y column index. |
colErr | y error column index. |
errorBars | true to plot error bars. |
symbol | symbol type. |
|
static |
Reads plot file and initializes plot items.
url | URL of the file. |
list | list for plot items. |
window | pointer to main window. |
colorFrame | default color for frame and labels. |
colorGrid | default color for grids and tics. |
colorData | default color for data plot. |
symbol | default symbol type. |
x0 | default left page margin in cm. |
y0 | default bottom page margin in cm. |
width | default width in cm. |
height | default height in cm. |
gridMode | default frame grid mode. |
colX | default x column index. |
colY | default y column index. |
colErr | default y error column index. |
errorBars | default, true to plot error bars. |
bool KplScene::readPlo | ( | const QUrl & | url, |
QWidget * | window = nullptr ) |
Reads plot file, initializes items and adds them to the scene.
url | URL of the file. |
window | pointer to main window. |
bool KplScene::savePlo | ( | const QUrl & | url, |
bool | absolute = true, | ||
char | format = 'g', | ||
int | precision = 6 ) const |
Saves all plot items at URL.
url | URL of file. |
absolute | save absolute URL when true. |
format | format character for floating point number presentation. |
precision | precision (number of digits) for floating point number presentation. |
|
static |
Saves plot items of a given list at URL.
url | URL of file. |
list | list of items to save. |
absolute | save absolute URL when true. |
format | format character for floating point number presentation. |
precision | precision (number of digits) floating point number presentation. |
bool KplScene::savePS | ( | const QUrl & | url = QUrl(), |
bool | landscape = false, | ||
bool | boundingBox = true ) |
Generates PostScript file.
url | URL of the file (empty URL for preview of a temporary file). |
landscape | true for landscape orientation. |
boundingBox | true for calculation of bounding box. |
void KplScene::setProperties | ( | QGraphicsItem * | item | ) | const |
Sets item properties according to transformation matrix.
item | pointer to plot item. |
void KplScene::setSize | ( | const QSizeF & | size | ) |
Sets scene size and transformation matrix.
size | size in cm units. |
QPointF KplScene::steps | ( | int | z = -1 | ) | const |
Returns user unit steps for one pixel steps.
z | z value of item, -1 for end of list. |
void KplScene::updatePos | ( | QGraphicsItem * | item | ) |
Emits signal positionChanged.
item | pointer to plot item. |