grid_renderer.*

Provides

  • func:

    painter_save: Context manager saving and restoring painter state

  • func:

    painter_zoom: Context manager scaling and restoring the painter

  • func:

    painter_rotate: Context manager rotating and restoring the painter

  • GridCellNavigator: Find neighbors of a cell

  • EdgeBorders: Dataclass for edge properties

  • CellEdgeRenderer: Paints cell edges

  • QColorCache: QColor cache

  • CellRenderer: Paints cells

class grid_renderer.BorderColorBottomCache(grid, *args, **kwargs)[source]

Bases: BorderWidthBottomCache

BorderColorBottomCache cache

class grid_renderer.BorderColorRightCache(grid, *args, **kwargs)[source]

Bases: BorderWidthBottomCache

BorderColorBottomCache cache

class grid_renderer.BorderWidthBottomCache(grid, *args, **kwargs)[source]

Bases: dict

BorderWidthBottom cache

class grid_renderer.BorderWidthRightCache(grid, *args, **kwargs)[source]

Bases: BorderWidthBottomCache

BorderWidthRight cache

class grid_renderer.CellEdgeRenderer(painter, center, borders, rect, clip_path, zoom)[source]

Bases: object

Paints cell edges

Borders are provided by EdgeBorders in order: left, right, top, bottom

Parameters:
  • painter (QPainter) – Painter with which edge is drawn

  • center (QPointF) – Edge center

  • borders (EdgeBorders) – Border widths and colors

  • rect (QRectF) – Rect of the clip_path

  • clip_path (QPainterPath) – Clip rectangle that is required for QtSVG clipping

  • zoom (float) – Current zoom level

intersection_cache = {}
paint()[source]

Paints the edge

class grid_renderer.CellRenderer(grid, painter, option, index)[source]

Bases: object

Paints cells

Cell rendering governs the area of a cell inside its borders. It is done in a vector oriented way. Therefore, the following conventions shall apply:

  • Cell borders of width 1 shall be painted so that they appear only in the bottom and right edge of the cell.

  • Cell borders of all widths have the same center line.

  • Cell borders that are thicker than 1 are painted on all borders.

  • At the edges, borders are painted in the following order:
    1. Thin borders are painted first

    2. If border width is equal, lighter colors are painted first

Parameters:
  • grid (QTableView) – The main grid widget

  • painter (QPainter) – Painter with which borders are drawn

  • option (QStyleOptionViewItem) – Style option for rendering

  • index (QModelIndex) – Index of cell to be rendered

_draw_line(point1, point2, width, color, clip_path)[source]

Draws line

Uses drawLine for screen painting and QPainterPathStroker for svg painting.

Parameters:
  • point1 (QPointF) – Start point of line

  • point2 (QPointF) – End point of line

  • width (float) – Line width

  • color (QColor) – Line color

  • clip_path (QPainterPath) – Clip rectangle

static _get_border_pen(width, zoom)[source]

Gets zoomed border pen, white, fully transparent

Parameters:
  • width – Unzoomed line width

  • zoom – Current zoom level of grid

inner_rect(rect)[source]

Returns inner rect that is shrunk by border widths

For merged cells, minimum top/left border widths are taken into account

Parameters:

rect (QRectF) – Cell rect to be shrunk

Return type:

QRectF

paint()[source]

Paints the cell

paint_above_borders(rect, clip_path)[source]

Paint lower borders of all above cells

Parameters:
  • rect (QRectF) – Cell rect of below cell, in which the borders are painted

  • clip_path (QPainterPath) – Clip rectangle that is requuired for QtSVG clipping

paint_borders(rect)[source]

Paint cell borders

paint_bottom_border(rect, clip_path)[source]

Paint bottom border of cell

Parameters:
  • rect (QRectF) – Cell rect of the cell to be painted

  • clip_path (QPainterPath) – Clip rectangle that is required for QtSVG clipping

paint_bottom_left_edge(rect, clip_path)[source]

Paints bottom left edge of the cell

Parameters:
  • rect (QRectF) – Cell rect of cell, for which the edge is painted

  • clip_path (QPainterPath) –

    Clip rectangle that is requuired for QtSVG clipping

    top

    L | C

left ———— right
BL | B

bottom

paint_bottom_right_edge(rect, clip_path)[source]

Paints bottom right edge of the cell

Parameters:
  • rect (QRectF) – Cell rect of cell, for which the edge is painted

  • clip_path (QPainterPath) –

    Clip rectangle that is requuired for QtSVG clipping

    top

    C | R

left ———– right
B | BR

bottom

paint_content(rect)[source]
Parameters:

rect (QRectF) – Cell rect of the cell to be painted

paint_left_borders(rect, clip_path)[source]

Paint right borders of all left cells

Parameters:
  • rect (QRectF) – Cell rect of right cell, in which the borders are painted

  • clip_path (QPainterPath) – Clip rectangle that is requuired for QtSVG clipping

paint_right_border(rect, clip_path)[source]

Paint right border of cell

Parameters:
  • rect (QRectF) – Cell rect of the cell to be painted

  • clip_path (QPainterPath) – Clip rectangle that is requuired for QtSVG clipping

paint_top_left_edge(rect, clip_path)[source]

Paints top left edge of the cell

Parameters:
  • rect (QRectF) – Cell rect of cell, for which the edge is painted

  • clip_path (QPainterPath) –

    Clip rectangle that is requuired for QtSVG clipping

    top

    TL | T

left ———— right
L | C

bottom

paint_top_right_edge(rect, clip_path)[source]

Paints top right edge of the cell

Parameters:
  • rect (QRectF) – Cell rect of cell, for which the edge is painted

  • clip_path (QPainterPath) –

    Clip rectangle that is requuired for QtSVG clipping

    top

    T | TR

left ———— right
C | R

bottom

class grid_renderer.EdgeBorders(left_width, right_width, top_width, bottom_width, left_color, right_color, top_color, bottom_color, left_x, right_x, top_y, bottom_y)[source]

Bases: object

Holds border data for an edge and provides effective edge properties

property _border_colors: Tuple[QColor, QColor, QColor, QColor]

Tuple of border colors in order left, right, top, bottom

property _border_widths: Tuple[float, float, float, float]

Tuple of border widths in order left, right, top, bottom

_color_cache = None
bottom_color: QColor
bottom_width: float
bottom_y: float
property color: QColor

Edge color, i.e. darkest color of thickest edge border

property height: float

Edge height, i.e. thickest horizontal border

left_color: QColor
left_width: float
left_x: float
right_color: QColor
right_width: float
right_x: float
top_color: QColor
top_width: float
top_y: float
property width: float

Edge width, i.e. thickest vertical border

class grid_renderer.EdgeBordersCache[source]

Bases: dict

Cache of all EdgeBorders objects

class grid_renderer.GridCellNavigator(grid, key)[source]

Bases: object

Find neighbors of a cell

Parameters:
  • grid (QTableView) – The main grid widget

  • key (Tuple[int, int, int]) – Key of cell fow which neighbors are identified

above_keys()[source]

Key list of neighboring cells above the key cell

Return type:

List[Tuple[int, int, int]]

above_left_key()[source]

Key of neighboring cell above left of the key cell

Return type:

Tuple[int, int, int]

above_right_key()[source]

Key of neighboring cell above right of the key cell

Return type:

Tuple[int, int, int]

below_keys()[source]

Key list of neighboring cells below the key cell

Return type:

List[Tuple[int, int, int]]

below_left_key()[source]

Key of neighboring cell below left of the key cell

Return type:

Tuple[int, int, int]

below_right_key()[source]

Key of neighboring cell below right of the key cell

Return type:

Tuple[int, int, int]

property border_color_bottom: QColor

Color of bottom border line

property border_color_right: QColor

Color of right border line

property borderwidth_bottom: float

Width of bottom border line

property borderwidth_right: float

Width of right border line

left_keys()[source]

Key list of neighboring cells left of the key cell

Return type:

List[Tuple[int, int, int]]

property merge_area: Tuple[int, int, int, int]

Merge area of the key cell

merging_key(key)[source]

Merging cell if cell is merged else cell key

Parameters:

key (Tuple[int, int, int]) – Key of cell that is checked for being merged

Return type:

Tuple[int, int, int]

right_keys()[source]

Key list of neighboring cells right of the key cell

Return type:

List[Tuple[int, int, int]]

class grid_renderer.QColor[source]

Bases: QColor

Hashable QColor

class grid_renderer.QColorCache(grid, *args, **kwargs)[source]

Bases: dict

QColor cache that returns default color for None

grid_renderer.painter_rotate(painter, rect, angle=0)[source]

Context manager rotating and restoring the painter

Parameters:
  • painter (QPainter) – Painter, which is rotated

  • rect (QRectF) – Rect to be painted in

  • angle (int) – Rotataion angle must be in (0, 90, 180, 270)

Return type:

QRectF

grid_renderer.painter_save(painter)[source]

Context manager saving and restoring painter state

Parameters:

painter (QPainter) – Painter, for which the state is preserved

grid_renderer.painter_zoom(painter, zoom, rect)[source]

Context manager scaling and restoring the painter

(rect.x(), rect.y()) is invariant

Parameters:
  • painter (QPainter) – Painter, for which the state is preserved

  • zoom (float) – Zoom factor

  • rect (QRectF) – Rect for setting zoom invariant point (rect.x(), rect.y())

Return type:

QRectF