fb2logs.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef FB2LOGS_H
  2. #define FB2LOGS_H
  3. #include <QAbstractListModel>
  4. #include <QListView>
  5. #include <QDockWidget>
  6. class FbLogModel : public QAbstractListModel
  7. {
  8. Q_OBJECT
  9. public:
  10. FbLogModel(QObject *parent = 0);
  11. void add(QtMsgType type, int row, int col, const QString &msg);
  12. void add(QtMsgType type, const QString &msg);
  13. public:
  14. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  15. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
  16. signals:
  17. void changeCurrent(const QModelIndex &index);
  18. private:
  19. class FbLogItem
  20. {
  21. public:
  22. FbLogItem(QtMsgType type, int row, int col, const QString &msg)
  23. : m_type(type), m_msg(msg), m_row(row), m_col(col) {}
  24. FbLogItem(QtMsgType type, const QString &msg)
  25. : m_type(type), m_msg(msg), m_row(0), m_col(0) {}
  26. const QString & msg() const { return m_msg; }
  27. QtMsgType type() const { return m_type; }
  28. int row() const { return m_row; }
  29. int col() const { return m_row; }
  30. QVariant icon() const;
  31. private:
  32. QtMsgType m_type;
  33. QString m_msg;
  34. int m_row;
  35. int m_col;
  36. };
  37. private:
  38. QList<FbLogItem*> m_list;
  39. };
  40. class FbLogList: public QListView
  41. {
  42. Q_OBJECT
  43. public:
  44. explicit FbLogList(QWidget *parent = 0);
  45. QSize sizeHint() const {
  46. QSize sh = QListView::sizeHint();
  47. sh.setHeight(40);
  48. return sh;
  49. }
  50. };
  51. class FbLogDock: public QDockWidget
  52. {
  53. Q_OBJECT
  54. public:
  55. explicit FbLogDock(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = {});
  56. void append(QtMsgType type, const QString &message);
  57. private:
  58. FbLogModel *m_model;
  59. FbLogList *m_list;
  60. };
  61. #endif // FB2LOGS_H