comparison src/grapher.h @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents grapher.h@cc95394e2392
children f051d210521e
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 GRAPHER_H
19 #define GRAPHER_H
20
21 #include "changeset.h"
22 #include "changesetitem.h"
23 #include "uncommitteditem.h"
24 #include "changesetscene.h"
25
26 #include <QSet>
27 #include <QMap>
28 #include <QPair>
29
30 #include <exception>
31
32 class Grapher
33 {
34 public:
35 Grapher(ChangesetScene *scene);
36
37 void layout(Changesets csets,
38 QStringList uncommittedParents,
39 QString uncommittedBranch);
40
41 ChangesetItem *getItemFor(Changeset *cs);
42
43 UncommittedItem *getUncommittedItem() { return m_uncommitted; }
44
45 class LayoutException : public std::exception {
46 public:
47 LayoutException(QString message) throw() : m_message(message) { }
48 virtual ~LayoutException() throw() { }
49 virtual const char *what() const throw() {
50 return m_message.toLocal8Bit().data();
51 }
52 protected:
53 QString m_message;
54 };
55
56 private:
57 ChangesetScene *m_scene;
58
59 typedef QMap<QString, Changeset *> IdChangesetMap;
60 IdChangesetMap m_changesets;
61
62 typedef QMap<QString, ChangesetItem *> IdItemMap;
63 IdItemMap m_items;
64
65 typedef QSet<int> ColumnSet;
66 typedef QMap<int, ColumnSet> GridAlloc;
67 GridAlloc m_alloc;
68
69 typedef QPair<int, int> Range;
70 typedef QMap<QString, Range> BranchRangeMap;
71 BranchRangeMap m_branchRanges;
72
73 typedef QMap<QString, int> BranchColumnMap;
74 BranchColumnMap m_branchHomes;
75
76 typedef QSet<QString> IdSet;
77 IdSet m_handled;
78
79 typedef QMap<int, QString> RowDateMap;
80 RowDateMap m_rowDates;
81
82 bool m_showDates;
83
84 QStringList m_uncommittedParents;
85 int m_uncommittedParentRow;
86 UncommittedItem *m_uncommitted;
87 bool m_haveAllocatedUncommittedColumn;
88
89 void layoutRow(QString id);
90 void layoutCol(QString id);
91 void allocateBranchHomes(Changesets csets);
92 bool rangesConflict(const Range &r1, const Range &r2);
93 int findAvailableColumn(int row, int parent, bool preferParentCol);
94 bool isAvailable(int row, int col);
95 };
96
97 #endif