MERGE branch STM 325:449 into trunk

git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@450 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
matlabbe
2012-03-03 01:46:30 +00:00
parent c4aff5f20a
commit a2eb8bcab6
100 changed files with 76652 additions and 5164 deletions

View File

@@ -18,24 +18,42 @@
*/
#include "ConsoleWidget.h"
#include "ui_consoleWidget.h"
#include <utilite/ULogger.h>
#include <utilite/UEventsManager.h>
#include <QtGui/QMessageBox>
#include <QtGui/QTextCursor>
#include <QtCore/QTimer>
#define OLD_TIME 1000 //ms
#define MAXIMUM_ITEMS 100
namespace rtabmap {
ConsoleWidget::ConsoleWidget(QWidget * parent) :
QWidget(parent)
{
_ui.setupUi(this);
_ui = new Ui_consoleWidget();
_ui->setupUi(this);
UEventsManager::addHandler(this);
_ui->textEdit->document()->setMaximumBlockCount(MAXIMUM_ITEMS);
_textCursor = new QTextCursor(_ui->textEdit->document());
_ui->textEdit->setFontPointSize(10);
QPalette p(_ui->textEdit->palette());
p.setColor(QPalette::Base, Qt::black);
_ui->textEdit->setPalette(p);
_errorMessage = new QMessageBox(QMessageBox::Critical, tr("Fatal error occurred"), "", QMessageBox::Ok, this);
_errorMessageMutex.lock();
_time.start();
_timer.setSingleShot(true);
connect(_ui->pushButton_clear, SIGNAL(clicked()), _ui->textEdit, SLOT(clear()));
connect(this, SIGNAL(msgReceived(const QString &, int)), this, SLOT(appendMsg(const QString &, int)));
_ui.textEdit->document()->setMaximumBlockCount(100);
_ui.textEdit->setFontPointSize(10);
connect(&_timer, SIGNAL(timeout()), this, SLOT(flushConsole()));
}
ConsoleWidget::~ConsoleWidget()
{
delete _ui;
}
void ConsoleWidget::handleEvent(UEvent * anEvent)
@@ -44,12 +62,37 @@ void ConsoleWidget::handleEvent(UEvent * anEvent)
if(anEvent->getClassName().compare("ULogEvent") == 0)
{
ULogEvent * logEvent = (ULogEvent*)anEvent;
emit msgReceived(logEvent->getMsg().c_str(), logEvent->getCode());
_msgListMutex.lock();
_msgList.append(QPair<QString, int>(logEvent->getMsg().c_str(), logEvent->getCode()));
if(_msgList.size()>MAXIMUM_ITEMS)
{
_msgList.pop_front();
}
_msgListMutex.unlock();
if(_time.restart() < OLD_TIME)
{
if(logEvent->getCode() == ULogger::kFatal)
{
_timer.start(0);
}
else
{
_timer.start(OLD_TIME);
}
}
else
{
_timer.start(0);
}
if(logEvent->getCode() == ULogger::kFatal)
{
//The application will exit, so warn the user.
QMessageBox::critical(this, tr("Fatal error occurred"), tr("Error! :\n \"%1\"\nThe application will now exit...").arg(logEvent->getMsg().c_str()), QMessageBox::Ok);
//This thread will wait until the message box is closed...
// Assuming that error messages come from a different thread.
_errorMessageMutex.lock();
}
}
}
@@ -58,20 +101,48 @@ void ConsoleWidget::appendMsg(const QString & msg, int level)
switch(level)
{
case 0:
_ui.textEdit->setTextColor(Qt::darkGreen);
_ui->textEdit->setTextColor(Qt::darkGreen);
break;
case 2:
_ui.textEdit->setTextColor(Qt::darkYellow);
_ui->textEdit->setTextColor(Qt::yellow);
break;
case 3:
case 4:
_ui.textEdit->setTextColor(Qt::darkRed);
_ui->textEdit->setTextColor(Qt::red);
break;
default:
_ui.textEdit->setTextColor(Qt::black);
_ui->textEdit->setTextColor(Qt::white);
break;
}
_ui.textEdit->append(msg);
_ui->textEdit->append(msg);
if(level == ULogger::kFatal)
{
_textCursor->endEditBlock();
QTextCursor cursor = _ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
_ui->textEdit->setTextCursor(cursor);
//The application will exit, so warn the user.
_errorMessage->setText(tr("Description:\n\n%1\n\nThe application will now exit...").arg(msg));
_errorMessage->exec();
_errorMessageMutex.unlock();
}
}
void ConsoleWidget::flushConsole()
{
_msgListMutex.lock();
_textCursor->beginEditBlock();
for(int i=0; i<_msgList.size(); ++i)
{
appendMsg(_msgList[i].first, _msgList[i].second);
}
_textCursor->endEditBlock();
_msgList.clear();
_msgListMutex.unlock();
QTextCursor cursor = _ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
_ui->textEdit->setTextCursor(cursor);
}
}