WordTree
|
00001 /* 00002 * header file for WTBackend class 00003 * written by: christian moellinger <ch.moellinger@gmail.com> 00004 * 03/2011 - 06/2011 Project "InfoVis: Word Tree" 00005 */ 00006 00007 #ifndef WTBACKEND_H 00008 #define WTBACKEND_H 00009 00010 #include <QObject> 00011 #include <QSharedPointer> 00012 #include <QStringList> 00013 #include <QVector> 00014 #include <QMap> 00015 00016 class WTVisualizedTree; 00017 00018 class WTBackend : public QObject 00019 { 00020 Q_OBJECT 00021 00022 public: 00023 /*! \name Public types */ 00024 //@{ 00025 /// a coded phrase, which stores the whole phrase, 00026 /// a list of all words, and for each word an unique code 00027 struct TCodedPhrase 00028 { 00029 QStringList m_lsWords; 00030 QVector<long long int> m_vCodesForWords; 00031 }; 00032 //@} 00033 00034 /*! \name Constructor / Destructor */ 00035 //@{ 00036 /// Constructor 00037 explicit WTBackend(QObject *parent = 0); 00038 //@} 00039 00040 00041 /*! \name Public methods */ 00042 //@{ 00043 /// This method creates a word tree, which can be visualized with WTTreeVisualizer 00044 QSharedPointer<WTVisualizedTree> CreateWordTree(QString sSearchPhrase); 00045 //@} 00046 00047 public slots: 00048 /*! \name Public slots */ 00049 //@{ 00050 /// this method loads a given file 00051 void LoadFile(QString sFilename); 00052 //@} 00053 00054 private: 00055 /*! \name Private types */ 00056 //@{ 00057 /// this class represents a node in the word tree 00058 class TItlNode 00059 { 00060 public: 00061 /*! \name Public attributes */ 00062 //@{ 00063 /// returns the word list 00064 QStringList GetWordList() { return m_lsWords; } 00065 00066 /// returns the number of children 00067 int NumChildren() const { return m_vChildren.size(); } 00068 00069 /// returns a vector with the children 00070 QVector<QSharedPointer<TItlNode> > GetChildren() { return m_vChildren; } 00071 //@} 00072 00073 /*! \name Public methods */ 00074 //@{ 00075 /// adds a new child 00076 void AddChild(QSharedPointer<TItlNode> spNode) { m_vChildren.push_back(spNode); } 00077 //@} 00078 00079 00080 /*! \name Public variables, should be moved to private */ 00081 //@{ 00082 QStringList m_lsWords; 00083 QString m_sPhrase; 00084 QMap<int, QVector<long long int> > m_mCodesForWords; 00085 //@} 00086 00087 private: 00088 /*! \name Private member variables */ 00089 //@{ 00090 QVector<QSharedPointer<TItlNode> > m_vChildren; 00091 //@} 00092 00093 }; 00094 //@} 00095 00096 /*! \name Internal methods */ 00097 //@{ 00098 /// this method creates a word list of the given phrase 00099 QStringList ItlCreateWordList(QString sPhrase); 00100 00101 /// this method recursively draws a given node in the given visualized tree object 00102 void ItlDrawNode(int iStartX, 00103 int iStartY, 00104 int &rUsedHeight, 00105 QSharedPointer<WTBackend::TItlNode> spRootNode, 00106 QSharedPointer<WTVisualizedTree> spVisualizedTree); 00107 00108 /// this method generates a phrase tree, that means a data structure with connected nodes 00109 QSharedPointer<WTBackend::TItlNode> ItlCreatePhraseTree(QVector<TCodedPhrase> lPhrases); 00110 00111 /// this medhod recursively generates a node from the given phrases 00112 QSharedPointer<TItlNode> ItlCreateNode(QVector<TCodedPhrase> lCodedPhrases, int iPosition); 00113 //@} 00114 00115 /*! \name Internal member variables */ 00116 //@{ 00117 /// the coded phrases of the currently loaded file 00118 QVector<TCodedPhrase> m_vCodedPhrases; 00119 //@} 00120 }; 00121 00122 #endif // WTBACKEND_H