Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GraphicsViewAdapterForQt Class Reference

Implementation of the GraphicsViewAdapter in Qt using QGraphicsView. More...

#include <graphicsviewadapterforqt.h>

+ Inheritance diagram for GraphicsViewAdapterForQt:
+ Collaboration diagram for GraphicsViewAdapterForQt:

Public Member Functions

 GraphicsViewAdapterForQt (QWidget *parent, DrawerBase *drawer, QRectF sceneRect)
 Constructor. More...
 
 ~GraphicsViewAdapterForQt ()
 Destructor, removing all graphics items from the list. More...
 
void setSceneRect (const QRectF &rect)
 Setter function for the scene rectangle. More...
 
QPointF convertRelToAbs (const QPointF &p) const
 Converting from relative to absolute coordinates. More...
 
QSizeF convertRelToAbs (const QSizeF &s) const
 Converting from relative to absolute coordinates. More...
 
QLineF convertRelToAbsLine (qreal x1, qreal y1, qreal x2, qreal y2) const
 Converting of a line from relative to absolute coordinates. More...
 
QPointF convertAbsToRel (const QPointF &p) const
 Converting from absolute to relative coordinates. More...
 
- Public Member Functions inherited from GraphicsViewAdapter
 GraphicsViewAdapter ()
 Empty constructor. More...
 
 ~GraphicsViewAdapter ()
 Destructor clearing the view. More...
 
GraphicItemsListgetGraphicItems ()
 Get the list of the graphic items. More...
 
const GraphicItemsListgetGraphicItems () const
 Get a constant list of the graphic items. More...
 
GraphicsItemgetGraphicItem (int keyIndex, RoleType role)
 Get a single graphics element specified by its index and its role. More...
 
GraphicsItemgetGraphicItemByRole (RoleType role)
 Get the first of all graphics elements with a given role. More...
 
GraphicItemsList getGraphicItems (int keyIndex)
 Get a list of graphic items that match with the keyIndex. More...
 
GraphicItemsList getGraphicItemsByRole (RoleType role)
 Get a list of graphic items that match with the given role. More...
 
GraphicItemsList getGraphicItems (int keyIndex, RoleType role)
 Get the list of all graphics elements of a given key and role. More...
 

Protected Member Functions

Reimplemented functions for managing the scene (panel):
void showEvent (QShowEvent *event) override
 Show the scene (reimplemented show event). More...
 
void resizeEvent (QResizeEvent *event) override
 Resize the scene (reimplemented resize event). More...
 
virtual void clear () override
 Clear the scene. More...
 
Reimplemented functions for drawing:
virtual GraphicsItemdrawLine (double x1, double y1, double x2, double y2, PenType pen) override
 Abstract function: Draw a line. More...
 
virtual GraphicsItemdrawChart (const std::vector< Point > &points, PenType pen) override
 Abstract function: Draw a chart (polygon). More...
 
virtual GraphicsItemdrawFilledRect (double x, double y, double w, double h, PenType pen, FillTypes fill) override
 Abstract function: Draw a filled rectangle. More...
 
virtual void drawStroboscope (const ComplexVector &data) override
 

Protected Attributes

DrawerBasemDrawer
 The drawer of this GraphicsViewAdapterForQt. More...
 
QGraphicsScene mScene
 The QGraphicsScene. More...
 
QRectF mSceneRect
 The scene rect. More...
 

Private Member Functions

QPen getPen (PenType penType, bool cosmetic=true) const
 Get a QPen for the given value of PenTypes. More...
 
QBrush getFill (FillTypes fill) const
 Create a QBrush for the given value of FillTypes. More...
 

Additional Inherited Members

- Public Types inherited from GraphicsViewAdapter
enum  PenType {
  PEN_THIN_BLACK, PEN_MEDIUM_BLACK, PEN_THIN_VERY_LIGHT_GRAY, PEN_THIN_LIGHT_GRAY,
  PEN_THIN_DARK_GRAY, PEN_MEDIUM_LIGHT_GRAY, PEN_MEDIUM_DARK_GRAY, PEN_MEDIUM_GRAY,
  PEN_THIN_CYAN, PEN_MEDIUM_CYAN, PEN_MEDIUM_ORANGE, PEN_MEDIUM_MAGENTA,
  PEN_THIN_MAGENTA, PEN_THIN_RED, PEN_MEDIUM_RED, PEN_THIN_BLUE,
  PEN_THIN_TRANSPARENT, PEN_MEDIUM_DARK_GREEN
}
 Available pen types for drawing. More...
 
enum  FillTypes {
  FILL_TRANSPARENT, FILL_LIGHT_GRAY, FILL_RED, FILL_ORANGE,
  FILL_GREEN, FILL_LIGHT_GREEN, FILL_BLUE
}
 Available filling colors (e.g. to fill rectangles) More...
 
using RoleType = GraphicsItem::RoleType
 
using ComplexVector = std::vector< std::complex< double >>
 Abstract function: Draw stroboscope. More...
 

Detailed Description

Implementation of the GraphicsViewAdapter in Qt using QGraphicsView.

This class handles the drawing of lines, charts and filled rectangles and will create GraphicsItemForQt as GraphicsItem. It also handles the conversion from relative to absolute coordinates.

The mSceneRect is used for converting relative to absolute coordinates. It will always be fully displayed in the QGraphicsView.

Definition at line 40 of file graphicsviewadapterforqt.h.

Constructor & Destructor Documentation

GraphicsViewAdapterForQt::GraphicsViewAdapterForQt ( QWidget *  parent,
DrawerBase drawer,
QRectF  sceneRect 
)

Constructor.

Parameters
parent: The parent widget
drawer: The drawer that draws into this graphics view
sceneRect: The scene rectange for QGraphicsView

Definition at line 39 of file graphicsviewadapterforqt.cpp.

GraphicsViewAdapterForQt::~GraphicsViewAdapterForQt ( )

Destructor, removing all graphics items from the list.

Definition at line 65 of file graphicsviewadapterforqt.cpp.

+ Here is the call graph for this function:

Member Function Documentation

void GraphicsViewAdapterForQt::clear ( )
overrideprotectedvirtual

Clear the scene.

This function clears the QGraphicsScene and calls GraphicsViewAdapter::clear()

Reimplemented from GraphicsViewAdapter.

Reimplemented in StroboscopicViewAdapterForQt.

Definition at line 142 of file graphicsviewadapterforqt.cpp.

+ Here is the call graph for this function:

QPointF GraphicsViewAdapterForQt::convertAbsToRel ( const QPointF &  p) const

Converting from absolute to relative coordinates.

Parameters
p: A QPointF in absolute coordinates
Returns
The QPointF in relative coordinates

Definition at line 332 of file graphicsviewadapterforqt.cpp.

QPointF GraphicsViewAdapterForQt::convertRelToAbs ( const QPointF &  p) const

Converting from relative to absolute coordinates.

Parameters
p: A QPointF in relative coordinates
Returns
The QPointF in absolute coordinates

Definition at line 305 of file graphicsviewadapterforqt.cpp.

QSizeF GraphicsViewAdapterForQt::convertRelToAbs ( const QSizeF &  s) const

Converting from relative to absolute coordinates.

Parameters
s: A QSizeF in relative coordinates
Returns
The QSizeF in absolute coordinates

Definition at line 313 of file graphicsviewadapterforqt.cpp.

QLineF GraphicsViewAdapterForQt::convertRelToAbsLine ( qreal  x1,
qreal  y1,
qreal  x2,
qreal  y2 
) const

Converting of a line from relative to absolute coordinates.

Parameters
x1: The starting point x-coord of the line
y1: The starting point y-coord of the line
x2: The ending point x-coord of the line
y2: The ending point y-coord of the line
Returns
QLineF in absolute coordinates

Definition at line 321 of file graphicsviewadapterforqt.cpp.

GraphicsItem * GraphicsViewAdapterForQt::drawChart ( const std::vector< Point > &  points,
PenType  pen 
)
overrideprotectedvirtual

Abstract function: Draw a chart (polygon).

This function draws a chart (polygon) of points connected by straight lines. The points are passed to the function as a vector. The function is abstract and has to be overridden in the implementation.

Parameters
points: Vector of points.
pen: The pen used to draw the polygon.
Returns
The newly created graphics item or nullptr if out of range.

Implements GraphicsViewAdapter.

Definition at line 167 of file graphicsviewadapterforqt.cpp.

+ Here is the call graph for this function:

GraphicsItem * GraphicsViewAdapterForQt::drawFilledRect ( double  x,
double  y,
double  w,
double  h,
PenType  pen,
FillTypes  fill 
)
overrideprotectedvirtual

Abstract function: Draw a filled rectangle.

This function draws a filled rectangle. It is a pure virtual function which has to be overridden in the respective implementation.

Parameters
x: Left x coordinate
y: Upper y coordinate
w: Width of the rectangle
h: Height of the rectangle
pen: The pen used to draw the border
fill: The filling color used to fill the rectangle.
Returns
The newly created graphics item or nullptr if out of range.

Implements GraphicsViewAdapter.

Definition at line 193 of file graphicsviewadapterforqt.cpp.

+ Here is the call graph for this function:

GraphicsItem * GraphicsViewAdapterForQt::drawLine ( double  x1,
double  y1,
double  x2,
double  y2,
PenType  pen 
)
overrideprotectedvirtual

Abstract function: Draw a line.

Parameters
x1: Starting point x coordinate between 0 and 1
y1: Starting point y coordinate between 0 and 1
x2: Ending point x coordinate between 0 and 1
y2: Ending point y coordinate between 0 and 1
pen: The pen to be used
Returns
The newly created graphics item or nullptr if out of range.

Implements GraphicsViewAdapter.

Definition at line 153 of file graphicsviewadapterforqt.cpp.

+ Here is the call graph for this function:

virtual void GraphicsViewAdapterForQt::drawStroboscope ( const ComplexVector data)
inlineoverrideprotectedvirtual

Implements GraphicsViewAdapter.

Reimplemented in StroboscopicViewAdapterForQt.

Definition at line 60 of file graphicsviewadapterforqt.h.

QBrush GraphicsViewAdapterForQt::getFill ( FillTypes  fill) const
private

Create a QBrush for the given value of FillTypes.

Parameters
fill: The fill type
Returns
The created QBrush

Definition at line 280 of file graphicsviewadapterforqt.cpp.

QPen GraphicsViewAdapterForQt::getPen ( PenType  penType,
bool  cosmetic = true 
) const
private

Get a QPen for the given value of PenTypes.

Parameters
penType: The pen type
cosmetic: A cosmetic pen does not scale with the QGraphicsView
Returns
The created QPen

Definition at line 211 of file graphicsviewadapterforqt.cpp.

void GraphicsViewAdapterForQt::resizeEvent ( QResizeEvent *  event)
overrideprotected

Resize the scene (reimplemented resize event).

Parameters
event: The QResizeEvent event

This function resizes the existing mSceneRect in the QGraphicsViewer.

Definition at line 124 of file graphicsviewadapterforqt.cpp.

void GraphicsViewAdapterForQt::setSceneRect ( const QRectF &  rect)

Setter function for the scene rectangle.

Parameters
rect: The new scene rect of QGraphicsView

Changing the scene rect will also force the drawer to redraw.

Definition at line 88 of file graphicsviewadapterforqt.cpp.

+ Here is the call graph for this function:

void GraphicsViewAdapterForQt::showEvent ( QShowEvent *  event)
overrideprotected

Show the scene (reimplemented show event).

Parameters
event: The QShowEvent event

This function fits the mSceneRect into the view of the QGraphicsViewer.

Definition at line 106 of file graphicsviewadapterforqt.cpp.

Member Data Documentation

DrawerBase* GraphicsViewAdapterForQt::mDrawer
protected

The drawer of this GraphicsViewAdapterForQt.

Definition at line 119 of file graphicsviewadapterforqt.h.

QGraphicsScene GraphicsViewAdapterForQt::mScene
protected

The QGraphicsScene.

Definition at line 120 of file graphicsviewadapterforqt.h.

QRectF GraphicsViewAdapterForQt::mSceneRect
protected

The scene rect.

Definition at line 121 of file graphicsviewadapterforqt.h.


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