QGIS API Documentation  2.99.0-Master (19b062c)
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 
21 QgsMessageViewer::QgsMessageViewer( QWidget *parent, Qt::WindowFlags fl, bool deleteOnClose )
22  : QDialog( parent, fl )
23 {
24  setupUi( this );
25  connect( checkBox, &QCheckBox::toggled, this, &QgsMessageViewer::checkBox_toggled );
26  if ( deleteOnClose )
27  {
28  setAttribute( Qt::WA_DeleteOnClose );
29  }
30  // Default state for the checkbox
31  setCheckBoxVisible( false );
32  setCheckBoxState( Qt::Unchecked );
33 
34  QgsSettings settings;
35  restoreGeometry( settings.value( QStringLiteral( "Windows/MessageViewer/geometry" ) ).toByteArray() );
36 }
37 
39 {
40  QgsSettings settings;
41  settings.setValue( QStringLiteral( "Windows/MessageViewer/geometry" ), saveGeometry() );
42 }
43 
44 void QgsMessageViewer::setMessageAsHtml( const QString &msg )
45 {
46  txtMessage->setHtml( msg );
47 }
48 
49 void QgsMessageViewer::setMessageAsPlainText( const QString &msg )
50 {
51  txtMessage->setPlainText( msg );
52 }
53 
54 void QgsMessageViewer::appendMessage( const QString &msg )
55 {
56  txtMessage->append( msg );
57 }
58 
59 
60 void QgsMessageViewer::setMessage( const QString &message, MessageType msgType )
61 {
62  if ( msgType == MessageHtml )
63  setMessageAsHtml( message );
64  else
65  setMessageAsPlainText( message );
66 }
67 
68 void QgsMessageViewer::showMessage( bool blocking )
69 {
70  if ( blocking )
71  {
72  QApplication::setOverrideCursor( Qt::ArrowCursor );
73  exec();
74  QApplication::restoreOverrideCursor();
75  }
76  else
77  {
78  show();
79  }
80 }
81 
82 void QgsMessageViewer::setTitle( const QString &title )
83 {
84  setWindowTitle( title );
85 }
86 
87 void QgsMessageViewer::setCheckBoxText( const QString &text )
88 {
89  checkBox->setText( text );
90 }
91 
93 {
94  checkBox->setVisible( visible );
95 }
96 
97 void QgsMessageViewer::setCheckBoxState( Qt::CheckState state )
98 {
99  checkBox->setCheckState( state );
100 }
101 
103 {
104  return checkBox->checkState();
105 }
106 
108 {
109  mCheckBoxQgsSettingsLabel = label;
110 }
111 
112 
113 void QgsMessageViewer::checkBox_toggled( bool toggled )
114 {
115  Q_UNUSED( toggled );
116  if ( !mCheckBoxQgsSettingsLabel.isEmpty() )
117  {
118  QgsSettings settings;
119  if ( checkBox->checkState() == Qt::Checked )
120  settings.setValue( mCheckBoxQgsSettingsLabel, false );
121  else
122  settings.setValue( mCheckBoxQgsSettingsLabel, true );
123  }
124 }
MessageType
message can be in plain text or in html format
This class is a composition of two QSettings instances:
Definition: qgssettings.h:55
Qt::CheckState checkBoxState()
virtual void setTitle(const QString &title) override
set title for the messages
void setMessageAsHtml(const QString &msg)
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void setCheckBoxState(Qt::CheckState state)
void setMessageAsPlainText(const QString &msg)
virtual void appendMessage(const QString &message) override
message to be appended to the current text
virtual void showMessage(bool blocking=true) override
display the message to the user and deletes itself
virtual void setMessage(const QString &message, MessageType msgType) override
set message, it won't be displayed until
void setCheckBoxText(const QString &text)
void setCheckBoxQgsSettingsLabel(const QString &label)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
QgsMessageViewer(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, bool deleteOnClose=true)
void setCheckBoxVisible(bool visible)