libkpl  6.0
A Library for Graphical Presentation of Data Sets and Functions
KplScene Class Reference

Kpl graphics scene class. More...

#include <kplscene.h>

Inheritance diagram for KplScene:

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

FrameItemframe (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
 

Detailed Description

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.

Author
Werner Stille

Constructor & Destructor Documentation

◆ KplScene()

KplScene::KplScene ( const QSizeF & size = QSizeF(21, 14.8),
QObject * parent = nullptr )

Constructor.

Parameters
sizescene size in cm units.
parentpointer to parent QObject.

Member Function Documentation

◆ exportImage()

bool KplScene::exportImage ( const QUrl & url,
bool boundingBox = true )

Exports as image file.

Parameters
urlURL of the file.
boundingBoxtrue for calculation of bounding box.
Returns
true when file is saved.

◆ frame()

FrameItem * KplScene::frame ( int z = -1) const
protected

Finds parent item corresponding to a z value of a plot item.

Parameters
zz value of item, -1 for end of list.
Returns
pointer to parent frame or zero if no parent exists.

◆ framelike()

static bool KplScene::framelike ( int type)
static

Checks if type of an item is that of a FrameItem or an item inheriting from FrameItem.

Parameters
typeitem type as returned by the item's function type() reimplemented from QGraphicsItem::type().
Returns
true for type equal to FrameItem::Type, Array3DItem::Type or Fun3DItem::Type.

◆ insertItem()

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.

Parameters
itempointer to plot item.
zz value of item, -1 for appending.

◆ items()

QList< QGraphicsItem * > KplScene::items ( Qt::SortOrder order) const

Returns ordered list of items.

Parameters
ordersort order: Qt::AscendingOrder or Qt::DescendingOrder.
Returns
ordered list.

◆ map()

QPointF KplScene::map ( const QPointF & p) const

Maps from cm to pixel units.

Parameters
pposition in cm.
Returns
position in pixel units.

◆ mapInv()

QPointF KplScene::mapInv ( const QPointF & p) const

Maps from pixel to cm units.

Parameters
pposition in pixel units.
Returns
position in cm units.

◆ mouseMoved

void KplScene::mouseMoved ( const QPointF & pos,
const FrameItem * frame )
signal

Emitted when mouse has moved within the plot window.

Parameters
posmouse cursor position.
framepointer to frame containing pos item or 0 if pos not within a frame item.

◆ mouseMoveEvent()

virtual void KplScene::mouseMoveEvent ( QGraphicsSceneMouseEvent * e)
overrideprotectedvirtual

Emits signal mouseMoved to indicate actual position and the frame item under the mouse cursor.

Parameters
emouse event.

◆ mousePressed

void KplScene::mousePressed ( const QPointF & pos,
Qt::MouseButtons buttons )
signal

Emitted when mouse button has been pressed.

Parameters
posmouse cursor position.
buttonscombination of pressed mouse buttons.

◆ mousePressEvent()

virtual void KplScene::mousePressEvent ( QGraphicsSceneMouseEvent * e)
overrideprotectedvirtual

Emits signal mousePressed to indicate actual position and pressed button.

Parameters
emouse event.

◆ positionChanged

void KplScene::positionChanged ( QGraphicsItem * item)
signal

Emitted when position of item has changed.

Parameters
itempointer to plot item.

◆ previewCreated

void KplScene::previewCreated ( const QString & filename)
signal

Emitted after creation of a preview file to allow scheduling for cleanup.

Parameters
filenamefull path of preview file.

◆ print()

void KplScene::print ( QPrinter * printer)

Prints plot.

Parameters
printerpointer to printer object.

◆ readData()

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.

Parameters
urlURL of the file.
decimalChardecimal symbol of floating point numbers used in file.
autoPathHeadertrue for setting the heading to the path of the URL.
autoNormtrue for automatic normalization.
logXtrue for logarithmic x axis.
logYtrue for logarithmic y axis.
x0left page margin in cm.
y0bottom page margin in cm.
widthwidth in cm.0
heightheight in cm.
colorFramecolor for frame and labels.
colorGridcolor for grids and tics.
colorDatacolor for data plot.
gridModegrid mode of frame item.
xTextx axis text.
yTexty axis text.
headerheader text.
relSizerelative size of text, markers and lines.
colXx column index.
colYy column index.
colErry error column index.
errorBarstrue to plot error bars.
symbolsymbol type.
Returns
true when when succeeded.

◆ readPlo() [1/2]

static bool KplScene::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 )
static

Reads plot file and initializes plot items.

Parameters
urlURL of the file.
listlist for plot items.
windowpointer to main window.
colorFramedefault color for frame and labels.
colorGriddefault color for grids and tics.
colorDatadefault color for data plot.
symboldefault symbol type.
x0default left page margin in cm.
y0default bottom page margin in cm.
widthdefault width in cm.
heightdefault height in cm.
gridModedefault frame grid mode.
colXdefault x column index.
colYdefault y column index.
colErrdefault y error column index.
errorBarsdefault, true to plot error bars.
Returns
true for success.

◆ readPlo() [2/2]

bool KplScene::readPlo ( const QUrl & url,
QWidget * window = nullptr )

Reads plot file, initializes items and adds them to the scene.

Parameters
urlURL of the file.
windowpointer to main window.
Returns
true for success.

◆ savePlo() [1/2]

bool KplScene::savePlo ( const QUrl & url,
bool absolute = true,
char format = 'g',
int precision = 6 ) const

Saves all plot items at URL.

Parameters
urlURL of file.
absolutesave absolute URL when true.
formatformat character for floating point number presentation.
precisionprecision (number of digits) for floating point number presentation.
Returns
true for success.

◆ savePlo() [2/2]

static bool KplScene::savePlo ( const QUrl & url,
const QList< QGraphicsItem * > & list,
bool absolute = true,
char format = 'g',
int precision = 6 )
static

Saves plot items of a given list at URL.

Parameters
urlURL of file.
listlist of items to save.
absolutesave absolute URL when true.
formatformat character for floating point number presentation.
precisionprecision (number of digits) floating point number presentation.
Returns
true for success.

◆ savePS()

bool KplScene::savePS ( const QUrl & url = QUrl(),
bool landscape = false,
bool boundingBox = true )

Generates PostScript file.

Parameters
urlURL of the file (empty URL for preview of a temporary file).
landscapetrue for landscape orientation.
boundingBoxtrue for calculation of bounding box.
Returns
true when file is saved.

◆ setProperties()

void KplScene::setProperties ( QGraphicsItem * item) const

Sets item properties according to transformation matrix.

Parameters
itempointer to plot item.

◆ setSize()

void KplScene::setSize ( const QSizeF & size)

Sets scene size and transformation matrix.

Parameters
sizesize in cm units.

◆ steps()

QPointF KplScene::steps ( int z = -1) const

Returns user unit steps for one pixel steps.

Parameters
zz value of item, -1 for end of list.
Returns
user unit steps.

◆ updatePos()

void KplScene::updatePos ( QGraphicsItem * item)

Emits signal positionChanged.

Parameters
itempointer to plot item.

The documentation for this class was generated from the following file: