Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

repomodel: simplify maxWidthValueForColumn, give graph width

This function is not called often enough to justify a dictionary
of lambda functions. Supply a real width for the revision graph.

Changeset 263c67a126cf

Parent 1cf89f23fd4d

by Steve Borho

Changes to 2 files · Browse files at 263c67a126cf Showing diff from parent 1cf89f23fd4d Diff from another changeset...

 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
252
253
254
255
256
257
258
259
260
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
263
264
 
86
87
88
 
 
 
 
 
 
 
 
 
 
 
89
90
91
 
241
242
243
 
 
 
 
 
 
 
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
@@ -86,17 +86,6 @@
  'Filename': lambda ctx, gnode: gnode.extra[0],   }   -# in following lambdas, r is a hg repo -_maxwidth = {'ID': lambda self, r: str(len(r)), - 'Date': lambda self, r: cvrt_date(r[None].date()), - 'Tags': lambda self, r: sorted(r.tags().keys(), - key=lambda x: len(x))[-1][:10], - 'Branch': lambda self, r: sorted(r.branchtags().keys(), - key=lambda x: len(x))[-1], - 'Author': lambda self, r: 'author name', # TODO get actual max - 'Filename': lambda self, r: self.filename, - } -  def datacached(meth):   """   decorator used to cache 'data' method of Qt models. It will *not* @@ -252,13 +241,29 @@
  def columnCount(self, parent=None):   return len(self._columns)   - def maxWidthValueForColumn(self, column): - column = self._columns[column] - try: - if column in _maxwidth: - return _maxwidth[column](self, self.repo) - except IndexError: - pass + def maxWidthValueForColumn(self, col): + column = self._columns[col] + if column == 'ID': + return str(len(self.repo)) + if column == 'Date': + return cvrt_date(self.repo[None].date()) + if column == 'Tags': + try: + return sorted(r.tags().keys(), key=lambda x: len(x))[-1][:10] + except IndexError: + pass + if column == 'Branch': + try: + return sorted(r.branchtags().keys(), key=lambda x: len(x))[-1] + except IndexError: + pass + if column == 'Author': + return 'author name' # TODO get actual max + if column == 'Filename': + return self.filename + if column == 'Graph': + return self.col2x(self.graph.max_cols) + # Fall through for Log   return None     def user_color(self, user):
 
213
214
215
216
 
 
 
217
218
219
 
213
214
215
 
216
217
218
219
220
221
@@ -213,7 +213,9 @@
  tot_stretch += model._stretchs[model._columns[c]]   continue   w = model.maxWidthValueForColumn(c) - if w is not None: + if isinstance(w, int): + self.setColumnWidth(c, w) + elif w is not None:   w = fontm.width(unicode(w) + 'w')   self.setColumnWidth(c, w)   else: