Add support for log messages. Show them inside the MdiArea

This commit is contained in:
2015-04-12 21:53:06 +01:00
parent dd5b694102
commit e63075119b
10 changed files with 90 additions and 53 deletions
+3 -2
View File
@@ -23,6 +23,7 @@
*/
#include <cstdio>
#include "PlaYUVerApp.h"
#include "ModulesHandle.h"
#include "PlaYUVerSubWindowHandle.h"
#include "VideoSubWindow.h"
@@ -296,7 +297,7 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf )
if( videoSubWindowList.size() == 0 )
{
qobject_cast<QMainWindow*>( m_pcParent )->statusBar()->showMessage( "Error! Module cannot be applied", 2000 );
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! Module cannot be applied", LOG_ERROR );
destroyModuleIf( pcCurrModuleIf );
return;
}
@@ -335,7 +336,7 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf )
if( !moduleCreated )
{
qobject_cast<QMainWindow*>( m_pcParent )->statusBar()->showMessage( "Error! Module cannot be applied", 2000 );
qobject_cast<PlaYUVerApp*>( m_pcParent )->printMessage( "Error! Module cannot be applied", LOG_ERROR );
destroyModuleIf( pcCurrModuleIf );
return;
}
+25 -17
View File
@@ -192,7 +192,7 @@ Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo )
{
if( !QFileInfo( fileName ).exists() )
{
statusBar()->showMessage( "File " + fileName + " do not exist!", 2000 );
printMessage( "File " + fileName + " do not exist!", LOG_ERROR );
return;
}
VideoSubWindow *videoSubWindow = PlaYUVerApp::findVideoStreamSubWindow( m_pcWindowHandle, fileName );
@@ -220,7 +220,7 @@ Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo )
if( opened )
{
statusBar()->showMessage( tr( "Loading file..." ) );
printMessage( "Loading file...", LOG_INFO );
m_pcWindowHandle->addSubWindow( videoSubWindow );
videoSubWindow->show();
@@ -236,7 +236,7 @@ Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo )
addStreamInfoToRecentList( videoSubWindow->getStreamInfo() );
statusBar()->showMessage( tr( "File loaded" ), 2000 );
printMessage( "File loaded", LOG_INFO );
m_cLastOpenPath = QFileInfo( fileName ).path();
}
else
@@ -249,8 +249,7 @@ Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo )
videoSubWindow->close();
QString warningMsg = "Cannot open file " + QFileInfo( fileName ).fileName() + " with the following error: \n" + msg;
QMessageBox::warning( this, QApplication::applicationName(), warningMsg );
statusBar()->showMessage( warningMsg, 2000 );
qDebug( ) << warningMsg;
printMessage( warningMsg, LOG_ERROR );
}
}
@@ -359,7 +358,7 @@ Void PlaYUVerApp::format()
{
QString warningMsg = "Cannot change format of " + QFileInfo( pcVideoSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" + msg;
QMessageBox::warning( this, QApplication::applicationName(), warningMsg );
statusBar()->showMessage( warningMsg, 2000 );
printMessage( warningMsg, LOG_ERROR );
qDebug( ) << warningMsg;
m_pcCurrentSubWindow->close();
}
@@ -402,9 +401,9 @@ Void PlaYUVerApp::loadAll()
{
if( m_pcCurrentVideoSubWindow )
{
statusBar()->showMessage( tr( "Loading file into memory ..." ) );
printMessage( "Loading file into memory...", LOG_INFO );
m_pcCurrentVideoSubWindow->loadAll();
statusBar()->showMessage( tr( "File loaded" ), 2000 );
printMessage( "File loaded", LOG_INFO );
}
}
@@ -553,16 +552,25 @@ Void PlaYUVerApp::update()
updateMenus();
}
Void PlaYUVerApp::updateStatusBar( const QString& statusBarString )
Void PlaYUVerApp::printMessage( const QString& msg )
{
if( !statusBarString.isEmpty() )
printMessage( msg, 0 );
}
Void PlaYUVerApp::printMessage( const QString& msg, UInt logLevel )
{
if( !msg.isEmpty() )
{
statusBar()->showMessage( statusBarString, 5000 );
}
else
{
statusBar()->showMessage( " " );
statusBar()->showMessage( msg, 5000 );
if( logLevel >= LOG_INFO )
{
m_pcWindowHandle->processLogMsg( msg );
}
}
// else
// {
// statusBar()->showMessage( " " );
// }
}
Void PlaYUVerApp::updateMenus()
@@ -855,9 +863,9 @@ Void PlaYUVerApp::createDockWidgets()
Void PlaYUVerApp::createStatusBar()
{
//! Warning: the following widget cannot change size too much
//! Warning: the following widget cannot change size too much
statusBar()->addPermanentWidget( m_appModuleVideo->createStatusBarMessage() );
statusBar()->showMessage( tr( "Ready" ) );
printMessage( "Ready!", LOG_INFO );
}
Void PlaYUVerApp::addStreamInfoToRecentList( PlaYUVerStreamInfo streamInfo )
+4 -1
View File
@@ -77,6 +77,10 @@ public:
Bool parseArgs( Int argc, Char *argv[] );
Void loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo = NULL );
public Q_SLOTS:
void printMessage( const QString& msg );
void printMessage( const QString& msg, UInt logLevel );
protected:
Void closeEvent( QCloseEvent *event );
@@ -114,7 +118,6 @@ private Q_SLOTS:
void update();
void updateZoomFactorSBox();
void updateStatusBar( const QString& );
private:
+24 -2
View File
@@ -22,8 +22,8 @@
* \brief Handle multiple sub-windows
*/
#include "PlaYUVerApp.h"
#include "PlaYUVerSubWindowHandle.h"
#include "PlaYUVerApp.h"
#include "PlaYUVerMdiSubWindow.h"
#include "SubWindowAbstract.h"
@@ -39,6 +39,14 @@ public:
{
setBackgroundRole( QPalette::Background );
}
Void appendLogMessage( const QString& msg )
{
m_acLogMessages.push_front( msg );
if( m_acLogMessages.size() > 5 )
m_acLogMessages.removeLast();
update();
}
protected:
void paintEvent( QPaintEvent *event )
{
@@ -49,9 +57,15 @@ protected:
int x = width() / 2 - pixFinalLogo.width() / 2;
int y = height() / 2 - pixFinalLogo.height() / 2;
painter.drawPixmap( x, y, pixFinalLogo );
// for( Int i = 0; i < m_acLogMessages.size(); i++ )
// {
// painter.drawText( 5, height() - 5 - i * 15, m_acLogMessages.at( i ) );
// }
// QPoint bottomLeftCorner( 0, viewport()->height() );
}
private:
QVector<QString> m_acLogMessages;
QPixmap m_pixmapLogo;
};
@@ -70,6 +84,14 @@ PlaYUVerSubWindowHandle::PlaYUVerSubWindowHandle( QWidget *parent ) :
setWindowMode( MDISUBWINDOWMODE );
}
Void PlaYUVerSubWindowHandle::processLogMsg( const QString& msg )
{
if( m_pcMdiArea )
{
m_pcMdiArea->appendLogMessage( msg );
}
}
Void PlaYUVerSubWindowHandle::resetWindowMode()
{
QList<SubWindowAbstract*> apcSubWindowList = m_apcSubWindowList;
@@ -198,7 +220,7 @@ Void PlaYUVerSubWindowHandle::addSubWindow( SubWindowAbstract *window, Qt::Windo
{
if( window )
{
connect( window, SIGNAL( updateStatusBar( const QString& ) ), m_pcApp, SLOT( updateStatusBar( const QString& ) ) );
connect( window, SIGNAL( updateStatusBar( const QString& ) ), m_pcApp, SLOT( printMessage( const QString& ) ) );
connect( window, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_pcApp, SLOT( updateZoomFactorSBox() ) );
if( m_iWindowMode == DETACHEDSUBWINDOWMODE )
{
+2
View File
@@ -48,6 +48,8 @@ Q_OBJECT
public:
PlaYUVerSubWindowHandle( QWidget *parent );
Void processLogMsg( const QString& msg );
Void addSubWindow( SubWindowAbstract *widget, Qt::WindowFlags flags = 0 );
SubWindowAbstract *activeSubWindow() const;
+1
View File
@@ -22,6 +22,7 @@
* \brief Class to handle video playback
*/
#include "PlaYUVerApp.h"
#include "VideoHandle.h"
#include "VideoSubWindow.h"
#include "PlaYUVerSubWindowHandle.h"
+8
View File
@@ -106,6 +106,14 @@ typedef UChar Byte;
// PlaYUVer definitions
// ====================================================================================================================
enum LOG_LEVEL
{
LOG_INFO = 1,
LOG_WARNINGS = 2,
LOG_RESULT = 3,
LOG_ERROR = 4,
};
enum YUVcomponent
{
LUMA = 0,
+1 -1
View File
@@ -84,7 +84,7 @@ Int CommandLineHandle::parseToolsArgs( Int argc, Char *argv[] )
if( m_bQuiet )
{
m_uiLogLevel = RESULT;
m_uiLogLevel = LOG_RESULT;
}
if( Opts()["module"]->count() && Opts()["help"]->count() )
-7
View File
@@ -42,13 +42,6 @@ public:
CommandLineHandle();
~CommandLineHandle();
enum LOG_LEVEL
{
INFO = 0,
WARNINGS = 1,
RESULT = 2,
ERROR = 3,
};
Void setLogLevel( enum LOG_LEVEL level )
{
m_uiLogLevel = level;
+22 -23
View File
@@ -81,14 +81,14 @@ Int PlaYUVerTools::openInputs()
{
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 8, 1 ) )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
return 2;
}
m_apcInputStreams.push_back( pcStream );
}
catch( const char *msg )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg );
m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg );
return 2;
}
}
@@ -134,7 +134,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
std::string qualityMetric = m_cCmdLineHandler.m_strQualityMetric;
// if( m_apcInputStreams.size() != 2 )
// {
// m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " );
// m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of inputs! " );
// return 2;
// }
for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ )
@@ -146,12 +146,12 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
if( m_uiQualityMetric == -1 )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid quality metric! " );
m_cCmdLineHandler.log( LOG_ERROR, "Invalid quality metric! " );
return 2;
}
m_uiOperation = QUALITY_OPERATION;
m_fpProcess = &PlaYUVerTools::QualityOperation;
m_cCmdLineHandler.log( CommandLineHandle::INFO, "PlaYUVer Quality\n" );
m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Quality\n" );
}
/**
@@ -174,7 +174,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
if( m_apcInputStreams.size() != m_pcCurrModuleIf->m_uiNumberOfFrames )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " );
m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of inputs! " );
return 2;
}
@@ -198,7 +198,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
if( !moduleCreated )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Module is not supported with the selected inputs! " );
m_cCmdLineHandler.log( LOG_ERROR, "Module is not supported with the selected inputs! " );
return 2;
}
@@ -231,19 +231,19 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
}
else
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "One output is required! " );
m_cCmdLineHandler.log( LOG_ERROR, "One output is required! " );
return 2;
}
}
m_uiOperation = MODULE_OPERATION;
m_fpProcess = &PlaYUVerTools::ModuleOperation;
m_cCmdLineHandler.log( CommandLineHandle::INFO, "PlaYUVer Module\n" );
m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Module\n" );
}
if( m_uiOperation == INVALID_OPERATION )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "No operation was selected! " );
m_cCmdLineHandler.log( LOG_ERROR, "No operation was selected! " );
return 2;
}
return iRet;
@@ -267,8 +267,7 @@ Int PlaYUVerTools::QualityOperation()
Double adAverageQuality[MAX_NUMBER_INPUTS - 1][MAX_NUMBER_COMPONENTS];
Double dQuality;
m_cCmdLineHandler.log( CommandLineHandle::INFO, " Measuring Quality using %s ... \n",
PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() );
m_cCmdLineHandler.log( LOG_INFO, " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
{
@@ -280,21 +279,21 @@ Int PlaYUVerTools::QualityOperation()
}
for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ )
{
m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame );
m_cCmdLineHandler.log( LOG_INFO, " %3d", frame );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
apcCurrFrame[s] = m_apcInputStreams[s]->getCurrFrame();
for( UInt s = 1; s < m_apcInputStreams.size(); s++ )
{
m_cCmdLineHandler.log( CommandLineHandle::RESULT, " " );
m_cCmdLineHandler.log( LOG_RESULT, " " );
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
dQuality = apcCurrFrame[s]->getQuality( m_uiQualityMetric, apcCurrFrame[0], c );
adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 );
m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %5.3f", dQuality );
m_cCmdLineHandler.log( LOG_RESULT, " %5.3f", dQuality );
}
}
m_cCmdLineHandler.log( CommandLineHandle::RESULT, "\n" );
m_cCmdLineHandler.log( LOG_RESULT, "\n" );
for( UInt s = 0; s < m_apcInputStreams.size(); s++ )
{
abEOF[s] = m_apcInputStreams[s]->setNextFrame();
@@ -304,15 +303,15 @@ Int PlaYUVerTools::QualityOperation()
}
}
}
m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n Mean Values: \n " );
m_cCmdLineHandler.log( LOG_INFO, "\n Mean Values: \n " );
for( UInt s = 0; s < m_apcInputStreams.size() - 1; s++ )
{
for( UInt c = 0; c < m_uiNumberOfComponents; c++ )
{
m_cCmdLineHandler.log( CommandLineHandle::INFO, " %5.3f", adAverageQuality[s][c] );
m_cCmdLineHandler.log( LOG_INFO, " %5.3f", adAverageQuality[s][c] );
}
}
m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n" );
m_cCmdLineHandler.log( LOG_INFO, "\n" );
return 0;
}
@@ -329,7 +328,7 @@ PlaYUVerFrame* PlaYUVerTools::applyFrameModule()
Int PlaYUVerTools::ModuleOperation()
{
std::vector<PlaYUVerFrame*> apcFrameList;
m_cCmdLineHandler.log( CommandLineHandle::INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName );
m_cCmdLineHandler.log( LOG_INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName );
PlaYUVerFrame* pcProcessedFrame = NULL;
Double dMeasurementResult = 0.0;
@@ -370,8 +369,8 @@ Int PlaYUVerTools::ModuleOperation()
{
dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() );
}
m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame );
m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %8.3f \n", dMeasurementResult );
m_cCmdLineHandler.log( LOG_INFO, " %3d", frame );
m_cCmdLineHandler.log( LOG_RESULT, " %8.3f \n", dMeasurementResult );
dAveragedMeasurementResult = ( dAveragedMeasurementResult * Double( frame ) + dMeasurementResult ) / Double( frame + 1 );
}
@@ -387,7 +386,7 @@ Int PlaYUVerTools::ModuleOperation()
if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE )
{
m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult );
m_cCmdLineHandler.log( LOG_INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult );
}
return 0;