1. Yuya Nishihara
  2. thg-qt-mq

Commits

Yuya Nishihara  committed 5d2beeb

update hack

  • Participants
  • Parent commits 2e6e8c5
  • Branches default

Comments (0)

Files changed (1)

File repom-graphscene-exp.diff

View file
 # HG changeset patch
 # Date 1395675363 -32400
-# Parent f28e1f17420305eaedb6b39d3820b10d7ea7412f
+# Parent 56eb33dbcacfb51e4798e92042201eb1bd04136e
 repomodel: render graph by QGraphicsScene (HACK)
 
 1. put new nodes and edges on QGraphicsScene immediately
 
 No optimization for QGraphicsScene are included.
 
-diff --git a/tortoisehg/hgqt/repomodel.py b/tortoisehg/hgqt/repomodel.py
---- a/tortoisehg/hgqt/repomodel.py
-+++ b/tortoisehg/hgqt/repomodel.py
-@@ -162,6 +162,8 @@ class HgRepoListModel(QAbstractTableMode
-         QAbstractTableModel.__init__(self, parent)
-         self._cache = []
-         self.graph = None
+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._graphbottomrow = 0
-         self.timerHandle = None
-         self.dotradius = 8
-         self.rowheight = 20
-@@ -275,7 +277,11 @@ class HgRepoListModel(QAbstractTableMode
-             required = row - n + self.fill_step
-         if required or buildrev:
-             self.graph.build_nodes(nnodes=required, rev=buildrev)
-+            self._drawgraph()
-             self.updateRowCount()
-+        else:
-+            # in case cache was invalidated
-+            self._drawgraph()
++        self._drawnrows = set()
+         # assumes 4px as text and decoration margins of other columns
+         fm = QFontMetrics(QFont())
+         self._rowheight = max(fm.height() + 4, 16)
  
-         if self.rowcount >= len(self.graph):
-             return  # no need to update row count
-@@ -303,9 +309,12 @@ class HgRepoListModel(QAbstractTableMode
-             elif not self.graph.build_nodes():
-                 self.killTimer(self.timerHandle)
-                 self.timerHandle = None
-+                self._drawgraph()
-                 self.updateRowCount()
-                 self.showMessage.emit('')
-                 self.loaded.emit()
-+            else:
-+                self._drawgraph()
+     def invalidate(self):
+-        pass
++        self._graphscene.clear()
++        self._drawnrows.clear()
  
-     def updateRowCount(self):
-         currentlen = self.rowcount
-@@ -373,7 +382,7 @@ class HgRepoListModel(QAbstractTableMode
-         maxradius = self.rowheight / 2
-         return maxradius * (col + 1)
+     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 graphctx(self, ctx, gnode):
-+    def graphctx(self, row, gnode):
-         w = self.col2x(gnode.cols)
-         h = self.rowheight
+-    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
  
-@@ -381,17 +390,28 @@ class HgRepoListModel(QAbstractTableMode
-         pix.fill(QColor(0,0,0,0))
-         painter = QPainter(pix)
-         try:
--            self._drawgraphctx(painter, pix, ctx, gnode)
-+            painter.setRenderHint(QPainter.Antialiasing)
-+            self._graphscene.render(painter,
-+                                    QRectF(0, 0, pix.width(), pix.height()),
-+                                    QRectF(0, row * h,
-+                                           pix.width(), pix.height()))
-         finally:
-             painter.end()
-         return QVariant(pix)
- 
--    def _drawgraphctx(self, painter, pix, ctx, gnode):
-+    def _drawgraph(self):
-+        endrow = len(self.graph)
-+        for row in xrange(self._graphbottomrow, endrow):
-+            gnode = self.graph[row]
-+            ctx = self.repo.changectx(gnode.rev)
-+            self._drawgraphctx(row, ctx, gnode)
-+        self._graphbottomrow = endrow
-+
-+    def _drawgraphctx(self, row, ctx, gnode):
-         revset = self.revset
--        h = pix.height()
--        dot_y = h / 2
--
--        painter.setRenderHint(QPainter.Antialiasing)
-+        scene = self._graphscene
-+        h = self.rowheight
-+        dot_y = h / 2 + row * h
- 
-         if revset:
-             def isactive(start, end, color, line_type, children, rev):
-@@ -401,7 +421,7 @@ class HgRepoListModel(QAbstractTableMode
-                 return True
+         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)):
++                              #(dot_y - h, dot_y, gnode.toplines)):
++                              ):
              y2 = y1 + 1 * (y4 - y1)/4
              ymid = (y1 + y4)/2
              y3 = y1 + 3 * (y4 - y1)/4
-@@ -412,11 +432,10 @@ class HgRepoListModel(QAbstractTableMode
-                 lpen = QPen(QColor(active and get_color(color) or "gray"))
-                 lpen.setStyle(get_style(line_type, active))
-                 lpen.setWidth(get_width(line_type, active))
+ 
+             # 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)
+                 x1 = self._col2x(start)
+                 x2 = self._col2x(end)
                  if x1 == x2:
 -                    painter.drawLine(x1, y1, x2, y4)
-+                    scene.addLine(x1, y1, x2, y4, lpen)
++                    self._graphscene.addLine(x1, y1, x2, y4, lpen)
                  else:
                      path = QPainterPath()
                      path.moveTo(x1, y1)
-@@ -426,7 +445,7 @@ class HgRepoListModel(QAbstractTableMode
+@@ -508,9 +514,9 @@ class GraphDelegate(QStyledItemDelegate)
                      path.cubicTo(x2, y3,
                                   x2, y3,
                                   x2, y4)
 -                    painter.drawPath(path)
-+                    scene.addPath(path, lpen)
++                    self._graphscene.addPath(path, lpen)
  
-         # Draw node
-         if revset and gnode.rev not in revset:
-@@ -443,20 +462,20 @@ class HgRepoListModel(QAbstractTableMode
+-    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 = h/2
-+        centre_y = dot_y
+         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)
-+            scene.addEllipse(rect, pen, brush)
++            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_)
-+            scene.addRect(rect_, pen, brush)
++            self._graphscene.addRect(rect_, pen, brush)
  
          def diamond(r):
              poly = QPolygonF([QPointF(centre_x - r, centre_y),
-@@ -464,11 +483,11 @@ class HgRepoListModel(QAbstractTableMode
+@@ -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)
-+            scene.addPolygon(poly, pen, brush)
++            self._graphscene.addPolygon(poly, pen, brush)
  
-         hiddenrev = ctx.hidden()
+         hiddenrev = gnode.hidden
          if hiddenrev:
 -            painter.setBrush(truewhite)
 +            brush = truewhite
              white.setAlpha(64)
              fillcolor.setAlpha(64)
-         if ctx.thgmqappliedpatch():  # diamonds for patches
-@@ -476,36 +495,38 @@ class HgRepoListModel(QAbstractTableMode
+         if gnode.shape == graph.NODE_SHAPE_APPLIEDPATCH:
+@@ -559,32 +565,32 @@ class GraphDelegate(QStyledItemDelegate)
              if hiddenrev:
                  diamond(symbolsize)
-             if ctx.thgwdparent():
+             if gnode.wdparent:
 -                painter.setBrush(white)
 +                brush = white
                  diamond(2 * 0.9 * symbolsize)
 -            painter.setBrush(fillcolor)
 +            brush = fillcolor
              diamond(symbolsize)
-         elif ctx.thgmqunappliedpatch():
+         elif gnode.shape == graph.NODE_SHAPE_UNAPPLIEDPATCH:
              symbolsize = radius / 1.5
              if hiddenrev:
                  diamond(symbolsize)
 +            brush = patchcolor
 +            pen = patchcolor
              diamond(symbolsize)
-         elif ctx.extra().get('close'):
+         elif gnode.shape == graph.NODE_SHAPE_CLOSEDBRANCH:
              symbolsize = 0.5 * radius
              if hiddenrev:
                  closesymbol(symbolsize)
              symbolsize = 0.5 * radius
              if hiddenrev:
                  circle(symbolsize)
-             if ctx.thgwdparent():
+             if gnode.wdparent:
 -                painter.setBrush(white)
 +                brush = white
                  circle(0.9 * radius)
 +            brush = fillcolor
              circle(symbolsize)
  
-     def invalidateCache(self):
-         self._cache = []
-+        self._graphscene.clear()
-+        self._graphbottomrow = 0
- 
-     _roleoffsets = {
-         Qt.DisplayRole: 0,
-@@ -577,7 +598,7 @@ class HgRepoListModel(QAbstractTableMode
-             if column == BranchColumn:
-                 return QVariant(QColor(self.namedbranch_color(ctx.branch())))
-         elif role == GraphRole:
--            return self.graphctx(ctx, gnode)
-+            return self.graphctx(row, gnode)
-         return nullvariant
- 
-     def flags(self, index):
+     def sizeHint(self, option, index):