1
0

fb2head.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. Auth,
  15. Cover,
  16. Image,
  17. Seqn,
  18. FB2_END_KEYLIST
  19. public:
  20. explicit Fb2HeadItem(QWebElement &element, Fb2HeadItem *parent = 0);
  21. virtual ~Fb2HeadItem();
  22. Fb2HeadItem * item(const QModelIndex &index) const;
  23. Fb2HeadItem * item(int row) const;
  24. int index(Fb2HeadItem * child) const {
  25. return m_list.indexOf(child);
  26. }
  27. int count() const {
  28. return m_list.size();
  29. }
  30. Fb2HeadItem * parent() const {
  31. return m_parent;
  32. }
  33. QString text(int col = 0) const;
  34. const QString & id() const {
  35. return m_id;
  36. }
  37. const QString & name() const {
  38. return m_name;
  39. }
  40. QString sub(const QString &key) const;
  41. private:
  42. class HintHash : public QHash<QString, QString>
  43. {
  44. public:
  45. explicit HintHash();
  46. };
  47. private:
  48. void addChildren(QWebElement &parent);
  49. QString value() const;
  50. QString hint() const;
  51. private:
  52. QList<Fb2HeadItem*> m_list;
  53. QWebElement m_element;
  54. QString m_name;
  55. QString m_text;
  56. Fb2HeadItem * m_parent;
  57. QString m_id;
  58. };
  59. class Fb2HeadModel: public QAbstractItemModel
  60. {
  61. Q_OBJECT
  62. public:
  63. explicit Fb2HeadModel(QWebView &view, QObject *parent = 0);
  64. virtual ~Fb2HeadModel();
  65. void select(const QModelIndex &index);
  66. void expand(QTreeView *view);
  67. public:
  68. virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  69. virtual QModelIndex parent(const QModelIndex &child) const;
  70. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
  71. virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
  72. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  73. virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  74. protected:
  75. Fb2HeadItem * item(const QModelIndex &index) const;
  76. private:
  77. QWebView & m_view;
  78. Fb2HeadItem * m_root;
  79. };
  80. #endif // FB2HEAD_H