KWeatherCore

alertinfo.h
1 /*
2  * SPDX-FileCopyrightText: 2021 Han Young <[email protected]>
3  * SPDX-FileCopyrightText: 2021 Anjani Kumar <[email protected]>
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #pragma once
7 #include "kweathercore/kweathercore_export.h"
8 #include <QDateTime>
9 #include <QObject>
10 #include <QString>
11 #include <memory>
12 #include <tuple>
13 #include <vector>
14 namespace KWeatherCore
15 {
16 // code name (FIPS6, UGC...)/code value (002050, AKZ155)
17 using AreaCodeVec = std::vector<std::pair<QString, QString>>;
18 using Parameter = std::vector<std::pair<QString, QString>>;
19 /**
20  * @short Class represents single CAP
21  *
22  * This class contains the parsed CAP FEED entry
23  *
24  * @author Han Young <[email protected]>
25  * @author Anjani Kumar <[email protected]>
26  */
27 class KWEATHERCORE_EXPORT AlertInfo
28 {
29  Q_GADGET
30  Q_PROPERTY(QString headline READ headline WRITE setHeadline)
31  Q_PROPERTY(QString description READ description WRITE setDescription)
32  Q_PROPERTY(QString event READ event WRITE setEvent)
33  Q_PROPERTY(QDateTime effectiveTime READ effectiveTime WRITE setEffectiveTime)
34  Q_PROPERTY(QDateTime expireTime READ expireTime WRITE setExpireTime)
35 
36 public:
37  enum class Category {
38  Unknown = 0,
39  Geo = 0b1,
40  Met = 0b10,
41  Safety = 0b100,
42  Security = 0b1000,
43  Rescue = 0b10000,
44  Fire = 0b100000,
45  Health = 0b1000000,
46  Env = 0b10000000,
47  Transport = 0b100000000,
48  Infra = 0b1000000000,
49  CBRNE = 0b10000000000,
50  Other = 0b100000000000
51  };
52  enum class Urgency { Immediate, Expected, Future, Past, Unknown };
53  enum class Severity { Extreme, Severe, Moderate, Minor, Unknown };
54  enum class Certainty { Observed, Likely, Possible, Unlikely, Unknown };
55 
56  /**
57  * default constructor
58  */
59  AlertInfo();
60  AlertInfo(const AlertInfo &other);
61  AlertInfo(AlertInfo &&other);
62  ~AlertInfo();
63  /**
64  * The text denoting the type of the subject
65  * event of the alert message
66  */
67  const QString &event() const;
68  /**
69  * areaCodes
70  * @return pairs of QString, the first one is code type,
71  * ie. {"UGC", "AKZ017 AKZ020 AKZ021 AKZ022 AKZ023"}
72  */
73  const AreaCodeVec &areaCodes() const;
74  /**
75  * The effective time of the information of the alert message
76  */
77  const QDateTime &effectiveTime() const;
78  /**
79  * The onset time of the information of the alert message
80  */
81  const QDateTime &onsetTime() const;
82  /**
83  * The expire time of the information of the alert message
84  */
85  const QDateTime &expireTime() const;
86  /**
87  * The text headline of the alert message
88  */
89  const QString &headline() const;
90  /**
91  * The description of the alert message
92  */
93  const QString &description() const;
94  /**
95  * The instruction of the alert message
96  */
97  const QString &instruction() const;
98  /**
99  * The sender of the alert message
100  */
101  const QString &sender() const;
102  /**
103  * The code denoting the language of the info
104  * default to "en-US"
105  * @return Natural language identifier per [RFC 3066].
106  */
107  const QString &language() const;
108  /**
109  * The category of the alert message
110  * @return default to Unknown, value is bit or-ed
111  */
112  Category category() const;
113  /**
114  * The urgency of the alert message
115  * @return default to Unknown
116  */
117  Urgency urgency() const;
118  /**
119  * The severity of the alert message
120  * @return default to Unknown
121  */
122  Severity severity() const;
123  /**
124  * The certainty of the alert message
125  * @return default to Unknown
126  */
127  Certainty certainty() const;
128  /**
129  * The Parameter of the alert message
130  * refer to CAP protocol v1.2
131  */
132  const Parameter &parameter() const;
133  /**
134  * Text describe the area of the alert message
135  */
136  const QString &areaDesc() const;
137  /**
138  * area polygon
139  * @return latitude longitude pairs
140  */
141  const std::vector<std::vector<std::pair<float, float>>> &polygon() const;
142  void setHeadline(const QString &headline);
143  void setDescription(const QString &description);
144  void setInstruction(const QString &instruction);
145  void setSender(const QString &sender);
146  void setLanguage(const QString &language);
147  void setCategory(Category category);
148  void addCategory(Category category);
149  void setEvent(const QString &event);
150  void setAreaCodes(const AreaCodeVec &areaCodes);
151  void addAreaCode(std::pair<QString, QString> &areaCode);
152  void setEffectiveTime(const QDateTime &time);
153  void setOnsetTime(const QDateTime &time);
154  void setExpireTime(const QDateTime &time);
155  void setUrgency(Urgency urgency);
156  void setSeverity(Severity severity);
157  void setCertainty(Certainty certainty);
158  void setParameter(const Parameter &parameter);
159  void addParameter(std::pair<QString, QString> &);
160  void setAreaDesc(const QString &areaDesc);
161  void setPolygon(const std::vector<std::vector<std::pair<float, float>>> &area);
162  void setPolygon(std::vector<std::vector<std::pair<float, float>>> &&area);
163  void addPolygon(const std::vector<std::pair<float, float>> &area);
164  void addPolygon(std::vector<std::pair<float, float>> &&area);
165  AlertInfo &operator=(const AlertInfo &other);
166  AlertInfo &operator=(AlertInfo &&other);
167 
168 private:
169  class AlertInfoPrivate;
170  std::unique_ptr<AlertInfoPrivate> d;
171 };
172 using Category = KWeatherCore::AlertInfo::Category;
173 inline Category operator|(Category a, Category b)
174 {
175  return static_cast<Category>(static_cast<int>(a) | static_cast<int>(b));
176 }
177 
178 inline Category operator&(Category a, Category b)
179 {
180  return static_cast<Category>(static_cast<int>(a) & static_cast<int>(b));
181 }
182 
183 inline Category &operator|=(Category &a, Category b)
184 {
185  return a = a | b;
186 }
187 }
Class represents single CAP.
Definition: alertinfo.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Oct 21 2021 23:05:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.