display all log data on load

This commit is contained in:
Stojce Slavkovski 2013-12-17 03:07:57 +01:00
parent 5a27ded669
commit cc6f7ed4cc
7 changed files with 29 additions and 13 deletions

View file

@ -87,7 +87,7 @@ const float MIRROR_REARVIEW_BODY_DISTANCE = 1.f;
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
fprintf(stdout, "%s", message.toLocal8Bit().constData());
Menu::getInstance()->appendLogLine(message.toLocal8Bit().constData());
LogDisplay::instance.addMessage(message.toLocal8Bit().constData());
}
Application::Application(int& argc, char** argv, timeval &startup_time) :
@ -153,9 +153,10 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
QFontDatabase::addApplicationFont(resourcesPath + "/styles/Inconsolata.otf");
_window->setWindowTitle("Interface");
qInstallMessageHandler(messageHandler);
// call Menu getInstance static method to set up the menu
_window->setMenuBar(Menu::getInstance());
qInstallMessageHandler(messageHandler);
qDebug( "[VERSION] Build sequence: %i", BUILD_VERSION);

View file

@ -90,6 +90,7 @@ void LogDisplay::setCharacterSize(unsigned width, unsigned height) {
void LogDisplay::addMessage(const char* ptr) {
emit logReceived(ptr);
pthread_mutex_lock(& _mutex);
// T-pipe, if requested

View file

@ -14,7 +14,8 @@
#include "ui/TextRenderer.h"
class LogDisplay {
class LogDisplay : public QObject {
Q_OBJECT
public:
static LogDisplay instance;
@ -43,6 +44,12 @@ public:
static unsigned const LINE_BUFFER_SIZE = 256; // number of lines that are buffered
static unsigned const MAX_MESSAGE_LENGTH = 512; // maximum number of characters for a message
char** getLogData() { return _lines; };
char** getLastLinePos() { return _lastLinePos; }
signals:
void logReceived(QString message);
private:
// use static 'instance' to access the single instance
LogDisplay();

View file

@ -1014,12 +1014,6 @@ void Menu::pasteToVoxel() {
sendFakeEnterEvent();
}
void Menu::appendLogLine(QString logLine) {
if (_logDialog) {
_logDialog->appendLogLine(logLine);
}
}
void Menu::showLogDialog() {
if (! _logDialog) {
_logDialog = new LogDialog(Application::getInstance()->getGLWidget());

View file

@ -49,7 +49,6 @@ public:
void triggerOption(const QString& menuOption);
QAction* getActionForOption(const QString& menuOption);
bool isVoxelModeActionChecked();
void appendLogLine(QString logLine);
float getAudioJitterBufferSamples() const { return _audioJitterBufferSamples; }
float getFieldOfView() const { return _fieldOfView; }

View file

@ -12,6 +12,7 @@
#include "SharedUtil.h"
#include "ui/LogDialog.h"
#include "LogDisplay.h"
#define INITIAL_WIDTH_RATIO 0.3
#define INITIAL_HEIGHT_RATIO 0.6
@ -37,7 +38,7 @@ LogDialog::LogDialog(QWidget* parent) :
QDesktopWidget* desktop = new QDesktopWidget();
QRect screen = desktop->screenGeometry();
resize((int)(screen.width() * INITIAL_WIDTH_RATIO), (int)(screen.height() * INITIAL_HEIGHT_RATIO));
resize(static_cast<int>(screen.width() * INITIAL_WIDTH_RATIO), static_cast<int>(screen.height() * INITIAL_HEIGHT_RATIO));
move(screen.center() - rect().center());
delete desktop;
}
@ -49,6 +50,18 @@ LogDialog::~LogDialog() {
void LogDialog::showEvent(QShowEvent *e) {
_logTextBox->clear();
pthread_mutex_lock(& _mutex);
char** _lines = LogDisplay::instance.getLogData();
char** _lastLinePos = LogDisplay::instance.getLastLinePos();
int i = 0;
while (_lines[i] != *_lastLinePos) {
appendLogLine(_lines[i]);
i++;
}
connect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine);
pthread_mutex_unlock(& _mutex);
}
void LogDialog::resizeEvent(QResizeEvent *e) {
@ -63,7 +76,7 @@ void LogDialog::appendLogLine(QString logLine) {
}
void LogDialog::reject() {
this->QDialog::close();
close();
}
void LogDialog::closeEvent(QCloseEvent* event) {

View file

@ -18,13 +18,13 @@ class LogDialog : public QDialog {
public:
LogDialog(QWidget* parent);
~LogDialog();
void appendLogLine(QString logLine);
signals:
void closed();
public slots:
void reject();
void appendLogLine(QString logLine);
protected:
// Emits a 'closed' signal when this dialog is closed.
@ -34,6 +34,7 @@ protected:
private:
QPlainTextEdit* _logTextBox;
pthread_mutex_t _mutex;
};