Ejemplo n.º 1
0
 def drawSimpleRichText(self, painter, rect, flags, text):
     txt = text.clone()
     painter.save()
     unscaledRect = QRectF(rect)
     if painter.font().pixelSize() < 0:
         res = qwtScreenResolution()
         pd = painter.device()
         if pd.logicalDpiX() != res.width()\
            or pd.logicalDpiY() != res.height():
             transform = QTransform()
             transform.scale(res.width()/float(pd.logicalDpiX()),
                             res.height()/float(pd.logicalDpiY()))
             painter.setWorldTransform(transform, True)
             invtrans, _ok = transform.inverted()
             unscaledRect = invtrans.mapRect(rect)
     txt.setDefaultFont(painter.font())
     txt.setPageSize(QSizeF(unscaledRect.width(), QWIDGETSIZE_MAX))
     layout = txt.documentLayout()
     height = layout.documentSize().height()
     y = unscaledRect.y()
     if flags & Qt.AlignBottom:
         y += unscaledRect.height()-height
     elif flags & Qt.AlignVCenter:
         y += (unscaledRect.height()-height)/2
     context = QAbstractTextDocumentLayout.PaintContext()
     context.palette.setColor(QPalette.Text, painter.pen().color())
     painter.translate(unscaledRect.x(), y)
     layout.draw(painter, context)
     painter.restore()
Ejemplo n.º 2
0
    def colorBarRect(self, rect):
        """
        Calculate the the rectangle for the color bar

        :param QRectF rect: Bounding rectangle for all components of the scale
        :return: Rectangle for the color bar
        """
        cr = QRectF(rect)
        if self.__data.scaleDraw.orientation() == Qt.Horizontal:
            cr.setLeft(cr.left() + self.__data.borderDist[0])
            cr.setWidth(cr.width() - self.__data.borderDist[1] + 1)
        else:
            cr.setTop(cr.top() + self.__data.borderDist[0])
            cr.setHeight(cr.height() - self.__data.borderDist[1] + 1)
        sda = self.__data.scaleDraw.alignment()
        if sda == QwtScaleDraw.LeftScale:
            cr.setLeft(cr.right() - self.__data.margin -
                       self.__data.colorBar.width)
            cr.setWidth(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.RightScale:
            cr.setLeft(cr.left() + self.__data.margin)
            cr.setWidth(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.BottomScale:
            cr.setTop(cr.top() + self.__data.margin)
            cr.setHeight(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.TopScale:
            cr.setTop(cr.bottom() - self.__data.margin -
                      self.__data.colorBar.width)
            cr.setHeight(self.__data.colorBar.width)
        return cr
Ejemplo n.º 3
0
 def drawSimpleRichText(self, painter, rect, flags, text):
     txt = text.clone()
     painter.save()
     unscaledRect = QRectF(rect)
     if painter.font().pixelSize() < 0:
         res = qwtScreenResolution()
         pd = painter.device()
         if pd.logicalDpiX() != res.width()\
            or pd.logicalDpiY() != res.height():
             transform = QTransform()
             transform.scale(res.width() / float(pd.logicalDpiX()),
                             res.height() / float(pd.logicalDpiY()))
             painter.setWorldTransform(transform, True)
             invtrans, _ok = transform.inverted()
             unscaledRect = invtrans.mapRect(rect)
     txt.setDefaultFont(painter.font())
     txt.setPageSize(QSizeF(unscaledRect.width(), QWIDGETSIZE_MAX))
     layout = txt.documentLayout()
     height = layout.documentSize().height()
     y = unscaledRect.y()
     if flags & Qt.AlignBottom:
         y += unscaledRect.height() - height
     elif flags & Qt.AlignVCenter:
         y += (unscaledRect.height() - height) / 2
     context = QAbstractTextDocumentLayout.PaintContext()
     context.palette.setColor(QPalette.Text, painter.pen().color())
     painter.translate(unscaledRect.x(), y)
     layout.draw(painter, context)
     painter.restore()
Ejemplo n.º 4
0
    def colorBarRect(self, rect):
        """
        Calculate the the rectangle for the color bar

        :param QRectF rect: Bounding rectangle for all components of the scale
        :return: Rectangle for the color bar
        """
        cr = QRectF(rect)
        if self.__data.scaleDraw.orientation() == Qt.Horizontal:
            cr.setLeft(cr.left() + self.__data.borderDist[0])
            cr.setWidth(cr.width() - self.__data.borderDist[1] + 1)
        else:
            cr.setTop(cr.top() + self.__data.borderDist[0])
            cr.setHeight(cr.height() - self.__data.borderDist[1] + 1)
        sda = self.__data.scaleDraw.alignment()
        if sda == QwtScaleDraw.LeftScale:
            cr.setLeft(cr.right()-self.__data.margin-self.__data.colorBar.width)
            cr.setWidth(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.RightScale:
            cr.setLeft(cr.left()+self.__data.margin)
            cr.setWidth(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.BottomScale:
            cr.setTop(cr.top()+self.__data.margin)
            cr.setHeight(self.__data.colorBar.width)
        elif sda == QwtScaleDraw.TopScale:
            cr.setTop(cr.bottom()-self.__data.margin-self.__data.colorBar.width)
            cr.setHeight(self.__data.colorBar.width)
        return cr
Ejemplo n.º 5
0
    def renderTo(self, plot, dest):
        """
        Render a plot to a file

        Supported formats are:

          - pdf: Portable Document Format PDF
          - ps: Postcript
          - svg: Scalable Vector Graphics SVG
          - all image formats supported by Qt, see QImageWriter.supportedImageFormats()

        Scalable vector graphic formats like PDF or SVG are superior to
        raster graphics formats.

        :param qwt.plot.QwtPlot plot: Plot widget
        :param str fileName: Path of the file, where the document will be stored
        :param str format: Format for the document
        :param QSizeF sizeMM: Size for the document in millimeters.
        :param int resolution: Resolution in dots per Inch (dpi)
        
        .. seealso::
        
            :py:meth:`renderTo()`, :py:meth:`render()`, 
            :py:meth:`qwt.painter.QwtPainter.setRoundingAlignment()`
        """
        if isinstance(dest, QPaintDevice):
            w = dest.width()
            h = dest.height()
            rect = QRectF(0, 0, w, h)
        elif isinstance(dest, QPrinter):
            w = dest.width()
            h = dest.height()
            rect = QRectF(0, 0, w, h)
            aspect = rect.width()/rect.height()
            if aspect < 1.:
                rect.setHeight(aspect*rect.width())
        elif isinstance(dest, QSvgGenerator):
            rect = dest.viewBoxF()
            if rect.isEmpty():
                rect.setRect(0, 0, dest.width(), dest.height())
            if rect.isEmpty():
                rect.setRect(0, 0, 800, 600)
        p = QPainter(dest)
        self.render(plot, p, rect)
Ejemplo n.º 6
0
    def renderTo(self, plot, dest):
        """
        Render a plot to a file

        Supported formats are:

          - pdf: Portable Document Format PDF
          - ps: Postcript
          - svg: Scalable Vector Graphics SVG
          - all image formats supported by Qt, see QImageWriter.supportedImageFormats()

        Scalable vector graphic formats like PDF or SVG are superior to
        raster graphics formats.

        :param qwt.plot.QwtPlot plot: Plot widget
        :param str fileName: Path of the file, where the document will be stored
        :param str format: Format for the document
        :param QSizeF sizeMM: Size for the document in millimeters.
        :param int resolution: Resolution in dots per Inch (dpi)
        
        .. seealso::
        
            :py:meth:`renderTo()`, :py:meth:`render()`, 
            :py:meth:`qwt.painter.QwtPainter.setRoundingAlignment()`
        """
        if isinstance(dest, QPaintDevice):
            w = dest.width()
            h = dest.height()
            rect = QRectF(0, 0, w, h)
        elif isinstance(dest, QPrinter):
            w = dest.width()
            h = dest.height()
            rect = QRectF(0, 0, w, h)
            aspect = rect.width() / rect.height()
            if aspect < 1.:
                rect.setHeight(aspect * rect.width())
        elif isinstance(dest, QSvgGenerator):
            rect = dest.viewBoxF()
            if rect.isEmpty():
                rect.setRect(0, 0, dest.width(), dest.height())
            if rect.isEmpty():
                rect.setRect(0, 0, 800, 600)
        p = QPainter(dest)
        self.render(plot, p, rect)
Ejemplo n.º 7
0
 def renderTo(self, plot, dest):
     if isinstance(dest, QPaintDevice):
         w = dest.width()
         h = dest.height()
         rect = QRectF(0, 0, w, h)
     elif isinstance(dest, QPrinter):
         w = dest.width()
         h = dest.height()
         rect = QRectF(0, 0, w, h)
         aspect = rect.width() / rect.height()
         if aspect < 1.:
             rect.setHeight(aspect * rect.width())
     elif isinstance(dest, QSvgGenerator):
         rect = dest.viewBoxF()
         if rect.isEmpty():
             rect.setRect(0, 0, dest.width(), dest.height())
         if rect.isEmpty():
             rect.setRect(0, 0, 800, 600)
     p = QPainter(dest)
     self.render(plot, p, rect)
Ejemplo n.º 8
0
 def renderTo(self, plot, dest):
     if isinstance(dest, QPaintDevice):
         w = dest.width()
         h = dest.height()
         rect = QRectF(0, 0, w, h)
     elif isinstance(dest, QPrinter):
         w = dest.width()
         h = dest.height()
         rect = QRectF(0, 0, w, h)
         aspect = rect.width()/rect.height()
         if aspect < 1.:
             rect.setHeight(aspect*rect.width())
     elif isinstance(dest, QSvgGenerator):
         rect = dest.viewBoxF()
         if rect.isEmpty():
             rect.setRect(0, 0, dest.width(), dest.height())
         if rect.isEmpty():
             rect.setRect(0, 0, 800, 600)
     p = QPainter(dest)
     self.render(plot, p, rect)
Ejemplo n.º 9
0
def qwtDrawStar1Symbols(painter, points, numPoints, symbol):
    size =symbol.size()
    painter.setPen(symbol.pen())
    sqrt1_2 = np.sqrt(.5)
    r = QRectF(0, 0, size.width(), size.height())
    for pos in points:
        r.moveCenter(pos.toPoint())
        c = QPointF(r.center())
        d1 = r.width()/2.*(1.-sqrt1_2)
        painter.drawLine(r.left()+d1, r.top()+d1, r.right()-d1, r.bottom()-d1)
        painter.drawLine(r.left()+d1, r.bottom()-d1, r.right()-d1, r.top()+d1)
        painter.drawLine(c.x(), r.top(), c.x(), r.bottom())
        painter.drawLine(r.left(), c.y(), r.right(), c.y())
Ejemplo n.º 10
0
 def boundingRect(self):
     rect = QRectF(self.data().boundingRect())
     if not rect.isValid():
         return rect
     if self.orientation() == Qt.Horizontal:
         rect = QRectF(rect.y(), rect.x(), rect.height(), rect.width())
         if rect.left() > self.__data.baseline:
             rect.setLeft(self.__data.baseline)
         elif rect.right() < self.__data.baseline:
             rect.setRight(self.__data.baseline)
     else:
         if rect.bottom() < self.__data.baseline:
             rect.setBottom(self.__data.baseline)
         elif rect.top() > self.__data.baseline:
             rect.setTop(self.__data.baseline)
     return rect
Ejemplo n.º 11
0
def qwtDrawStar1Symbols(painter, points, numPoints, symbol):
    size = symbol.size()
    painter.setPen(symbol.pen())
    sqrt1_2 = np.sqrt(.5)
    r = QRectF(0, 0, size.width(), size.height())
    for pos in points:
        r.moveCenter(pos.toPoint())
        c = QPointF(r.center())
        d1 = r.width() / 2. * (1. - sqrt1_2)
        painter.drawLine(r.left() + d1,
                         r.top() + d1,
                         r.right() - d1,
                         r.bottom() - d1)
        painter.drawLine(r.left() + d1,
                         r.bottom() - d1,
                         r.right() - d1,
                         r.top() + d1)
        painter.drawLine(c.x(), r.top(), c.x(), r.bottom())
        painter.drawLine(r.left(), c.y(), r.right(), c.y())
Ejemplo n.º 12
0
def qwtDrawSvgSymbols(painter, points, numPoints, renderer, symbol):
    if renderer is None or not renderer.isValid():
        return
    viewBox = QRectF(renderer.viewBoxF())
    if viewBox.isEmpty():
        return
    sz = QSizeF(symbol.size())
    if not sz.isValid():
        sz = viewBox.size()
    sx = sz.width() / viewBox.width()
    sy = sz.height() / viewBox.height()
    pinPoint = QPointF(viewBox.center())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    dx = sx * (pinPoint.x() - viewBox.left())
    dy = sy * (pinPoint.y() - viewBox.top())
    for pos in points:
        x = pos.x() - dx
        y = pos.y() - dy
        renderer.render(painter, QRectF(x, y, sz.width(), sz.height()))
Ejemplo n.º 13
0
def qwtDrawSvgSymbols(painter, points, numPoints, renderer, symbol):
    if renderer is None or not renderer.isValid():
        return
    viewBox = QRectF(renderer.viewBoxF())
    if viewBox.isEmpty():
        return
    sz = QSizeF(symbol.size())
    if not sz.isValid():
        sz = viewBox.size()
    sx = sz.width()/viewBox.width()
    sy = sz.height()/viewBox.height()
    pinPoint = QPointF(viewBox.center())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    dx = sx*(pinPoint.x()-viewBox.left())
    dy = sy*(pinPoint.y()-viewBox.top())
    for pos in points:
        x = pos.x()-dx
        y = pos.y()-dy
        renderer.render(painter, QRectF(x, y, sz.width(), sz.height()))
Ejemplo n.º 14
0
 def colorBarRect(self, rect):
     cr = QRectF(rect)
     if self.__data.scaleDraw.orientation() == Qt.Horizontal:
         cr.setLeft(cr.left() + self.__data.borderDist[0])
         cr.setWidth(cr.width() - self.__data.borderDist[1] + 1)
     else:
         cr.setTop(cr.top() + self.__data.borderDist[0])
         cr.setHeight(cr.height() - self.__data.borderDist[1] + 1)
     sda = self.__data.scaleDraw.alignment()
     if sda == QwtScaleDraw.LeftScale:
         cr.setLeft(cr.right()-self.__data.margin-self.__data.colorBar.width)
         cr.setWidth(self.__data.colorBar.width)
     elif sda == QwtScaleDraw.RightScale:
         cr.setLeft(cr.left()+self.__data.margin)
         cr.setWidth(self.__data.colorBar.width)
     elif sda == QwtScaleDraw.BottomScale:
         cr.setTop(cr.top()+self.__data.margin)
         cr.setHeight(self.__data.colorBar.width)
     elif sda == QwtScaleDraw.TopScale:
         cr.setTop(cr.bottom()-self.__data.margin-self.__data.colorBar.width)
         cr.setHeight(self.__data.colorBar.width)
     return cr
Ejemplo n.º 15
0
def qwtDrawGraphicSymbols(painter, points, numPoint, graphic, symbol):
    pointRect = QRectF(graphic.controlPointRect())
    if pointRect.isEmpty():
        return
    sx = 1.
    sy = 1.
    sz = symbol.size()
    if sz.isValid():
        sx = sz.width()/pointRect.width()
        sy = sz.height()/pointRect.height()
    pinPoint = QPointF(pointRect.center())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    transform = QTransform(painter.transform())
    for pos in points:
        tr = QTransform(transform)
        tr.translate(pos.x(), pos.y())
        tr.scale(sx, sy)
        tr.translate(-pinPoint.x(), -pinPoint.y())
        painter.setTransform(tr)
        graphic.render(painter)
    painter.setTransform(transform)
Ejemplo n.º 16
0
def qwtDrawGraphicSymbols(painter, points, numPoint, graphic, symbol):
    pointRect = QRectF(graphic.controlPointRect())
    if pointRect.isEmpty():
        return
    sx = 1.
    sy = 1.
    sz = symbol.size()
    if sz.isValid():
        sx = sz.width() / pointRect.width()
        sy = sz.height() / pointRect.height()
    pinPoint = QPointF(pointRect.center())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    transform = QTransform(painter.transform())
    for pos in points:
        tr = QTransform(transform)
        tr.translate(pos.x(), pos.y())
        tr.scale(sx, sy)
        tr.translate(-pinPoint.x(), -pinPoint.y())
        painter.setTransform(tr)
        graphic.render(painter)
    painter.setTransform(transform)
Ejemplo n.º 17
0
    def draw(self, painter, rect, flags, text):
        """
        Draw the text in a clipping rectangle

        :param QPainter painter: Painter
        :param QRectF rect: Clipping rectangle
        :param int flags: Bitwise OR of the flags like in for QPainter::drawText()
        :param str text: Text to be rendered
        """
        txt = QwtRichTextDocument(text, flags, painter.font())
        painter.save()
        unscaledRect = QRectF(rect)
        if painter.font().pixelSize() < 0:
            res = qwtScreenResolution()
            pd = painter.device()
            if pd.logicalDpiX() != res.width()\
               or pd.logicalDpiY() != res.height():
                transform = QTransform()
                transform.scale(res.width() / float(pd.logicalDpiX()),
                                res.height() / float(pd.logicalDpiY()))
                painter.setWorldTransform(transform, True)
                invtrans, _ok = transform.inverted()
                unscaledRect = invtrans.mapRect(rect)
        txt.setDefaultFont(painter.font())
        txt.setPageSize(QSizeF(unscaledRect.width(), QWIDGETSIZE_MAX))
        layout = txt.documentLayout()
        height = layout.documentSize().height()
        y = unscaledRect.y()
        if flags & Qt.AlignBottom:
            y += unscaledRect.height() - height
        elif flags & Qt.AlignVCenter:
            y += (unscaledRect.height() - height) / 2
        context = QAbstractTextDocumentLayout.PaintContext()
        context.palette.setColor(QPalette.Text, painter.pen().color())
        painter.translate(unscaledRect.x(), y)
        layout.draw(painter, context)
        painter.restore()
Ejemplo n.º 18
0
 def colorBarRect(self, rect):
     cr = QRectF(rect)
     if self.__data.scaleDraw.orientation() == Qt.Horizontal:
         cr.setLeft(cr.left() + self.__data.borderDist[0])
         cr.setWidth(cr.width() - self.__data.borderDist[1] + 1)
     else:
         cr.setTop(cr.top() + self.__data.borderDist[0])
         cr.setHeight(cr.height() - self.__data.borderDist[1] + 1)
     sda = self.__data.scaleDraw.alignment()
     if sda == QwtScaleDraw.LeftScale:
         cr.setLeft(cr.right() - self.__data.margin -
                    self.__data.colorBar.width)
         cr.setWidth(self.__data.colorBar.width)
     elif sda == QwtScaleDraw.RightScale:
         cr.setLeft(cr.left() + self.__data.margin)
         cr.setWidth(self.__data.colorBar.width)
     elif sda == QwtScaleDraw.BottomScale:
         cr.setTop(cr.top() + self.__data.margin)
         cr.setHeight(self.__data.colorBar.width)
     elif sda == QwtScaleDraw.TopScale:
         cr.setTop(cr.bottom() - self.__data.margin -
                   self.__data.colorBar.width)
         cr.setHeight(self.__data.colorBar.width)
     return cr
Ejemplo n.º 19
0
    def activate(self, plot, plotRect, options=0x00):
        self.invalidate()
        rect = QRectF(plotRect)
        self.__data.layoutData.init(plot, rect)
        if not (options & self.IgnoreLegend) and plot.legend() and\
           not plot.legend().isEmpty():
            self.__data.legendRect = self.layoutLegend(options, rect)
            region = QRegion(rect.toRect())
            rect = region.subtracted(QRegion(self.__data.legendRect.toRect())
                                     ).boundingRect()
            if self.__data.legendPos == QwtPlot.LeftLegend:
                rect.setLeft(rect.left()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.RightLegend:
                rect.setRight(rect.right()-self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.TopLegend:
                rect.setTop(rect.top()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.BottomLegend:
                rect.setBottom(rect.bottom()-self.__data.spacing)
        
#     +---+-----------+---+
#     |       Title       |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     | A |           | A |
#     | x |  Canvas   | x |
#     | i |           | i |
#     | s |           | s |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     |      Footer       |
#     +---+-----------+---+

        dimTitle, dimFooter, dimAxes = self.expandLineBreaks(options, rect)
        if dimTitle > 0:
            self.__data.titleRect.setRect(rect.left(), rect.top(),
                                          rect.width(), dimTitle)
            rect.setTop(self.__data.titleRect.bottom()+self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.titleRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.titleRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        if dimFooter > 0:
            self.__data.footerRect.setRect(rect.left(),
                           rect.bottom()-dimFooter, rect.width(), dimFooter)
            rect.setBottom(self.__data.footerRect.top()-self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.footerRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.footerRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        self.__data.canvasRect.setRect(
                rect.x()+dimAxes[QwtPlot.yLeft],
                rect.y()+dimAxes[QwtPlot.xTop],
                rect.width()-dimAxes[QwtPlot.yRight]-dimAxes[QwtPlot.yLeft],
                rect.height()-dimAxes[QwtPlot.xBottom]-dimAxes[QwtPlot.xTop])
        for axis in range(QwtPlot.axisCnt):
            if dimAxes[axis]:
                dim = dimAxes[axis]
                scaleRect = self.__data.scaleRect[axis]
                scaleRect.setRect(*self.__data.canvasRect.getRect())
                if axis == QwtPlot.yLeft:
                    scaleRect.setX(self.__data.canvasRect.left()-dim)
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.yRight:
                    scaleRect.setX(self.__data.canvasRect.right())
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.xBottom:
                    scaleRect.setY(self.__data.canvasRect.bottom())
                    scaleRect.setHeight(dim)
                elif axis == QwtPlot.xTop:
                    scaleRect.setY(self.__data.canvasRect.top()-dim)
                    scaleRect.setHeight(dim)
                scaleRect = scaleRect.normalized()
                
#       +---+-----------+---+
#       |  <-   Axis   ->   |
#       +-^-+-----------+-^-+
#       | | |           | | |
#       |   |           |   |
#       | A |           | A |
#       | x |  Canvas   | x |
#       | i |           | i |
#       | s |           | s |
#       |   |           |   |
#       | | |           | | |
#       +-V-+-----------+-V-+
#       |   <-  Axis   ->   |
#       +---+-----------+---+
                
        self.alignScales(options, self.__data.canvasRect,
                         self.__data.scaleRect)
        if not self.__data.legendRect.isEmpty():
            self.__data.legendRect = self.alignLegend(self.__data.canvasRect,
                                                      self.__data.legendRect)
Ejemplo n.º 20
0
    def activate(self, plot, plotRect, options=0x00):
        """
        Recalculate the geometry of all components.
        
        :param qwt.plot.QwtPlot plot: Plot to be layout
        :param QRectF plotRect: Rectangle where to place the components
        :param options: Layout options
        """
        self.invalidate()
        rect = QRectF(plotRect)
        self.__data.layoutData.init(plot, rect)
        if not (options & self.IgnoreLegend) and plot.legend() and\
           not plot.legend().isEmpty():
            self.__data.legendRect = self.layoutLegend(options, rect)
            region = QRegion(rect.toRect())
            rect = region.subtracted(QRegion(self.__data.legendRect.toRect())
                                     ).boundingRect()
            if self.__data.legendPos == QwtPlot.LeftLegend:
                rect.setLeft(rect.left()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.RightLegend:
                rect.setRight(rect.right()-self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.TopLegend:
                rect.setTop(rect.top()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.BottomLegend:
                rect.setBottom(rect.bottom()-self.__data.spacing)
        
#     +---+-----------+---+
#     |       Title       |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     | A |           | A |
#     | x |  Canvas   | x |
#     | i |           | i |
#     | s |           | s |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     |      Footer       |
#     +---+-----------+---+

        #  title, footer and axes include text labels. The height of each
        #  label depends on its line breaks, that depend on the width
        #  for the label. A line break in a horizontal text will reduce
        #  the available width for vertical texts and vice versa.
        #  expandLineBreaks finds the height/width for title, footer and axes
        #  including all line breaks.

        dimTitle, dimFooter, dimAxes = self.expandLineBreaks(options, rect)
        if dimTitle > 0:
            self.__data.titleRect.setRect(rect.left(), rect.top(),
                                          rect.width(), dimTitle)
            rect.setTop(self.__data.titleRect.bottom()+self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.titleRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.titleRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        if dimFooter > 0:
            self.__data.footerRect.setRect(rect.left(),
                           rect.bottom()-dimFooter, rect.width(), dimFooter)
            rect.setBottom(self.__data.footerRect.top()-self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.footerRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.footerRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        self.__data.canvasRect.setRect(
                rect.x()+dimAxes[QwtPlot.yLeft],
                rect.y()+dimAxes[QwtPlot.xTop],
                rect.width()-dimAxes[QwtPlot.yRight]-dimAxes[QwtPlot.yLeft],
                rect.height()-dimAxes[QwtPlot.xBottom]-dimAxes[QwtPlot.xTop])
        for axis in QwtPlot.validAxes:
            if dimAxes[axis]:
                dim = dimAxes[axis]
                scaleRect = self.__data.scaleRect[axis]
                scaleRect.setRect(*self.__data.canvasRect.getRect())
                if axis == QwtPlot.yLeft:
                    scaleRect.setX(self.__data.canvasRect.left()-dim)
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.yRight:
                    scaleRect.setX(self.__data.canvasRect.right())
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.xBottom:
                    scaleRect.setY(self.__data.canvasRect.bottom())
                    scaleRect.setHeight(dim)
                elif axis == QwtPlot.xTop:
                    scaleRect.setY(self.__data.canvasRect.top()-dim)
                    scaleRect.setHeight(dim)
                scaleRect = scaleRect.normalized()
                
#       +---+-----------+---+
#       |  <-   Axis   ->   |
#       +-^-+-----------+-^-+
#       | | |           | | |
#       |   |           |   |
#       | A |           | A |
#       | x |  Canvas   | x |
#       | i |           | i |
#       | s |           | s |
#       |   |           |   |
#       | | |           | | |
#       +-V-+-----------+-V-+
#       |   <-  Axis   ->   |
#       +---+-----------+---+

        #  The ticks of the axes - not the labels above - should
        #  be aligned to the canvas. So we try to use the empty
        #  corners to extend the axes, so that the label texts
        #  left/right of the min/max ticks are moved into them.
                
        self.alignScales(options, self.__data.canvasRect,
                         self.__data.scaleRect)
        if not self.__data.legendRect.isEmpty():
            self.__data.legendRect = self.alignLegend(self.__data.canvasRect,
                                                      self.__data.legendRect)
Ejemplo n.º 21
0
    def activate(self, plot, plotRect, options=0x00):
        self.invalidate()
        rect = QRectF(plotRect)
        self.__data.layoutData.init(plot, rect)
        if not (options & self.IgnoreLegend) and plot.legend() and\
           not plot.legend().isEmpty():
            self.__data.legendRect = self.layoutLegend(options, rect)
            region = QRegion(rect.toRect())
            rect = region.subtracted(QRegion(
                self.__data.legendRect.toRect())).boundingRect()
            if self.__data.legendPos == QwtPlot.LeftLegend:
                rect.setLeft(rect.left() + self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.RightLegend:
                rect.setRight(rect.right() - self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.TopLegend:
                rect.setTop(rect.top() + self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.BottomLegend:
                rect.setBottom(rect.bottom() - self.__data.spacing)

#     +---+-----------+---+
#     |       Title       |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     | A |           | A |
#     | x |  Canvas   | x |
#     | i |           | i |
#     | s |           | s |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     |      Footer       |
#     +---+-----------+---+

        dimTitle, dimFooter, dimAxes = self.expandLineBreaks(options, rect)
        if dimTitle > 0:
            self.__data.titleRect.setRect(rect.left(), rect.top(),
                                          rect.width(), dimTitle)
            rect.setTop(self.__data.titleRect.bottom() + self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.titleRect.setX(rect.left() +
                                           dimAxes[QwtPlot.yLeft])
                self.__data.titleRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        if dimFooter > 0:
            self.__data.footerRect.setRect(rect.left(),
                                           rect.bottom() - dimFooter,
                                           rect.width(), dimFooter)
            rect.setBottom(self.__data.footerRect.top() - self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.footerRect.setX(rect.left() +
                                            dimAxes[QwtPlot.yLeft])
                self.__data.footerRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        self.__data.canvasRect.setRect(
            rect.x() + dimAxes[QwtPlot.yLeft],
            rect.y() + dimAxes[QwtPlot.xTop],
            rect.width() - dimAxes[QwtPlot.yRight] - dimAxes[QwtPlot.yLeft],
            rect.height() - dimAxes[QwtPlot.xBottom] - dimAxes[QwtPlot.xTop])
        for axis in range(QwtPlot.axisCnt):
            if dimAxes[axis]:
                dim = dimAxes[axis]
                scaleRect = self.__data.scaleRect[axis]
                scaleRect.setRect(*self.__data.canvasRect.getRect())
                if axis == QwtPlot.yLeft:
                    scaleRect.setX(self.__data.canvasRect.left() - dim)
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.yRight:
                    scaleRect.setX(self.__data.canvasRect.right())
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.xBottom:
                    scaleRect.setY(self.__data.canvasRect.bottom())
                    scaleRect.setHeight(dim)
                elif axis == QwtPlot.xTop:
                    scaleRect.setY(self.__data.canvasRect.top() - dim)
                    scaleRect.setHeight(dim)
                scaleRect = scaleRect.normalized()

#       +---+-----------+---+
#       |  <-   Axis   ->   |
#       +-^-+-----------+-^-+
#       | | |           | | |
#       |   |           |   |
#       | A |           | A |
#       | x |  Canvas   | x |
#       | i |           | i |
#       | s |           | s |
#       |   |           |   |
#       | | |           | | |
#       +-V-+-----------+-V-+
#       |   <-  Axis   ->   |
#       +---+-----------+---+

        self.alignScales(options, self.__data.canvasRect,
                         self.__data.scaleRect)
        if not self.__data.legendRect.isEmpty():
            self.__data.legendRect = self.alignLegend(self.__data.canvasRect,
                                                      self.__data.legendRect)