QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  {
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 }
QgsMessageViewer::appendMessage
void appendMessage(const QString &message) override
message to be appended to the current text
Definition: qgsmessageviewer.cpp:51
QgsMessageViewer::setCheckBoxVisible
void setCheckBoxVisible(bool visible)
Definition: qgsmessageviewer.cpp:88
QgsMessageViewer::setCheckBoxState
void setCheckBoxState(Qt::CheckState state)
Definition: qgsmessageviewer.cpp:93
qgsgui.h
QgsMessageViewer::checkBoxState
Qt::CheckState checkBoxState()
Definition: qgsmessageviewer.cpp:98
QgsMessageViewer::setMessageAsPlainText
void setMessageAsPlainText(const QString &msg)
Definition: qgsmessageviewer.cpp:46
QgsMessageViewer::setTitle
void setTitle(const QString &title) override
Sets title for the messages.
Definition: qgsmessageviewer.cpp:78
QgsMessageViewer::setMessageAsHtml
void setMessageAsHtml(const QString &msg)
Definition: qgsmessageviewer.cpp:41
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QgsMessageViewer::QgsMessageViewer
QgsMessageViewer(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, bool deleteOnClose=true)
Definition: qgsmessageviewer.cpp:22
QgsGui::enableAutoGeometryRestore
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:139
QgsMessageViewer::setCheckBoxQgsSettingsLabel
void setCheckBoxQgsSettingsLabel(const QString &label)
Definition: qgsmessageviewer.cpp:103
qgsmessageviewer.h
QgsMessageViewer::setMessage
void setMessage(const QString &message, MessageType msgType) override
Sets message, it won't be displayed until.
Definition: qgsmessageviewer.cpp:57
QgsSettings::setValue
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Definition: qgssettings.cpp:289
QgsMessageOutput::MessageType
MessageType
message can be in plain text or in html format
Definition: qgsmessageoutput.h:47
qgssettings.h
QgsMessageOutput::MessageHtml
@ MessageHtml
Definition: qgsmessageoutput.h:47
QgsMessageViewer::showMessage
void showMessage(bool blocking=true) override
display the message to the user and deletes itself
Definition: qgsmessageviewer.cpp:65
QgsTemporaryCursorRestoreOverride
Temporarily removes all cursor overrides for the QApplication for the lifetime of the object.
Definition: qgsguiutils.h:254
QgsMessageViewer::setCheckBoxText
void setCheckBoxText(const QString &text)
Definition: qgsmessageviewer.cpp:83