PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/tortoisehg/hgqt/filerevmodel.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 69 lines | 42 code | 5 blank | 22 comment | 0 complexity | 19f14456ad87da89d1c849fc3dbe07c5 MD5 | raw file
 1# Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE).
 2# http://www.logilab.fr/ -- mailto:contact@logilab.fr
 3#
 4# This program is free software; you can redistribute it and/or modify it under
 5# the terms of the GNU General Public License as published by the Free Software
 6# Foundation; either version 2 of the License, or (at your option) any later
 7# version.
 8#
 9# This program is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# this program; if not, write to the Free Software Foundation, Inc.,
15# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
17from tortoisehg.hgqt.repomodel import HgRepoListModel
18from tortoisehg.hgqt.graph import Graph, filelog_grapher
19
20from PyQt4.QtCore import *
21
22class FileRevModel(HgRepoListModel):
23    """
24    Model used to manage the list of revisions of a file, in file
25    viewer of in diff-file viewer dialogs.
26    """
27    filled = pyqtSignal()
28
29    _allcolumns = ('Rev', 'Branch', 'Description', 'Author', 'Age',
30                   'LocalTime', 'UTCTime', 'Tags', 'Filename')
31    _columns = ('Rev', 'Branch', 'Description', 'Author', 'Age', 'Filename')
32    _stretchs = {'Description': 1, }
33    _getcolumns = "getFilelogColumns"
34
35    def __init__(self, repo, filename=None, parent=None):
36        """
37        data is a HgHLRepo instance
38        """
39        HgRepoListModel.__init__(self, repo, '', [], False, parent)
40        self.setFilename(filename)
41
42    def setRepo(self, repo, branch='', fromhead=None, follow=False):
43        self.repo = repo
44        self._datacache = {}
45        self.reloadConfig()
46
47    def setFilename(self, filename):
48        self.filename = filename
49
50        self._user_colors = {}
51        self._branch_colors = {}
52
53        self.rowcount = 0
54        self._datacache = {}
55
56        if self.filename:
57            grapher = filelog_grapher(self.repo, self.filename)
58            self.graph = Graph(self.repo, grapher)
59            fl = self.repo.file(self.filename)
60            # we use fl.index here (instead of linkrev) cause
61            # linkrev API changed between 1.0 and 1.?. So this
62            # works with both versions.
63            self.heads = [fl.index[fl.rev(x)][4] for x in fl.heads()]
64            self.ensureBuilt(row=self.fill_step/2)
65            QTimer.singleShot(0, lambda: self.filled.emit())
66            self._fill_timer = self.startTimer(500)
67        else:
68            self.graph = None
69            self.heads = []