diff --git a/hurricane/src/hurricane/Backtrace.cpp b/hurricane/src/hurricane/Backtrace.cpp index b1bd9080..13e9425c 100644 --- a/hurricane/src/hurricane/Backtrace.cpp +++ b/hurricane/src/hurricane/Backtrace.cpp @@ -127,7 +127,7 @@ namespace Hurricane { ostringstream where; for ( size_t depth=0 ; depth<_stack.size() ; ++depth ) - where << "[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "
\n"; + where << "[" << setw(2) << setfill('0') << depth << "] " << _stack[depth] << "
"; return where.str(); } diff --git a/hurricane/src/viewer/ExceptionWidget.cpp b/hurricane/src/viewer/ExceptionWidget.cpp index 66a53935..2a707dc3 100644 --- a/hurricane/src/viewer/ExceptionWidget.cpp +++ b/hurricane/src/viewer/ExceptionWidget.cpp @@ -23,17 +23,20 @@ // x-----------------------------------------------------------------x +#include +#include #include #include #include #include +#include #include #include #include #include #include #include - +#include "hurricane/Error.h" #include "hurricane/Exception.h" #include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/ExceptionWidget.h" @@ -41,13 +44,39 @@ 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 ) : QDialog (parent) , _header (new QLabel()) , _message (new QLabel()) - , _trace (new QLabel()) - , _traceArea(new QScrollArea()) + , _trace (new QTextEdit()) { setAttribute ( Qt::WA_DeleteOnClose ); setModal ( true ); @@ -61,15 +90,13 @@ namespace Hurricane { _message->setTextFormat ( Qt::RichText ); _message->setText ( "Oups! I did it again!" ); - _trace->setTextFormat ( Qt::RichText ); - _trace->setText ( "No program trace sets yet." ); - _trace->setSizePolicy ( QSizePolicy::Ignored, QSizePolicy::Ignored ); - - - _traceArea->setWidget ( _trace ); - _traceArea->hide (); - //_traceArea->setSizePolicy ( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ); - _traceArea->setMinimumSize ( QSize(700,500) ); + _trace->setTextInteractionFlags ( Qt::TextBrowserInteraction ); + _trace->setAcceptRichText ( true ); + _trace->setHtml ( "No program trace sets yet." ); + _trace->setMinimumSize ( QSize(800,500) ); + _trace->setLineWrapMode ( QTextEdit::NoWrap ); + //_trace->setSizePolicy ( QSizePolicy::Ignored, QSizePolicy::Ignored ); + _trace->hide (); QCheckBox* showTrace = new QCheckBox (); showTrace->setText ( "Show Program Trace" ); @@ -107,7 +134,7 @@ namespace Hurricane { vLayout1->addWidget ( _message , 0, Qt::AlignLeft ); vLayout1->addWidget ( separator ); vLayout1->addWidget ( showTrace , 0, Qt::AlignLeft ); - vLayout1->addWidget ( _traceArea, 0, Qt::AlignLeft ); + vLayout1->addWidget ( _trace , 0, Qt::AlignLeft ); vLayout1->addSpacing ( 10 ); vLayout1->addLayout ( hLayout2 , Qt::AlignCenter ); @@ -128,9 +155,7 @@ namespace Hurricane { void ExceptionWidget::closeEvent ( QCloseEvent* event ) - { - event->ignore (); - } + { event->ignore (); } void ExceptionWidget::setMessage ( const QString& message ) @@ -151,23 +176,15 @@ namespace Hurricane { void ExceptionWidget::setTrace ( const QString& 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 ); - } + { _trace->setHtml ( where ); } void ExceptionWidget::_showTrace ( int state ) { - if ( state == Qt::Checked ) _traceArea->show (); - else _traceArea->hide (); + if ( state == Qt::Checked ) _trace->show (); + else _trace->hide (); + + adjustPosition ( NULL ); } diff --git a/hurricane/src/viewer/HApplication.cpp b/hurricane/src/viewer/HApplication.cpp index 581178e0..1605a85e 100644 --- a/hurricane/src/viewer/HApplication.cpp +++ b/hurricane/src/viewer/HApplication.cpp @@ -23,10 +23,8 @@ // x-----------------------------------------------------------------x -#include #include #include - #include "hurricane/Error.h" #include "hurricane/viewer/Graphics.h" #include "hurricane/viewer/ExceptionWidget.h" @@ -35,7 +33,6 @@ namespace Hurricane { - using std::cerr; using std::endl; using std::setw; @@ -80,33 +77,19 @@ namespace Hurricane { return QApplication::notify ( object, event ); } catch ( Error& e ) { - ExceptionWidget* ew = new ExceptionWidget (); - ew->setMessage ( e.htmlWhat ().c_str() ); - ew->setTrace ( e.htmlWhere().c_str() ); - if ( ew->exec() == QDialog::Rejected ) - kill ( getpid(), SIGSEGV ); + ExceptionWidget::run ( e ); } catch ( Exception& e ) { - ExceptionWidget* ew = new ExceptionWidget (); - ew->setMessage ( e.htmlWhat().c_str() ); - if ( ew->exec() == QDialog::Rejected ) - kill ( getpid(), SIGSEGV ); + ExceptionWidget::run ( e ); } catch ( exception& e ) { - ExceptionWidget* ew = new ExceptionWidget (); - ew->setMessage ( e.what() ); - if ( ew->exec() == QDialog::Rejected ) - kill ( getpid(), SIGSEGV ); } catch ( ... ) { static const char* message = "  Unmanaged exception, neither a Hurricane::Error
" "nor a std::exception."; - ExceptionWidget* ew = new ExceptionWidget (); - ew->setMessage ( message ); - if ( ew->exec() == QDialog::Rejected ) - kill ( getpid(), SIGSEGV ); + ExceptionWidget::run ( message ); } return true; } diff --git a/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h b/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h index cce6af0a..aa57f2ad 100644 --- a/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h +++ b/hurricane/src/viewer/hurricane/viewer/ExceptionWidget.h @@ -26,17 +26,25 @@ #ifndef __HURRICANE_EXCEPTION_WIDGET__ #define __HURRICANE_EXCEPTION_WIDGET__ - +#include #include class QLabel; -class QScrollArea; +class QTextEdit; namespace Hurricane { + class Error; + class Exception; + class ExceptionWidget : public QDialog { 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: ExceptionWidget ( QWidget* parent=NULL); void setMessage ( const QString& ); @@ -48,8 +56,7 @@ namespace Hurricane { private: QLabel* _header; QLabel* _message; - QLabel* _trace; - QScrollArea* _traceArea; + QTextEdit* _trace; };