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