comparison hgtabwidget.cpp @ 96:87ef2fa9ee8b

* Rename HgExpWidget to HgTabWidget
author Chris Cannam
date Wed, 24 Nov 2010 16:40:57 +0000
parents hgexpwidget.cpp@d1be9712818a
children 0bd32aedc6f6
comparison
equal deleted inserted replaced
95:d1be9712818a 96:87ef2fa9ee8b
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on HgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2010 Chris Cannam
9 Copyright (c) 2010 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "hgtabwidget.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"
27
28 #include <QClipboard>
29 #include <QContextMenuEvent>
30 #include <QApplication>
31
32 #include <iostream>
33
34 HgTabWidget::HgTabWidget(QWidget *parent,
35 QString remoteRepo,
36 QString workFolderPath) :
37 QTabWidget(parent)
38 {
39 // Work page
40 fileStatusWidget = new FileStatusWidget;
41 fileStatusWidget->setLocalPath(workFolderPath);
42 fileStatusWidget->setRemoteURL(remoteRepo);
43 connect(fileStatusWidget, SIGNAL(selectionChanged()),
44 this, SIGNAL(selectionChanged()));
45 addTab(fileStatusWidget, tr("My work"));
46
47 // History graph page
48 historyGraphPageWidget = new QWidget;
49 Panned *panned = new Panned;
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 }
61
62 void HgTabWidget::clearSelections()
63 {
64 fileStatusWidget->clearSelections();
65 }
66
67 bool HgTabWidget::canCommit() const
68 {
69 return fileStatusWidget->haveChangesToCommit();
70 }
71
72 bool HgTabWidget::canAdd() const
73 {
74 if (fileStatusWidget->getSelectedAddableFiles().empty()) return false;
75 if (!fileStatusWidget->getSelectedCommittableFiles().empty()) return false;
76 if (!fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
77 return true;
78 }
79
80 bool HgTabWidget::canRemove() const
81 {
82 if (fileStatusWidget->getSelectedRemovableFiles().empty()) return false;
83 if (!fileStatusWidget->getSelectedAddableFiles().empty()) return false;
84 return true;
85 }
86
87 bool HgTabWidget::canDoDiff() const
88 {
89 return canCommit();
90 }
91
92 QStringList HgTabWidget::getAllSelectedFiles() const
93 {
94 return fileStatusWidget->getAllSelectedFiles();
95 }
96
97 QStringList HgTabWidget::getSelectedCommittableFiles() const
98 {
99 return fileStatusWidget->getSelectedCommittableFiles();
100 }
101
102 QStringList HgTabWidget::getSelectedAddableFiles() const
103 {
104 return fileStatusWidget->getSelectedAddableFiles();
105 }
106
107 QStringList HgTabWidget::getSelectedRemovableFiles() const
108 {
109 return fileStatusWidget->getSelectedRemovableFiles();
110 }
111
112 void HgTabWidget::updateWorkFolderFileList(QString fileList)
113 {
114 fileStates.parseStates(fileList);
115 fileStatusWidget->setFileStates(fileStates);
116 }
117
118 void HgTabWidget::updateLocalRepoHgLogList(QString hgLogList)
119 {
120 //!!!
121 Panned *panned = static_cast<Panned *>(historyGraphWidget);
122 Panner *panner = static_cast<Panner *>(historyGraphPanner);
123 QGraphicsScene *scene = new QGraphicsScene();
124 Changesets csets = parseChangeSets(hgLogList);
125 if (csets.empty()) return;
126 Grapher g(scene);
127 try {
128 g.layout(csets);
129 } catch (std::string s) {
130 std::cerr << "Internal error: Layout failed: " << s << std::endl;
131 }
132 QGraphicsScene *oldScene = panned->scene();
133 panned->setScene(scene);
134 panner->setScene(scene);
135 if (oldScene) delete oldScene;
136 ChangesetItem *tipItem = g.getItemFor(csets[0]);
137 if (tipItem) tipItem->ensureVisible();
138 }
139
140 Changesets HgTabWidget::parseChangeSets(QString changeSetsStr)
141 {
142 Changesets csets;
143 LogList log = LogParser(changeSetsStr).parse();
144 foreach (LogEntry e, log) {
145 Changeset *cs = new Changeset();
146 foreach (QString key, e.keys()) {
147 if (key == "parents") {
148 QStringList parents = e.value(key).split
149 (" ", QString::SkipEmptyParts);
150 cs->setParents(parents);
151 } else if (key == "timestamp") {
152 cs->setTimestamp(e.value(key).split(" ")[0].toULongLong());
153 } else {
154 cs->setProperty(key.toLocal8Bit().data(), e.value(key));
155 }
156 }
157 csets.push_back(cs);
158 }
159 for (int i = 0; i+1 < csets.size(); ++i) {
160 Changeset *cs = csets[i];
161 if (cs->parents().empty()) {
162 QStringList list;
163 list.push_back(csets[i+1]->id());
164 cs->setParents(list);
165 }
166 }
167 return csets;
168 }
169
170 void HgTabWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath)
171 {
172 fileStatusWidget->setLocalPath(workFolderPath);
173 fileStatusWidget->setRemoteURL(remoteRepoPath);
174 }