1
0

fb2head.h 2.0 KB

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