Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.1, 2.0.2, and 2.0.3

stable repowidget, repoview: implemented storing of col widths and reimplemented col elasticity

- The column widths of the repoview are saved to settings on exit and graph rebuild
- The description column is now resized when the workbench is resized
- A redundant function was removed

Changeset 9d149b6dd5fa

Parent 38a9ea4aa38c

by Michael De Wildt

Changes to 2 files · Browse files at 9d149b6dd5fa Showing diff from parent 38a9ea4aa38c Diff from another changeset...

 
36
37
38
 
39
40
41
 
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
 
138
139
140
141
142
143
144
145
146
 
147
148
149
 
237
238
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
40
41
42
 
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
 
138
139
140
 
 
 
 
 
 
141
142
143
144
 
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
@@ -36,6 +36,7 @@
  QTableView.__init__(self, parent)   self.repo = repo   self.current_rev = -1 + self.resized = False   self.setShowGrid(False)     vh = self.verticalHeader() @@ -101,35 +102,34 @@
  self.setItemDelegateForColumn(c, self.standardDelegate)     def resizeColumns(self, *args): - # resize columns the smart way: the column holding Description - # is resized according to the total widget size.   if not self.model():   return   hh = self.horizontalHeader()   hh.setStretchLastSection(False)   self._resizeColumns()   hh.setStretchLastSection(True) + self.resized = True     def _resizeColumns(self):   # _resizeColumns misbehaves if called with last section streched   for c, w in enumerate(self._columnWidthHints()):   self.setColumnWidth(c, w)   - def sizeHintForColumn(self, column): - return self._columnWidthHints()[column] -   def _columnWidthHints(self):   """Return list of recommended widths of all columns"""   model = self.model() - col1_width = self.viewport().width()   fontm = QFontMetrics(self.font()) - tot_stretch = 0.0   widths = [-1 for _i in xrange(model.columnCount(QModelIndex()))] + + key = 'repoview/column_widths/%s' % str(self.repo[0]) + col_widths = [int(w) for w in QSettings().value(key).toStringList()] +   for c in range(model.columnCount(QModelIndex())): - if model._columns[c] in model._stretchs: - tot_stretch += model._stretchs[model._columns[c]] - continue - w = model.maxWidthValueForColumn(c) + if c < len(col_widths) and col_widths[c] > 0: + w = col_widths[c] + else: + w = model.maxWidthValueForColumn(c) +   if isinstance(w, int):   widths[c] = w   elif w is not None: @@ -138,12 +138,7 @@
  else:   w = super(HgRepoView, self).sizeHintForColumn(c)   widths[c] = w - col1_width -= widths[c] - col1_width = max(col1_width, 100) - for c in range(model.columnCount(QModelIndex())): - if model._columns[c] in model._stretchs: - w = model._stretchs[model._columns[c]] / tot_stretch - widths[c] = col1_width * w +   return widths     def revFromindex(self, index): @@ -237,3 +232,39 @@
  idx = self.model().indexFromRev(rev)   if idx is not None:   self.setCurrentIndex(idx) + + def saveSettings(self, s = None): + if not s: + s = QSettings() + + col_widths = [] + for c in range(self.model().columnCount(QModelIndex())): + col_widths.append(self.columnWidth(c)) + + key = 'repoview/column_widths/%s' % str(self.repo[0]) + s.setValue(key, col_widths) + s.setValue('repoview/widget_width', self.viewport().width()) + + def resizeEvent(self, e): + # re-size columns the smart way: the column holding Description + # is re-sized according to the total widget size. + widget_width = QSettings().value('repoview/widget_width').toInt()[0] + if self.resized and widget_width: + model = self.model() + vp_width = self.viewport().width() + total_width = stretch_col = 0 + + if vp_width != widget_width: + for c in range(model.columnCount(QModelIndex())): + if model._columns[c] in model._stretchs: + #save the description column + stretch_col = c + else: + #total the other widths + total_width += self.columnWidth(c) + + width = max(vp_width - total_width, 100) + self.setColumnWidth(stretch_col, width) + + super(HgRepoView, self).resizeEvent(e) +
 
673
674
675
 
676
677
678
 
795
796
797
 
798
799
800
 
673
674
675
676
677
678
679
 
796
797
798
799
800
801
802
@@ -673,6 +673,7 @@
    self.setupModels()   self.filterbar.refresh() + self.repoview.saveSettings()     def reloadTaskTab(self):   tti = self.taskTabsWidget.currentIndex() @@ -795,6 +796,7 @@
  self.manifestDemand.forward('saveSettings', s, 'workbench')   self.grepDemand.forward('saveSettings', s)   self.filterbar.saveSettings(s) + self.repoview.saveSettings(s)   return True     def incoming(self):