diff --git a/2024/idees_tp/flags/country.cpp b/2024/idees_tp/flags/country.cpp new file mode 100644 index 0000000..2bdc8cf --- /dev/null +++ b/2024/idees_tp/flags/country.cpp @@ -0,0 +1,70 @@ +#include "country.h" + +Country::Country(QString name, QString capital, QString iso, QString region, QString alt, QObject *object) + +{} + +QString Country::capital() const +{ + return m_capital; +} + +void Country::setCapital(const QString &newCapital) +{ + if (m_capital == newCapital) + return; + m_capital = newCapital; + emit capitalChanged(); +} + +QString Country::name() const +{ + return m_name; +} + +void Country::setName(const QString &newName) +{ + if (m_name == newName) + return; + m_name = newName; + emit nameChanged(); +} + +QString Country::iso() const +{ + return m_iso; +} + +void Country::setIso(const QString &newIso) +{ + if (m_iso == newIso) + return; + m_iso = newIso; + emit isoChanged(); +} + +QString Country::region() const +{ + return m_region; +} + +void Country::setRegion(const QString &newRegion) +{ + if (m_region == newRegion) + return; + m_region = newRegion; + emit regionChanged(); +} + +QString Country::alt() const +{ + return m_alt; +} + +void Country::setAlt(const QString &newAlt) +{ + if (m_alt == newAlt) + return; + m_alt = newAlt; + emit altChanged(); +} diff --git a/2024/idees_tp/flags/country.h b/2024/idees_tp/flags/country.h new file mode 100644 index 0000000..af25ef3 --- /dev/null +++ b/2024/idees_tp/flags/country.h @@ -0,0 +1,52 @@ +#ifndef COUNTRY_H +#define COUNTRY_H + +#include +#include + +class Country : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL); + Q_PROPERTY(QString capital READ capital WRITE setCapital NOTIFY capitalChanged FINAL) + Q_PROPERTY(QString iso READ iso WRITE setIso NOTIFY isoChanged FINAL) + Q_PROPERTY(QString region READ region WRITE setRegion NOTIFY regionChanged FINAL) + Q_PROPERTY(QString alt READ alt WRITE setAlt NOTIFY altChanged FINAL) + + +public: + Country(QString name, QString capital, QString iso, QString region, QString alt, QObject *object); + QString capital() const; + void setCapital(const QString &newCapital); + QString name() const; + void setName(const QString &newName); + + QString iso() const; + void setIso(const QString &newIso); + + QString region() const; + void setRegion(const QString &newRegion); + + QString alt() const; + void setAlt(const QString &newAlt); + +signals: + void capitalChanged(); + void nameChanged(); + + void isoChanged(); + + void regionChanged(); + + void altChanged(); + +private: + QString m_name; + QString m_capital; + QString m_iso; + QString m_region; + QString m_alt; +}; + +#endif // COUNTRY_H diff --git a/2024/idees_tp/flags/countryfactory.cpp b/2024/idees_tp/flags/countryfactory.cpp index 97af16d..a778b10 100644 --- a/2024/idees_tp/flags/countryfactory.cpp +++ b/2024/idees_tp/flags/countryfactory.cpp @@ -5,7 +5,7 @@ #include #include -void CountryFactory::load(QString filename) { +QList CountryFactory::load(QString filename) { QFile file(filename); file.open(QIODevice::ReadOnly); @@ -19,4 +19,6 @@ void CountryFactory::load(QString filename) { for ( QJsonValue value : liste) { qWarning() << value["name"].toString(); } + + return {}; } diff --git a/2024/idees_tp/flags/countryfactory.h b/2024/idees_tp/flags/countryfactory.h index e98add2..ad72b3b 100644 --- a/2024/idees_tp/flags/countryfactory.h +++ b/2024/idees_tp/flags/countryfactory.h @@ -2,12 +2,15 @@ #define COUNTRYFACTORY_H #include +#include + +class Country; class CountryFactory { public: - static void load(QString filename); + static QList load(QString filename); }; #endif // COUNTRYFACTORY_H diff --git a/2024/idees_tp/flags/flags.pro b/2024/idees_tp/flags/flags.pro index da25e85..acc4150 100644 --- a/2024/idees_tp/flags/flags.pro +++ b/2024/idees_tp/flags/flags.pro @@ -5,6 +5,7 @@ QT += quick #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + country.cpp \ countryfactory.cpp \ main.cpp @@ -22,4 +23,5 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ + country.h \ countryfactory.h