1/*
2 Author: Marco Costalba (C) 2005-2007
3
4 Copyright: See COPYING file that comes with this distribution
5
6*/
7#ifndef LANES_H
8#define LANES_H
9
10#include <QString>
11#include <QVector>
12
13#include <LaneType.h>
14#include <Lane.h>
15
16//
17// At any given time, the Lanes class represents a single revision (row) of the history graph.
18// The Lanes class contains a vector of the sha1 hashes of the next commit to appear in each lane (column).
19// The Lanes class also contains a vector used to decide which glyph to draw on the history graph.
20//
21// For each revision (row) (from recent (top) to ancient past (bottom)), the Lanes class is updated, and the
22// current revision (row) of glyphs is saved elsewhere (via getLanes()).
23//
24// The ListView class is responsible for rendering the glyphs.
25//
26
27class Lanes
28{
29public:
30 Lanes() = default;
31 bool isEmpty() { return typeVec.empty(); }
32 void init(const QString &expectedSha);
33 void clear();
34 bool isFork(const QString &sha, bool &isDiscontinuity);
35 void setFork(const QString &sha);
36 void setMerge(const QStringList &parents);
37 void setInitial();
38 void changeActiveLane(const QString &sha);
39 void afterMerge();
40 void afterFork();
41 bool isBranch();
42 void afterBranch();
43 void nextParent(const QString &sha);
44 void setLanes(QVector<Lane> &ln) { ln = typeVec; } // O(1) vector is implicitly shared
45 QVector<Lane> getLanes() const { return typeVec; }
46
47private:
48 int findNextSha(const QString &next, int pos);
49 int findType(LaneType type, int pos);
50 int add(LaneType type, const QString &next, int pos);
51 bool isNode(Lane lane) const;
52
53 int activeLane;
54 QVector<Lane> typeVec; // Describes which glyphs should be drawn.
55 QVector<QString> nextShaVec; // The sha1 hashes of the next commit to appear in each lane (column).
56 LaneType NODE = LaneType::MERGE_FORK;
57 LaneType NODE_R = LaneType::MERGE_FORK_R;
58 LaneType NODE_L = LaneType::MERGE_FORK_L;
59};
60
61#endif
62