dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
globalmessaging.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
29 #include "globalmessaging.h"
30 
31 namespace Core {
32 
33 GlobalMessage::GlobalMessage(QString brief, QString description, MessageType type, QObject *parent)
34  : QObject(parent)
35  , m_brief(brief)
36  , m_description(description)
37  , m_type(type)
38  , m_active(true)
39 {
40 }
41 
43  : QObject(parent)
44  , m_type(type)
45  , m_active(true)
46 {
47 }
48 
49 void GlobalMessage::setActive(bool value)
50 {
51  m_active = value;
52  emit changed(this);
53 }
54 
55 GlobalMessage *GlobalMessaging::addErrorMessage(QString brief, QString description)
56 {
57  GlobalMessage *message = new GlobalMessage(brief, description, ERROR, this);
58  connect(message, SIGNAL(destroyed()), this, SLOT(messageDeleted()));
59  connect(message, SIGNAL(changed(GlobalMessage *)), this,
60  SIGNAL(changedMessage(GlobalMessage *)));
61  connect(message, SIGNAL(changed(GlobalMessage *)), this, SIGNAL(changedError(GlobalMessage *)));
62  errorList.append(message);
63  emit newMessage(message);
64  emit newError(message);
65  return message;
66 }
67 
68 GlobalMessage *GlobalMessaging::addWarningMessage(QString brief, QString description)
69 {
70  GlobalMessage *message = new GlobalMessage(brief, description, WARNING, this);
71  connect(message, SIGNAL(destroyed()), this, SLOT(messageDeleted()));
72  connect(message, SIGNAL(changed(GlobalMessage *)), this,
73  SIGNAL(changedMessage(GlobalMessage *)));
74  connect(message, SIGNAL(changed(GlobalMessage *)), this,
75  SIGNAL(changedWarning(GlobalMessage *)));
76  warningList.append(message);
77  emit newMessage(message);
78  emit newWarning(message);
79  return message;
80 }
81 
82 GlobalMessage *GlobalMessaging::addInfoMessage(QString brief, QString description)
83 {
84  GlobalMessage *message = new GlobalMessage(brief, description, INFO, this);
85  connect(message, SIGNAL(destroyed()), this, SLOT(messageDeleted()));
86  connect(message, SIGNAL(changed(GlobalMessage *)), this,
87  SIGNAL(changedMessage(GlobalMessage *)));
88  connect(message, SIGNAL(changed(GlobalMessage *)), this, SIGNAL(changedInfo(GlobalMessage *)));
89  infoList.append(message);
90  emit newMessage(message);
91  emit newInfo(message);
92  return message;
93 }
94 
96 {
97  connect(message, SIGNAL(destroyed()), this, SLOT(messageDeleted()));
98  connect(message, SIGNAL(changed(GlobalMessage *)), this,
99  SIGNAL(changedMessage(GlobalMessage *)));
100  connect(message, SIGNAL(changed(GlobalMessage *)), this, SIGNAL(changedInfo(GlobalMessage *)));
101  switch (message->getType()) {
102  case ERROR:
103  errorList.append(message);
104  emit newError(message);
105  break;
106  case WARNING:
107  warningList.append(message);
108  emit newWarning(message);
109  break;
110  case INFO:
111  infoList.append(message);
112  emit newInfo(message);
113  break;
114  default:
115  break;
116  }
117  emit newMessage(message);
118 }
119 
121 {
123  foreach (GlobalMessage *message, errorList) {
124  if (message->isActive())
125  temp.append(message);
126  }
127  return temp;
128 }
129 
131 {
133  foreach (GlobalMessage *message, warningList) {
134  if (message->isActive())
135  temp.append(message);
136  }
137  return temp;
138 }
139 
141 {
143  foreach (GlobalMessage *message, infoList) {
144  if (message->isActive())
145  temp.append(message);
146  }
147  return temp;
148 }
149 
151 {
152  return errorList;
153 }
155 {
156  return warningList;
157 }
159 {
160  return infoList;
161 }
162 
164 {
165  GlobalMessage *message = dynamic_cast<GlobalMessage *>(sender());
166  if (!message)
167  return;
168  switch (message->getType()) {
169  case ERROR:
170  errorList.removeAll(message);
171  emit deletedError();
172  break;
173  case WARNING:
174  warningList.removeAll(message);
175  emit deletedWarning();
176  break;
177  case INFO:
178  infoList.removeAll(message);
179  emit deletedInfo();
180  break;
181  default:
182  break;
183  }
184  emit deletedMessage();
185 }
186 
188  : QObject(parent)
189 {
190 }
191 }
GlobalMessage * addErrorMessage(QString brief, QString description)
MessageType getType()
void addMessage(GlobalMessage *)
void changedInfo(GlobalMessage *)
QList< GlobalMessage * > getActiveWarnings()
QList< GlobalMessage * > getWarnings()
void setActive(bool value)
GlobalMessage(QString brief, QString description, MessageType type, QObject *parent=nullptr)
QList< GlobalMessage * > getActiveInfos()
GlobalMessage * addInfoMessage(QString brief, QString description)
void newError(GlobalMessage *)
QList< GlobalMessage * > getInfos()
void changedMessage(GlobalMessage *)
void changed(GlobalMessage *)
void newWarning(GlobalMessage *)
void changedWarning(GlobalMessage *)
QList< GlobalMessage * > getActiveErrors()
Definition: icore.h:39
GlobalMessage * addWarningMessage(QString brief, QString description)
QList< GlobalMessage * > getErrors()
GlobalMessaging(QObject *parent=nullptr)
void changedError(GlobalMessage *)
void newMessage(GlobalMessage *)
void newInfo(GlobalMessage *)