diff --git a/CMakeLists.txt b/CMakeLists.txt index afa21c54eb01a91fdfb1e12f61808643a57adcce..061755655b88f0dab364200cdb9d3c96762aff61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) bookingdialog.h bookingdialog.cpp bookingdialog.ui station.h station.cpp airport.h airport.cpp + mapjson.h mapjson.cpp ) # Define target properties for Android with Qt 6 as: # set_property(TARGET praktikum4 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 95e6171fa3d557e31614bcbb377556d8d489b0ef..09fa01a22be5d88289e932b7724b50fe46e1e907 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 12.0.1, 2024-01-04T20:40:23. --> +<!-- Written by QtCreator 12.0.1, 2024-01-16T12:41:35. --> <qtcreator> <data> <variable>EnvironmentId</variable> diff --git a/bookingdialog.cpp b/bookingdialog.cpp index eaac382c2792c504f10e6ab83edc0312db94bc9a..bbe1ca81966f6a5b7852d5d8654ad32d6ded00c0 100644 --- a/bookingdialog.cpp +++ b/bookingdialog.cpp @@ -41,10 +41,11 @@ std::vector<std::string> splitLayovers(const std::string &str) { return result; } BookingDialog::BookingDialog(shared_ptr<TravelAgency> Agency, string bookingId_, - TravelAgencyUI *parent_) + string travelid_, TravelAgencyUI *parent_) : QDialog(parent_), ui(new Ui::BookingDialog) { ui->setupUi(this); + this->travelId = travelid_; this->bookingId = bookingId_; this->Agency = Agency; this->parent = parent_; @@ -93,18 +94,24 @@ BookingDialog::BookingDialog(shared_ptr<TravelAgency> Agency, string bookingId_, this->ui->tabWidget->setTabEnabled(2, false); this->ui->tabWidget->setTabEnabled(3, false); + this->ui->fromDestName->setStyleSheet("color:red;"); + this->ui->toDestName->setStyleSheet("color:red;"); + this->ui->fromDestination->setText( QString::fromStdString(fromDestination_)); if (this->Agency->airports.count(fromDestination_) > 0) { this->ui->fromDestName->setText(QString::fromStdString( this->Agency->airports.at(fromDestination_)->name)); + this->ui->fromDestName->setStyleSheet("color:black;"); } this->ui->toDestination->setText(QString::fromStdString(toDestination_)); if (this->Agency->airports.count(toDestination_) > 0) { + this->ui->toDestName->setText(QString::fromStdString( this->Agency->airports.at(toDestination_)->name)); + this->ui->toDestName->setStyleSheet("color:black;"); } this->ui->Airline->setText(QString::fromStdString(airline_)); @@ -374,3 +381,7 @@ void BookingDialog::on_ticketclass_textEdited(const QString &arg1) { void BookingDialog::on_buttonBox_rejected() { this->ui->buttonBox->setEnabled(false); } + +void BookingDialog::on_renderMap_clicked() { + this->Agency->getJSON(this->travelId); +} diff --git a/bookingdialog.h b/bookingdialog.h index 96cdb0789b3f162d6e0d8f9813c6622c643e256e..af3e5797f14bc23f176cbaed1ea85bbb96702d22 100644 --- a/bookingdialog.h +++ b/bookingdialog.h @@ -14,7 +14,7 @@ class BookingDialog : public QDialog { public: explicit BookingDialog(shared_ptr<TravelAgency> Agency, string bookingId_, - TravelAgencyUI *parent_ = nullptr); + string travelid_, TravelAgencyUI *parent_ = nullptr); ~BookingDialog(); private slots: @@ -61,11 +61,14 @@ private slots: void on_buttonBox_rejected(); + void on_renderMap_clicked(); + private: Ui::BookingDialog *ui; TravelAgencyUI *parent; shared_ptr<TravelAgency> Agency; string bookingId; + string travelId; }; #endif // BOOKINGDIALOG_H diff --git a/bookingdialog.ui b/bookingdialog.ui index 22aabccd3e69952928b2292ccefb23098d53d73e..ac5ab1daad4141ccf808a4f3ea5162b5b8415f13 100644 --- a/bookingdialog.ui +++ b/bookingdialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>627</width> - <height>598</height> + <height>638</height> </rect> </property> <property name="windowTitle"> @@ -335,6 +335,13 @@ </widget> </widget> </item> + <item> + <widget class="QPushButton" name="renderMap"> + <property name="text"> + <string>Map</string> + </property> + </widget> + </item> <item> <widget class="QDialogButtonBox" name="buttonBox"> <property name="orientation"> diff --git a/mapjson.cpp b/mapjson.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a86e63c34a39b8a7eabd47bbdfca9e0549fcf8e0 --- /dev/null +++ b/mapjson.cpp @@ -0,0 +1,6 @@ +#include "mapjson.h" + +mapjson::mapjson() +{ + +} diff --git a/mapjson.h b/mapjson.h new file mode 100644 index 0000000000000000000000000000000000000000..5980bc2ec6167ee774f6899f06075c8aca885bc3 --- /dev/null +++ b/mapjson.h @@ -0,0 +1,11 @@ +#ifndef MAPJSON_H +#define MAPJSON_H + + +class mapjson +{ +public: + mapjson(); +}; + +#endif // MAPJSON_H diff --git a/travelagency.cpp b/travelagency.cpp index 8f356a52872a36f40690139ea55f6d5860ceff6f..5628a3bca8e1a51f750d05e0efcbb62bf579cf9e 100644 --- a/travelagency.cpp +++ b/travelagency.cpp @@ -44,6 +44,94 @@ shared_ptr<Customer> TravelAgency::findCustomer(long id) { return NULL; } +std::string TravelAgency::getJSON(std::string travelid) { + shared_ptr<Travel> travel = this->findTravel(std::stol(travelid)); + vector<shared_ptr<Booking>> bookings = travel->getBookings(); + cout << bookings.size() << endl; + for (const auto &booking : bookings) { + Details details = booking->showDetails(); + auto [id_, price_, fromDate_, toDate_, + + pickupLocation_, pickupLatitude, pickupLongitude, returnLocation_, + returnLatitude, returnLongitude, company_, vehicleClass_, + + hotel_, hotelLatitude, hotelLongitude, town_, roomType_, + + fromDestination_, fromDestLatitude, fromDestLongitude, toDestination_, + toDestLatitude, toDestLongitude, airline_, bookingClass_, + + fromStation_, fromStationLatitude, fromStationLongitude, toStation_, + toStationLatitude, toStationLongitude, departureTime_, arrivalTime_, + connectingStations_] = details; + nlohmann::json j; + j["type"] = "FeatureCollection"; + + j["features"] = nlohmann::json::array(); + + cout << "WHERE ERROR" << endl; + if (booking->gettype() == "Flight") { + cout << "WHERE ERROR" << endl; + nlohmann::json line = json::parse(R"({ + "type": "Feature", + "geometry": { + "type": "LineString", + "coordinates": [] + }, + "properties": {} + })"); + + line["geometry"]["coordinates"][0] = nlohmann::json::array(); + line["geometry"]["coordinates"][1] = nlohmann::json::array(); + // std::format("[{} , {}]", fromDestLatitude, fromDestLongitude); + line["geometry"]["coordinates"][0].push_back(fromDestLongitude); + line["geometry"]["coordinates"][0].push_back(fromDestLatitude); + line["geometry"]["coordinates"][1].push_back(toDestLongitude); + line["geometry"]["coordinates"][1].push_back(toDestLatitude); + j["features"].push_back(line); + + nlohmann::json fromDest = json::parse(R"({ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [] + }, + "properties": { + "label": "" + } + })"); + fromDest["geometry"]["coordinates"].push_back(fromDestLongitude); + fromDest["geometry"]["coordinates"].push_back(fromDestLatitude); + fromDest["properties"]["label"] = fromDestination_; + j["features"].push_back(fromDest); + nlohmann::json toDest = json::parse(R"({ + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [] + }, + "properties": { + "label": "" + } + })"); + toDest["geometry"]["coordinates"].push_back(toDestLongitude); + toDest["geometry"]["coordinates"].push_back(toDestLatitude); + toDest["properties"]["label"] = toDestination_; + j["features"].push_back(toDest); + cout << j.dump() << endl; + } + if (booking->gettype() == "Train") { + nlohmann::json train; + } + if (booking->gettype() == "RentalCar") { + nlohmann::json rentalcar; + } + if (booking->gettype() == "Hotel") { + nlohmann::json hotel; + } + } + return "HMMMM"; +} + void TravelAgency::readFile() { this->allBookings.clear(); this->allCustomers.clear(); @@ -303,6 +391,7 @@ void TravelAgency::readFile() { this->airports.insert(make_pair(iata_code, ptr)); } + cout << "AIRPORT SIZE: " << this->airports.size() << endl; } std::string TravelAgency::getResults() { return this->results; } std::vector<shared_ptr<Booking>> TravelAgency::getBookings() { diff --git a/travelagency.h b/travelagency.h index bb9f4f9ab1ef3916f0e7064599ccd94677b3b553..f62acdd466065ffef7b828f4b4d3a004499d6272 100644 --- a/travelagency.h +++ b/travelagency.h @@ -20,6 +20,7 @@ public: void setfile(); void readFile(); std::string getResults(); + std::string getJSON(std::string travelid); std::vector<shared_ptr<Booking>> getBookings(); shared_ptr<Booking> findBooking(string id); shared_ptr<Travel> findTravel(long id); diff --git a/travelagencyui.cpp b/travelagencyui.cpp index 52ede609f62cdc35855b3a0bad766baa0fcac6a2..bc3aa85368c015e36ec1a3f78c32e8c7a874e1c9 100644 --- a/travelagencyui.cpp +++ b/travelagencyui.cpp @@ -195,7 +195,8 @@ void TravelAgencyUI::on_BookingsTable_cellClicked(int row, int column) { string bookingId = bookings[row]->getid(); - QDialog *bookingdialog = new BookingDialog(this->Agency, bookingId, this); + QDialog *bookingdialog = + new BookingDialog(this->Agency, bookingId, travelid, this); bookingdialog->exec(); saveButtonClickable = true; } @@ -215,3 +216,11 @@ void TravelAgencyUI::on_actionSearch_triggered() { searchDialog->exec(); } } + +void TravelAgencyUI::on_actionSpeichern_triggered() { + if (saveButtonClickable) { + this->ui->TravelView->setVisible(false); + this->ui->CustomerView->setVisible(false); + this->Agency->setfile(); + } +} diff --git a/travelagencyui.h b/travelagencyui.h index e2eb5c76115d2ad6405bcbff04279cd757d1f9a5..94ba43aa891712ea04f7a8832157bda6fdf584e0 100644 --- a/travelagencyui.h +++ b/travelagencyui.h @@ -30,6 +30,8 @@ private slots: void on_actionSearch_triggered(); + void on_actionSpeichern_triggered(); + private: Ui::TravelAgencyUI *ui; shared_ptr<TravelAgency> Agency; diff --git a/travelagencyui.ui b/travelagencyui.ui index a461ecec3b18f5310bd7f45e0a3f02599558c324..6c6cc2171fb7f13601f5e29e025313a002f76687 100644 --- a/travelagencyui.ui +++ b/travelagencyui.ui @@ -226,28 +226,7 @@ </item> <item row="0" column="0"> <widget class="QWidget" name="widget_6" native="true"> - <layout class="QHBoxLayout" name="horizontalLayout_6"> - <item> - <widget class="QPushButton" name="save"> - <property name="text"> - <string>Speichern</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> + <layout class="QHBoxLayout" name="horizontalLayout_6"/> </widget> </item> <item row="4" column="0"> @@ -286,10 +265,42 @@ </property> <addaction name="actionSearch"/> </widget> + <widget class="QMenu" name="menuSpeichern"> + <property name="title"> + <string>Speichern</string> + </property> + <addaction name="actionSpeichern"/> + </widget> <addaction name="menuUp_and_Away"/> <addaction name="menuSearchButton"/> + <addaction name="menuSpeichern"/> </widget> <widget class="QStatusBar" name="statusbar"/> + <widget class="QToolBar" name="toolBar"> + <property name="windowTitle"> + <string>toolBar</string> + </property> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + <addaction name="Einlesen"/> + <addaction name="actionSearch"/> + <addaction name="actionSpeichern"/> + </widget> + <widget class="QToolBar" name="toolBar_2"> + <property name="windowTitle"> + <string>toolBar_2</string> + </property> + <attribute name="toolBarArea"> + <enum>BottomToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> <action name="Einlesen"> <property name="icon"> <iconset theme="document-open"/> @@ -312,10 +323,21 @@ li.checked::marker { content: "\2612"; } </property> </action> <action name="actionSearch"> + <property name="icon"> + <iconset theme="system-search"/> + </property> <property name="text"> <string>Search</string> </property> </action> + <action name="actionSpeichern"> + <property name="icon"> + <iconset theme="document-save-as"/> + </property> + <property name="text"> + <string>Speichern</string> + </property> + </action> </widget> <resources/> <connections/>