Commits

Yuya Nishihara committed f8e5edc

rename

Comments (0)

Files changed (3)

graphdele-scene-exp.diff

+# HG changeset patch
+# Date 1395675363 -32400
+# Parent 56eb33dbcacfb51e4798e92042201eb1bd04136e
+repomodel: render graph by QGraphicsScene (HACK)
+
+1. put new nodes and edges on QGraphicsScene immediately
+   (ignores redundant toplines)
+2. render it on data() request
+
+No optimization for QGraphicsScene are included.
+
+diff --git a/tortoisehg/hgqt/repoview.py b/tortoisehg/hgqt/repoview.py
+--- a/tortoisehg/hgqt/repoview.py
++++ b/tortoisehg/hgqt/repoview.py
+@@ -436,12 +436,15 @@ class GraphDelegate(QStyledItemDelegate)
+ 
+     def __init__(self, parent=None):
+         super(GraphDelegate, self).__init__(parent)
++        self._graphscene = QGraphicsScene(self)
++        self._drawnrows = set()
+         # assumes 4px as text and decoration margins of other columns
+         fm = QFontMetrics(QFont())
+         self._rowheight = max(fm.height() + 4, 16)
+ 
+     def invalidate(self):
+-        pass
++        self._graphscene.clear()
++        self._drawnrows.clear()
+ 
+     def _col2x(self, col):
+         maxradius = self._rowheight / 2
+@@ -454,20 +457,23 @@ class GraphDelegate(QStyledItemDelegate)
+         QStyledItemDelegate.paint(self, painter, option, index)
+         # update to the actual height that should be the same for all rows
+         self._rowheight = option.rect.height()
+-        gnode = index.data(repomodel.GraphNodeRole).toPyObject()
++        if index.row() not in self._drawnrows:
++            gnode = index.data(repomodel.GraphNodeRole).toPyObject()
++            self._drawEdges(index, gnode)
++            self._drawNode(index, gnode)
++            self._drawnrows.add(index.row())
+         painter.save()
+         try:
+-            painter.setClipRect(option.rect)
+             painter.setRenderHint(QPainter.Antialiasing)
+-            painter.translate(option.rect.topLeft())
+-            self._drawEdges(painter, index, gnode)
+-            self._drawNode(painter, index, gnode)
++            t = QRectF(option.rect)
++            s = QRectF(QPointF(0, index.row() * self._rowheight), t.size())
++            self._graphscene.render(painter, t, s)
+         finally:
+             painter.restore()
+ 
+-    def _drawEdges(self, painter, index, gnode):
++    def _drawEdges(self, index, gnode):
+         h = self._rowheight
+-        dot_y = h / 2
++        dot_y = h / 2 + index.row() * h
+ 
+         def isactive(e):
+             m = index.model()
+@@ -478,13 +484,14 @@ class GraphDelegate(QStyledItemDelegate)
+             return isactive(pe[1]), pe[1].importance
+ 
+         for y1, y4, lines in ((dot_y, dot_y + h, gnode.bottomlines),
+-                              (dot_y - h, dot_y, gnode.toplines)):
++                              #(dot_y - h, dot_y, gnode.toplines)):
++                              ):
+             y2 = y1 + 1 * (y4 - y1)/4
+             ymid = (y1 + y4)/2
+             y3 = y1 + 3 * (y4 - y1)/4
+ 
+             # remove hidden lines that can be partly visible due to antialiasing
+-            lines = dict(sorted(lines, key=lineimportance)).items()
++            #lines = dict(sorted(lines, key=lineimportance)).items()
+             # still necessary to sort by importance because lines can partially
+             # overlap near contact point
+             lines.sort(key=lineimportance)
+@@ -494,11 +501,10 @@ class GraphDelegate(QStyledItemDelegate)
+                 lpen = QPen(QColor(_edge_color(e, active)))
+                 lpen.setStyle(get_style(e.linktype, active))
+                 lpen.setWidth(get_width(e.linktype, active))
+-                painter.setPen(lpen)
+                 x1 = self._col2x(start)
+                 x2 = self._col2x(end)
+                 if x1 == x2:
+-                    painter.drawLine(x1, y1, x2, y4)
++                    self._graphscene.addLine(x1, y1, x2, y4, lpen)
+                 else:
+                     path = QPainterPath()
+                     path.moveTo(x1, y1)
+@@ -508,9 +514,9 @@ class GraphDelegate(QStyledItemDelegate)
+                     path.cubicTo(x2, y3,
+                                  x2, y3,
+                                  x2, y4)
+-                    painter.drawPath(path)
++                    self._graphscene.addPath(path, lpen)
+ 
+-    def _drawNode(self, painter, index, gnode):
++    def _drawNode(self, index, gnode):
+         if not (index.flags() & Qt.ItemIsEnabled):
+             dot_color = QColor("gray")
+             radius = self._dotradius() * 0.8
+@@ -525,20 +531,20 @@ class GraphDelegate(QStyledItemDelegate)
+ 
+         pen = QPen(pencolor)
+         pen.setWidthF(1.5)
+-        painter.setPen(pen)
++        brush = QBrush()
+ 
+         centre_x = self._col2x(gnode.x)
+-        centre_y = self._rowheight / 2
++        centre_y = self._rowheight / 2 + index.row() * self._rowheight
+ 
+         def circle(r):
+             rect = QRectF(centre_x - r,
+                           centre_y - r,
+                           2 * r, 2 * r)
+-            painter.drawEllipse(rect)
++            self._graphscene.addEllipse(rect, pen, brush)
+ 
+         def closesymbol(s):
+             rect_ = QRectF(centre_x - 1.5 * s, centre_y - 0.5 * s, 3 * s, s)
+-            painter.drawRect(rect_)
++            self._graphscene.addRect(rect_, pen, brush)
+ 
+         def diamond(r):
+             poly = QPolygonF([QPointF(centre_x - r, centre_y),
+@@ -546,11 +552,11 @@ class GraphDelegate(QStyledItemDelegate)
+                               QPointF(centre_x + r, centre_y),
+                               QPointF(centre_x, centre_y + r),
+                               QPointF(centre_x - r, centre_y),])
+-            painter.drawPolygon(poly)
++            self._graphscene.addPolygon(poly, pen, brush)
+ 
+         hiddenrev = gnode.hidden
+         if hiddenrev:
+-            painter.setBrush(truewhite)
++            brush = truewhite
+             white.setAlpha(64)
+             fillcolor.setAlpha(64)
+         if gnode.shape == graph.NODE_SHAPE_APPLIEDPATCH:
+@@ -559,32 +565,32 @@ class GraphDelegate(QStyledItemDelegate)
+             if hiddenrev:
+                 diamond(symbolsize)
+             if gnode.wdparent:
+-                painter.setBrush(white)
++                brush = white
+                 diamond(2 * 0.9 * symbolsize)
+-            painter.setBrush(fillcolor)
++            brush = fillcolor
+             diamond(symbolsize)
+         elif gnode.shape == graph.NODE_SHAPE_UNAPPLIEDPATCH:
+             symbolsize = radius / 1.5
+             if hiddenrev:
+                 diamond(symbolsize)
+             patchcolor = QColor('#dddddd')
+-            painter.setBrush(patchcolor)
+-            painter.setPen(patchcolor)
++            brush = patchcolor
++            pen = patchcolor
+             diamond(symbolsize)
+         elif gnode.shape == graph.NODE_SHAPE_CLOSEDBRANCH:
+             symbolsize = 0.5 * radius
+             if hiddenrev:
+                 closesymbol(symbolsize)
+-            painter.setBrush(fillcolor)
++            brush = fillcolor
+             closesymbol(symbolsize)
+         else:  # circles for normal revisions
+             symbolsize = 0.5 * radius
+             if hiddenrev:
+                 circle(symbolsize)
+             if gnode.wdparent:
+-                painter.setBrush(white)
++                brush = white
+                 circle(0.9 * radius)
+-            painter.setBrush(fillcolor)
++            brush = fillcolor
+             circle(symbolsize)
+ 
+     def sizeHint(self, option, index):

repom-graphscene-exp.diff

-# HG changeset patch
-# Date 1395675363 -32400
-# Parent 56eb33dbcacfb51e4798e92042201eb1bd04136e
-repomodel: render graph by QGraphicsScene (HACK)
-
-1. put new nodes and edges on QGraphicsScene immediately
-   (ignores redundant toplines)
-2. render it on data() request
-
-No optimization for QGraphicsScene are included.
-
-diff --git a/tortoisehg/hgqt/repoview.py b/tortoisehg/hgqt/repoview.py
---- a/tortoisehg/hgqt/repoview.py
-+++ b/tortoisehg/hgqt/repoview.py
-@@ -436,12 +436,15 @@ class GraphDelegate(QStyledItemDelegate)
- 
-     def __init__(self, parent=None):
-         super(GraphDelegate, self).__init__(parent)
-+        self._graphscene = QGraphicsScene(self)
-+        self._drawnrows = set()
-         # assumes 4px as text and decoration margins of other columns
-         fm = QFontMetrics(QFont())
-         self._rowheight = max(fm.height() + 4, 16)
- 
-     def invalidate(self):
--        pass
-+        self._graphscene.clear()
-+        self._drawnrows.clear()
- 
-     def _col2x(self, col):
-         maxradius = self._rowheight / 2
-@@ -454,20 +457,23 @@ class GraphDelegate(QStyledItemDelegate)
-         QStyledItemDelegate.paint(self, painter, option, index)
-         # update to the actual height that should be the same for all rows
-         self._rowheight = option.rect.height()
--        gnode = index.data(repomodel.GraphNodeRole).toPyObject()
-+        if index.row() not in self._drawnrows:
-+            gnode = index.data(repomodel.GraphNodeRole).toPyObject()
-+            self._drawEdges(index, gnode)
-+            self._drawNode(index, gnode)
-+            self._drawnrows.add(index.row())
-         painter.save()
-         try:
--            painter.setClipRect(option.rect)
-             painter.setRenderHint(QPainter.Antialiasing)
--            painter.translate(option.rect.topLeft())
--            self._drawEdges(painter, index, gnode)
--            self._drawNode(painter, index, gnode)
-+            t = QRectF(option.rect)
-+            s = QRectF(QPointF(0, index.row() * self._rowheight), t.size())
-+            self._graphscene.render(painter, t, s)
-         finally:
-             painter.restore()
- 
--    def _drawEdges(self, painter, index, gnode):
-+    def _drawEdges(self, index, gnode):
-         h = self._rowheight
--        dot_y = h / 2
-+        dot_y = h / 2 + index.row() * h
- 
-         def isactive(e):
-             m = index.model()
-@@ -478,13 +484,14 @@ class GraphDelegate(QStyledItemDelegate)
-             return isactive(pe[1]), pe[1].importance
- 
-         for y1, y4, lines in ((dot_y, dot_y + h, gnode.bottomlines),
--                              (dot_y - h, dot_y, gnode.toplines)):
-+                              #(dot_y - h, dot_y, gnode.toplines)):
-+                              ):
-             y2 = y1 + 1 * (y4 - y1)/4
-             ymid = (y1 + y4)/2
-             y3 = y1 + 3 * (y4 - y1)/4
- 
-             # remove hidden lines that can be partly visible due to antialiasing
--            lines = dict(sorted(lines, key=lineimportance)).items()
-+            #lines = dict(sorted(lines, key=lineimportance)).items()
-             # still necessary to sort by importance because lines can partially
-             # overlap near contact point
-             lines.sort(key=lineimportance)
-@@ -494,11 +501,10 @@ class GraphDelegate(QStyledItemDelegate)
-                 lpen = QPen(QColor(_edge_color(e, active)))
-                 lpen.setStyle(get_style(e.linktype, active))
-                 lpen.setWidth(get_width(e.linktype, active))
--                painter.setPen(lpen)
-                 x1 = self._col2x(start)
-                 x2 = self._col2x(end)
-                 if x1 == x2:
--                    painter.drawLine(x1, y1, x2, y4)
-+                    self._graphscene.addLine(x1, y1, x2, y4, lpen)
-                 else:
-                     path = QPainterPath()
-                     path.moveTo(x1, y1)
-@@ -508,9 +514,9 @@ class GraphDelegate(QStyledItemDelegate)
-                     path.cubicTo(x2, y3,
-                                  x2, y3,
-                                  x2, y4)
--                    painter.drawPath(path)
-+                    self._graphscene.addPath(path, lpen)
- 
--    def _drawNode(self, painter, index, gnode):
-+    def _drawNode(self, index, gnode):
-         if not (index.flags() & Qt.ItemIsEnabled):
-             dot_color = QColor("gray")
-             radius = self._dotradius() * 0.8
-@@ -525,20 +531,20 @@ class GraphDelegate(QStyledItemDelegate)
- 
-         pen = QPen(pencolor)
-         pen.setWidthF(1.5)
--        painter.setPen(pen)
-+        brush = QBrush()
- 
-         centre_x = self._col2x(gnode.x)
--        centre_y = self._rowheight / 2
-+        centre_y = self._rowheight / 2 + index.row() * self._rowheight
- 
-         def circle(r):
-             rect = QRectF(centre_x - r,
-                           centre_y - r,
-                           2 * r, 2 * r)
--            painter.drawEllipse(rect)
-+            self._graphscene.addEllipse(rect, pen, brush)
- 
-         def closesymbol(s):
-             rect_ = QRectF(centre_x - 1.5 * s, centre_y - 0.5 * s, 3 * s, s)
--            painter.drawRect(rect_)
-+            self._graphscene.addRect(rect_, pen, brush)
- 
-         def diamond(r):
-             poly = QPolygonF([QPointF(centre_x - r, centre_y),
-@@ -546,11 +552,11 @@ class GraphDelegate(QStyledItemDelegate)
-                               QPointF(centre_x + r, centre_y),
-                               QPointF(centre_x, centre_y + r),
-                               QPointF(centre_x - r, centre_y),])
--            painter.drawPolygon(poly)
-+            self._graphscene.addPolygon(poly, pen, brush)
- 
-         hiddenrev = gnode.hidden
-         if hiddenrev:
--            painter.setBrush(truewhite)
-+            brush = truewhite
-             white.setAlpha(64)
-             fillcolor.setAlpha(64)
-         if gnode.shape == graph.NODE_SHAPE_APPLIEDPATCH:
-@@ -559,32 +565,32 @@ class GraphDelegate(QStyledItemDelegate)
-             if hiddenrev:
-                 diamond(symbolsize)
-             if gnode.wdparent:
--                painter.setBrush(white)
-+                brush = white
-                 diamond(2 * 0.9 * symbolsize)
--            painter.setBrush(fillcolor)
-+            brush = fillcolor
-             diamond(symbolsize)
-         elif gnode.shape == graph.NODE_SHAPE_UNAPPLIEDPATCH:
-             symbolsize = radius / 1.5
-             if hiddenrev:
-                 diamond(symbolsize)
-             patchcolor = QColor('#dddddd')
--            painter.setBrush(patchcolor)
--            painter.setPen(patchcolor)
-+            brush = patchcolor
-+            pen = patchcolor
-             diamond(symbolsize)
-         elif gnode.shape == graph.NODE_SHAPE_CLOSEDBRANCH:
-             symbolsize = 0.5 * radius
-             if hiddenrev:
-                 closesymbol(symbolsize)
--            painter.setBrush(fillcolor)
-+            brush = fillcolor
-             closesymbol(symbolsize)
-         else:  # circles for normal revisions
-             symbolsize = 0.5 * radius
-             if hiddenrev:
-                 circle(symbolsize)
-             if gnode.wdparent:
--                painter.setBrush(white)
-+                brush = white
-                 circle(0.9 * radius)
--            painter.setBrush(fillcolor)
-+            brush = fillcolor
-             circle(symbolsize)
- 
-     def sizeHint(self, option, index):
 graphdele-invalidate.diff
-repom-graphscene-exp.diff
+graphdele-scene-exp.diff
 repom-symmetrical-hack.diff
 graphdele-shadow-exp.diff
 fv-chunkmsplit.diff