comparison src/changeset.h @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents changeset.h@8fd71f570884
children c623ce6b3104
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
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) 2011 Chris Cannam
9 Copyright (c) 2011 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 #ifndef CHANGESET_H
19 #define CHANGESET_H
20
21 #include <QObject>
22 #include <QString>
23 #include <QStringList>
24 #include <QList>
25 #include <QSharedPointer>
26
27 #include "logparser.h"
28
29 class Changeset;
30
31 typedef QList<Changeset *> Changesets;
32
33 class Changeset : public QObject
34 {
35 Q_OBJECT
36
37 Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged STORED true);
38 Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged STORED true);
39 Q_PROPERTY(QString branch READ branch WRITE setBranch NOTIFY branchChanged STORED true);
40 Q_PROPERTY(QStringList tags READ tags WRITE setTags NOTIFY tagsChanged STORED true);
41 Q_PROPERTY(QString datetime READ datetime WRITE setDatetime NOTIFY datetimeChanged STORED true);
42 Q_PROPERTY(qulonglong timestamp READ timestamp WRITE setTimestamp NOTIFY timestampChanged STORED true);
43 Q_PROPERTY(QString age READ age WRITE setAge NOTIFY ageChanged STORED true);
44 Q_PROPERTY(QStringList parents READ parents WRITE setParents NOTIFY parentsChanged STORED true);
45 Q_PROPERTY(QStringList children READ children WRITE setChildren NOTIFY childrenChanged STORED true);
46 Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY commentChanged STORED true);
47
48 public:
49 Changeset() : QObject() { }
50 explicit Changeset(const LogEntry &e);
51
52 QString id() const { return m_id; }
53 QString author() const { return m_author; }
54 QString branch() const { return m_branch; }
55 QStringList tags() const { return m_tags; }
56 QString datetime() const { return m_datetime; }
57 qulonglong timestamp() const { return m_timestamp; }
58 QString age() const { return m_age; }
59 QStringList parents() const { return m_parents; }
60 QString comment() const { return m_comment; }
61
62 /**
63 * The children property is not obtained from Hg, but set in
64 * Grapher::layout() based on reported parents
65 */
66 QStringList children() const { return m_children; }
67
68 int number() const {
69 return id().split(':')[0].toInt();
70 }
71
72 QString authorName() const {
73 QString a = author();
74 return a.replace(QRegExp("\\s*<[^>]*>"), "");
75 }
76
77 QString date() const {
78 return datetime().split(' ')[0];
79 }
80
81 bool isOnBranch(QString branch) {
82 QString b = m_branch;
83 if (branch == "") branch = "default";
84 if (b == "") b = "default";
85 if (branch == b) return true;
86 return false;
87 }
88
89 static QString hashOf(QString id) {
90 return id.split(':')[1];
91 }
92
93 static QStringList getIds(Changesets csets) {
94 QStringList ids;
95 foreach (Changeset *cs, csets) ids.push_back(cs->id());
96 return ids;
97 }
98
99 static Changesets parseChangesets(QString logText) {
100 Changesets csets;
101 LogList log = LogParser(logText).parse();
102 foreach (LogEntry e, log) {
103 csets.push_back(new Changeset(e));
104 }
105 return csets;
106 }
107
108 static QString getLogTemplate();
109
110 QString formatHtml();
111
112 signals:
113 void idChanged(QString id);
114 void authorChanged(QString author);
115 void branchChanged(QString branch);
116 void tagsChanged(QStringList tags);
117 void datetimeChanged(QString datetime);
118 void timestampChanged(qulonglong timestamp);
119 void ageChanged(QString age);
120 void parentsChanged(QStringList parents);
121 void childrenChanged(QStringList children);
122 void commentChanged(QString comment);
123
124 public slots:
125 void setId(QString id) { m_id = id; emit idChanged(id); }
126 void setAuthor(QString author) { m_author = author; emit authorChanged(author); }
127 void setBranch(QString branch) { m_branch = branch; emit branchChanged(branch); }
128 void setTags(QStringList tags) { m_tags = tags; emit tagsChanged(tags); }
129 void addTag(QString tag) { m_tags.push_back(tag); emit tagsChanged(m_tags); }
130 void setDatetime(QString datetime) { m_datetime = datetime; emit datetimeChanged(datetime); }
131 void setTimestamp(qulonglong timestamp) { m_timestamp = timestamp; emit timestampChanged(timestamp); }
132 void setAge(QString age) { m_age = age; emit ageChanged(age); }
133 void setParents(QStringList parents) { m_parents = parents; emit parentsChanged(parents); }
134 void setChildren(QStringList children) { m_children = children; emit childrenChanged(m_children); }
135 void addChild(QString child) { m_children.push_back(child); emit childrenChanged(m_children); }
136 void setComment(QString comment) { m_comment = comment; emit commentChanged(comment); }
137
138 private:
139 QString m_id;
140 QString m_author;
141 QString m_branch;
142 QStringList m_tags;
143 QString m_datetime;
144 qulonglong m_timestamp;
145 QString m_age;
146 QStringList m_parents;
147 QStringList m_children;
148 QString m_comment;
149 };
150
151
152 #endif // CHANGESET_H