fb2tree.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. private:
  31. void addChildren(QWebElement &parent);
  32. private:
  33. QList<Fb2TreeItem*> m_list;
  34. QString m_name;
  35. QString m_text;
  36. Fb2TreeItem * m_parent;
  37. QWebElement m_element;
  38. QString m_id;
  39. };
  40. class Fb2TreeModel: public QAbstractItemModel
  41. {
  42. Q_OBJECT
  43. public:
  44. explicit Fb2TreeModel(QWebView &view, QObject *parent = 0);
  45. virtual ~Fb2TreeModel();
  46. void select(const QModelIndex &index);
  47. void expand(QTreeView *view);
  48. public:
  49. virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  50. virtual QModelIndex parent(const QModelIndex &child) const;
  51. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
  52. virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
  53. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  54. protected:
  55. Fb2TreeItem * item(const QModelIndex &index) const;
  56. private:
  57. QWebView & m_view;
  58. Fb2TreeItem * m_root;
  59. };
  60. #endif // FB2TREE_H