fb2tree.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef FB2TREE_H
  2. #define FB2TREE_H
  3. #include <QAbstractItemModel>
  4. #include <QWebElement>
  5. #include <QWebView>
  6. QT_BEGIN_NAMESPACE
  7. class QTreeView;
  8. QT_END_NAMESPACE
  9. class Fb2TreeItem: public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit Fb2TreeItem(QWebElement &element, Fb2TreeItem *parent = 0);
  14. virtual ~Fb2TreeItem();
  15. Fb2TreeItem * item(const QModelIndex &index) const;
  16. Fb2TreeItem * item(int row) const;
  17. int index(Fb2TreeItem * child) const {
  18. return m_list.indexOf(child);
  19. }
  20. int count() const {
  21. return m_list.size();
  22. }
  23. Fb2TreeItem * parent() const {
  24. return m_parent;
  25. }
  26. QString text() const;
  27. const QString & id() const {
  28. return m_id;
  29. }
  30. const QString & name() const {
  31. return m_name;
  32. }
  33. private:
  34. void addChildren(QWebElement &parent);
  35. private:
  36. QList<Fb2TreeItem*> m_list;
  37. QString m_name;
  38. QString m_text;
  39. Fb2TreeItem * m_parent;
  40. QString m_id;
  41. };
  42. class Fb2TreeModel: public QAbstractItemModel
  43. {
  44. Q_OBJECT
  45. public:
  46. explicit Fb2TreeModel(QWebView &view, QObject *parent = 0);
  47. virtual ~Fb2TreeModel();
  48. void select(const QModelIndex &index);
  49. void expand(QTreeView *view);
  50. public:
  51. virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  52. virtual QModelIndex parent(const QModelIndex &child) const;
  53. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
  54. virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
  55. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  56. protected:
  57. Fb2TreeItem * item(const QModelIndex &index) const;
  58. private:
  59. QWebView & m_view;
  60. Fb2TreeItem * m_root;
  61. };
  62. #endif // FB2TREE_H