* ./hurricane/src/viewer:
- New: In ExceptionWidget, mimic more closely the behavior of a QDialog. Uses QTextEdit/QTextDocument for the trace. Static "all in one" methods, build from various exceptions/Errors & QString. Automatic window centering when the trace is displayed.
This commit is contained in:
parent
5273be039e
commit
b8e42d2efc
|
@ -127,7 +127,7 @@ namespace Hurricane {
|
||||||
ostringstream where;
|
ostringstream where;
|
||||||
|
|
||||||
for ( size_t depth=0 ; depth<_stack.size() ; ++depth )
|
for ( size_t depth=0 ; depth<_stack.size() ; ++depth )
|
||||||
where << "<tt>[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "</tt><br>\n";
|
where << "<tt>[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "</tt><br>";
|
||||||
|
|
||||||
return where.str();
|
return where.str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,20 @@
|
||||||
// x-----------------------------------------------------------------x
|
// x-----------------------------------------------------------------x
|
||||||
|
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
#include <memory>
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
#include <QTextEdit>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
#include "hurricane/Error.h"
|
||||||
#include "hurricane/Exception.h"
|
#include "hurricane/Exception.h"
|
||||||
#include "hurricane/viewer/Graphics.h"
|
#include "hurricane/viewer/Graphics.h"
|
||||||
#include "hurricane/viewer/ExceptionWidget.h"
|
#include "hurricane/viewer/ExceptionWidget.h"
|
||||||
|
@ -41,13 +44,39 @@
|
||||||
|
|
||||||
namespace Hurricane {
|
namespace Hurricane {
|
||||||
|
|
||||||
|
using std::auto_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
void ExceptionWidget::run ( Error& e )
|
||||||
|
{ run ( e.htmlWhat().c_str(), e.htmlWhere().c_str() ); }
|
||||||
|
|
||||||
|
|
||||||
|
void ExceptionWidget::run ( Exception& e )
|
||||||
|
{ run ( e.htmlWhat().c_str(), "" ); }
|
||||||
|
|
||||||
|
|
||||||
|
void ExceptionWidget::run ( exception& e )
|
||||||
|
{ run ( e.what() ); }
|
||||||
|
|
||||||
|
|
||||||
|
void ExceptionWidget::run ( const QString& what, const QString& where )
|
||||||
|
{
|
||||||
|
ExceptionWidget* ew = new ExceptionWidget();
|
||||||
|
|
||||||
|
ew->setMessage ( what );
|
||||||
|
if ( not where.isEmpty() )
|
||||||
|
ew->setTrace ( where );
|
||||||
|
|
||||||
|
if ( ew->exec() == QDialog::Rejected )
|
||||||
|
kill ( getpid(), SIGSEGV );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ExceptionWidget::ExceptionWidget ( QWidget* parent )
|
ExceptionWidget::ExceptionWidget ( QWidget* parent )
|
||||||
: QDialog (parent)
|
: QDialog (parent)
|
||||||
, _header (new QLabel())
|
, _header (new QLabel())
|
||||||
, _message (new QLabel())
|
, _message (new QLabel())
|
||||||
, _trace (new QLabel())
|
, _trace (new QTextEdit())
|
||||||
, _traceArea(new QScrollArea())
|
|
||||||
{
|
{
|
||||||
setAttribute ( Qt::WA_DeleteOnClose );
|
setAttribute ( Qt::WA_DeleteOnClose );
|
||||||
setModal ( true );
|
setModal ( true );
|
||||||
|
@ -61,15 +90,13 @@ namespace Hurricane {
|
||||||
_message->setTextFormat ( Qt::RichText );
|
_message->setTextFormat ( Qt::RichText );
|
||||||
_message->setText ( "<b>Oups! I did it again!</b>" );
|
_message->setText ( "<b>Oups! I did it again!</b>" );
|
||||||
|
|
||||||
_trace->setTextFormat ( Qt::RichText );
|
_trace->setTextInteractionFlags ( Qt::TextBrowserInteraction );
|
||||||
_trace->setText ( "<b>No program trace sets yet.</b>" );
|
_trace->setAcceptRichText ( true );
|
||||||
_trace->setSizePolicy ( QSizePolicy::Ignored, QSizePolicy::Ignored );
|
_trace->setHtml ( "<b>No program trace sets yet.</b>" );
|
||||||
|
_trace->setMinimumSize ( QSize(800,500) );
|
||||||
|
_trace->setLineWrapMode ( QTextEdit::NoWrap );
|
||||||
_traceArea->setWidget ( _trace );
|
//_trace->setSizePolicy ( QSizePolicy::Ignored, QSizePolicy::Ignored );
|
||||||
_traceArea->hide ();
|
_trace->hide ();
|
||||||
//_traceArea->setSizePolicy ( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) );
|
|
||||||
_traceArea->setMinimumSize ( QSize(700,500) );
|
|
||||||
|
|
||||||
QCheckBox* showTrace = new QCheckBox ();
|
QCheckBox* showTrace = new QCheckBox ();
|
||||||
showTrace->setText ( "Show Program Trace" );
|
showTrace->setText ( "Show Program Trace" );
|
||||||
|
@ -107,7 +134,7 @@ namespace Hurricane {
|
||||||
vLayout1->addWidget ( _message , 0, Qt::AlignLeft );
|
vLayout1->addWidget ( _message , 0, Qt::AlignLeft );
|
||||||
vLayout1->addWidget ( separator );
|
vLayout1->addWidget ( separator );
|
||||||
vLayout1->addWidget ( showTrace , 0, Qt::AlignLeft );
|
vLayout1->addWidget ( showTrace , 0, Qt::AlignLeft );
|
||||||
vLayout1->addWidget ( _traceArea, 0, Qt::AlignLeft );
|
vLayout1->addWidget ( _trace , 0, Qt::AlignLeft );
|
||||||
vLayout1->addSpacing ( 10 );
|
vLayout1->addSpacing ( 10 );
|
||||||
vLayout1->addLayout ( hLayout2 , Qt::AlignCenter );
|
vLayout1->addLayout ( hLayout2 , Qt::AlignCenter );
|
||||||
|
|
||||||
|
@ -128,9 +155,7 @@ namespace Hurricane {
|
||||||
|
|
||||||
|
|
||||||
void ExceptionWidget::closeEvent ( QCloseEvent* event )
|
void ExceptionWidget::closeEvent ( QCloseEvent* event )
|
||||||
{
|
{ event->ignore (); }
|
||||||
event->ignore ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExceptionWidget::setMessage ( const QString& message )
|
void ExceptionWidget::setMessage ( const QString& message )
|
||||||
|
@ -151,23 +176,15 @@ namespace Hurricane {
|
||||||
|
|
||||||
|
|
||||||
void ExceptionWidget::setTrace ( const QString& where )
|
void ExceptionWidget::setTrace ( const QString& where )
|
||||||
{
|
{ _trace->setHtml ( where ); }
|
||||||
QFont font = Graphics::getFixedFont(QFont::Bold);
|
|
||||||
QFontMetrics metrics = QFontMetrics ( font );
|
|
||||||
QSize textSize = metrics.size ( 0, where );
|
|
||||||
|
|
||||||
//textSize.setWidth ( textSize.width () / 2 );
|
|
||||||
textSize.setHeight ( textSize.height() + 70 );
|
|
||||||
|
|
||||||
_trace->setText ( where );
|
|
||||||
_trace->resize ( textSize );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ExceptionWidget::_showTrace ( int state )
|
void ExceptionWidget::_showTrace ( int state )
|
||||||
{
|
{
|
||||||
if ( state == Qt::Checked ) _traceArea->show ();
|
if ( state == Qt::Checked ) _trace->show ();
|
||||||
else _traceArea->hide ();
|
else _trace->hide ();
|
||||||
|
|
||||||
|
adjustPosition ( NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,8 @@
|
||||||
// x-----------------------------------------------------------------x
|
// x-----------------------------------------------------------------x
|
||||||
|
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "hurricane/Error.h"
|
#include "hurricane/Error.h"
|
||||||
#include "hurricane/viewer/Graphics.h"
|
#include "hurricane/viewer/Graphics.h"
|
||||||
#include "hurricane/viewer/ExceptionWidget.h"
|
#include "hurricane/viewer/ExceptionWidget.h"
|
||||||
|
@ -35,7 +33,6 @@
|
||||||
|
|
||||||
namespace Hurricane {
|
namespace Hurricane {
|
||||||
|
|
||||||
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::setw;
|
using std::setw;
|
||||||
|
@ -80,33 +77,19 @@ namespace Hurricane {
|
||||||
return QApplication::notify ( object, event );
|
return QApplication::notify ( object, event );
|
||||||
}
|
}
|
||||||
catch ( Error& e ) {
|
catch ( Error& e ) {
|
||||||
ExceptionWidget* ew = new ExceptionWidget ();
|
ExceptionWidget::run ( e );
|
||||||
ew->setMessage ( e.htmlWhat ().c_str() );
|
|
||||||
ew->setTrace ( e.htmlWhere().c_str() );
|
|
||||||
if ( ew->exec() == QDialog::Rejected )
|
|
||||||
kill ( getpid(), SIGSEGV );
|
|
||||||
}
|
}
|
||||||
catch ( Exception& e ) {
|
catch ( Exception& e ) {
|
||||||
ExceptionWidget* ew = new ExceptionWidget ();
|
ExceptionWidget::run ( e );
|
||||||
ew->setMessage ( e.htmlWhat().c_str() );
|
|
||||||
if ( ew->exec() == QDialog::Rejected )
|
|
||||||
kill ( getpid(), SIGSEGV );
|
|
||||||
}
|
}
|
||||||
catch ( exception& e ) {
|
catch ( exception& e ) {
|
||||||
ExceptionWidget* ew = new ExceptionWidget ();
|
|
||||||
ew->setMessage ( e.what() );
|
|
||||||
if ( ew->exec() == QDialog::Rejected )
|
|
||||||
kill ( getpid(), SIGSEGV );
|
|
||||||
}
|
}
|
||||||
catch ( ... ) {
|
catch ( ... ) {
|
||||||
static const char* message =
|
static const char* message =
|
||||||
" Unmanaged exception, neither a <b>Hurricane::Error</b><br>"
|
" Unmanaged exception, neither a <b>Hurricane::Error</b><br>"
|
||||||
"nor a <b>std::exception</b>.";
|
"nor a <b>std::exception</b>.";
|
||||||
|
|
||||||
ExceptionWidget* ew = new ExceptionWidget ();
|
ExceptionWidget::run ( message );
|
||||||
ew->setMessage ( message );
|
|
||||||
if ( ew->exec() == QDialog::Rejected )
|
|
||||||
kill ( getpid(), SIGSEGV );
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,17 +26,25 @@
|
||||||
#ifndef __HURRICANE_EXCEPTION_WIDGET__
|
#ifndef __HURRICANE_EXCEPTION_WIDGET__
|
||||||
#define __HURRICANE_EXCEPTION_WIDGET__
|
#define __HURRICANE_EXCEPTION_WIDGET__
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QScrollArea;
|
class QTextEdit;
|
||||||
|
|
||||||
|
|
||||||
namespace Hurricane {
|
namespace Hurricane {
|
||||||
|
|
||||||
|
class Error;
|
||||||
|
class Exception;
|
||||||
|
|
||||||
|
|
||||||
class ExceptionWidget : public QDialog {
|
class ExceptionWidget : public QDialog {
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
|
public:
|
||||||
|
static void run ( Error& );
|
||||||
|
static void run ( Exception& );
|
||||||
|
static void run ( std::exception& );
|
||||||
|
static void run ( const QString&, const QString& where="" );
|
||||||
public:
|
public:
|
||||||
ExceptionWidget ( QWidget* parent=NULL);
|
ExceptionWidget ( QWidget* parent=NULL);
|
||||||
void setMessage ( const QString& );
|
void setMessage ( const QString& );
|
||||||
|
@ -48,8 +56,7 @@ namespace Hurricane {
|
||||||
private:
|
private:
|
||||||
QLabel* _header;
|
QLabel* _header;
|
||||||
QLabel* _message;
|
QLabel* _message;
|
||||||
QLabel* _trace;
|
QTextEdit* _trace;
|
||||||
QScrollArea* _traceArea;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue