#include "presenter.h" Presenter::Presenter(QObject *parent) : QObject(parent) { client = new ApiClient(); window = new MainWindow(); connect(client, &ApiClient::devicesReceived, this, &Presenter::onDevicesReceived); connect(client, &ApiClient::departmentsReceived, this, &Presenter::onDepartmentsReceived); connect(client, &ApiClient::deviceModelsReceived, this, &Presenter::onDeviceModelsReceived); connect(client, &ApiClient::deviceTypesReceived, this, &Presenter::onDeviceTypesReceived); connect(client, &ApiClient::locationsReceived, this, &Presenter::onLocationsReceived); connect(client, &ApiClient::manufacturersReceived, this, &Presenter::onManufacturersReceived); window->setClient(client); client->getEntities("/api/locations"); client->getEntities("/api/departments"); client->getEntities("/api/manufacturers"); client->getEntities("/api/devicetypes"); client->getEntities("/api/devicemodels"); } Presenter::~Presenter() { client->deleteLater(); window->deleteLater(); } void Presenter::onLocationsReceived(const QMap &locations) { window->setMapLocations(locations); } void Presenter::onDepartmentsReceived(const QMap &departments) { window->setMapDepartments(departments); } void Presenter::onManufacturersReceived(const QMap &manufacturers) { window->setMapManufacturers(manufacturers); } void Presenter::onDeviceTypesReceived(const QMap &deviceTypes) { window->setMapDeviceTypes(deviceTypes); } void Presenter::onDeviceModelsReceived(const QMap &deviceModels) { window->setMapDeviceModels(deviceModels); client->getFilteredDevices( false, 0.00, std::numeric_limits::max(), false, false, -1, -1, "", "Сначала новые" ); } void Presenter::onDevicesReceived(const QList &devices) { disconnect(client, &ApiClient::devicesReceived, this, &Presenter::onDevicesReceived); QMap devicesMap; QMap deviceModels = window->getMapDeviceModels(); for (const Device &device : devices) { int deviceModelId = device.deviceModel().id(); if (deviceModels.contains(deviceModelId)) { Device updatedDevice = device; updatedDevice.setDeviceModel(deviceModels[deviceModelId]); devicesMap.insert(updatedDevice.id(), updatedDevice); } else { devicesMap.insert(device.id(), device); } } window->setMapDevices(devicesMap); window->show(); }