Groom  1.1
BTS SNIR LaSalle Avignon 2021
Evenement.cpp
Aller à la documentation de ce fichier.
1 #include "Evenement.h"
2 #include <QDateTime>
3 #include <QDebug>
4 
15 {
16  nomsAttributs.push_back("calendrier");
17  //nomsAttributs.push_back("uid");
18  nomsAttributs.push_back("dtstart");
19  nomsAttributs.push_back("dtend");
20  nomsAttributs.push_back("categories");
21  nomsAttributs.push_back("summary");
22  nomsAttributs.push_back("location");
23  //nomsAttributs.push_back("description");
24  //nomsAttributs.push_back("url");
25  foreach (const QString &key, nomsAttributs)
26  {
27  attributs[key] = "";
28  }
29 }
30 
31 Evenement::Evenement(const Evenement &evt) : QObject(nullptr)
32 {
33  nomsAttributs.push_back("calendrier");
34  //nomsAttributs.push_back("uid");
35  nomsAttributs.push_back("dtstart");
36  nomsAttributs.push_back("dtend");
37  nomsAttributs.push_back("categories");
38  nomsAttributs.push_back("summary");
39  nomsAttributs.push_back("location");
40  //nomsAttributs.push_back("description");
41  //nomsAttributs.push_back("url");
42  foreach (const QString &key, nomsAttributs)
43  {
44  attributs[key] = evt.attributs[key];
45  }
46 }
47 
49 {
50  if(this != &evt)
51  {
52  foreach (const QString &key, nomsAttributs)
53  {
54  attributs[key] = evt.attributs[key];
55  }
56  }
57  return *this;
58 }
59 
60 QList<QString> Evenement::getNomsAttributs() const
61 {
62  return nomsAttributs;
63 }
64 
65 QString Evenement::getAttribut(QString nomAttribut) const
66 {
67  return attributs[nomAttribut];
68 }
69 
70 void Evenement::setAttribut(QString nomAttribut, QString valeur)
71 {
72  attributs[nomAttribut] = valeur;
73 }
74 
75 QString Evenement::toString() const
76 {
77  QString s = "Evenement(";
78  foreach (const QString &key, getNomsAttributs())
79  {
80  s += " " + key + " : " + getAttribut(key) + " ";
81  }
82  s += ")";
83 
84  return s;
85 }
86 
87 QDateTime Evenement::convertirHorodatage(QString horodatage, bool &ok)
88 {
89  //20200325T123000Z
90  QDateTime utcTime = QDateTime::fromString(horodatage, "yyyyMMdd'T'hhmmss'Z'");
91  if (utcTime.isValid())
92  {
93  ok = true;
94  return utcTime;
95  }
96  utcTime = QDateTime::fromString(horodatage, "yyyyMMdd'T'hhmmss");
97  if (utcTime.isValid())
98  {
99  ok = true;
100  return utcTime;
101  }
102  utcTime = QDateTime::fromString(horodatage, "yyyyMMddhhmmss");
103  if (utcTime.isValid())
104  {
105  ok = true;
106  return utcTime;
107  }
108  utcTime = QDateTime::fromString(horodatage, "yyyyMMdd");
109  if (utcTime.isValid())
110  {
111  ok = true;
112  return utcTime;
113  }
114 
115  utcTime = QDateTime();
116  ok = false;
117 
118  return utcTime;
119 }
120 
121 QDebug operator<<(QDebug dbg, const Evenement &e)
122 {
123  dbg.nospace() << "Evenement(";
124  foreach (const QString &key, e.getNomsAttributs())
125  {
126  dbg.nospace() << " " << key << " : " << e.getAttribut(key) << " ";
127  }
128  dbg.nospace() << ")";
129 
130  return dbg.space();
131 }
Evenement::getAttribut
QString getAttribut(QString nomAttribut) const
Definition: Evenement.cpp:65
Evenement::operator=
Evenement & operator=(const Evenement &evt)
Definition: Evenement.cpp:48
Evenement::attributs
QMap< QString, QString > attributs
Definition: Evenement.h:49
Evenement
Déclaration de la classe Evenement.
Definition: Evenement.h:36
Evenement::toString
QString toString() const
Definition: Evenement.cpp:75
Evenement::setAttribut
void setAttribut(QString nomAttribut, QString valeur)
Definition: Evenement.cpp:70
Evenement::nomsAttributs
QList< QString > nomsAttributs
Definition: Evenement.h:50
Evenement::convertirHorodatage
static QDateTime convertirHorodatage(QString horodatage, bool &ok)
Definition: Evenement.cpp:87
operator<<
QDebug operator<<(QDebug dbg, const Evenement &e)
Definition: Evenement.cpp:121
Evenement::getNomsAttributs
QList< QString > getNomsAttributs() const
Definition: Evenement.cpp:60
QObject
Evenement::Evenement
Evenement(QObject *parent=nullptr)
Definition: Evenement.cpp:14
Evenement.h
Déclaration de la classe Evenement.