fb2head.hpp 2.4 KB

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