def updateMainViewBox(self, srcview=None): if not self.graphicsview.scene(): return if not srcview: # @TODO: check API srcview = self.app.currentGraphicsView() elif srcview is not self.app.currentGraphicsView(): # current view not yet updated: do nothing return if srcview: assert srcview.scene() == self.graphicsview.scene() # @TODO: check hbar = srcview.horizontalScrollBar() vbar = srcview.verticalScrollBar() # @TODO: bug report: mapping to scene seems to introduce a # spurious offset "x1 = 2*x0" and y1 = 2*y0; # this doesn't happen for "w" and "h" #polygon = srcview.mapToScene(hbar.value(), vbar.value(), # hbar.pageStep(), vbar.pageStep()) #@TODO: in case of rotations it should be better keep using # a polygon #self.graphicsview.viewbox = polygon.boundingRect() # @NOTE: this is a workaround; mapToScene should be used instead rect = QtCore.QRectF(hbar.value(), vbar.value(), hbar.pageStep(), vbar.pageStep()) transform = srcview.transform().inverted()[0] self.graphicsview.viewbox = transform.mapRect(rect)
def __init__(self, gdalobj, parent=None, **kwargs): super(BaseGdalGraphicsItem, self).__init__(parent, **kwargs) # @COMPATIBILITY: Qt >= 4.6.0 needs this flag to be set otherwise the # exact exposedRect is not computed # @SEEALSO: ItemUsesExtendedStyleOption item at # http://doc.qt.nokia.com/4.6/qgraphicsitem.html#GraphicsItemFlag-enum try: self.setFlag(QtWidgets.QGraphicsItem.ItemUsesExtendedStyleOptions) except AttributeError: self.setFlag(QtWidgets.QGraphicsItem.GraphicsItemFlag(0x200)) self.gdalobj = gdalobj try: # dataset w = gdalobj.RasterXSize h = gdalobj.RasterYSize except AttributeError: # raster band w = gdalobj.XSize h = gdalobj.YSize self._boundingRect = QtCore.QRectF(0, 0, w, h) #self.read_threshold = 1600*1200 self.stretch = imgutils.LinearStretcher() # @TODO: use lazy gaphicsitem initialization # @TODO: initialize stretching explicitly self._stretch_initialized = False self._data_preproc = None self.colortable = None
def sceneEventFilter(self, obj, event): if event.type() == QtCore.QEvent.GraphicsSceneMouseRelease: p0 = event.buttonDownScenePos(QtCore.Qt.LeftButton) p1 = event.scenePos() rect = QtCore.QRectF(p0, p1).normalized() self.rubberBandSeclection.emit(rect) return True #return obj.eventFilter(obj, event) # @TODO: check #return QtWidgets.QGraphicsScene.eventFilter(self, obj, event) return False