Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@57
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@560
|
8 Copyright (c) 2012 Chris Cannam
|
Chris@560
|
9 Copyright (c) 2012 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
Chris@57
|
17
|
Chris@43
|
18 #ifndef CHANGESET_H
|
Chris@43
|
19 #define CHANGESET_H
|
Chris@43
|
20
|
Chris@43
|
21 #include <QObject>
|
Chris@43
|
22 #include <QString>
|
Chris@43
|
23 #include <QStringList>
|
Chris@43
|
24 #include <QList>
|
Chris@106
|
25 #include <QSharedPointer>
|
Chris@106
|
26
|
Chris@106
|
27 #include "logparser.h"
|
Chris@43
|
28
|
Chris@108
|
29 class Changeset;
|
Chris@108
|
30
|
Chris@150
|
31 typedef QList<Changeset *> Changesets;
|
Chris@108
|
32
|
Chris@43
|
33 class Changeset : public QObject
|
Chris@43
|
34 {
|
Chris@43
|
35 Q_OBJECT
|
Chris@43
|
36
|
Chris@43
|
37 Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged STORED true);
|
Chris@128
|
38 Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged STORED true);
|
Chris@43
|
39 Q_PROPERTY(QString branch READ branch WRITE setBranch NOTIFY branchChanged STORED true);
|
Chris@128
|
40 Q_PROPERTY(QStringList tags READ tags WRITE setTags NOTIFY tagsChanged STORED true);
|
Chris@520
|
41 Q_PROPERTY(QStringList bookmarks READ bookmarks WRITE setBookmarks NOTIFY bookmarksChanged STORED true);
|
Chris@52
|
42 Q_PROPERTY(QString datetime READ datetime WRITE setDatetime NOTIFY datetimeChanged STORED true);
|
Chris@52
|
43 Q_PROPERTY(qulonglong timestamp READ timestamp WRITE setTimestamp NOTIFY timestampChanged STORED true);
|
Chris@43
|
44 Q_PROPERTY(QString age READ age WRITE setAge NOTIFY ageChanged STORED true);
|
Chris@43
|
45 Q_PROPERTY(QStringList parents READ parents WRITE setParents NOTIFY parentsChanged STORED true);
|
Chris@47
|
46 Q_PROPERTY(QStringList children READ children WRITE setChildren NOTIFY childrenChanged STORED true);
|
Chris@43
|
47 Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY commentChanged STORED true);
|
Chris@43
|
48
|
Chris@43
|
49 public:
|
Chris@43
|
50 Changeset() : QObject() { }
|
Chris@106
|
51 explicit Changeset(const LogEntry &e);
|
Chris@43
|
52
|
Chris@43
|
53 QString id() const { return m_id; }
|
Chris@128
|
54 QString author() const { return m_author; }
|
Chris@43
|
55 QString branch() const { return m_branch; }
|
Chris@128
|
56 QStringList tags() const { return m_tags; }
|
Chris@520
|
57 QStringList bookmarks() const { return m_bookmarks; }
|
Chris@51
|
58 QString datetime() const { return m_datetime; }
|
Chris@52
|
59 qulonglong timestamp() const { return m_timestamp; }
|
Chris@43
|
60 QString age() const { return m_age; }
|
Chris@43
|
61 QStringList parents() const { return m_parents; }
|
Chris@123
|
62 QString comment() const { return m_comment; }
|
Chris@123
|
63
|
Chris@123
|
64 /**
|
Chris@123
|
65 * The children property is not obtained from Hg, but set in
|
Chris@123
|
66 * Grapher::layout() based on reported parents
|
Chris@123
|
67 */
|
Chris@47
|
68 QStringList children() const { return m_children; }
|
Chris@43
|
69
|
Chris@510
|
70 /**
|
Chris@510
|
71 * The closed property is not obtained from Hg, but set in
|
Chris@510
|
72 * Grapher::layout() based on traversing closed branch graphs
|
Chris@510
|
73 */
|
Chris@510
|
74 bool closed() const { return m_closed; }
|
Chris@510
|
75
|
Chris@43
|
76 int number() const {
|
Chris@43
|
77 return id().split(':')[0].toInt();
|
Chris@43
|
78 }
|
Chris@43
|
79
|
Chris@128
|
80 QString authorName() const {
|
Chris@128
|
81 QString a = author();
|
Chris@44
|
82 return a.replace(QRegExp("\\s*<[^>]*>"), "");
|
Chris@44
|
83 }
|
Chris@44
|
84
|
Chris@51
|
85 QString date() const {
|
Chris@51
|
86 return datetime().split(' ')[0];
|
Chris@51
|
87 }
|
Chris@51
|
88
|
Chris@108
|
89 bool isOnBranch(QString branch) {
|
Chris@108
|
90 QString b = m_branch;
|
Chris@108
|
91 if (branch == "") branch = "default";
|
Chris@108
|
92 if (b == "") b = "default";
|
Chris@108
|
93 if (branch == b) return true;
|
Chris@108
|
94 return false;
|
Chris@108
|
95 }
|
Chris@108
|
96
|
Chris@153
|
97 static QString hashOf(QString id) {
|
Chris@153
|
98 return id.split(':')[1];
|
Chris@153
|
99 }
|
Chris@153
|
100
|
Chris@150
|
101 static QStringList getIds(Changesets csets) {
|
Chris@150
|
102 QStringList ids;
|
Chris@150
|
103 foreach (Changeset *cs, csets) ids.push_back(cs->id());
|
Chris@150
|
104 return ids;
|
Chris@150
|
105 }
|
Chris@150
|
106
|
Chris@108
|
107 static Changesets parseChangesets(QString logText) {
|
Chris@108
|
108 Changesets csets;
|
Chris@108
|
109 LogList log = LogParser(logText).parse();
|
Chris@108
|
110 foreach (LogEntry e, log) {
|
Chris@108
|
111 csets.push_back(new Changeset(e));
|
Chris@108
|
112 }
|
Chris@108
|
113 return csets;
|
Chris@108
|
114 }
|
Chris@108
|
115
|
Chris@125
|
116 static QString getLogTemplate();
|
Chris@125
|
117
|
Chris@125
|
118 QString formatHtml();
|
Chris@125
|
119
|
Chris@43
|
120 signals:
|
Chris@43
|
121 void idChanged(QString id);
|
Chris@128
|
122 void authorChanged(QString author);
|
Chris@43
|
123 void branchChanged(QString branch);
|
Chris@128
|
124 void tagsChanged(QStringList tags);
|
Chris@520
|
125 void bookmarksChanged(QStringList bookmarks);
|
Chris@51
|
126 void datetimeChanged(QString datetime);
|
Chris@52
|
127 void timestampChanged(qulonglong timestamp);
|
Chris@43
|
128 void ageChanged(QString age);
|
Chris@43
|
129 void parentsChanged(QStringList parents);
|
Chris@47
|
130 void childrenChanged(QStringList children);
|
Chris@510
|
131 void closedChanged(bool closed);
|
Chris@43
|
132 void commentChanged(QString comment);
|
Chris@43
|
133
|
Chris@43
|
134 public slots:
|
Chris@43
|
135 void setId(QString id) { m_id = id; emit idChanged(id); }
|
Chris@128
|
136 void setAuthor(QString author) { m_author = author; emit authorChanged(author); }
|
Chris@43
|
137 void setBranch(QString branch) { m_branch = branch; emit branchChanged(branch); }
|
Chris@128
|
138 void setTags(QStringList tags) { m_tags = tags; emit tagsChanged(tags); }
|
Chris@128
|
139 void addTag(QString tag) { m_tags.push_back(tag); emit tagsChanged(m_tags); }
|
Chris@520
|
140 void setBookmarks(QStringList bmarks) { m_bookmarks = bmarks; emit bookmarksChanged(bmarks); }
|
Chris@520
|
141 void addBookmark(QString b) { m_bookmarks.push_back(b); emit bookmarksChanged(m_bookmarks); }
|
Chris@52
|
142 void setDatetime(QString datetime) { m_datetime = datetime; emit datetimeChanged(datetime); }
|
Chris@52
|
143 void setTimestamp(qulonglong timestamp) { m_timestamp = timestamp; emit timestampChanged(timestamp); }
|
Chris@43
|
144 void setAge(QString age) { m_age = age; emit ageChanged(age); }
|
Chris@43
|
145 void setParents(QStringList parents) { m_parents = parents; emit parentsChanged(parents); }
|
Chris@47
|
146 void setChildren(QStringList children) { m_children = children; emit childrenChanged(m_children); }
|
Chris@47
|
147 void addChild(QString child) { m_children.push_back(child); emit childrenChanged(m_children); }
|
Chris@510
|
148 void setClosed(bool closed) { m_closed = closed; emit closedChanged(closed); }
|
Chris@43
|
149 void setComment(QString comment) { m_comment = comment; emit commentChanged(comment); }
|
Chris@43
|
150
|
Chris@43
|
151 private:
|
Chris@43
|
152 QString m_id;
|
Chris@128
|
153 QString m_author;
|
Chris@43
|
154 QString m_branch;
|
Chris@128
|
155 QStringList m_tags;
|
Chris@520
|
156 QStringList m_bookmarks;
|
Chris@51
|
157 QString m_datetime;
|
Chris@52
|
158 qulonglong m_timestamp;
|
Chris@43
|
159 QString m_age;
|
Chris@43
|
160 QStringList m_parents;
|
Chris@47
|
161 QStringList m_children;
|
Chris@510
|
162 bool m_closed;
|
Chris@43
|
163 QString m_comment;
|
Chris@43
|
164 };
|
Chris@43
|
165
|
Chris@43
|
166
|
Chris@43
|
167 #endif // CHANGESET_H
|