Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

logcolumns: allow different log columns in workbench, file history, file diff

Closes #454, #490

Changeset a9011b36e99e

Parent a8d27ba47d50

by Phil Currier

Changes to 7 files · Browse files at a9011b36e99e Showing diff from parent a8d27ba47d50 Diff from another changeset...

 
120
121
122
123
124
 
 
125
126
127
 
146
147
148
149
 
 
 
150
151
152
 
315
316
317
318
319
 
 
 
320
321
 
 
322
323
324
 
406
407
408
409
 
 
 
410
411
412
 
120
121
122
 
 
123
124
125
126
127
 
146
147
148
 
149
150
151
152
153
154
 
317
318
319
 
 
320
321
322
323
 
324
325
326
327
328
 
410
411
412
 
413
414
415
416
417
418
@@ -120,8 +120,8 @@
    self.splitter = QSplitter(Qt.Vertical)   self.setCentralWidget(self.splitter) - self.repoview = repoview.HgRepoView(self.repo, 'fileLogDialog', - self.splitter) + cs = ('fileLogDialog', _('File History Log Columns')) + self.repoview = repoview.HgRepoView(self.repo, cs[0], cs, self.splitter)   self.contentframe = QFrame(self.splitter)     vbox = QVBoxLayout() @@ -146,7 +146,9 @@
  self.editToolbar.addAction(self.actionForward)     def setupModels(self): - self.filerevmodel = filerevmodel.FileRevModel(self.repo, parent=self) + self.filerevmodel = filerevmodel.FileRevModel(self.repo, + self.repoview.colselect[0], + parent=self)   self.repoview.setModel(self.filerevmodel)   self.repoview.revisionSelected.connect(self.onRevisionSelected)   self.repoview.revisionActivated.connect(self.onRevisionActivated) @@ -315,10 +317,12 @@
  self.splitter = QSplitter(Qt.Vertical)   self.setCentralWidget(self.splitter)   self.horizontalLayout = QHBoxLayout() - self.tableView_revisions_left = repoview.HgRepoView(self.repo, - 'fileDiffDialogLeft', self) + cs = ('fileDiffDialogLeft', _('File Differences Log Columns')) + self.tableView_revisions_left = repoview.HgRepoView(self.repo, cs[0], + cs, self)   self.tableView_revisions_right = repoview.HgRepoView(self.repo, - 'fileDiffDialogRight', self) + 'fileDiffDialogRight', + cs, self)   self.horizontalLayout.addWidget(self.tableView_revisions_left)   self.horizontalLayout.addWidget(self.tableView_revisions_right)   self.frame = QFrame() @@ -406,7 +410,9 @@
  def setupModels(self):   self.filedata = {'left': None, 'right': None}   self._invbarchanged = False - self.filerevmodel = filerevmodel.FileRevModel(self.repo, self.filename, parent=self) + self.filerevmodel = filerevmodel.FileRevModel(self.repo, + self.tableView_revisions_left.colselect[0], + self.filename, parent=self)   self.filerevmodel.filled.connect(self.modelFilled)   self.tableView_revisions_left.setModel(self.filerevmodel)   self.tableView_revisions_right.setModel(self.filerevmodel)
 
14
15
16
17
 
18
19
20
21
22
 
 
 
 
 
 
23
24
25
 
27
28
29
30
31
 
 
 
32
33
34
35
36
 
37
38
39
40
41
 
42
43
44
 
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
33
34
35
 
 
36
37
38
39
40
41
42
 
43
44
45
46
 
 
47
48
49
50
@@ -14,12 +14,18 @@
 # this program; if not, write to the Free Software Foundation, Inc.,  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.   -from tortoisehg.hgqt.repomodel import HgRepoListModel, COLUMNNAMES +from tortoisehg.hgqt.repomodel import HgRepoListModel, COLUMNHEADERS  from tortoisehg.hgqt.graph import Graph, filelog_grapher  from tortoisehg.hgqt.i18n import _    from PyQt4.QtCore import *   +FILE_HEADERS = (('Filename', _('Filename', 'column header')),) +UNUSED_HEADERS = ('Graph', 'Changes') + +FILE_COLUMNHEADERS = tuple(c for c in COLUMNHEADERS + if c[0] not in UNUSED_HEADERS) + FILE_HEADERS +  class FileRevModel(HgRepoListModel):   """   Model used to manage the list of revisions of a file, in file @@ -27,18 +33,18 @@
  """   filled = pyqtSignal()   - _allcolumns = ('Rev', 'Branch', 'Description', 'Author', 'Age', - 'LocalTime', 'UTCTime', 'Tags', 'Filename') + _allcolumns = tuple(h[0] for h in FILE_COLUMNHEADERS) + _allcolnames = dict(FILE_COLUMNHEADERS) +   _columns = ('Rev', 'Branch', 'Description', 'Author', 'Age', 'Filename')   _stretchs = {'Description': 1, }   _getcolumns = "getFilelogColumns"   - def __init__(self, repo, filename=None, parent=None): + def __init__(self, repo, cfgname, filename=None, parent=None):   """   data is a HgHLRepo instance   """ - HgRepoListModel.__init__(self, repo, '', [], False, parent) - COLUMNNAMES['Filename'] = _('Filename', 'column header') + HgRepoListModel.__init__(self, repo, cfgname, '', [], False, parent)   self.setFilename(filename)     def setRepo(self, repo, branch='', fromhead=None, follow=False):
 
16
17
18
19
 
20
 
 
 
 
 
 
 
 
21
22
 
23
24
25
26
27
 
28
29
30
 
31
32
 
 
33
34
35
 
41
42
43
44
 
45
46
47
 
51
52
53
54
 
55
56
57
 
81
82
83
84
 
85
86
87
88
89
90
91
 
 
16
17
18
 
19
20
21
22
23
24
25
26
27
28
29
 
30
31
32
33
34
 
35
36
37
 
38
39
 
40
41
42
43
44
 
50
51
52
 
53
54
55
56
 
60
61
62
 
63
64
65
66
 
90
91
92
 
93
94
95
96
97
98
99
 
100
@@ -16,20 +16,29 @@
 from PyQt4.QtGui import *    class ColumnSelectDialog(QDialog): - def __init__(self, all, curcolumns=None, parent=None): + def __init__(self, cfgname, name, model, parent=None):   QDialog.__init__(self, parent) + if model: + all = model._allcolumns + colnames = model._allcolnames + self.curcolumns = model._columns + else: + all = repomodel.HgRepoListModel._allcolumns + colnames = repomodel.HgRepoListModel._allcolnames + self.curcolumns = None   - self.setWindowTitle(_('Workbench Log Columns')) + self.setWindowTitle(name)   self.setWindowFlags(self.windowFlags() & \   ~Qt.WindowContextHelpButtonHint)   self.setMinimumSize(250, 265)   - self.curcolumns = curcolumns + self.cfgname = cfgname   if not self.curcolumns:   s = QSettings() - cols = s.value('workbench/columns').toStringList() + cols = s.value(self.cfgname + '/columns').toStringList()   if cols: - self.curcolumns = [c for c in cols if c in all] + self.curcolumns = [hglib.fromunicode(c) + for c in cols if c in all]   else:   self.curcolumns = all   self.disabled = [c for c in all if c not in self.curcolumns] @@ -41,7 +50,7 @@
  list = QListWidget()   # enabled cols are listed in sorted order   for c in self.curcolumns: - item = QListWidgetItem(repomodel.COLUMNNAMES[c]) + item = QListWidgetItem(colnames[c])   item.columnid = c   item.setFlags(Qt.ItemIsSelectable |   Qt.ItemIsEnabled | @@ -51,7 +60,7 @@
  list.addItem(item)   # disabled cols are listed last   for c in self.disabled: - item = QListWidgetItem(repomodel.COLUMNNAMES[c]) + item = QListWidgetItem(colnames[c])   item.columnid = c   item.setFlags(Qt.ItemIsSelectable |   Qt.ItemIsEnabled | @@ -81,11 +90,11 @@
  item = self.list.item(i)   if item.checkState() == Qt.Checked:   cols.append(item.columnid) - s.setValue('workbench/columns', cols) + s.setValue(self.cfgname + '/columns', cols)   QDialog.accept(self)     def reject(self):   QDialog.reject(self)    def run(ui, *pats, **opts): - return ColumnSelectDialog(repomodel.ALLCOLUMNS) + return ColumnSelectDialog('workbench', _('Workbench'), None)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
 
 
77
78
79
80
81
 
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
146
147
148
149
150
 
151
152
153
154
 
 
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
 
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
 
 
 
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
145
146
147
148
149
 
150
151
152
 
 
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
 
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
 # Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE).  # http://www.logilab.fr/ -- mailto:contact@logilab.fr  #  # This program is free software; you can redistribute it and/or modify it under  # the terms of the GNU General Public License as published by the Free Software  # Foundation; either version 2 of the License, or (at your option) any later  # version.  #  # This program is distributed in the hope that it will be useful, but WITHOUT  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS  # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.  #  # You should have received a copy of the GNU General Public License along with  # this program; if not, write to the Free Software Foundation, Inc.,  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    from mercurial import util, error  from mercurial.util import propertycache    from tortoisehg.util import hglib  from tortoisehg.hgqt.graph import Graph  from tortoisehg.hgqt.graph import revision_grapher  from tortoisehg.hgqt import qtlib    from tortoisehg.hgqt.i18n import _    from PyQt4.QtCore import *  from PyQt4.QtGui import *    nullvariant = QVariant()    # TODO: Remove these two when we adopt GTK author color scheme  COLORS = [ "blue", "darkgreen", "red", "green", "darkblue", "purple",   "cyan", Qt.darkYellow, "magenta", "darkred", "darkmagenta",   "darkcyan", "gray", "yellow", ]  COLORS = [str(QColor(x).name()) for x in COLORS]    COLUMNHEADERS = (   ('Graph', _('Graph', 'column header')),   ('Rev', _('Rev', 'column header')),   ('Branch', _('Branch', 'column header')),   ('Description', _('Description', 'column header')),   ('Author', _('Author', 'column header')),   ('Tags', _('Tags', 'column header')),   ('Node', _('Node', 'column header')),   ('Age', _('Age', 'column header')),   ('LocalTime', _('Local Time', 'column header')),   ('UTCTime', _('UTC Time', 'column header')),   ('Changes', _('Changes', 'column header')),   )   -COLUMNNAMES = dict(COLUMNHEADERS) - -ALLCOLUMNS = [h[0] for h in COLUMNHEADERS] -  UNAPPLIED_PATCH_COLOR = '#999999'    def get_color(n, ignore=()):   """   Return a color at index 'n' rotating in the available   colors. 'ignore' is a list of colors not to be chosen.   """   ignore = [str(QColor(x).name()) for x in ignore]   colors = [x for x in COLORS if x not in ignore]   if not colors: # ghh, no more available colors...   colors = COLORS   return colors[n % len(colors)]    class HgRepoListModel(QAbstractTableModel):   """   Model used for displaying the revisions of a Hg *local* repository   """   showMessage = pyqtSignal(unicode)   filled = pyqtSignal()   loaded = pyqtSignal()   + _allcolumns = tuple(h[0] for h in COLUMNHEADERS) + _allcolnames = dict(COLUMNHEADERS) +   _columns = ('Graph', 'Rev', 'Branch', 'Description', 'Author', 'Age', 'Tags',)   _stretchs = {'Description': 1, }   _mqtags = ('qbase', 'qtip', 'qparent')   - def __init__(self, repo, branch, revset, rfilter, parent): + def __init__(self, repo, cfgname, branch, revset, rfilter, parent):   """   repo is a hg repo instance   """   QAbstractTableModel.__init__(self, parent)   self._cache = []   self.graph = None   self.timerHandle = None   self.dotradius = 8   self.rowheight = 20   self.rowcount = 0   self.repo = repo   self.revset = revset   self.filterbyrevset = rfilter   self.unicodestar = True   self.unicodexinabox = True + self.cfgname = cfgname     # To be deleted   self._user_colors = {}   self._branch_colors = {}     self._columnmap = {   'Rev': self.getrev,   'Node': lambda ctx, gnode: str(ctx),   'Graph': lambda ctx, gnode: "",   'Description': self.getlog,   'Author': self.getauthor,   'Tags': self.gettags,   'Branch': self.getbranch,   'Filename': lambda ctx, gnode: gnode.extra[0],   'Age': lambda ctx, gnode: hglib.age(ctx.date()).decode('utf-8'),   'LocalTime':lambda ctx, gnode: hglib.displaytime(ctx.date()),   'UTCTime': lambda ctx, gnode: hglib.utctime(ctx.date()),   'Changes': self.getchanges,   }     if repo:   self.reloadConfig()   self.updateColumns()   self.setBranch(branch)     def setBranch(self, branch=None, allparents=True):   self.filterbranch = branch   self.invalidateCache()   if self.revset and self.filterbyrevset:   grapher = revision_grapher(self.repo, branch=branch, revset=self.revset)   self.graph = Graph(self.repo, grapher, include_mq=False)   else:   grapher = revision_grapher(self.repo, branch=branch,   allparents=allparents)   self.graph = Graph(self.repo, grapher, include_mq=True)   self.rowcount = 0   self.layoutChanged.emit()   self.ensureBuilt(row=0)   self.showMessage.emit('')   QTimer.singleShot(0, lambda: self.filled.emit())     def reloadConfig(self):   _ui = self.repo.ui   self.fill_step = int(_ui.config('tortoisehg', 'graphlimit', 500))   self.authorcolor = _ui.configbool('tortoisehg', 'authorcolor')     def updateColumns(self):   s = QSettings() - cols = s.value('workbench/columns').toStringList() + cols = s.value(self.cfgname + '/columns').toStringList()   cols = [str(col) for col in cols]   # Fixup older names for columns   if 'Log' in cols:   cols[cols.index('Log')] = 'Description' - s.setValue('workbench/columns', cols) + s.setValue(self.cfgname + '/columns', cols)   if 'ID' in cols:   cols[cols.index('ID')] = 'Rev' - s.setValue('workbench/columns', cols) - validcols = [col for col in cols if col in ALLCOLUMNS] + s.setValue(self.cfgname + '/columns', cols) + validcols = [col for col in cols if col in self._allcolumns]   if validcols:   self._columns = tuple(validcols)   self.invalidateCache()   self.layoutChanged.emit()     def invalidate(self):   self.reloadConfig()   self.invalidateCache()   self.layoutChanged.emit()     def branch(self):   return self.filterbranch     def ensureBuilt(self, rev=None, row=None):   """   Make sure rev data is available (graph element created).     """   if self.graph.isfilled():   return   required = 0   buildrev = rev   n = len(self.graph)   if rev is not None:   if n and self.graph[-1].rev <= rev:   buildrev = None   else:   required = self.fill_step/2   elif row is not None and row > (n - self.fill_step / 2):   required = row - n + self.fill_step   if required or buildrev:   self.graph.build_nodes(nnodes=required, rev=buildrev)   self.updateRowCount()     if self.rowcount >= len(self.graph):   return # no need to update row count   if row and row > self.rowcount:   # asked row was already built, but views where not aware of this   self.updateRowCount()   elif rev is not None and rev <= self.graph[self.rowcount].rev:   # asked rev was already built, but views where not aware of this   self.updateRowCount()     def loadall(self):   self.timerHandle = self.startTimer(1)     def timerEvent(self, event):   if event.timerId() == self.timerHandle:   self.showMessage.emit(_('filling (%d)')%(len(self.graph)))   if self.graph.isfilled():   self.killTimer(self.timerHandle)   self.timerHandle = None   self.showMessage.emit('')   self.loaded.emit()   # we only fill the graph data structures without telling   # views until the model is loaded, to keep maximal GUI   # reactivity   elif not self.graph.build_nodes():   self.killTimer(self.timerHandle)   self.timerHandle = None   self.updateRowCount()   self.showMessage.emit('')   self.loaded.emit()     def updateRowCount(self):   currentlen = self.rowcount   newlen = len(self.graph)     if newlen > self.rowcount:   self.beginInsertRows(QModelIndex(), currentlen, newlen-1)   self.rowcount = newlen   self.endInsertRows()     def rowCount(self, parent):   if parent.isValid():   return 0   return self.rowcount     def columnCount(self, parent):   if parent.isValid():   return 0   return len(self._columns)     def maxWidthValueForColumn(self, col):   if self.graph is None:   return 'XXXX'   column = self._columns[col]   if column == 'Rev':   return '8' * len(str(len(self.repo))) + '+'   if column == 'Node':   return '8' * 12 + '+'   if column in ('LocalTime', 'UTCTime'):   return hglib.displaytime(util.makedate())   if column == 'Tags':   try:   return sorted(self.repo.tags().keys(), key=lambda x: len(x))[-1][:10]   except IndexError:   pass   if column == 'Branch':   try:   return sorted(self.repo.branchtags().keys(), key=lambda x: len(x))[-1]   except IndexError:   pass   if column == 'Filename':   return self.filename   if column == 'Graph':   res = self.col2x(self.graph.max_cols)   return min(res, 150)   if column == 'Changes':   return 'Changes'   # Fall through for Description   return None     def user_color(self, user):   'deprecated, please replace with hgtk color scheme'   if user not in self._user_colors:   self._user_colors[user] = get_color(len(self._user_colors),   self._user_colors.values())   return self._user_colors[user]     def namedbranch_color(self, branch):   'deprecated, please replace with hgtk color scheme'   if branch not in self._branch_colors:   self._branch_colors[branch] = get_color(len(self._branch_colors))   return self._branch_colors[branch]     def col2x(self, col):   return 2 * self.dotradius * col + self.dotradius/2 + 8     def graphctx(self, ctx, gnode):   w = self.col2x(gnode.cols) + 10   h = self.rowheight     dot_y = h / 2     pix = QPixmap(w, h)   pix.fill(QColor(0,0,0,0))   painter = QPainter(pix)   painter.setRenderHint(QPainter.Antialiasing)     pen = QPen(Qt.blue)   pen.setWidth(2)   painter.setPen(pen)     lpen = QPen(pen)   lpen.setColor(Qt.black)   painter.setPen(lpen)   for y1, y4, lines in ((dot_y, dot_y + h, gnode.bottomlines),   (dot_y - h, dot_y, gnode.toplines)):   y2 = y1 + 1 * (y4 - y1)/4   ymid = (y1 + y4)/2   y3 = y1 + 3 * (y4 - y1)/4     for start, end, color in lines:   lpen = QPen(pen)   lpen.setColor(QColor(get_color(color)))   lpen.setWidth(2)   painter.setPen(lpen)   x1 = self.col2x(start)   x2 = self.col2x(end)   path = QPainterPath()   path.moveTo(x1, y1)   path.cubicTo(x1, y2,   x1, y2,   (x1 + x2)/2, ymid)   path.cubicTo(x2, y3,   x2, y3,   x2, y4)   painter.drawPath(path)     # Draw node   dot_color = QColor(self.namedbranch_color(ctx.branch()))   dotcolor = dot_color.lighter()   pencolor = dot_color.darker()   white = QColor("white")   fillcolor = gnode.rev is None and white or dotcolor     pen = QPen(pencolor)   pen.setWidthF(1.5)   painter.setPen(pen)     radius = self.dotradius   centre_x = self.col2x(gnode.x)   centre_y = h/2     def circle(r):   rect = QRectF(centre_x - r,   centre_y - r,   2 * r, 2 * r)   painter.drawEllipse(rect)     def closesymbol(s):   rect_ = QRectF(centre_x - 1.5 * s, centre_y - 0.5 * s, 3 * s, s)   painter.drawRect(rect_)     def diamond(r):   poly = QPolygonF([QPointF(centre_x - r, centre_y),   QPointF(centre_x, centre_y - r),   QPointF(centre_x + r, centre_y),   QPointF(centre_x, centre_y + r),   QPointF(centre_x - r, centre_y),])   painter.drawPolygon(poly)     if ctx.thgmqappliedpatch(): # diamonds for patches   if ctx.thgwdparent():   painter.setBrush(white)   diamond(2 * 0.9 * radius / 1.5)   painter.setBrush(fillcolor)   diamond(radius / 1.5)   elif ctx.thgmqunappliedpatch():   patchcolor = QColor('#dddddd')   painter.setBrush(patchcolor)   painter.setPen(patchcolor)   diamond(radius / 1.5)   elif ctx.extra().get('close'):   painter.setBrush(fillcolor)   closesymbol(0.5 * radius)   else: # circles for normal revisions   if ctx.thgwdparent():   painter.setBrush(white)   circle(0.9 * radius)   painter.setBrush(fillcolor)   circle(0.5 * radius)     painter.end()   return QVariant(pix)     def invalidateCache(self):   self._cache = []   for a in ('_roleoffsets',):   if hasattr(self, a):   delattr(self, a)     @propertycache   def _roleoffsets(self):   return {Qt.DisplayRole : 0,   Qt.ForegroundRole : len(self._columns),   Qt.DecorationRole : len(self._columns) * 2}     def data(self, index, role):   if not index.isValid():   return nullvariant   if role not in self._roleoffsets:   return nullvariant   try:   return self.safedata(index, role)   except Exception, e:   if role == Qt.DisplayRole:   return QVariant(hglib.tounicode(str(e)))   else:   return nullvariant     def safedata(self, index, role):   row = index.row()   self.ensureBuilt(row=row)   graphlen = len(self.graph)   cachelen = len(self._cache)   if graphlen > cachelen:   self._cache.extend([None,] * (graphlen-cachelen))   data = self._cache[row]   if data is None:   data = [None,] * (self._roleoffsets[Qt.DecorationRole]+1)   column = self._columns[index.column()]   offset = self._roleoffsets[role]   if role == Qt.DecorationRole:   if column != 'Graph':   return nullvariant   if data[offset] is None:   gnode = self.graph[row]   ctx = self.repo.changectx(gnode.rev)   data[offset] = self.graphctx(ctx, gnode)   self._cache[row] = data   return data[offset]   else:   idx = index.column() + offset   if data[idx] is None:   try:   result = self.rawdata(row, column, role)   except util.Abort:   result = nullvariant   data[idx] = result   self._cache[row] = data   return data[idx]     def rawdata(self, row, column, role):   gnode = self.graph[row]   ctx = self.repo.changectx(gnode.rev)     if role == Qt.DisplayRole:   text = self._columnmap[column](ctx, gnode)   if not isinstance(text, (QString, unicode)):   text = hglib.tounicode(text)   return QVariant(text)   elif role == Qt.ForegroundRole:   if ctx.thgmqunappliedpatch():   return QColor(UNAPPLIED_PATCH_COLOR)   if column == 'Author':   if self.authorcolor:   return QVariant(QColor(self.user_color(ctx.user())))   return nullvariant   if column == 'Branch':   return QVariant(QColor(self.namedbranch_color(ctx.branch())))   return nullvariant     def flags(self, index):   if not index.isValid():   return Qt.ItemFlags(0)   if not self.revset:   return Qt.ItemIsSelectable | Qt.ItemIsEnabled     row = index.row()   self.ensureBuilt(row=row)   gnode = self.graph[row]   ctx = self.repo.changectx(gnode.rev)     if ctx.rev() not in self.revset:   return Qt.ItemFlags(0)   return Qt.ItemIsSelectable | Qt.ItemIsEnabled     def headerData(self, section, orientation, role):   if orientation == Qt.Horizontal:   if role == Qt.DisplayRole: - return QVariant(COLUMNNAMES[self._columns[section]]) + return QVariant(self._allcolnames[self._columns[section]])   if role == Qt.TextAlignmentRole:   return QVariant(Qt.AlignLeft)   return nullvariant     def rowFromRev(self, rev):   row = self.graph.index(rev)   if row == -1:   row = None   return row     def indexFromRev(self, rev):   if self.graph is None:   return None   self.ensureBuilt(rev=rev)   row = self.rowFromRev(rev)   if row is not None:   return self.index(row, 0)   return None     def clear(self):   'empty the list'   self.graph = None   self.datacache = {}   self.layoutChanged.emit()     def getbranch(self, ctx, gnode):   b = hglib.tounicode(ctx.branch())   if ctx.extra().get('close'):   if self.unicodexinabox:   b += u' \u2327'   else:   b += u'--'   return b     def gettags(self, ctx, gnode):   if ctx.rev() is None:   return ''   tags = [t for t in ctx.tags() if t not in self._mqtags]   return hglib.tounicode(','.join(tags))     def getrev(self, ctx, gnode):   rev = ctx.rev()   if type(rev) is int:   return str(rev)   elif rev is None:   return u'%d+' % ctx.p1().rev()   else:   return ''     def getauthor(self, ctx, gnode):   try:   return hglib.username(ctx.user())   except error.Abort:   return _('Mercurial User')     def getlog(self, ctx, gnode):   if ctx.rev() is None:   msg = None   if self.unicodestar:   # The Unicode symbol is a black star:   msg = u'\u2605 ' + _('Working Directory') + u' \u2605'   else:   msg = '*** ' + _('Working Directory') + ' ***'     for pctx in ctx.parents():   if pctx.node() not in self.repo._branchheads:   text = _('Not a head revision!')   msg += " " + qtlib.markup(text, fg='red', weight='bold')     return msg     msg = ctx.longsummary()     if ctx.thgmqunappliedpatch():   effects = qtlib.geteffect('log.unapplied_patch')   text = qtlib.applyeffects(' %s ' % ctx._patchname, effects)   # qtlib.markup(msg, fg=UNAPPLIED_PATCH_COLOR)   msg = qtlib.markup(msg)   return hglib.tounicode(text + ' ') + msg     parts = []   if ctx.thgbranchhead():   branchu = hglib.tounicode(ctx.branch())   effects = qtlib.geteffect('log.branch')   parts.append(qtlib.applyeffects(u' %s ' % branchu, effects))     for mark in ctx.bookmarks():   style = 'log.bookmark'   if mark == self.repo._bookmarkcurrent:   bn = self.repo._bookmarks[self.repo._bookmarkcurrent]   if bn in self.repo.dirstate.parents():   style = 'log.curbookmark'   marku = hglib.tounicode(mark)   effects = qtlib.geteffect(style)   parts.append(qtlib.applyeffects(u' %s ' % marku, effects))     for tag in ctx.thgtags():   if self.repo.thgmqtag(tag):   style = 'log.patch'   else:   style = 'log.tag'   tagu = hglib.tounicode(tag)   effects = qtlib.geteffect(style)   parts.append(qtlib.applyeffects(u' %s ' % tagu, effects))     if msg:   if ctx.thgwdparent():   msg = qtlib.markup(msg, weight='bold')   else:   msg = qtlib.markup(msg)   parts.append(hglib.tounicode(msg))     return ' '.join(parts)     def getchanges(self, ctx, gnode):   """Return the MAR status for the given ctx."""   changes = []   M, A, R = ctx.changesToParent(0)   def addtotal(files, style):   effects = qtlib.geteffect(style)   text = qtlib.applyeffects(' %s ' % len(files), effects)   changes.append(text)   if M:   addtotal(M, 'log.modified')   if A:   addtotal(A, 'log.added')   if R:   addtotal(R, 'log.removed')   return ''.join(changes)
 
19
20
21
 
22
23
24
25
 
 
 
 
 
26
27
28
 
32
33
34
35
 
36
37
38
39
40
 
41
42
43
44
45
46
47
 
 
 
 
 
 
48
49
50
 
70
71
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
74
75
 
129
130
131
 
 
 
 
 
 
132
133
134
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
38
39
40
 
41
42
43
44
45
46
47
48
49
50
51
52
53
 
54
55
56
57
58
59
60
61
62
 
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 
158
159
160
161
162
163
164
165
166
167
168
169
@@ -19,10 +19,16 @@
 from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import htmldelegate +from tortoisehg.hgqt.logcolumns import ColumnSelectDialog    from PyQt4.QtCore import *  from PyQt4.QtGui import *   +class HgRepoViewHeader(QHeaderView): + menuRequested = pyqtSignal(QPoint) + def contextMenuEvent(self, event): + self.menuRequested.emit(event.globalPos()) +  class HgRepoView(QTableView):     revisionClicked = pyqtSignal(object) @@ -32,19 +38,25 @@
  menuRequested = pyqtSignal(QPoint, object)   showMessage = pyqtSignal(unicode)   - def __init__(self, repo, cfgname, parent=None): + def __init__(self, repo, cfgname, colselect, parent=None):   QTableView.__init__(self, parent)   self.repo = repo   self.current_rev = -1   self.resized = False   self.cfgname = cfgname + self.colselect = colselect   self.setShowGrid(False)     vh = self.verticalHeader()   vh.hide()   vh.setDefaultSectionSize(20)   - self.horizontalHeader().setHighlightSections(False) + header = HgRepoViewHeader(Qt.Horizontal, self) + header.setHighlightSections(False) + header.menuRequested.connect(self.headerMenuRequest) + self.setHorizontalHeader(header) + + self.createActions()     self.standardDelegate = self.itemDelegate()   self.htmlDelegate = htmldelegate.HTMLDelegate(self) @@ -70,6 +82,23 @@
  def contextMenuEvent(self, event):   self.menuRequested.emit(event.globalPos(), self.selectedRevisions())   + def createActions(self): + menu = QMenu(self) + act = QAction(_('Choose log columns...'), self) + act.triggered.connect(self.setHistoryColumns) + menu.addAction(act) + self.headermenu = menu + + def headerMenuRequest(self, point): + self.headermenu.exec_(point) + + def setHistoryColumns(self): + dlg = ColumnSelectDialog(self.colselect[0], self.colselect[1], + self.model()) + if dlg.exec_() == QDialog.Accepted: + self.model().updateColumns() + self.resizeColumns() +   def setModel(self, model):   QTableView.setModel(self, model)   #Check if the font contains the glyph needed by the model @@ -129,6 +158,12 @@
  key = '%s/column_widths/%s' % (self.cfgname, str(self.repo[0]))   col_widths = [int(w) for w in QSettings().value(key).toStringList()]   + if len(model._columns) <> len(col_widths): + # If the columns and widths don't match, use the calculated + # widths as they will probably be a better fit (likely because + # columns were changed without updating the widths) + col_widths = [] +   for c in range(model.columnCount(QModelIndex())):   if c < len(col_widths) and col_widths[c] > 0:   w = col_widths[c]
 
132
133
134
135
 
 
136
137
138
 
606
607
608
609
 
 
610
611
612
 
779
780
781
782
 
 
 
783
784
785
 
132
133
134
 
135
136
137
138
139
 
607
608
609
 
610
611
612
613
614
 
781
782
783
 
784
785
786
787
788
789
@@ -132,7 +132,8 @@
    self.layout().addWidget(self.repotabs_splitter)   - self.repoview = view = HgRepoView(self.repo, 'repoWidget', self) + cs = ('workbench', _('Workbench Log Columns')) + self.repoview = view = HgRepoView(self.repo, 'repoWidget', cs, self)   view.revisionClicked.connect(self.onRevisionClicked)   view.revisionSelected.connect(self.onRevisionSelected)   view.revisionAltClicked.connect(self.onRevisionSelected) @@ -606,7 +607,8 @@
  # Filter revision set in case revisions were removed   self.revset = [r for r in self.revset if r < len(self.repo)]   branch = hglib.fromunicode(self.ubranch) - self.repomodel = HgRepoListModel(self.repo, branch, self.revset, + self.repomodel = HgRepoListModel(self.repo, self.repoview.colselect[0], + branch, self.revset,   self.revsetfilter, self)   self.repomodel.filled.connect(self.modelFilled)   self.repomodel.loaded.connect(self.modelLoaded) @@ -779,7 +781,9 @@
  self.rebuildGraph()   except (error.RevlogError, error.RepoError), e:   self.showMessage(hglib.tounicode(str(e))) - self.repomodel = HgRepoListModel(None, None, None, False, self) + self.repomodel = HgRepoListModel(None, + self.repoview.colselect[0], + None, None, False, self)   self.repoview.setModel(self.repomodel)   else:   self.dirty = True
 
14
15
16
17
 
18
19
20
 
639
640
641
642
643
 
 
644
645
646
 
14
15
16
 
17
18
19
20
 
639
640
641
 
 
642
643
644
645
646
@@ -14,7 +14,7 @@
 from mercurial.error import RepoError  from tortoisehg.util import paths, hglib   -from tortoisehg.hgqt import repomodel, thgrepo, cmdui, qtlib +from tortoisehg.hgqt import thgrepo, cmdui, qtlib  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt.repowidget import RepoWidget  from tortoisehg.hgqt.reporegistry import RepoRegistryView @@ -639,8 +639,8 @@
  def setHistoryColumns(self, *args):   """Display the column selection dialog"""   w = self.repoTabsWidget.currentWidget() - dlg = ColumnSelectDialog(repomodel.ALLCOLUMNS, - w and w.repoview.model()._columns) + dlg = ColumnSelectDialog('workbench', _('Workbench'), + w and w.repoview.model() or None)   if dlg.exec_() == QDialog.Accepted:   if w:   w.repoview.model().updateColumns()