Commit b96798a3 authored by Jan Möbius's avatar Jan Möbius

More speeeed ... modify logger to limit redraws to 500 msec updates

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8407 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 61bfeff6
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
#include <math.h> #include <math.h>
LoggerWidget::LoggerWidget( QWidget *parent) LoggerWidget::LoggerWidget( QWidget *parent)
: QWidget(parent) : QWidget(parent),
newData_(true)
{ {
QVBoxLayout* vlayout = new QVBoxLayout(); QVBoxLayout* vlayout = new QVBoxLayout();
QHBoxLayout* hlayout = new QHBoxLayout(); QHBoxLayout* hlayout = new QHBoxLayout();
...@@ -84,6 +85,11 @@ LoggerWidget::LoggerWidget( QWidget *parent) ...@@ -84,6 +85,11 @@ LoggerWidget::LoggerWidget( QWidget *parent)
connect (scrollBar_, SIGNAL(valueChanged(int)), this, SLOT(scrollTo(int))); connect (scrollBar_, SIGNAL(valueChanged(int)), this, SLOT(scrollTo(int)));
connect (list_->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(mapScrollPosition(int))); connect (list_->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(mapScrollPosition(int)));
connect (&loggerUpdateTimer_, SIGNAL(timeout ()), this, SLOT(slotScrollUpdate()));
// Single shot timer every 500 msecs
loggerUpdateTimer_.setSingleShot(true);
loggerUpdateTimer_.setInterval(500);
hlayout2->addWidget(list_); hlayout2->addWidget(list_);
hlayout2->addWidget(scrollBar_); hlayout2->addWidget(scrollBar_);
...@@ -167,9 +173,6 @@ void LoggerWidget::scrollTo(int _pos){ ...@@ -167,9 +173,6 @@ void LoggerWidget::scrollTo(int _pos){
/// Append a new logmessage to log viewer /// Append a new logmessage to log viewer
void LoggerWidget::append(QString _text, Logtype _type){ void LoggerWidget::append(QString _text, Logtype _type){
QTime time;
time.start();
list_->addItem(_text); list_->addItem(_text);
QListWidgetItem* item = list_->item( list_->count()-1 ); QListWidgetItem* item = list_->item( list_->count()-1 );
...@@ -206,8 +209,44 @@ void LoggerWidget::append(QString _text, Logtype _type){ ...@@ -206,8 +209,44 @@ void LoggerWidget::append(QString _text, Logtype _type){
break; break;
} }
if ( !isHidden() ) // If the logger is hidden, we just ignore the update ... done by showEvent later
if ( isHidden() )
return;
// Remember that we have new logs to show
newData_ = true;
// Check if we already have a running timer.
// If so, the timeout of that timer will trigger the redraw.
// Otherwise, we redraw and start the timer to block concurrent redraws.
// Only if new data is available, the redraw at the timers timeout will be done.
if ( ! loggerUpdateTimer_.isActive() ) {
// Update the logger
list_->scrollToBottom();
// Remember that there is no new data now.
// This might change again on a call to this function, while the timer is active.
newData_ = false;
// start the timer
loggerUpdateTimer_.start();
}
}
//-------------------------------------------------------------------------------------
void LoggerWidget::slotScrollUpdate() {
// If the logger is hidden, we just ignore this event
if ( isHidden() )
return;
// If there is data to show, do it.
if ( newData_ ) {
list_->scrollToBottom(); list_->scrollToBottom();
newData_ = false;
}
} }
......
...@@ -106,6 +106,11 @@ class LoggerWidget : public QWidget ...@@ -106,6 +106,11 @@ class LoggerWidget : public QWidget
QMenu* context_; QMenu* context_;
QTimer loggerUpdateTimer_;
// true if new data is available
bool newData_;
private slots: private slots:
/// update the list if a button was pressed /// update the list if a button was pressed
void updateList(); void updateList();
...@@ -114,8 +119,11 @@ class LoggerWidget : public QWidget ...@@ -114,8 +119,11 @@ class LoggerWidget : public QWidget
void scrollTo(int _pos); void scrollTo(int _pos);
/// map scroll position of list to scrollbar position /// map scroll position of list to scrollbar position
void mapScrollPosition(int _pos); void mapScrollPosition(int _pos);
///copy Selected rows to clipboard /// copy Selected rows to clipboard
void copySelected(); void copySelected();
/// Called when we want to scroll to the bottom
void slotScrollUpdate();
}; };
#endif //LOGGERWIDGET_HH #endif //LOGGERWIDGET_HH
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment