QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 <QSettings>
20 
21 QgsMessageViewer::QgsMessageViewer( QWidget *parent, const Qt::WindowFlags& fl, bool deleteOnClose )
22  : QDialog( parent, fl )
23 {
24  setupUi( this );
25  if ( deleteOnClose )
26  {
27  setAttribute( Qt::WA_DeleteOnClose );
28  }
29  // Default state for the checkbox
30  setCheckBoxVisible( false );
31  setCheckBoxState( Qt::Unchecked );
32 
33  mCheckBoxQSettingsLabel = "";
34 
35  QSettings settings;
36  restoreGeometry( settings.value( "/Windows/MessageViewer/geometry" ).toByteArray() );
37 }
38 
40 {
41  QSettings settings;
42  settings.setValue( "/Windows/MessageViewer/geometry", saveGeometry() );
43 }
44 
46 {
47  txtMessage->setHtml( msg );
48 }
49 
51 {
52  txtMessage->setPlainText( msg );
53 }
54 
56 {
57  txtMessage->append( msg );
58 }
59 
60 
61 void QgsMessageViewer::setMessage( const QString &message, MessageType msgType )
62 {
63  if ( msgType == MessageHtml )
64  setMessageAsHtml( message );
65  else
66  setMessageAsPlainText( message );
67 }
68 
69 void QgsMessageViewer::showMessage( bool blocking )
70 {
71  if ( blocking )
72  {
73  QApplication::setOverrideCursor( Qt::ArrowCursor );
74  exec();
76  }
77  else
78  {
79  show();
80  }
81 }
82 
83 void QgsMessageViewer::setTitle( const QString& title )
84 {
85  setWindowTitle( title );
86 }
87 
89 {
90  checkBox->setText( text );
91 }
92 
94 {
95  checkBox->setVisible( visible );
96 }
97 
98 void QgsMessageViewer::setCheckBoxState( Qt::CheckState state )
99 {
100  checkBox->setCheckState( state );
101 }
102 
104 {
105  return checkBox->checkState();
106 }
107 
109 {
110  mCheckBoxQSettingsLabel = label;
111 }
112 
113 
114 void QgsMessageViewer::on_checkBox_toggled( bool toggled )
115 {
116  Q_UNUSED( toggled );
117  if ( !mCheckBoxQSettingsLabel.isEmpty() )
118  {
119  QSettings settings;
120  if ( checkBox->checkState() == Qt::Checked )
121  settings.setValue( mCheckBoxQSettingsLabel, false );
122  else
123  settings.setValue( mCheckBoxQSettingsLabel, true );
124  }
125 }
QByteArray toByteArray() const
void setupUi(QWidget *widget)
MessageType
message can be in plain text or in html format
Qt::CheckState checkBoxState()
virtual void setTitle(const QString &title) override
set title for the messages
void setAttribute(Qt::WidgetAttribute attribute, bool on)
int exec()
void setMessageAsHtml(const QString &msg)
void setValue(const QString &key, const QVariant &value)
bool restoreGeometry(const QByteArray &geometry)
bool isEmpty() const
void setCheckBoxState(Qt::CheckState state)
void setOverrideCursor(const QCursor &cursor)
void setMessageAsPlainText(const QString &msg)
virtual void appendMessage(const QString &message) override
message to be appended to the current text
void restoreOverrideCursor()
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&#39;t be displayed until
void setCheckBoxText(const QString &text)
void setCheckBoxQSettingsLabel(const QString &label)
QVariant value(const QString &key, const QVariant &defaultValue) const
QgsMessageViewer(QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags, bool deleteOnClose=true)
QByteArray saveGeometry() const
void setWindowTitle(const QString &)
typedef WindowFlags
void show()
void setCheckBoxVisible(bool visible)