diff --git a/2024/idees_tp/flags/countryfactory.cpp b/2024/idees_tp/flags/countryfactory.cpp new file mode 100644 index 0000000..97af16d --- /dev/null +++ b/2024/idees_tp/flags/countryfactory.cpp @@ -0,0 +1,22 @@ +#include "countryfactory.h" + +#include +#include +#include +#include + +void CountryFactory::load(QString filename) { + QFile file(filename); + + file.open(QIODevice::ReadOnly); + QByteArray data = file.readAll(); + + QJsonDocument doc(QJsonDocument::fromJson(data)); + QJsonValue objet = doc["countries"]; + + QJsonArray liste = objet["country"].toArray(); + + for ( QJsonValue value : liste) { + qWarning() << value["name"].toString(); + } +} diff --git a/2024/idees_tp/flags/countryfactory.h b/2024/idees_tp/flags/countryfactory.h new file mode 100644 index 0000000..e98add2 --- /dev/null +++ b/2024/idees_tp/flags/countryfactory.h @@ -0,0 +1,13 @@ +#ifndef COUNTRYFACTORY_H +#define COUNTRYFACTORY_H + +#include + +class CountryFactory +{ +public: + + static void load(QString filename); +}; + +#endif // COUNTRYFACTORY_H diff --git a/2024/idees_tp/flags/flags.pro b/2024/idees_tp/flags/flags.pro index b86ec65..da25e85 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 += \ + countryfactory.cpp \ main.cpp RESOURCES += qml.qrc @@ -19,3 +20,6 @@ QML_DESIGNER_IMPORT_PATH = qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +HEADERS += \ + countryfactory.h diff --git a/2024/idees_tp/flags/main.cpp b/2024/idees_tp/flags/main.cpp index 6493740..57885ed 100644 --- a/2024/idees_tp/flags/main.cpp +++ b/2024/idees_tp/flags/main.cpp @@ -1,28 +1,7 @@ #include #include -#include -#include -#include -#include -void load() { - QFile file(":/assets/data_en-GB.json"); - - file.open(QIODevice::ReadOnly); - QByteArray data = file.readAll(); - - QJsonDocument doc(QJsonDocument::fromJson(data)); - QJsonValue objet = doc.object()["countries"]; - - QJsonArray liste = objet["country"].toArray(); - - for ( int i = 0 ; i < liste.size() ; ++i ) { - QJsonValue value = liste[i]; - qWarning() << value["name"].toString(); - } - - return; -} +#include "countryfactory.h" int main(int argc, char *argv[]) { @@ -43,7 +22,7 @@ int main(int argc, char *argv[]) }, Qt::QueuedConnection); - load(); + CountryFactory::load(":/assets/data_en-GB.json"); engine.load(url); return app.exec();