Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 1 | #ifndef DIGESTTREESCENE_H |
| 2 | #define DIGESTTREESCENE_H |
| 3 | |
| 4 | #include <QtGui/QGraphicsScene> |
| 5 | #include "ogdf/basic/GraphAttributes.h" |
| 6 | #include "ogdf/basic/Graph.h" |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame^] | 7 | #include <sync-seq-no.h> |
| 8 | #include <sync-logic.h> |
| 9 | #include <ctime> |
| 10 | #include <QMap> |
| 11 | #include <vector> |
| 12 | #include <tr1/memory> |
| 13 | |
| 14 | class QGraphicsTextItem; |
| 15 | |
| 16 | class User; |
| 17 | class DisplayUser; |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 18 | |
| 19 | class DigestTreeScene : public QGraphicsScene |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame^] | 23 | typedef std::tr1::shared_ptr<DisplayUser> DisplayUserPtr; |
| 24 | typedef QMap<QString, DisplayUserPtr> Roster; |
| 25 | typedef QMap<QString, DisplayUserPtr>::iterator Roster_iterator; |
| 26 | typedef QMapIterator<QString, DisplayUserPtr> RosterIterator; |
| 27 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 28 | public: |
| 29 | DigestTreeScene(QWidget *parent = 0); |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame^] | 30 | void processUpdate(std::vector<Sync::MissingDataInfo> &v, QString digest); |
| 31 | void msgReceived(QString prefix, QString nick); |
| 32 | void plot(QString digest); |
| 33 | void plotEdge(ogdf::GraphAttributes &GA); |
| 34 | void plotNode(ogdf::GraphAttributes &GA, int rootIndex, QString digest); |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 35 | private: |
| 36 | ogdf::Graph m_graph; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame^] | 37 | Roster m_roster; |
| 38 | QGraphicsTextItem *m_rootDigest; |
| 39 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 40 | }; |
Zhenkai Zhu | 71b42cb | 2012-06-04 09:42:53 -0700 | [diff] [blame^] | 41 | |
| 42 | class User |
| 43 | { |
| 44 | public: |
| 45 | User():m_received(time(NULL)) {} |
| 46 | User(QString n, QString p, QString c): m_nick(n), m_prefix(p), m_chatroom(c), m_received(time(NULL)) {} |
| 47 | void setNick(QString nick) {m_nick = nick;} |
| 48 | void setPrefix(QString prefix) {m_prefix = prefix;} |
| 49 | void setChatroom(QString chatroom) {m_chatroom = chatroom;} |
| 50 | void setSeq(Sync::SeqNo seq) {m_seq = seq;} |
| 51 | void setReceived() {m_received = time(NULL);} |
| 52 | QString getNick() { return m_nick;} |
| 53 | QString getPrefix() { return m_prefix;} |
| 54 | QString getChatroom() { return m_chatroom;} |
| 55 | Sync::SeqNo getSeqNo() { return m_seq;} |
| 56 | time_t getReceived() { return m_received;} |
| 57 | private: |
| 58 | QString m_nick; |
| 59 | QString m_prefix; |
| 60 | QString m_chatroom; |
| 61 | Sync::SeqNo m_seq; |
| 62 | time_t m_received; |
| 63 | }; |
| 64 | |
| 65 | class DisplayUser : public User |
| 66 | { |
| 67 | public: |
| 68 | DisplayUser():m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 69 | DisplayUser(QString n, QString p , QString c): User(n, p, c), m_seqTextItem(NULL), m_nickTextItem(NULL), m_rimRectItem(NULL) {} |
| 70 | QGraphicsTextItem *getSeqTextItem() {return m_seqTextItem;} |
| 71 | QGraphicsTextItem *getNickTextItem() {return m_nickTextItem;} |
| 72 | QGraphicsRectItem *getRimRectItem() {return m_rimRectItem;} |
| 73 | void setSeqTextItem(QGraphicsTextItem *item) { m_seqTextItem = item;} |
| 74 | void setNickTextItem(QGraphicsTextItem *item) { m_nickTextItem = item;} |
| 75 | void setRimRectItem(QGraphicsRectItem *item) {m_rimRectItem = item;} |
| 76 | private: |
| 77 | QGraphicsTextItem *m_seqTextItem; |
| 78 | QGraphicsTextItem *m_nickTextItem; |
| 79 | QGraphicsRectItem *m_rimRectItem; |
| 80 | }; |
| 81 | |
Zhenkai Zhu | f474a0a | 2012-05-30 15:06:29 -0700 | [diff] [blame] | 82 | #endif |