Skip to content

Commit

Permalink
remove translateGraphicsItem : workaround for PyQt < 4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
pijyoi committed Mar 6, 2022
1 parent 8f6b623 commit f8da909
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 54 deletions.
51 changes: 1 addition & 50 deletions pyqtgraph/GraphicsScene/GraphicsScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@
from .. import debug as debug
from .. import getConfigOption
from ..Point import Point
from ..Qt import QT_LIB, QtCore, QtGui, QtWidgets, isQObjectAlive
from ..Qt import QtCore, QtGui, QtWidgets, isQObjectAlive
from .mouseEvents import HoverEvent, MouseClickEvent, MouseDragEvent

getMillis = lambda: perf_counter_ns() // 10 ** 6


if QT_LIB.startswith('PyQt'):
from ..Qt import sip
HAVE_SIP = True
else:
HAVE_SIP = False


__all__ = ['GraphicsScene']

class GraphicsScene(QtWidgets.QGraphicsScene):
Expand Down Expand Up @@ -404,18 +397,6 @@ def removeItem(self, item):
self.sigItemRemoved.emit(item)
return ret

def items(self, *args):
items = QtWidgets.QGraphicsScene.items(self, *args)
return self.translateGraphicsItems(items)

def selectedItems(self, *args):
items = QtWidgets.QGraphicsScene.selectedItems(self, *args)
return self.translateGraphicsItems(items)

def itemAt(self, *args):
item = QtWidgets.QGraphicsScene.itemAt(self, *args)
return self.translateGraphicsItem(item)

def itemsNearEvent(self, event, selMode=QtCore.Qt.ItemSelectionMode.IntersectsItemShape, sortOrder=QtCore.Qt.SortOrder.DescendingOrder, hoverable=False):
"""
Return an iterator that iterates first through the items that directly intersect point (in Z order)
Expand Down Expand Up @@ -478,20 +459,6 @@ def absZValue(item):
def getViewWidget(self):
return self.views()[0]

#def getViewWidget(self, widget):
### same pyqt bug -- mouseEvent.widget() doesn't give us the original python object.
### [[doesn't seem to work correctly]]
#if HAVE_SIP and isinstance(self, sip.wrapper):
#addr = sip.unwrapinstance(sip.cast(widget, QtWidgets.QWidget))
##print "convert", widget, addr
#for v in self.views():
#addr2 = sip.unwrapinstance(sip.cast(v, QtWidgets.QWidget))
##print " check:", v, addr2
#if addr2 == addr:
#return v
#else:
#return widget

def addParentContextMenus(self, item, menu, event):
"""
Can be called by any item in the scene to expand its context menu to include parent context menus.
Expand Down Expand Up @@ -557,19 +524,3 @@ def showExportDialog(self):
from . import exportDialog
self.exportDialog = exportDialog.ExportDialog(self)
self.exportDialog.show(self.contextMenuItem)

@staticmethod
def translateGraphicsItem(item):
# This function is intended as a workaround for a problem with older
# versions of PyQt (< 4.9?), where methods returning 'QGraphicsItem *'
# lose the type of the QGraphicsObject subclasses and instead return
# generic QGraphicsItem wrappers.
if HAVE_SIP and isinstance(item, sip.wrapper):
obj = item.toGraphicsObject()
if obj is not None:
item = obj
return item

@staticmethod
def translateGraphicsItems(items):
return list(map(GraphicsScene.translateGraphicsItem, items))
6 changes: 2 additions & 4 deletions pyqtgraph/graphicsItems/GraphicsItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ def viewPos(self):
return self.mapToView(self.mapFromParent(self.pos()))

def parentItem(self):
## PyQt bug -- some items are returned incorrectly.
return GraphicsScene.translateGraphicsItem(self._qtBaseClass.parentItem(self))
return self._qtBaseClass.parentItem(self)

def setParentItem(self, parent):
## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616
Expand All @@ -420,8 +419,7 @@ def setParentItem(self, parent):
return self._qtBaseClass.setParentItem(self, parent)

def childItems(self):
## PyQt bug -- some child items are returned incorrectly.
return list(map(GraphicsScene.translateGraphicsItem, self._qtBaseClass.childItems(self)))
return self._qtBaseClass.childItems(self)


def sceneTransform(self):
Expand Down

0 comments on commit f8da909

Please sign in to comment.