Mercurial > hg > easyhg
comparison hgtabwidget.cpp @ 116:807c79350bf1
* Pull history tab out into its own widget
author | Chris Cannam |
---|---|
date | Fri, 26 Nov 2010 22:06:52 +0000 |
parents | 78374cefa10f |
children | d5db15bf250c |
comparison
equal
deleted
inserted
replaced
115:78374cefa10f | 116:807c79350bf1 |
---|---|
15 COPYING included with this distribution for more information. | 15 COPYING included with this distribution for more information. |
16 */ | 16 */ |
17 | 17 |
18 #include "hgtabwidget.h" | 18 #include "hgtabwidget.h" |
19 #include "common.h" | 19 #include "common.h" |
20 #include "logparser.h" | |
21 #include "changeset.h" | |
22 #include "changesetitem.h" | |
23 #include "grapher.h" | |
24 #include "panner.h" | |
25 #include "panned.h" | |
26 #include "filestatuswidget.h" | 20 #include "filestatuswidget.h" |
21 #include "historywidget.h" | |
27 | 22 |
28 #include <QClipboard> | 23 #include <QClipboard> |
29 #include <QContextMenuEvent> | 24 #include <QContextMenuEvent> |
30 #include <QApplication> | 25 #include <QApplication> |
31 | 26 |
35 QString remoteRepo, | 30 QString remoteRepo, |
36 QString workFolderPath) : | 31 QString workFolderPath) : |
37 QTabWidget(parent) | 32 QTabWidget(parent) |
38 { | 33 { |
39 // Work page | 34 // Work page |
40 fileStatusWidget = new FileStatusWidget; | 35 m_fileStatusWidget = new FileStatusWidget; |
41 fileStatusWidget->setLocalPath(workFolderPath); | 36 m_fileStatusWidget->setLocalPath(workFolderPath); |
42 fileStatusWidget->setRemoteURL(remoteRepo); | 37 m_fileStatusWidget->setRemoteURL(remoteRepo); |
43 connect(fileStatusWidget, SIGNAL(selectionChanged()), | 38 connect(m_fileStatusWidget, SIGNAL(selectionChanged()), |
44 this, SIGNAL(selectionChanged())); | 39 this, SIGNAL(selectionChanged())); |
45 addTab(fileStatusWidget, tr("My work")); | 40 addTab(m_fileStatusWidget, tr("My work")); |
46 | 41 |
47 // History graph page | 42 // History graph page |
48 historyGraphPageWidget = new QWidget; | 43 m_historyWidget = new HistoryWidget; |
49 Panned *panned = new Panned; | 44 addTab(m_historyWidget, tr("History")); |
50 Panner *panner = new Panner; | |
51 historyGraphWidget = panned; | |
52 historyGraphPanner = panner; | |
53 QGridLayout *layout = new QGridLayout; | |
54 layout->addWidget(historyGraphWidget, 0, 0); | |
55 layout->addWidget(historyGraphPanner, 0, 1); | |
56 panner->setMaximumWidth(80); | |
57 panner->connectToPanned(panned); | |
58 historyGraphPageWidget->setLayout(layout); | |
59 addTab(historyGraphPageWidget, tr("History")); | |
60 } | 45 } |
61 | 46 |
62 void HgTabWidget::clearSelections() | 47 void HgTabWidget::clearSelections() |
63 { | 48 { |
64 fileStatusWidget->clearSelections(); | 49 m_fileStatusWidget->clearSelections(); |
65 } | 50 } |
66 | 51 |
67 bool HgTabWidget::canCommit() const | 52 bool HgTabWidget::canCommit() const |
68 { | 53 { |
69 if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false; | 54 if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false; |
70 return fileStatusWidget->haveChangesToCommit(); | 55 return m_fileStatusWidget->haveChangesToCommit(); |
71 } | 56 } |
72 | 57 |
73 bool HgTabWidget::canRevert() const | 58 bool HgTabWidget::canRevert() const |
74 { | 59 { |
75 return fileStatusWidget->haveChangesToCommit() || | 60 return m_fileStatusWidget->haveChangesToCommit() || |
76 !fileStatusWidget->getSelectedRevertableFiles().empty(); | 61 !m_fileStatusWidget->getSelectedRevertableFiles().empty(); |
77 } | 62 } |
78 | 63 |
79 bool HgTabWidget::canAdd() const | 64 bool HgTabWidget::canAdd() const |
80 { | 65 { |
81 if (fileStatusWidget->getSelectedAddableFiles().empty()) return false; | 66 if (m_fileStatusWidget->getSelectedAddableFiles().empty()) return false; |
82 if (!fileStatusWidget->getSelectedCommittableFiles().empty()) return false; | 67 if (!m_fileStatusWidget->getSelectedCommittableFiles().empty()) return false; |
83 if (!fileStatusWidget->getSelectedRemovableFiles().empty()) return false; | 68 if (!m_fileStatusWidget->getSelectedRemovableFiles().empty()) return false; |
84 return true; | 69 return true; |
85 } | 70 } |
86 | 71 |
87 bool HgTabWidget::canRemove() const | 72 bool HgTabWidget::canRemove() const |
88 { | 73 { |
89 if (fileStatusWidget->getSelectedRemovableFiles().empty()) return false; | 74 if (m_fileStatusWidget->getSelectedRemovableFiles().empty()) return false; |
90 if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false; | 75 if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false; |
91 return true; | 76 return true; |
92 } | 77 } |
93 | 78 |
94 bool HgTabWidget::canDoDiff() const | 79 bool HgTabWidget::canDoDiff() const |
95 { | 80 { |
96 return canCommit(); | 81 return canCommit(); |
97 } | 82 } |
98 | 83 |
99 QStringList HgTabWidget::getAllSelectedFiles() const | 84 QStringList HgTabWidget::getAllSelectedFiles() const |
100 { | 85 { |
101 return fileStatusWidget->getAllSelectedFiles(); | 86 return m_fileStatusWidget->getAllSelectedFiles(); |
102 } | 87 } |
103 | 88 |
104 QStringList HgTabWidget::getAllCommittableFiles() const | 89 QStringList HgTabWidget::getAllCommittableFiles() const |
105 { | 90 { |
106 return fileStatusWidget->getAllCommittableFiles(); | 91 return m_fileStatusWidget->getAllCommittableFiles(); |
107 } | 92 } |
108 | 93 |
109 QStringList HgTabWidget::getSelectedCommittableFiles() const | 94 QStringList HgTabWidget::getSelectedCommittableFiles() const |
110 { | 95 { |
111 return fileStatusWidget->getSelectedCommittableFiles(); | 96 return m_fileStatusWidget->getSelectedCommittableFiles(); |
112 } | 97 } |
113 | 98 |
114 QStringList HgTabWidget::getAllRevertableFiles() const | 99 QStringList HgTabWidget::getAllRevertableFiles() const |
115 { | 100 { |
116 return fileStatusWidget->getAllRevertableFiles(); | 101 return m_fileStatusWidget->getAllRevertableFiles(); |
117 } | 102 } |
118 | 103 |
119 QStringList HgTabWidget::getSelectedRevertableFiles() const | 104 QStringList HgTabWidget::getSelectedRevertableFiles() const |
120 { | 105 { |
121 return fileStatusWidget->getSelectedRevertableFiles(); | 106 return m_fileStatusWidget->getSelectedRevertableFiles(); |
122 } | 107 } |
123 | 108 |
124 QStringList HgTabWidget::getSelectedAddableFiles() const | 109 QStringList HgTabWidget::getSelectedAddableFiles() const |
125 { | 110 { |
126 return fileStatusWidget->getSelectedAddableFiles(); | 111 return m_fileStatusWidget->getSelectedAddableFiles(); |
127 } | 112 } |
128 | 113 |
129 QStringList HgTabWidget::getAllRemovableFiles() const | 114 QStringList HgTabWidget::getAllRemovableFiles() const |
130 { | 115 { |
131 return fileStatusWidget->getAllRemovableFiles(); | 116 return m_fileStatusWidget->getAllRemovableFiles(); |
132 } | 117 } |
133 | 118 |
134 QStringList HgTabWidget::getSelectedRemovableFiles() const | 119 QStringList HgTabWidget::getSelectedRemovableFiles() const |
135 { | 120 { |
136 return fileStatusWidget->getSelectedRemovableFiles(); | 121 return m_fileStatusWidget->getSelectedRemovableFiles(); |
137 } | 122 } |
138 | 123 |
139 void HgTabWidget::updateWorkFolderFileList(QString fileList) | 124 void HgTabWidget::updateWorkFolderFileList(QString fileList) |
140 { | 125 { |
141 fileStates.parseStates(fileList); | 126 m_fileStates.parseStates(fileList); |
142 fileStatusWidget->setFileStates(fileStates); | 127 m_fileStatusWidget->setFileStates(m_fileStates); |
143 } | 128 } |
144 | 129 |
145 void HgTabWidget::updateLocalRepoHgLogList(QString hgLogList) | 130 void HgTabWidget::updateLocalRepoHgLogList(QString hgLogList) |
146 { | 131 { |
147 //!!! | 132 m_historyWidget->parseLog(hgLogList); |
148 Panned *panned = static_cast<Panned *>(historyGraphWidget); | |
149 Panner *panner = static_cast<Panner *>(historyGraphPanner); | |
150 QGraphicsScene *scene = new QGraphicsScene(); | |
151 Changesets csets = parseChangeSets(hgLogList); | |
152 if (csets.empty()) return; | |
153 Grapher g(scene); | |
154 try { | |
155 g.layout(csets); | |
156 } catch (std::string s) { | |
157 std::cerr << "Internal error: Layout failed: " << s << std::endl; | |
158 } | |
159 QGraphicsScene *oldScene = panned->scene(); | |
160 panned->setScene(scene); | |
161 panner->setScene(scene); | |
162 if (oldScene) delete oldScene; | |
163 ChangesetItem *tipItem = g.getItemFor(csets[0]); | |
164 if (tipItem) tipItem->ensureVisible(); | |
165 //!!! track lifecycle of those Changesets | |
166 } | |
167 | |
168 Changesets HgTabWidget::parseChangeSets(QString changeSetsStr) | |
169 { | |
170 Changesets csets = Changeset::parseChangesets(changeSetsStr); | |
171 for (int i = 0; i+1 < csets.size(); ++i) { | |
172 Changeset *cs = csets[i]; | |
173 if (cs->parents().empty()) { | |
174 QStringList list; | |
175 list.push_back(csets[i+1]->id()); | |
176 cs->setParents(list); | |
177 } | |
178 } | |
179 return csets; | |
180 } | 133 } |
181 | 134 |
182 void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath) | 135 void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath) |
183 { | 136 { |
184 fileStatusWidget->setLocalPath(workFolderPath); | 137 m_fileStatusWidget->setLocalPath(workFolderPath); |
185 fileStatusWidget->setRemoteURL(remoteRepoPath); | 138 m_fileStatusWidget->setRemoteURL(remoteRepoPath); |
186 } | 139 } |
187 | 140 |
188 void HgTabWidget::setState(QString state) | 141 void HgTabWidget::setState(QString state) |
189 { | 142 { |
190 fileStatusWidget->setState(state); | 143 m_fileStatusWidget->setState(state); |
191 } | 144 } |