From e4c88541592544cd3d4a92ec02a62d6b48be6dfd Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 Jul 2015 17:47:48 +0200 Subject: [PATCH] Added lazy rendering mode for HTML reporter widget (allows a faster report creation, when the report has many lines) --- common/dialogs/wx_html_report_panel.cpp | 32 ++++++++++++++++++-- common/dialogs/wx_html_report_panel.h | 22 ++++++++++++++ common/dialogs/wx_html_report_panel_base.cpp | 7 ++--- common/dialogs/wx_html_report_panel_base.fbp | 4 +-- common/dialogs/wx_html_report_panel_base.h | 1 + common/reporter.cpp | 17 +++++++++++ include/reporter.h | 18 +++++++++++ 7 files changed, 93 insertions(+), 8 deletions(-) diff --git a/common/dialogs/wx_html_report_panel.cpp b/common/dialogs/wx_html_report_panel.cpp index 42d884f58f..3c7b4d1976 100644 --- a/common/dialogs/wx_html_report_panel.cpp +++ b/common/dialogs/wx_html_report_panel.cpp @@ -32,7 +32,8 @@ WX_HTML_REPORT_PANEL::WX_HTML_REPORT_PANEL( wxWindow* parent, WX_HTML_REPORT_PANEL_BASE( parent, id, pos, size, style ), m_reporter( this ), m_severities( -1 ), - m_showAll( true ) + m_showAll( true ), + m_lazyUpdate( false ) { syncCheckboxes(); m_htmlView->SetPage( addHeader( "" ) ); @@ -57,7 +58,26 @@ void WX_HTML_REPORT_PANEL::Report( const wxString& aText, REPORTER::SEVERITY aSe line.severity = aSeverity; m_report.push_back( line ); - m_htmlView->AppendToPage( generateHtml( line ) ); + + m_html += generateHtml( line ); + + if( !m_lazyUpdate ) + { + m_htmlView->AppendToPage( generateHtml( line ) ); + scrollToBottom(); + } +} + + +void WX_HTML_REPORT_PANEL::SetLazyUpdate( bool aLazyUpdate ) +{ + m_lazyUpdate = aLazyUpdate; +} + + +void WX_HTML_REPORT_PANEL::Flush() +{ + m_htmlView->SetPage( m_html ); scrollToBottom(); } @@ -65,6 +85,7 @@ void WX_HTML_REPORT_PANEL::Report( const wxString& aText, REPORTER::SEVERITY aSe void WX_HTML_REPORT_PANEL::scrollToBottom() { int x, y, xUnit, yUnit; + m_htmlView->GetVirtualSize( &x, &y ); m_htmlView->GetScrollPixelsPerUnit( &xUnit, &yUnit ); m_htmlView->Scroll( 0, y / yUnit ); @@ -242,5 +263,12 @@ void WX_HTML_REPORT_PANEL::onBtnSaveToFile( wxCommandEvent& event ) void WX_HTML_REPORT_PANEL::Clear() { + m_html.clear(); m_report.clear(); } + + +void WX_HTML_REPORT_PANEL::SetLabel( const wxString& aLabel ) +{ + m_box->GetStaticBox()->SetLabel( aLabel ); +} diff --git a/common/dialogs/wx_html_report_panel.h b/common/dialogs/wx_html_report_panel.h index 953a49be03..6442cf3c3f 100644 --- a/common/dialogs/wx_html_report_panel.h +++ b/common/dialogs/wx_html_report_panel.h @@ -55,6 +55,24 @@ public: ///> clears the report panel void Clear(); + ///> sets the frame label + void SetLabel( const wxString& aLabel ); + + ///> Sets the lasy update. If this mode is on, messages are stored but the display + ///> is not updated (Updating display can be very time consumming if there are many messages) + ///> A call to Flush() will be needed after build the report + void SetLazyUpdate( bool aLazyUpdate ); + + ///> Forces updating the HTML page, after the report is built in lazy mode + void Flush(); + + void SetVisibleSeverities( int aSeverities ) + { + m_showAll = false; + m_severities = aSeverities; + syncCheckboxes(); + } + private: struct REPORT_LINE { @@ -91,6 +109,10 @@ private: ///> show all messages flag (overrides m_severities) bool m_showAll; + + wxString m_html; + + bool m_lazyUpdate; }; #endif //__WX_HTML_REPORT_PANEL_H__ diff --git a/common/dialogs/wx_html_report_panel_base.cpp b/common/dialogs/wx_html_report_panel_base.cpp index fc47a8d0b4..80be22c349 100644 --- a/common/dialogs/wx_html_report_panel_base.cpp +++ b/common/dialogs/wx_html_report_panel_base.cpp @@ -11,8 +11,7 @@ WX_HTML_REPORT_PANEL_BASE::WX_HTML_REPORT_PANEL_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) { - wxStaticBoxSizer* sbSizer3; - sbSizer3 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Messages:") ), wxVERTICAL ); + m_box = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Messages:") ), wxVERTICAL ); wxFlexGridSizer* fgSizer4; fgSizer4 = new wxFlexGridSizer( 2, 1, 0, 0 ); @@ -67,10 +66,10 @@ WX_HTML_REPORT_PANEL_BASE::WX_HTML_REPORT_PANEL_BASE( wxWindow* parent, wxWindow fgSizer4->Add( fgSizer3, 1, wxEXPAND, 5 ); - sbSizer3->Add( fgSizer4, 1, wxEXPAND|wxALL, 5 ); + m_box->Add( fgSizer4, 1, wxEXPAND|wxALL, 5 ); - this->SetSizer( sbSizer3 ); + this->SetSizer( m_box ); this->Layout(); // Connect Events diff --git a/common/dialogs/wx_html_report_panel_base.fbp b/common/dialogs/wx_html_report_panel_base.fbp index 0dc2fc1ac3..f707d9dddd 100644 --- a/common/dialogs/wx_html_report_panel_base.fbp +++ b/common/dialogs/wx_html_report_panel_base.fbp @@ -82,9 +82,9 @@ wxID_ANY Messages: - sbSizer3 + m_box wxVERTICAL - none + protected 5 diff --git a/common/dialogs/wx_html_report_panel_base.h b/common/dialogs/wx_html_report_panel_base.h index 3db31f387d..240b08f934 100644 --- a/common/dialogs/wx_html_report_panel_base.h +++ b/common/dialogs/wx_html_report_panel_base.h @@ -34,6 +34,7 @@ class WX_HTML_REPORT_PANEL_BASE : public wxPanel private: protected: + wxStaticBoxSizer* m_box; wxHtmlWindow* m_htmlView; wxStaticText* m_staticText3; wxCheckBox* m_checkBoxShowAll; diff --git a/common/reporter.cpp b/common/reporter.cpp index fa641609a7..2efc475834 100644 --- a/common/reporter.cpp +++ b/common/reporter.cpp @@ -62,3 +62,20 @@ REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSever m_panel->Report( aText, aSeverity ); return *this; } + +REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity ) +{ + return *this; +} + +REPORTER& NULL_REPORTER::GetInstance() +{ + static REPORTER* s_nullReporter = NULL; + + if( !s_nullReporter ) + { + s_nullReporter = new NULL_REPORTER(); + } + + return *s_nullReporter; +} diff --git a/include/reporter.h b/include/reporter.h index 117e56f6db..47fc17fdd6 100644 --- a/include/reporter.h +++ b/include/reporter.h @@ -147,4 +147,22 @@ public: REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ); }; +/** + * Class NULL_REPORTER + * + * A singleton reporter that reports to nowhere. Used as to simplify code by + * avoiding the reportee to check for a non-NULL reporter object. + */ +class NULL_REPORTER : public REPORTER +{ + public: + NULL_REPORTER() + { + }; + + static REPORTER& GetInstance(); + + REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ); +}; + #endif // _REPORTER_H_