Image Component Library (ICL)
|
The PlotWidget is an abstract base class for 2D plotting components. More...
#include <AbstractPlotWidget.h>
Classes | |
struct | Locker |
utility class for scoped locking More... | |
struct | Pen |
Utility structure for styles usend in subclasses. More... | |
Public Types | |
enum | PenType { X_AXIS_PEN, Y_AXIS_PEN, X_TIC_PEN, Y_TIC_PEN, X_LABEL_PEN, Y_LABEL_PEN, X_GRID_PEN, Y_GRID_PEN, AXIS_NAME_PEN, NUM_PEN_TYPES } |
different pen types More... | |
typedef utils::SmartPtr< Pen > | PenPtr |
typedef for managed row-style pointers | |
typedef utils::Function< float, float, float > | bgFunction |
function that is used to render a non-homo | |
Public Member Functions | |
void | install (MouseHandler *h) |
adds a new mouse handler | |
void | uninstall (MouseHandler *h) |
removes a mouse handler | |
AbstractPlotWidget (QWidget *parent=0) | |
Base constructor. | |
~AbstractPlotWidget () | |
destructor | |
virtual void | paintEvent (QPaintEvent *evt) |
custom drawing | |
virtual void | keyPressEvent (QKeyEvent *event) |
listens for F11 which enables the fullscreen mode | |
void | renderTo (QPainter &p) |
renders the whole content using the given qpainter | |
void | setBackground (const QBrush &bgBrush) |
sets the background brush | |
void | setPen (PenType p, const QPen &pen) |
sets the pen for one of the widget compoments | |
void | render () |
updates the screen | |
virtual utils::Rect32f | getDataViewPort () const |
returns the given data vieport | |
void | setDataViewPort (const utils::Rect32f &viewPort) |
sets the default dataviewport | |
void | setDataViewPort (const utils::Range32f &xrange, const utils::Range32f &yrange) |
sets the default viewport | |
void | lock () const |
locks drawing / data updates in subclasses | |
void | unlock () const |
unlocks drawing / data updates in subclasses | |
void | addAnnotations (const char type, const float *data, int num=1, const QPen &linePen=QColor(255, 0, 0), const QBrush &brush=Qt::NoBrush, const std::string &text="", const std::string &textDelim=",") |
adds an annotation to the data viewport | |
void | clearAnnotations () |
removes all existing annotations | |
virtual void | clear () |
clears everything from the widget | |
void | setBackgroundFunction (bgFunction f) |
sets the background function | |
void | updateBackgroundFunction () |
forces a repaint on the background function in the next rendering cycle | |
void | removeBackgroundFunction () |
removes the background function | |
Protected Member Functions | |
bool | isZoomed () const |
returns whether the zoom is active | |
virtual void | mouseDoubleClickEvent (QMouseEvent *event) |
internally used | |
virtual void | mouseMoveEvent (QMouseEvent *event) |
internally used | |
virtual void | mousePressEvent (QMouseEvent *event) |
internally used | |
virtual void | mouseReleaseEvent (QMouseEvent *event) |
internally used | |
virtual void | enterEvent (QEvent *event) |
internally used | |
virtual void | leaveEvent (QEvent *event) |
internally used | |
virtual bool | drawData (QPainter &p)=0 |
this must be implemented by the specific drawers | |
virtual void | drawLegend (QPainter &p, const utils::Rect &where, bool horizontal) |
draws the ledgend | |
void | drawDefaultLedgend (QPainter &p, const utils::Rect &where, bool horizontal, const std::vector< std::string > &rowNames, const std::vector< PenPtr > &pens) |
draws a default ledgen into the given quad | |
float | winToDrawX (int winX) const |
converts a window x coordinate to logical drawing coordinate | |
float | winToDrawY (int winY) const |
converts a window y coordinate to logical drawing coordinate | |
utils::Point32f | winToDraw (const utils::Point &p) const |
converts a window coordinates to logical drawing coordinates | |
int | drawToWinX (float drawX) const |
convert logical drawing x coordinate to window coordinate | |
int | drawToWinY (float drawY) const |
convert logical drawing y coordinate to window coordinate | |
utils::Point | drawToWin (const utils::Point32f &p) const |
convert logical drawing coordinates to window coordinates | |
utils::Rect32f | getDynamicDataViewPort () const |
returns the current data viewport w.r.t. the current zoom | |
Static Protected Member Functions | |
template<char s> | |
static void | draw_symbol (QPainter &p, int size, float x, float y) |
draws one of the Symbols (filled symbols are drawn by setting the QPainters brush manually) | |
Private Member Functions | |
void | property_changed (const Property &) |
internally used | |
Private Attributes | |
Data * | data |
pimpl |
The PlotWidget is an abstract base class for 2D plotting components.
Since the PlotWidget is just an abstract interface, it does not define how the actual data is shaped. Use the derived classes LowLevelPlotWidget or PlotWidget to visualize your data. We strongly recommend to use the (high level) PlotWidget class, whose interface is designed in ICL manner.
The Abstract PlotWidget provides setting, visualizing and navigating within a data viewport. The data viewport can be set explicitly -- in this case, data that is outside the viewport is clipped -- or not. If not data viewport is given, it is estimated before every drawing step dynamically. The created Widged shows a coordinate frame, tics, a grid, and tic labels. All of these features can be adapted and deactivated dynamically. Furthermore, the uses can use the left mouse button to zoom the viewport to a specific sub-rect of the current viewport. The subrect is intuitively defined by holding the left-mouse-button. Pressing the left mousebutton zooms back to the former viewport.
In addition to the abstract data visualization interface, the AbstractPlotWidget provides the AbstractPlotWidget::addAnnotations method. This can be used to add annotations (such as rectangles, circles, lines or texts) to the data viewport. The annotaiton iterface is hold very low-level. Perhaps extending classes provide simpler interfaces.
typedef utils::Function<float,float,float> icl::qt::AbstractPlotWidget::bgFunction |
function that is used to render a non-homo
typedef for managed row-style pointers
different pen types
icl::qt::AbstractPlotWidget::AbstractPlotWidget | ( | QWidget * | parent = 0 | ) |
Base constructor.
destructor
void icl::qt::AbstractPlotWidget::addAnnotations | ( | const char | type, |
const float * | data, | ||
int | num = 1 , |
||
const QPen & | linePen = QColor(255, 0, 0) , |
||
const QBrush & | brush = Qt::NoBrush , |
||
const std::string & | text = "" , |
||
const std::string & | textDelim = "," |
||
) |
adds an annotation to the data viewport
annotations are used to add some extra information to the data that is already displayed. Please note, that annotation points are not used to estimate the data viewport. If you need the data viewport to be adapted automatically to show all your annotations, you have to compute and set the data viewport manually.
type | annotation primitive type
|
rectangles and circles can optionally be labelled with text labels The text labels are displayed centered at the annotations, but the text is not scaled. For text primitives, a non-""-text is mandatory.
data | packed data that is used to draw 'num' primitives. I.e. for rectangles, data contains num * 4 floats |
This is not the way, data shall be visualized, the method is not optimized for speed and rendering and it will always copy the given data deeply.
num | |
linePen | |
brush | |
text | |
textDelim |
virtual void icl::qt::AbstractPlotWidget::clear | ( | ) | [inline, virtual] |
clears everything from the widget
'Everything' means all data and all annotations
Reimplemented in icl::qt::LowLevelPlotWidget, and icl::qt::PlotWidget.
removes all existing annotations
static void icl::qt::AbstractPlotWidget::draw_symbol | ( | QPainter & | p, |
int | size, | ||
float | x, | ||
float | y | ||
) | [inline, static, protected] |
draws one of the Symbols (filled symbols are drawn by setting the QPainters brush manually)
Please note that this template is not specialized for filled symbols like filledRect or filledCircle. These shapes must be drawn by setting up the given QPainters brush appropriately before calling the function with the corresponding unfilled shape
virtual bool icl::qt::AbstractPlotWidget::drawData | ( | QPainter & | p | ) | [protected, pure virtual] |
this must be implemented by the specific drawers
if 0 is returned, no data is available
Implemented in icl::qt::LowLevelPlotWidget.
void icl::qt::AbstractPlotWidget::drawDefaultLedgend | ( | QPainter & | p, |
const utils::Rect & | where, | ||
bool | horizontal, | ||
const std::vector< std::string > & | rowNames, | ||
const std::vector< PenPtr > & | pens | ||
) | [protected] |
draws a default ledgen into the given quad
virtual void icl::qt::AbstractPlotWidget::drawLegend | ( | QPainter & | p, |
const utils::Rect & | where, | ||
bool | horizontal | ||
) | [protected, virtual] |
draws the ledgend
Reimplemented in icl::qt::LowLevelPlotWidget.
utils::Point icl::qt::AbstractPlotWidget::drawToWin | ( | const utils::Point32f & | p | ) | const [protected] |
convert logical drawing coordinates to window coordinates
int icl::qt::AbstractPlotWidget::drawToWinX | ( | float | drawX | ) | const [protected] |
convert logical drawing x coordinate to window coordinate
int icl::qt::AbstractPlotWidget::drawToWinY | ( | float | drawY | ) | const [protected] |
convert logical drawing y coordinate to window coordinate
virtual void icl::qt::AbstractPlotWidget::enterEvent | ( | QEvent * | event | ) | [protected, virtual] |
internally used
virtual utils::Rect32f icl::qt::AbstractPlotWidget::getDataViewPort | ( | ) | const [virtual] |
returns the given data vieport
in subclasses, the data viewport can be estimated from the given data dynamically
Reimplemented in icl::qt::LowLevelPlotWidget.
utils::Rect32f icl::qt::AbstractPlotWidget::getDynamicDataViewPort | ( | ) | const [protected] |
returns the current data viewport w.r.t. the current zoom
void icl::qt::AbstractPlotWidget::install | ( | MouseHandler * | h | ) |
adds a new mouse handler
Please note, the current implementation is not complete: only mouse press, release, move and drag-events are supported custom handlers are only triggered if one of CTRL, ALT or Shift modifiers is active events cannot be removed
bool icl::qt::AbstractPlotWidget::isZoomed | ( | ) | const [protected] |
returns whether the zoom is active
virtual void icl::qt::AbstractPlotWidget::keyPressEvent | ( | QKeyEvent * | event | ) | [virtual] |
listens for F11 which enables the fullscreen mode
virtual void icl::qt::AbstractPlotWidget::leaveEvent | ( | QEvent * | event | ) | [protected, virtual] |
internally used
void icl::qt::AbstractPlotWidget::lock | ( | ) | const |
locks drawing / data updates in subclasses
virtual void icl::qt::AbstractPlotWidget::mouseDoubleClickEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
internally used
virtual void icl::qt::AbstractPlotWidget::mouseMoveEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
internally used
virtual void icl::qt::AbstractPlotWidget::mousePressEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
internally used
virtual void icl::qt::AbstractPlotWidget::mouseReleaseEvent | ( | QMouseEvent * | event | ) | [protected, virtual] |
internally used
virtual void icl::qt::AbstractPlotWidget::paintEvent | ( | QPaintEvent * | evt | ) | [virtual] |
custom drawing
void icl::qt::AbstractPlotWidget::property_changed | ( | const Property & | ) | [private] |
internally used
removes the background function
void icl::qt::AbstractPlotWidget::render | ( | ) | [inline] |
updates the screen
a shortcut to ThreadedUpdatableWidget::updateFromOtherThread()
void icl::qt::AbstractPlotWidget::renderTo | ( | QPainter & | p | ) |
renders the whole content using the given qpainter
void icl::qt::AbstractPlotWidget::setBackground | ( | const QBrush & | bgBrush | ) |
sets the background brush
sets the background function
The function is then evaluated every time, the viewport or the window size. is adapted. I.e. when the data viewport is set, or adapted automatically, or when the widget is zoomed or when the the widget is resized.
The given background functions is always called with x- and y-parameters in the logical function space rather than in window coordinates. Please note, that constantly changing viewports (i.e. due to dynamic viewport mode) will entail constant recreation of the background image. Which can be quite slow in case of complex background functions.
void icl::qt::AbstractPlotWidget::setDataViewPort | ( | const utils::Rect32f & | viewPort | ) |
sets the default dataviewport
if width is 0, the xrange is taken from the data if height is 0, the yrange is taken from the data
Important: The viewport needs to be given normalized. I.e.
void icl::qt::AbstractPlotWidget::setDataViewPort | ( | const utils::Range32f & | xrange, |
const utils::Range32f & | yrange | ||
) |
sets the default viewport
void icl::qt::AbstractPlotWidget::setPen | ( | PenType | p, |
const QPen & | pen | ||
) |
sets the pen for one of the widget compoments
void icl::qt::AbstractPlotWidget::uninstall | ( | MouseHandler * | h | ) |
removes a mouse handler
not yet supported properly
void icl::qt::AbstractPlotWidget::unlock | ( | ) | const |
unlocks drawing / data updates in subclasses
forces a repaint on the background function in the next rendering cycle
Forces the background function to be updated next time. E.g. if the given background function is changed internally (note, it could be a functor, that has other parameters then the exposed x,y position
utils::Point32f icl::qt::AbstractPlotWidget::winToDraw | ( | const utils::Point & | p | ) | const [protected] |
converts a window coordinates to logical drawing coordinates
float icl::qt::AbstractPlotWidget::winToDrawX | ( | int | winX | ) | const [protected] |
converts a window x coordinate to logical drawing coordinate
float icl::qt::AbstractPlotWidget::winToDrawY | ( | int | winY | ) | const [protected] |
converts a window y coordinate to logical drawing coordinate
Data* icl::qt::AbstractPlotWidget::data [private] |