QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsmessageviewer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmessageviewer.cpp - description
3  -------------------
4  begin : Wed Jun 4 2003
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.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 
18 #include "qgsmessageviewer.h"
19 #include "qgssettings.h"
20 #include "qgsgui.h"
21 
22 QgsMessageViewer::QgsMessageViewer( QWidget *parent, Qt::WindowFlags fl, bool deleteOnClose )
23  : QDialog( parent, fl )
24 {
25  setupUi( this );
27 
28  connect( checkBox, &QCheckBox::toggled, this, &QgsMessageViewer::checkBox_toggled );
29  if ( deleteOnClose )
30  {
31  setAttribute( Qt::WA_DeleteOnClose );
32  }
33  // Default state for the checkbox
34  setCheckBoxVisible( false );
35  setCheckBoxState( Qt::Unchecked );
36 
37  txtMessage->setTextInteractionFlags( Qt::TextBrowserInteraction );
38  txtMessage->setOpenExternalLinks( true );
39 }
40 
41 void QgsMessageViewer::setMessageAsHtml( const QString &msg )
42 {
43  txtMessage->setHtml( msg );
44 }
45 
46 void QgsMessageViewer::setMessageAsPlainText( const QString &msg )
47 {
48  txtMessage->setPlainText( msg );
49 }
50 
51 void QgsMessageViewer::appendMessage( const QString &msg )
52 {
53  txtMessage->append( msg );
54 }
55 
56 
57 void QgsMessageViewer::setMessage( const QString &message, MessageType msgType )
58 {
59  if ( msgType == MessageHtml )
60  setMessageAsHtml( message );
61  else
62  setMessageAsPlainText( message );
63 }
64 
65 void QgsMessageViewer::showMessage( bool blocking )
66 {
67  if ( blocking )
68  {
69  const QgsTemporaryCursorRestoreOverride override;
70  exec();
71  }
72  else
73  {
74  show();
75  }
76 }
77 
78 void QgsMessageViewer::setTitle( const QString &title )
79 {
80  setWindowTitle( title );
81 }
82 
83 void QgsMessageViewer::setCheckBoxText( const QString &text )
84 {
85  checkBox->setText( text );
86 }
87 
89 {
90  checkBox->setVisible( visible );
91 }
92 
93 void QgsMessageViewer::setCheckBoxState( Qt::CheckState state )
94 {
95  checkBox->setCheckState( state );
96 }
97 
99 {
100  return checkBox->checkState();
101 }
102 
104 {
105  mCheckBoxQgsSettingsLabel = label;
106 }
107 
108 
109 void QgsMessageViewer::checkBox_toggled( bool toggled )
110 {
111  Q_UNUSED( toggled )
112  if ( !mCheckBoxQgsSettingsLabel.isEmpty() )
113  {
114  QgsSettings settings;
115  if ( checkBox->checkState() == Qt::Checked )
116  settings.setValue( mCheckBoxQgsSettingsLabel, false );
117  else
118  settings.setValue( mCheckBoxQgsSettingsLabel, true );
119  }
120 }
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:168
MessageType
message can be in plain text or in html format
void setCheckBoxQgsSettingsLabel(const QString &label)
void setTitle(const QString &title) override
Sets title for the messages.
void setCheckBoxVisible(bool visible)
void setMessageAsPlainText(const QString &msg)
void setCheckBoxState(Qt::CheckState state)
void setMessage(const QString &message, MessageType msgType) override
Sets message, it won't be displayed until.
void showMessage(bool blocking=true) override
display the message to the user and deletes itself
void setMessageAsHtml(const QString &msg)
QgsMessageViewer(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, bool deleteOnClose=true)
void setCheckBoxText(const QString &text)
Qt::CheckState checkBoxState()
void appendMessage(const QString &message) override
message to be appended to the current text
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Temporarily removes all cursor overrides for the QApplication for the lifetime of the object.
Definition: qgsguiutils.h:253