QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgserrordialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgserrordialog.cpp - error description
3  -------------------
4  begin : October 2012
5  copyright : (C) October 2012 Radim Blazek
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include "qgserrordialog.h"
18 #include "qgssettings.h"
19 
20 #include <QMessageBox>
21 
22 QgsErrorDialog::QgsErrorDialog( const QgsError &error, const QString &title, QWidget *parent, Qt::WindowFlags fl )
23  : QDialog( parent, fl )
24  , mError( error )
25 {
26  setupUi( this );
27  connect( mDetailPushButton, &QPushButton::clicked, this, &QgsErrorDialog::mDetailPushButton_clicked );
28  connect( mDetailCheckBox, &QCheckBox::stateChanged, this, &QgsErrorDialog::mDetailCheckBox_stateChanged );
29 
30  if ( title.isEmpty() )
31  setWindowTitle( tr( "Error" ) );
32  else
33  setWindowTitle( title );
34 
35  // QMessageBox has static standardIcon( Icon icon ), but it is marked as obsolete
36  QMessageBox messageBox( QMessageBox::Critical, QString(), QString() );
37  mIconLabel->setPixmap( messageBox.iconPixmap() );
38  mSummaryTextBrowser->setOpenExternalLinks( true );
39  mDetailTextBrowser->setOpenExternalLinks( true );
40  mDetailTextBrowser->hide();
41 
42  QPalette p = palette();
43  p.setColor( QPalette::Base, Qt::transparent );
44  mSummaryTextBrowser->setPalette( p );
45 
46  mDetailCheckBox->hide();
47 
48  mSummaryTextBrowser->setText( mError.summary() );
49  mDetailTextBrowser->setText( mError.message( QgsErrorMessage::Html ) );
50 
51  resize( width(), 150 );
52 
53  QgsSettings settings;
54  Qt::CheckState state = ( Qt::CheckState ) settings.value( QStringLiteral( "Error/dialog/detail" ), 0 ).toInt();
55  mDetailCheckBox->setCheckState( state );
56  if ( state == Qt::Checked )
57  mDetailPushButton_clicked();
58 }
59 
60 void QgsErrorDialog::show( const QgsError &error, const QString &title, QWidget *parent, Qt::WindowFlags fl )
61 {
62  QgsErrorDialog d( error, title, parent, fl );
63  d.exec();
64 }
65 
66 void QgsErrorDialog::mDetailPushButton_clicked()
67 {
68  mSummaryTextBrowser->hide();
69  mDetailTextBrowser->show();
70  mDetailCheckBox->show();
71  mDetailPushButton->hide();
72  resize( width(), 400 );
73 }
74 
75 void QgsErrorDialog::mDetailCheckBox_stateChanged( int state )
76 {
77  QgsSettings settings;
78  settings.setValue( QStringLiteral( "Error/dialog/detail" ), state );
79 }
80 
QgsErrorDialog(const QgsError &error, const QString &title, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsErrorDialog.
static void show(const QgsError &error, const QString &title, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Show dialog with error.
QgsError is container for error messages (report).
Definition: qgserror.h:81
QString message(QgsErrorMessage::Format format=QgsErrorMessage::Html) const
Full error messages description.
Definition: qgserror.cpp:49
QString summary() const
Short error description, usually the first error in chain, the real error.
Definition: qgserror.cpp:129