Image Component Library (ICL)
AbstractPlotWidget.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/AbstractPlotWidget.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Range.h>
35 #include <ICLUtils/Rect32f.h>
36 #include <ICLUtils/Configurable.h>
37 #include <ICLMath/DynMatrix.h>
38 #include <ICLQt/MouseEvent.h>
39 #include <ICLQt/MouseHandler.h>
40 
42 
43 #include <QPen>
44 #include <QBrush>
45 #include <QPainter>
46 
47 namespace icl{
48  namespace qt{
49 
50 
52 
87  struct Data;
88  Data *data;
89 
91  void property_changed(const Property &);
92 
93  public:
94 
95 
97 
103  void install(MouseHandler *h);
104 
106 
107  void uninstall(MouseHandler *h);
108 
110  enum PenType{
120  NUM_PEN_TYPES
121  };
122 
123 
125  AbstractPlotWidget(QWidget *parent=0);
126 
129 
131  virtual void paintEvent(QPaintEvent *evt);
132 
134  virtual void keyPressEvent(QKeyEvent *event);
135 
137  void renderTo(QPainter &p);
138 
140  void setBackground(const QBrush &bgBrush);
141 
143  void setPen(PenType p, const QPen &pen);
144 
146 
147  struct Pen{
149 
152 
171  Pen(const QPen &linePen=Qt::NoPen,
172  const QPen &symbolPen=Qt::NoPen,
173  char symbol= ' ',
174  int symbolSize=5,
175  const QBrush &fillBrush=Qt::NoBrush):
176  linePen(linePen),symbolPen(symbolPen),symbol(symbol),symbolSize(symbolSize),fillBrush(fillBrush){}
177  QPen linePen;
178  QPen symbolPen;
179  char symbol;
181  QBrush fillBrush;
182  };
185 
186 
188 
189  inline void render() { updateFromOtherThread(); }
190 
192 
193  virtual utils::Rect32f getDataViewPort() const;
194 
196 
204  void setDataViewPort(const utils::Rect32f &viewPort);
205 
207 
210  void setDataViewPort(const utils::Range32f &xrange, const utils::Range32f &yrange);
211 
213  void lock() const;
214 
216  void unlock() const;
217 
219 
250  void addAnnotations(const char type,const float *data, int num=1,
251  const QPen &linePen = QColor(255,0,0),
252  const QBrush &brush = Qt::NoBrush,
253  const std::string &text="", const std::string &textDelim=",");
254 
256  void clearAnnotations();
257 
259 
260  virtual void clear() { clearAnnotations(); }
261 
264 
266 
276  void setBackgroundFunction(bgFunction f);
277 
279 
282  void updateBackgroundFunction();
283 
285  void removeBackgroundFunction();
286 
287  protected:
288 
290  bool isZoomed() const;
291 
293  virtual void mouseDoubleClickEvent(QMouseEvent *event);
294 
296  virtual void mouseMoveEvent(QMouseEvent *event);
297 
299  virtual void mousePressEvent(QMouseEvent *event);
300 
302  virtual void mouseReleaseEvent(QMouseEvent *event);
303 
305  virtual void enterEvent(QEvent *event);
306 
308  virtual void leaveEvent(QEvent *event);
309 
311 
312  virtual bool drawData(QPainter &p) = 0;
313 
315  virtual void drawLegend(QPainter &p,const utils::Rect &where, bool horizontal);
316 
317 
319  void drawDefaultLedgend(QPainter &p,const utils::Rect &where, bool horizontal,
320  const std::vector<std::string> &rowNames,
321  const std::vector<PenPtr> &pens);
322 
324 
327  template<char s> static inline void draw_symbol(QPainter &p,int size, float x, float y){
328  ERROR_LOG("undefined given symbol ID");
329  }
330 
332  float winToDrawX(int winX) const;
333 
335  float winToDrawY(int winY) const;
336 
338  utils::Point32f winToDraw(const utils::Point &p) const;
339 
341  int drawToWinX(float drawX) const;
342 
344  int drawToWinY(float drawY) const;
345 
347  utils::Point drawToWin(const utils::Point32f &p) const;
348 
350  utils::Rect32f getDynamicDataViewPort() const;
351 
353  struct Locker{
355  inline Locker(const AbstractPlotWidget *w):w(w){ this->w->lock(); }
358  inline Locker(const AbstractPlotWidget &w):w(&w){ this->w->lock();}
360  ~Locker() { w->unlock(); }
361  };
362  };
363 
365  // (specialized) note, points have not size: use circle for larger round points ...
366  template<> inline void AbstractPlotWidget::draw_symbol<'.'>(QPainter &p,int, float x, float y){
367  // p.drawPoint(QPoint(x,y));
368  p.drawLine(QPoint(x,y),QPoint(x,y));
369  }
370 
371  template<> inline void AbstractPlotWidget::draw_symbol<'x'>(QPainter &p,int size, float x, float y){
372  p.drawLine(QPoint(x-size,y-size),QPoint(x+size,y+size));
373  p.drawLine(QPoint(x-size,y+size),QPoint(x+size,y-size));
374  }
375 
376  template<> inline void AbstractPlotWidget::draw_symbol<'+'>(QPainter &p,int size, float x, float y){
377  p.drawLine(QPoint(x,y-size),QPoint(x,y+size));
378  p.drawLine(QPoint(x-size,y),QPoint(x+size,y));
379  }
380 
381  template<> inline void AbstractPlotWidget::draw_symbol<'*'>(QPainter &p,int size, float x, float y){
382  draw_symbol<'+'>(p,(size*2)/3,x,y);
383  draw_symbol<'x'>(p,size,x,y);
384  }
385 
387  template<> inline void AbstractPlotWidget::draw_symbol<'o'>(QPainter &p,int size, float x, float y){
388  p.drawEllipse(QRect(x-size,y-size,2*size,2*size));
389  }
390 
391  template<> inline void AbstractPlotWidget::draw_symbol<'s'>(QPainter &p,int size, float x, float y){
392  p.drawRect(QRect(x-size,y-size,2*size,2*size));
393  }
394 
395  template<> inline void AbstractPlotWidget::draw_symbol<'t'>(QPainter &p,int size, float x, float y){
396  const QPoint e[3] = { QPoint(x,y-size),QPoint(x+size,y+size),QPoint(x-size,y+size) };
397  p.drawConvexPolygon(e,3);
398  }
399 
400  template<> inline void AbstractPlotWidget::draw_symbol<'d'>(QPainter &p,int size, float x, float y){
401  const QPoint e[4] = { QPoint(x,y-size),QPoint(x+size,y),QPoint(x,y+size), QPoint(x-size,y) };
402  p.drawConvexPolygon(e,4);
403  }
405  } // namespace qt
406 }
407 
pen used to draw the y-tics
Definition: AbstractPlotWidget.h:114
The PlotWidget is an abstract base class for 2D plotting components.
Definition: AbstractPlotWidget.h:86
The General Function Template.
Definition: Function.h:284
undocument this line if you encounter any issues!
Definition: Any.h:37
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)
Definition: AbstractPlotWidget.h:327
pen used to draw the y-axis
Definition: AbstractPlotWidget.h:112
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
Data * data
pimpl
Definition: AbstractPlotWidget.h:87
QPen linePen
pen for line structures
Definition: AbstractPlotWidget.h:177
pen used to draw the x-labels
Definition: AbstractPlotWidget.h:115
Pen(const QPen &linePen=Qt::NoPen, const QPen &symbolPen=Qt::NoPen, char symbol=' ', int symbolSize=5, const QBrush &fillBrush=Qt::NoBrush)
creates a row style with given parameters
Definition: AbstractPlotWidget.h:171
utility class for scoped locking
Definition: AbstractPlotWidget.h:353
char symbol
symbol
Definition: AbstractPlotWidget.h:179
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
pen used to draw the y-grid lines
Definition: AbstractPlotWidget.h:118
QPen symbolPen
pen for symbols
Definition: AbstractPlotWidget.h:178
const AbstractPlotWidget * w
Definition: AbstractPlotWidget.h:354
pen used to draw the x-axis
Definition: AbstractPlotWidget.h:111
utils::SmartPtr< Pen > PenPtr
typedef for managed row-style pointers
Definition: AbstractPlotWidget.h:184
void unlock() const
unlocks drawing / data updates in subclasses
void lock() const
locks drawing / data updates in subclasses
pen used to draw the x-tics
Definition: AbstractPlotWidget.h:113
MouseEvent Handler.
Definition: MouseHandler.h:92
#define ERROR_LOG(x)
Definition: Macros.h:111
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
#define ICLQt_API
Definition: CompatMacros.h:178
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
Interface for classes that can be configured from configuration-files and GUI-Components.
Definition: Configurable.h:194
pen used to draw the axis labels
Definition: AbstractPlotWidget.h:119
~Locker()
destructor unlocks the widget
Definition: AbstractPlotWidget.h:360
Locker(const AbstractPlotWidget &w)
constructor locks the widget
Definition: AbstractPlotWidget.h:358
QBrush fillBrush
fill brush (this is e.g. used to fill the area beyond a function graph)
Definition: AbstractPlotWidget.h:181
void render()
updates the screen
Definition: AbstractPlotWidget.h:189
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
Represents a single property.
Definition: Configurable.h:200
virtual void clear()
clears everything from the widget
Definition: AbstractPlotWidget.h:260
pen used to draw the y-labels
Definition: AbstractPlotWidget.h:116
int symbolSize
symbol size (in pixels, point symbols are always size 1)
Definition: AbstractPlotWidget.h:180
utils::Function< float, float, float > bgFunction
function that is used to render a non-homo
Definition: AbstractPlotWidget.h:263
Compability class.
Definition: ThreadedUpdatableWidget.h:51
Specialization of the SmartPtrBase class for Pointers.
Definition: SmartPtr.h:75
PenType
different pen types
Definition: AbstractPlotWidget.h:110
pen used to draw the x-grid lines
Definition: AbstractPlotWidget.h:117
Utility structure for styles usend in subclasses.
Definition: AbstractPlotWidget.h:147