Skip to content

Commit

Permalink
Added tests around QwtSymbol (+bug fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Oct 15, 2023
1 parent 0ff8285 commit 03985c9
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 57 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
parallel = True
concurrency = multiprocessing,thread
omit =
*/qwt/tests/*

Expand Down
46 changes: 15 additions & 31 deletions qwt/painter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
:members:
"""

from qwt.color_map import QwtColorMap
from qwt.scale_map import QwtScaleMap

from qtpy import QtCore as QC
from qtpy.QtCore import QLineF, QPoint, QRect, QRectF, Qt
from qtpy.QtGui import (
QBrush,
QColor,
QLinearGradient,
QPaintEngine,
QPixmap,
QPainter,
QPainterPath,
QPalette,
QPen,
QBrush,
QPixmap,
QRegion,
QLinearGradient,
QPainterPath,
QColor,
)
from qtpy.QtWidgets import QFrame, QStyle, QStyleOptionFocusRect, QStyleOption
from qtpy.QtCore import Qt, QRect, QPoint, QRectF, QLineF
from qtpy import QtCore as QC
from qtpy.QtWidgets import QFrame, QStyle, QStyleOption, QStyleOptionFocusRect

from qwt.color_map import QwtColorMap
from qwt.scale_map import QwtScaleMap

QT_MAJOR_VERSION = int(QC.__version__.split(".")[0])

Expand Down Expand Up @@ -64,26 +64,10 @@ class QwtPainterClass(object):
"""A collection of `QPainter` workarounds"""

def drawImage(self, painter, rect, image):
alignedRect = rect.toAlignedRect()
if alignedRect != rect:
clipRect = rect.adjusted(0.0, 0.0, -1.0, -1.0)
painter.save()
painter.setClipRect(clipRect, Qt.IntersectClip)
painter.drawImage(alignedRect, image)
painter.restore()
else:
painter.drawImage(alignedRect, image)
painter.drawImage(rect, image)

def drawPixmap(self, painter, rect, pixmap):
alignedRect = rect.toAlignedRect()
if alignedRect != rect:
clipRect = rect.adjusted(0.0, 0.0, -1.0, -1.0)
painter.save()
painter.setClipRect(clipRect, Qt.IntersectClip)
painter.drawPixmap(alignedRect, pixmap)
painter.restore()
else:
painter.drawPixmap(alignedRect, pixmap)
painter.drawPixmap(rect, pixmap)

def drawFocusRect(self, *args):
if len(args) == 2:
Expand Down Expand Up @@ -397,7 +381,7 @@ def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation, rect)
pmPainter.setPen(c)
pmPainter.drawLine(QLineF(devRect.left(), y, devRect.right(), y))
pmPainter.end()
self.drawPixmap(painter, rect, pixmap)
self.drawPixmap(painter, devRect, pixmap)

def fillPixmap(self, widget, pixmap, offset=None):
"""
Expand Down Expand Up @@ -447,7 +431,7 @@ def drawBackground(self, painter, rect, widget):
if widget.testAttribute(Qt.WA_StyledBackground):
opt = QStyleOption()
opt.initFrom(widget)
opt.rect = QRectF(rect).toAlignedRect()
opt.rect = rect
widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter, widget)
else:
brush = widget.palette().brush(widget.backgroundRole())
Expand Down
26 changes: 12 additions & 14 deletions qwt/plot_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@

import os

from qwt.null_paintdevice import QwtNullPaintDevice
from qwt.painter import QwtPainter

from qtpy import QtCore as QC
from qtpy.QtCore import QEvent, QPointF, QRect, QRectF, QSizeF, Qt
from qtpy.QtGui import (
QPaintEngine,
QPen,
QBrush,
QRegion,
QGradient,
QImage,
QPaintEngine,
QPainter,
QPainterPath,
QPen,
QPixmap,
QGradient,
QPainter,
qAlpha,
QPolygonF,
QRegion,
qAlpha,
)
from qtpy.QtWidgets import QFrame, QStyleOption, QStyle
from qtpy.QtCore import Qt, QSizeF, QEvent, QPointF, QRectF, QRect
from qtpy import QtCore as QC
from qtpy.QtWidgets import QFrame, QStyle, QStyleOption

from qwt.null_paintdevice import QwtNullPaintDevice
from qwt.painter import QwtPainter

QT_MAJOR_VERSION = int(QC.__version__.split(".")[0])
QT_API = os.environ["QT_API"]
Expand Down Expand Up @@ -310,8 +309,7 @@ def qwtFillBackground(*args):
else:
clipRegion = widget.contentsRect()
bgWidget = qwtBackgroundWidget(widget.parentWidget())
for fillRect in fillRects:
rect = QRectF(fillRect).toAlignedRect()
for rect in fillRects:
if clipRegion.intersects(rect):
pm = QPixmap(rect.size())
QwtPainter.fillPixmap(
Expand Down
19 changes: 9 additions & 10 deletions qwt/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@

import math

from qwt.graphic import QwtGraphic
from qwt.painter import QwtPainter

from qtpy.QtCore import QLineF, QPoint, QPointF, QRect, QRectF, QSize, QSizeF, Qt
from qtpy.QtGui import (
QBrush,
QPainter,
QTransform,
QPixmap,
QPainterPath,
QPen,
QPixmap,
QPolygonF,
QPainterPath,
QBrush,
QTransform,
)
from qtpy.QtCore import QSize, QRect, QPointF, QRectF, QSizeF, Qt, QPoint, QLineF
from qtpy.QtSvg import QSvgRenderer

from qwt.graphic import QwtGraphic
from qwt.painter import QwtPainter

class QwtTriangle(object):

class QwtTriangle(object):
# enum Type
Left, Right, Up, Down = list(range(4))

Expand Down Expand Up @@ -357,7 +356,7 @@ class Pixmap(object):
def __init__(self):
self.pixmap = QPixmap()

self.pixmap = None # Pixmap()
self.pixmap = Pixmap()

class Graphic(object):
def __init__(self):
Expand Down
Loading

0 comments on commit 03985c9

Please sign in to comment.