[libcalamaresui] Polish on LogWidget
- apply coding style - reduce shadowed variables - use Q_EMIT to mark signals
This commit is contained in:
parent
d89955f4b3
commit
1a6fb1c3d2
@ -27,17 +27,17 @@
|
||||
#include "utils/Retranslator.h"
|
||||
#include "widgets/LogWidget.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
#include <QToolButton>
|
||||
#include <QTabWidget>
|
||||
#include <QDir>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QProgressBar>
|
||||
#include <QTabBar>
|
||||
#include <QTabWidget>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
static Calamares::Slideshow*
|
||||
makeSlideshow( QWidget* parent )
|
||||
@ -81,8 +81,8 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent )
|
||||
|
||||
m_progressBar->setMaximum( 10000 );
|
||||
|
||||
m_tab_widget->addTab(m_slideshow->widget(), "Slideshow");
|
||||
m_tab_widget->addTab(m_log_widget, "Log");
|
||||
m_tab_widget->addTab( m_slideshow->widget(), "Slideshow" );
|
||||
m_tab_widget->addTab( m_log_widget, "Log" );
|
||||
m_tab_widget->tabBar()->hide();
|
||||
|
||||
layout->addWidget( m_tab_widget );
|
||||
@ -94,13 +94,13 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent )
|
||||
bottomLayout->addWidget( m_label );
|
||||
|
||||
QToolBar* toolBar = new QToolBar;
|
||||
auto toggleLogAction = toolBar->addAction(QIcon::fromTheme("utilities-terminal"), "Toggle log");
|
||||
auto toggleLogButton = dynamic_cast<QToolButton*>(toolBar->widgetForAction(toggleLogAction));
|
||||
auto toggleLogAction = toolBar->addAction( QIcon::fromTheme( "utilities-terminal" ), "Toggle log" );
|
||||
auto toggleLogButton = dynamic_cast< QToolButton* >( toolBar->widgetForAction( toggleLogAction ) );
|
||||
connect( toggleLogButton, &QToolButton::clicked, this, &ExecutionViewStep::toggleLog );
|
||||
|
||||
|
||||
barLayout->addWidget(m_progressBar);
|
||||
barLayout->addWidget(toolBar);
|
||||
barLayout->addWidget( m_progressBar );
|
||||
barLayout->addWidget( toolBar );
|
||||
|
||||
|
||||
connect( JobQueue::instance(), &JobQueue::progress, this, &ExecutionViewStep::updateFromJobQueue );
|
||||
@ -176,7 +176,7 @@ ExecutionViewStep::onActivate()
|
||||
const auto instanceDescriptor
|
||||
= std::find_if( instanceDescriptors.constBegin(),
|
||||
instanceDescriptors.constEnd(),
|
||||
[=]( const Calamares::InstanceDescription& d ) { return d.key() == instanceKey; } );
|
||||
[ = ]( const Calamares::InstanceDescription& d ) { return d.key() == instanceKey; } );
|
||||
int weight = moduleDescriptor.weight();
|
||||
if ( instanceDescriptor != instanceDescriptors.constEnd() && instanceDescriptor->explicitWeight() )
|
||||
{
|
||||
@ -228,7 +228,7 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message )
|
||||
void
|
||||
ExecutionViewStep::toggleLog()
|
||||
{
|
||||
m_tab_widget->setCurrentIndex((m_tab_widget->currentIndex() + 1) % m_tab_widget->count());
|
||||
m_tab_widget->setCurrentIndex( ( m_tab_widget->currentIndex() + 1 ) % m_tab_widget->count() );
|
||||
}
|
||||
|
||||
void
|
||||
@ -239,4 +239,3 @@ ExecutionViewStep::onLeave()
|
||||
|
||||
|
||||
} // namespace Calamares
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
#include "LogWidget.h"
|
||||
#include <QStackedLayout>
|
||||
#include "utils/Logger.h"
|
||||
#include <QFile>
|
||||
#include <QStackedLayout>
|
||||
#include <QTextStream>
|
||||
#include <QThread>
|
||||
#include <QFile>
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
LogThread::LogThread(QObject *parent)
|
||||
: QThread(parent) {
|
||||
|
||||
LogThread::LogThread( QObject* parent )
|
||||
: QThread( parent )
|
||||
{
|
||||
}
|
||||
|
||||
LogThread::~LogThread()
|
||||
@ -20,63 +20,65 @@ LogThread::~LogThread()
|
||||
wait();
|
||||
}
|
||||
|
||||
void LogThread::run()
|
||||
void
|
||||
LogThread::run()
|
||||
{
|
||||
auto filePath = Logger::logFile();
|
||||
const auto filePath = Logger::logFile();
|
||||
|
||||
qint64 lastPosition = 0;
|
||||
|
||||
while (!QThread::currentThread()->isInterruptionRequested()) {
|
||||
auto filePath = Logger::logFile();
|
||||
QFile file(filePath);
|
||||
while ( !QThread::currentThread()->isInterruptionRequested() )
|
||||
{
|
||||
QFile file( filePath );
|
||||
|
||||
qint64 fileSize = file.size();
|
||||
// Check whether the file size has changed since last time
|
||||
// we read the file.
|
||||
if (lastPosition != fileSize && file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
if ( lastPosition != fileSize && file.open( QFile::ReadOnly | QFile::Text ) )
|
||||
{
|
||||
|
||||
// Start reading at the position we ended up last time we read the file.
|
||||
file.seek(lastPosition);
|
||||
file.seek( lastPosition );
|
||||
|
||||
QTextStream in(&file);
|
||||
QTextStream in( &file );
|
||||
auto chunk = in.readAll();
|
||||
qint64 newPosition = in.pos();
|
||||
|
||||
lastPosition = newPosition;
|
||||
|
||||
onLogChunk(chunk);
|
||||
Q_EMIT onLogChunk( chunk );
|
||||
}
|
||||
QThread::msleep(100);
|
||||
QThread::msleep( 100 );
|
||||
}
|
||||
}
|
||||
|
||||
LogWidget::LogWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
LogWidget::LogWidget( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, m_text( new QPlainTextEdit )
|
||||
, m_log_thread( this )
|
||||
{
|
||||
auto layout = new QStackedLayout(this);
|
||||
setLayout(layout);
|
||||
auto layout = new QStackedLayout( this );
|
||||
setLayout( layout );
|
||||
|
||||
m_text->setReadOnly(true);
|
||||
m_text->setReadOnly( true );
|
||||
|
||||
QFont monospaceFont("monospace");
|
||||
monospaceFont.setStyleHint(QFont::Monospace);
|
||||
m_text->setFont(monospaceFont);
|
||||
QFont monospaceFont( "monospace" );
|
||||
monospaceFont.setStyleHint( QFont::Monospace );
|
||||
m_text->setFont( monospaceFont );
|
||||
|
||||
layout->addWidget(m_text);
|
||||
layout->addWidget( m_text );
|
||||
|
||||
connect(&m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk);
|
||||
connect( &m_log_thread, &LogThread::onLogChunk, this, &LogWidget::handleLogChunk );
|
||||
|
||||
m_log_thread.start();
|
||||
}
|
||||
|
||||
void
|
||||
LogWidget::handleLogChunk(const QString &logChunk)
|
||||
LogWidget::handleLogChunk( const QString& logChunk )
|
||||
{
|
||||
m_text->appendPlainText(logChunk);
|
||||
m_text->moveCursor(QTextCursor::End);
|
||||
m_text->appendPlainText( logChunk );
|
||||
m_text->moveCursor( QTextCursor::End );
|
||||
m_text->ensureCursorVisible();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Calamares
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef LIBCALAMARESUI_LOGWIDGET_H
|
||||
#define LIBCALAMARESUI_LOGWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QThread>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
@ -15,11 +15,11 @@ class LogThread : public QThread
|
||||
void run() override;
|
||||
|
||||
public:
|
||||
explicit LogThread(QObject *parent = nullptr);
|
||||
explicit LogThread( QObject* parent = nullptr );
|
||||
~LogThread() override;
|
||||
|
||||
signals:
|
||||
void onLogChunk(const QString &logChunk);
|
||||
void onLogChunk( const QString& logChunk );
|
||||
};
|
||||
|
||||
class LogWidget : public QWidget
|
||||
@ -28,11 +28,12 @@ class LogWidget : public QWidget
|
||||
|
||||
QPlainTextEdit* m_text;
|
||||
LogThread m_log_thread;
|
||||
public:
|
||||
explicit LogWidget(QWidget *parent = nullptr);
|
||||
|
||||
void handleLogChunk(const QString &logChunk);
|
||||
public:
|
||||
explicit LogWidget( QWidget* parent = nullptr );
|
||||
|
||||
void handleLogChunk( const QString& logChunk );
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Calamares
|
||||
#endif // LOGWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user