libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
KplScene Class Reference

Kpl graphics scene class. More...

#include <kplscene.h>

Inheritance diagram for KplScene:
Inheritance graph
[legend]

Signals

void mouseMoved (const QPointF &pos, const FrameItem *frame)
 Emitted when mouse has moved within the plot window. More...
 
void mousePressed (const QPointF &pos, Qt::MouseButtons buttons)
 Emitted when mouse button has been pressed. More...
 
void positionChanged (QGraphicsItem *item)
 Emitted when position of item has changed. More...
 
void previewCreated (const QString &filename)
 Emitted after creation of a preview file to allow scheduling for cleanup. More...
 

Public Member Functions

 KplScene (const QSizeF &size=QSizeF(21, 14.8), QObject *parent=0)
 Constructor. More...
 
 ~KplScene ()
 Destructor. More...
 
bool exportImage (const QUrl &url, bool boundingBox=true)
 Exports as image file. More...
 
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. More...
 
QList< QGraphicsItem * > items (Qt::SortOrder order) const
 Returns ordered list of items. More...
 
QPointF map (const QPointF &p) const
 Maps from cm to pixel units. More...
 
QPointF mapInv (const QPointF &p) const
 Maps from pixel to cm units. More...
 
const QTransformmatrix () const
 Returns matrix for transformation from cm to pixel units. More...
 
void print (QPrinter *printer)
 Prints plot. More...
 
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. More...
 
bool readPlo (const QUrl &url, QWidget *window=0)
 Reads plot file, initializes items and adds them to the scene. More...
 
bool savePlo (const QUrl &url, bool absolute=true, char format= 'g', int precision=6) const
 Saves all plot items at URL. More...
 
bool savePS (const QUrl &url=QUrl(), bool landscape=false, bool boundingBox=true)
 Generates PostScript file. More...
 
const QSizeF size () const
 Returns scene size in cm units. More...
 
void setDashOffsets () const
 Sets offsets for dashed lines. More...
 
void setProperties (QGraphicsItem *item) const
 Sets item properties according to transformation matrix. More...
 
void setSize (const QSizeF &size)
 Sets scene size and transformation matrix. More...
 
QPointF steps (int z=-1) const
 Returns user unit steps for one pixel steps. More...
 
void updatePos (QGraphicsItem *item)
 Emits signal positionChanged. More...
 
- Public Member Functions inherited from QGraphicsScene
 QGraphicsScene (QObject *parent)
 
 QGraphicsScene (const QRectF &sceneRect, QObject *parent)
 
 QGraphicsScene (qreal x, qreal y, qreal width, qreal height, QObject *parent)
 
QRectF sceneRect () const
 
qreal width () const
 
qreal height () const
 
void setSceneRect (const QRectF &rect)
 
void setSceneRect (qreal x, qreal y, qreal w, qreal h)
 
void render (QPainter *painter, const QRectF &target, const QRectF &source, Qt::AspectRatioMode aspectRatioMode)
 
ItemIndexMethod itemIndexMethod () const
 
void setItemIndexMethod (ItemIndexMethod method)
 
bool isSortCacheEnabled () const
 
void setSortCacheEnabled (bool enabled)
 
int bspTreeDepth () const
 
void setBspTreeDepth (int depth)
 
QRectF itemsBoundingRect () const
 
QList< QGraphicsItem * > items (Qt::SortOrder order) const
 
QList< QGraphicsItem * > items (const QPointF &pos, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const
 
QList< QGraphicsItem * > items (const QRectF &rect, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const
 
QList< QGraphicsItem * > items (const QPolygonF &polygon, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const
 
QList< QGraphicsItem * > items (const QPainterPath &path, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const
 
QList< QGraphicsItem * > collidingItems (const QGraphicsItem *item, Qt::ItemSelectionMode mode) const
 
QGraphicsItemitemAt (const QPointF &position) const
 
QGraphicsItemitemAt (const QPointF &position, const QTransform &deviceTransform) const
 
QList< QGraphicsItem * > items (qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode) const
 
QList< QGraphicsItem * > items (qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode, Qt::SortOrder order, const QTransform &deviceTransform) const
 
QGraphicsItemitemAt (qreal x, qreal y) const
 
QGraphicsItemitemAt (qreal x, qreal y, const QTransform &deviceTransform) const
 
QList< QGraphicsItem * > selectedItems () const
 
QPainterPath selectionArea () const
 
void setSelectionArea (const QPainterPath &path, const QTransform &deviceTransform)
 
void setSelectionArea (const QPainterPath &path, Qt::ItemSelectionMode mode, const QTransform &deviceTransform)
 
void setSelectionArea (const QPainterPath &path, Qt::ItemSelectionOperation selectionOperation, Qt::ItemSelectionMode mode, const QTransform &deviceTransform)
 
QGraphicsItemGroupcreateItemGroup (const QList< QGraphicsItem * > &items)
 
void destroyItemGroup (QGraphicsItemGroup *group)
 
void addItem (QGraphicsItem *item)
 
QGraphicsEllipseItemaddEllipse (const QRectF &rect, const QPen &pen, const QBrush &brush)
 
QGraphicsLineItemaddLine (const QLineF &line, const QPen &pen)
 
QGraphicsPathItemaddPath (const QPainterPath &path, const QPen &pen, const QBrush &brush)
 
QGraphicsPixmapItemaddPixmap (const QPixmap &pixmap)
 
QGraphicsPolygonItemaddPolygon (const QPolygonF &polygon, const QPen &pen, const QBrush &brush)
 
QGraphicsRectItemaddRect (const QRectF &rect, const QPen &pen, const QBrush &brush)
 
QGraphicsTextItemaddText (const QString &text, const QFont &font)
 
QGraphicsSimpleTextItemaddSimpleText (const QString &text, const QFont &font)
 
QGraphicsProxyWidgetaddWidget (QWidget *widget, Qt::WindowFlags wFlags)
 
QGraphicsEllipseItemaddEllipse (qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush)
 
QGraphicsLineItemaddLine (qreal x1, qreal y1, qreal x2, qreal y2, const QPen &pen)
 
QGraphicsRectItemaddRect (qreal x, qreal y, qreal w, qreal h, const QPen &pen, const QBrush &brush)
 
void removeItem (QGraphicsItem *item)
 
QGraphicsItemfocusItem () const
 
void setFocusItem (QGraphicsItem *item, Qt::FocusReason focusReason)
 
bool hasFocus () const
 
void setFocus (Qt::FocusReason focusReason)
 
void clearFocus ()
 
void setStickyFocus (bool enabled)
 
bool stickyFocus () const
 
QGraphicsItemmouseGrabberItem () const
 
QBrush backgroundBrush () const
 
void setBackgroundBrush (const QBrush &brush)
 
QBrush foregroundBrush () const
 
void setForegroundBrush (const QBrush &brush)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
QList< QGraphicsView * > views () const
 
void update (qreal x, qreal y, qreal w, qreal h)
 
void invalidate (qreal x, qreal y, qreal w, qreal h, SceneLayers layers)
 
QStylestyle () const
 
void setStyle (QStyle *style)
 
QFont font () const
 
void setFont (const QFont &font)
 
QPalette palette () const
 
void setPalette (const QPalette &palette)
 
bool isActive () const
 
QGraphicsItemactivePanel () const
 
void setActivePanel (QGraphicsItem *item)
 
QGraphicsWidgetactiveWindow () const
 
void setActiveWindow (QGraphicsWidget *widget)
 
bool sendEvent (QGraphicsItem *item, QEvent *event)
 
qreal minimumRenderSize () const
 
void setMinimumRenderSize (qreal minSize)
 
void update (const QRectF &rect)
 
void invalidate (const QRectF &rect, SceneLayers layers)
 
void advance ()
 
void clearSelection ()
 
void clear ()
 
void changed (const QList< QRectF > &region)
 
void sceneRectChanged (const QRectF &rect)
 
void selectionChanged ()
 
void focusItemChanged (QGraphicsItem *newFocusItem, QGraphicsItem *oldFocusItem, Qt::FocusReason reason)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
virtual const QMetaObjectmetaObject () const
 
QString objectName () const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const
 
bool blockSignals (bool block)
 
QThreadthread () const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const
 
const QObjectList & children () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const
 
bool disconnect (const QObject *receiver, const char *method) const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const
 
bool inherits (const char *className) const
 
void deleteLater ()
 

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. More...
 
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. More...
 
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. More...
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 

Protected Member Functions

FrameItemframe (int z=-1) const
 Finds parent item corresponding to a z value of a plot item. More...
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *e)
 Emits signal mouseMoved to indicate actual position and the frame item under the mouse cursor. More...
 
virtual void mousePressEvent (QGraphicsSceneMouseEvent *e)
 Emits signal mousePressed to indicate actual position and pressed button. More...
 
- Protected Member Functions inherited from QGraphicsScene
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *contextMenuEvent)
 
virtual void dragEnterEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dragMoveEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dragLeaveEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void dropEvent (QGraphicsSceneDragDropEvent *event)
 
virtual void focusInEvent (QFocusEvent *focusEvent)
 
virtual void focusOutEvent (QFocusEvent *focusEvent)
 
virtual void helpEvent (QGraphicsSceneHelpEvent *helpEvent)
 
virtual void keyPressEvent (QKeyEvent *keyEvent)
 
virtual void keyReleaseEvent (QKeyEvent *keyEvent)
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *mouseEvent)
 
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *mouseEvent)
 
virtual void wheelEvent (QGraphicsSceneWheelEvent *wheelEvent)
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void drawBackground (QPainter *painter, const QRectF &rect)
 
virtual void drawForeground (QPainter *painter, const QRectF &rect)
 
virtual void drawItems (QPainter *painter, int numItems, QGraphicsItem *[] items, const QStyleOptionGraphicsItem[] options, QWidget *widget)
 
virtual bool focusNextPrevChild (bool next)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Protected Attributes

double m_sx
 
double m_sy
 
QTransform m_matrix
 
QTransform m_inv
 
QSizeF m_size
 

Additional Inherited Members

- Public Attributes inherited from QGraphicsScene
typedef SceneLayers
 
- Properties inherited from QGraphicsScene
 backgroundBrush
 
 foregroundBrush
 
 itemIndexMethod
 
 sceneRect
 
 bspTreeDepth
 
 palette
 
 font
 
 sortCacheEnabled
 
 stickyFocus
 
 minimumRenderSize
 
- Properties inherited from QObject
 objectName
 

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 ( const QSizeF size = QSizeF(21, 14.8),
QObject parent = 0 
)

Constructor.

Parameters
sizescene size in cm units.
parentpointer to parent QObject.
KplScene::~KplScene ( )

Destructor.

Member Function Documentation

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.
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.
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.
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.
QList<QGraphicsItem*> KplScene::items ( Qt::SortOrder  order) const

Returns ordered list of items.

Parameters
ordersort order: Qt::AscendingOrder or Qt::DescendingOrder.
Returns
ordered list.
QPointF KplScene::map ( const QPointF p) const

Maps from cm to pixel units.

Parameters
pposition in cm.
Returns
position in pixel units.
QPointF KplScene::mapInv ( const QPointF p) const

Maps from pixel to cm units.

Parameters
pposition in pixel units.
Returns
position in cm units.
const QTransform& KplScene::matrix ( ) const
inline

Returns matrix for transformation from cm to pixel units.

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.
virtual void KplScene::mouseMoveEvent ( QGraphicsSceneMouseEvent e)
protectedvirtual

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

Parameters
emouse event.

Reimplemented from QGraphicsScene.

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.
virtual void KplScene::mousePressEvent ( QGraphicsSceneMouseEvent e)
protectedvirtual

Emits signal mousePressed to indicate actual position and pressed button.

Parameters
emouse event.

Reimplemented from QGraphicsScene.

void KplScene::positionChanged ( QGraphicsItem item)
signal

Emitted when position of item has changed.

Parameters
itempointer to plot item.
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.
void KplScene::print ( QPrinter printer)

Prints plot.

Parameters
printerpointer 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",
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.

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.
bool KplScene::readPlo ( const QUrl url,
QWidget window = 0 
)

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

Parameters
urlURL of the file.
windowpointer to main window.
Returns
true for success.
static bool KplScene::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 
)
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.
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.
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.
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.
void KplScene::setDashOffsets ( ) const

Sets offsets for dashed lines.

void KplScene::setProperties ( QGraphicsItem item) const

Sets item properties according to transformation matrix.

Parameters
itempointer to plot item.
void KplScene::setSize ( const QSizeF size)

Sets scene size and transformation matrix.

Parameters
sizesize in cm units.
const QSizeF KplScene::size ( ) const
inline

Returns scene size in cm units.

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.
void KplScene::updatePos ( QGraphicsItem item)

Emits signal positionChanged.

Parameters
itempointer to plot item.

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