dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
globalmessaging.h
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef GLOBALMESSAGING_H
29 #define GLOBALMESSAGING_H
30 #include "core_global.h"
31 #include <QObject>
32 #include <QString>
33 
34 namespace Core {
35 
36 typedef enum { ERROR, WARNING, INFO } MessageType;
37 class CORE_EXPORT GlobalMessage : public QObject
38 {
39  Q_OBJECT
40 public:
41  explicit GlobalMessage(QString brief, QString description, MessageType type,
42  QObject *parent = nullptr);
43  explicit GlobalMessage(MessageType = ERROR, QObject *parent = nullptr);
44  void setActive(bool value);
45  bool isActive() { return m_active; }
46  void setText(QString brief, QString description)
47  {
48  m_brief = brief;
49  m_description = description;
50  emit changed(this);
51  }
52  void setBrief(QString brief)
53  {
54  m_brief = brief;
55  emit changed(this);
56  }
57  void setDescription(QString description)
58  {
59  m_description = description;
60  emit changed(this);
61  }
62  QString getBrief() { return m_brief; }
63  QString getDescription() { return m_description; }
64  MessageType getType() { return m_type; }
65 signals:
66  void changed(GlobalMessage *);
67 
68 private:
69  QString m_brief;
70  QString m_description;
71  MessageType m_type;
72  bool m_active;
73 };
74 
75 class CORE_EXPORT GlobalMessaging : public QObject
76 {
77  Q_OBJECT
78 public:
79  explicit GlobalMessaging(QObject *parent = nullptr);
80  GlobalMessage *addErrorMessage(QString brief, QString description);
81  GlobalMessage *addWarningMessage(QString brief, QString description);
82  GlobalMessage *addInfoMessage(QString brief, QString description);
83  void addMessage(GlobalMessage *);
84  QList<GlobalMessage *> getActiveErrors();
85  QList<GlobalMessage *> getActiveWarnings();
86  QList<GlobalMessage *> getActiveInfos();
87  QList<GlobalMessage *> getErrors();
88  QList<GlobalMessage *> getWarnings();
89  QList<GlobalMessage *> getInfos();
90 
91 signals:
92  void newMessage(GlobalMessage *);
93  void newError(GlobalMessage *);
94  void newWarning(GlobalMessage *);
95  void newInfo(GlobalMessage *);
96  void changedMessage(GlobalMessage *);
97  void changedError(GlobalMessage *);
98  void changedWarning(GlobalMessage *);
99  void changedInfo(GlobalMessage *);
100  void deletedMessage();
101  void deletedError();
102  void deletedWarning();
103  void deletedInfo();
104 
105 public slots:
106  void messageDeleted();
107 
108 private:
109  QList<GlobalMessage *> errorList;
110  QList<GlobalMessage *> warningList;
111  QList<GlobalMessage *> infoList;
112 };
113 }
114 #endif // GLOBALMESSAGING_H
void setBrief(QString brief)
void setText(QString brief, QString description)
MessageType getType()
void setDescription(QString description)
Definition: icore.h:39