| Chris@44 | 1 #ifndef GRAPHER_H | 
| Chris@44 | 2 #define GRAPHER_H | 
| Chris@44 | 3 | 
| Chris@44 | 4 #include "changeset.h" | 
| Chris@44 | 5 #include "changesetitem.h" | 
| Chris@44 | 6 | 
| cannam@45 | 7 #include <QSet> | 
| cannam@45 | 8 #include <QMap> | 
| Chris@46 | 9 #include <QPair> | 
| cannam@45 | 10 | 
| cannam@45 | 11 #include <exception> | 
| Chris@44 | 12 | 
| Chris@44 | 13 class Grapher | 
| Chris@44 | 14 { | 
| Chris@44 | 15 public: | 
| cannam@45 | 16     Grapher(QGraphicsScene *scene) { m_scene = scene; } | 
| cannam@45 | 17 | 
| cannam@45 | 18     void layout(Changesets csets); | 
| cannam@45 | 19 | 
| Chris@53 | 20     ChangesetItem *getItemFor(Changeset *cs); | 
| Chris@53 | 21 | 
| cannam@45 | 22     class LayoutException : public std::exception { | 
| cannam@45 | 23     public: | 
| cannam@45 | 24 	LayoutException(QString message) throw() : m_message(message) { } | 
| cannam@45 | 25 	virtual ~LayoutException() throw() { } | 
| cannam@45 | 26 	virtual const char *what() const throw() { | 
| cannam@45 | 27 	    return m_message.toLocal8Bit().data(); | 
| cannam@45 | 28 	} | 
| cannam@45 | 29     protected: | 
| cannam@45 | 30 	QString m_message; | 
| cannam@45 | 31     }; | 
| cannam@45 | 32 | 
| cannam@45 | 33 private: | 
| cannam@45 | 34     QGraphicsScene *m_scene; | 
| cannam@45 | 35 | 
| cannam@45 | 36     typedef QMap<QString, Changeset *> IdChangesetMap; | 
| Chris@46 | 37     IdChangesetMap m_changesets; | 
| cannam@45 | 38 | 
| cannam@45 | 39     typedef QMap<QString, ChangesetItem *> IdItemMap; | 
| cannam@45 | 40     IdItemMap m_items; | 
| cannam@45 | 41 | 
| cannam@45 | 42     typedef QSet<int> ColumnSet; | 
| cannam@45 | 43     typedef QMap<int, ColumnSet> GridAlloc; | 
| cannam@45 | 44     GridAlloc m_alloc; | 
| cannam@45 | 45 | 
| Chris@46 | 46     typedef QPair<int, int> Range; | 
| Chris@46 | 47     typedef QMap<QString, Range> BranchRangeMap; | 
| Chris@46 | 48     BranchRangeMap m_branchRanges; | 
| Chris@46 | 49 | 
| Chris@46 | 50     typedef QMap<QString, int> BranchColumnMap; | 
| Chris@46 | 51     BranchColumnMap m_branchHomes; | 
| Chris@46 | 52 | 
| cannam@45 | 53     typedef QSet<QString> IdSet; | 
| cannam@45 | 54     IdSet m_handled; | 
| Chris@46 | 55 | 
| Chris@51 | 56     typedef QMap<int, QString> RowDateMap; | 
| Chris@51 | 57     RowDateMap m_rowDates; | 
| Chris@51 | 58 | 
| Chris@46 | 59     void layoutRow(QString id); | 
| Chris@46 | 60     void layoutCol(QString id); | 
| Chris@46 | 61     void allocateBranchHomes(Changesets csets); | 
| Chris@46 | 62     bool rangesConflict(const Range &r1, const Range &r2); | 
| Chris@46 | 63     int findAvailableColumn(int row, int parent, bool preferParentCol); | 
| Chris@44 | 64 }; | 
| Chris@44 | 65 | 
| Chris@44 | 66 #endif |