#ifndef GTL_GUI_LOG_VIEWER_H #define GTL_GUI_LOG_VIEWER_H #include #include #include #include #include #include #include #include #include #include #include #include #include "gui_global.h" #include "core/gtl_logger.h" namespace gtl { namespace gui { /* * * * * * * * * * * * * * * * * * * * * * * * * * * * main view model */ class log_viewer_model : public QAbstractTableModel { Q_OBJECT public: log_viewer_model( QObject* parent = 0 ); int rowCount( const QModelIndex& parent = QModelIndex() ) const; int columnCount( const QModelIndex& paren = QModelIndex() ) const; QVariant data( const QModelIndex& index, int role ) const; bool setData( const QModelIndex& index, const QVariant& value, int role ); QVariant headerData( int section, Qt::Orientation orientation, int role ) const; void set_level_value(uint8_t val); void clear(void); public slots: void slt_append_string( const QString& level, const QString& date, const QString& time, const QString& tag, const QString& text ); signals: void sgnl_set_data(void); private: enum Column { LEVEL = 0, DATE, TIME, TAG, TEXT, LAST }; uint8_t m_select_levels; typedef QHash< Column, QVariant > LogViewerData; typedef QList< LogViewerData > Logs; Logs m_logs; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * proxy model */ class filter_proxy_model : public QSortFilterProxyModel { Q_OBJECT public: filter_proxy_model(QObject *parent = nullptr); void set_filter_level(const QString &level); void set_search_string(const QString &str); void set_enable_search_string(void); void set_disable_search_string(void); void set_enable_date_filter(void); void set_disable_date_filter(void); void set_datetime_filter(QDateTime from, QDateTime to); protected: QString m_filter_level; QString m_search_string; QDateTime m_dt_from; QDateTime m_dt_to; bool m_enable_text_search; bool m_enable_date_filter; bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; private: bool check_date_in_range(QDateTime date) const; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * custom QTableView class */ class MyTableVeiw : public QTableView { Q_OBJECT public: explicit MyTableVeiw(QWidget *parent = nullptr){}; enum Rotate { NONE = 0, DOWN, UP }; int flag_whell_rotate = DOWN; protected: virtual void wheelEvent(QWheelEvent *e) override { if (e->angleDelta().y() < 0) { flag_whell_rotate = DOWN; } else { flag_whell_rotate = UP; } QTableView::wheelEvent(e); }; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * log_viewer */ class GTL_GUI_EXPORT log_viewer : public QWidget { Q_OBJECT public: explicit log_viewer(QWidget *parent = nullptr); public slots: void slt_data_changed(void); void slt_rows_about_to_be_inserted(); void slt_check_levels(int index); void slt_update_search_string(void); void slt_reset_search(void); void slt_dialog_set_datetime(void); void slt_update_dt(void); void slt_set_scroll_range(int min, int max); void slt_set_scroll_value(); void slt_table_click(const QModelIndex &index); private: filter_proxy_model *m_proxy_model; MyTableVeiw *m_view; log_viewer_model *m_model; QModelIndex m_prev_index = QModelIndex(); int m_prev_value = -1; QComboBox *m_cbb_level; QLineEdit *m_le_search_string; QLineEdit *m_le_search_date; QLineEdit *m_le_search_time; QLineEdit *m_le_dt_from; QLineEdit *m_le_dt_to; QAction *m_action_le_dt_from; QAction *m_action_le_dt_to; QDate m_date_from; QTime m_time_from; QDate m_date_to; QTime m_time_to; QPushButton *m_b_reset_search; QPushButton *m_b_clear_data; QCalendarWidget *m_calendar_widget; QDialog *m_dialog_set_datetime; int m_scroll_min; int m_scroll_max; }; } } #endif // GTL_GUI_LOG_VIEWER_H