QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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, 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 
45 void QgsMessageViewer::setMessageAsHtml( const QString &msg )
46 {
47  txtMessage->setHtml( msg );
48 }
49 
50 void QgsMessageViewer::setMessageAsPlainText( const QString &msg )
51 {
52  txtMessage->setPlainText( msg );
53 }
54 
55 void QgsMessageViewer::appendMessage( const QString &msg )
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();
75  QApplication::restoreOverrideCursor();
76  }
77  else
78  {
79  show();
80  }
81 }
82 
83 void QgsMessageViewer::setTitle( const QString& title )
84 {
85  setWindowTitle( title );
86 }
87 
88 void QgsMessageViewer::setCheckBoxText( const QString& text )
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 }