QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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 "moc_qgserrordialog.cpp"
19#include "qgssettings.h"
20
21#include <QMessageBox>
22
23QgsErrorDialog::QgsErrorDialog( const QgsError &error, const QString &title, QWidget *parent, Qt::WindowFlags fl )
24 : QDialog( parent, fl )
25 , mError( error )
26{
27 setupUi( this );
28 connect( mDetailPushButton, &QPushButton::clicked, this, &QgsErrorDialog::mDetailPushButton_clicked );
29 connect( mDetailCheckBox, &QCheckBox::stateChanged, this, &QgsErrorDialog::mDetailCheckBox_stateChanged );
30
31 if ( title.isEmpty() )
32 setWindowTitle( tr( "Error" ) );
33 else
34 setWindowTitle( title );
35
36 // QMessageBox has static standardIcon( Icon icon ), but it is marked as obsolete
37 const QMessageBox messageBox( QMessageBox::Critical, QString(), QString() );
38 mIconLabel->setPixmap( messageBox.iconPixmap() );
39 mSummaryTextBrowser->setOpenExternalLinks( true );
40 mDetailTextBrowser->setOpenExternalLinks( true );
41 mDetailTextBrowser->hide();
42
43 QPalette p = palette();
44 p.setColor( QPalette::Base, Qt::transparent );
45 mSummaryTextBrowser->setPalette( p );
46
47 mDetailCheckBox->hide();
48
49 mSummaryTextBrowser->setText( mError.summary() );
50 mDetailTextBrowser->setText( mError.message( QgsErrorMessage::Html ) );
51
52 resize( width(), 150 );
53
54 const QgsSettings settings;
55 const Qt::CheckState state = ( Qt::CheckState ) settings.value( QStringLiteral( "Error/dialog/detail" ), 0 ).toInt();
56 mDetailCheckBox->setCheckState( state );
57 if ( state == Qt::Checked )
58 mDetailPushButton_clicked();
59}
60
61void QgsErrorDialog::show( const QgsError &error, const QString &title, QWidget *parent, Qt::WindowFlags fl )
62{
63 QgsErrorDialog d( error, title, parent, fl );
64 d.exec();
65}
66
67void QgsErrorDialog::mDetailPushButton_clicked()
68{
69 mSummaryTextBrowser->hide();
70 mDetailTextBrowser->show();
71 mDetailCheckBox->show();
72 mDetailPushButton->hide();
73 resize( width(), 400 );
74}
75
76void QgsErrorDialog::mDetailCheckBox_stateChanged( int state )
77{
78 QgsSettings settings;
79 settings.setValue( QStringLiteral( "Error/dialog/detail" ), state );
80}
81
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.
A container for error messages.
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
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.