diff --git a/autotests/datatypestest.cpp b/autotests/datatypestest.cpp --- a/autotests/datatypestest.cpp +++ b/autotests/datatypestest.cpp @@ -1,5 +1,6 @@ /* Copyright (c) 2018 Volker Krause + Copyright (c) 2018 Luca Beltrame This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by @@ -19,6 +20,7 @@ #include #include +#include #include #include #include @@ -82,6 +84,18 @@ Ticket ticket; QCOMPARE(JsonLdDocument::readProperty(QVariant::fromValue(ticket.ticketedSeat()), "className").toString(), QLatin1String("Seat")); + + Organization org; + org.setName(QLatin1String("JR East")); + org.setEmail(QLatin1String("nowhere@nowhere.com")); + org.setTelephone(QLatin1String("+55-1234-345")); + org.setUrl(QUrl(QLatin1String("http://www.jreast.co.jp/e/"))); + QCOMPARE(JsonLdDocument::readProperty(QVariant::fromValue(org), "className").toString(), QLatin1String("Organization")); + QCOMPARE(org.name(), QLatin1String("JR East")); + QCOMPARE(org.email(), QLatin1String("nowhere@nowhere.com")); + QCOMPARE(org.telephone(), QLatin1String("+55-1234-345")); + QCOMPARE(org.url(), QUrl(QLatin1String("http://www.jreast.co.jp/e/"))); + } void testQmlCompatibility() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ datatypes/bustrip.cpp datatypes/flight.cpp + datatypes/organization.cpp datatypes/person.cpp datatypes/place.cpp datatypes/reservation.cpp @@ -83,6 +84,7 @@ BusTrip Datatypes Flight + Organization Reservation Person Place diff --git a/src/datatypes/organization.h b/src/datatypes/organization.h new file mode 100644 --- /dev/null +++ b/src/datatypes/organization.h @@ -0,0 +1,53 @@ +/* + Copyright (C) 2018 Luca Beltrame + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + + +#ifndef KITINERARY_ORGANIZATION_H +#define KITINERARY_ORGANIZATION_H + +#include "kitinerary_export.h" + +#include "datatypes.h" +#include "place.h" + +class QUrl; + +namespace KItinerary { + +class OrganizationPrivate; + +/** An organization + * @see https://schema.org/Organization + */ + +class KITINERARY_EXPORT Organization +{ + KITINERARY_GADGET(Organization) + KITINERARY_PROPERTY(QString, name, setName) + KITINERARY_PROPERTY(QString, email, setEmail) + KITINERARY_PROPERTY(QString, telephone, setTelephone) + KITINERARY_PROPERTY(QUrl, url, setUrl) + KITINERARY_PROPERTY(KItinerary::PostalAddress, address, setAddress) +private: + QExplicitlySharedDataPointer d; +}; + +} // namespace KItinerary + +Q_DECLARE_METATYPE(KItinerary::Organization) + +#endif // KITINERARY_ORGANIZATION_H diff --git a/src/datatypes/organization.cpp b/src/datatypes/organization.cpp new file mode 100644 --- /dev/null +++ b/src/datatypes/organization.cpp @@ -0,0 +1,46 @@ +/* + Copyright (C) 2018 Luca Beltrame + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "organization.h" +#include "datatypes_p.h" + +#include + +using namespace KItinerary; + +namespace KItinerary { + +class OrganizationPrivate: public QSharedData +{ +public: + QString name; + QString email; + QString telephone; + QUrl url; + PostalAddress address; +}; + +KITINERARY_MAKE_SIMPLE_CLASS(Organization) +KITINERARY_MAKE_PROPERTY(Organization, QString, name, setName) +KITINERARY_MAKE_PROPERTY(Organization, QString, email, setEmail) +KITINERARY_MAKE_PROPERTY(Organization, QString, telephone, setTelephone) +KITINERARY_MAKE_PROPERTY(Organization, QUrl, url, setUrl) +KITINERARY_MAKE_PROPERTY(Organization, PostalAddress, address, setAddress) + +} + +#include "moc_organization.cpp" diff --git a/src/jsonlddocument.cpp b/src/jsonlddocument.cpp --- a/src/jsonlddocument.cpp +++ b/src/jsonlddocument.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -133,6 +134,7 @@ MAKE_FACTORY(BusStation); MAKE_FACTORY(BusTrip); MAKE_FACTORY(BusReservation); + MAKE_FACTORY(Organization); return {}; }