QGIS API Documentation  3.13.0-Master (5a3b1ced84)
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  QApplication::setOverrideCursor( Qt::ArrowCursor );
70  exec();
71  QApplication::restoreOverrideCursor();
72  }
73  else
74  {
75  show();
76  }
77 }
78 
79 void QgsMessageViewer::setTitle( const QString &title )
80 {
81  setWindowTitle( title );
82 }
83 
84 void QgsMessageViewer::setCheckBoxText( const QString &text )
85 {
86  checkBox->setText( text );
87 }
88 
90 {
91  checkBox->setVisible( visible );
92 }
93 
94 void QgsMessageViewer::setCheckBoxState( Qt::CheckState state )
95 {
96  checkBox->setCheckState( state );
97 }
98 
100 {
101  return checkBox->checkState();
102 }
103 
105 {
106  mCheckBoxQgsSettingsLabel = label;
107 }
108 
109 
110 void QgsMessageViewer::checkBox_toggled( bool toggled )
111 {
112  Q_UNUSED( toggled )
113  if ( !mCheckBoxQgsSettingsLabel.isEmpty() )
114  {
115  QgsSettings settings;
116  if ( checkBox->checkState() == Qt::Checked )
117  settings.setValue( mCheckBoxQgsSettingsLabel, false );
118  else
119  settings.setValue( mCheckBoxQgsSettingsLabel, true );
120  }
121 }
MessageType
message can be in plain text or in html format
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
Qt::CheckState checkBoxState()
void setTitle(const QString &title) override
Sets title for the messages.
void setMessageAsHtml(const QString &msg)
void setCheckBoxState(Qt::CheckState state)
void setMessageAsPlainText(const QString &msg)
void appendMessage(const QString &message) override
message to be appended to the current text
void showMessage(bool blocking=true) override
display the message to the user and deletes itself
void setMessage(const QString &message, MessageType msgType) override
Sets message, it won't be displayed until.
void setCheckBoxText(const QString &text)
void setCheckBoxQgsSettingsLabel(const QString &label)
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsMessageViewer(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, bool deleteOnClose=true)
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:133
void setCheckBoxVisible(bool visible)