87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
#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<int, Location> &locations)
|
|
{
|
|
window->setMapLocations(locations);
|
|
}
|
|
|
|
void Presenter::onDepartmentsReceived(const QMap<int, Department> &departments)
|
|
{
|
|
window->setMapDepartments(departments);
|
|
}
|
|
|
|
void Presenter::onManufacturersReceived(const QMap<int, Manufacturer> &manufacturers)
|
|
{
|
|
window->setMapManufacturers(manufacturers);
|
|
}
|
|
|
|
void Presenter::onDeviceTypesReceived(const QMap<int, DeviceType> &deviceTypes)
|
|
{
|
|
window->setMapDeviceTypes(deviceTypes);
|
|
}
|
|
|
|
void Presenter::onDeviceModelsReceived(const QMap<int, DeviceModel> &deviceModels)
|
|
{
|
|
window->setMapDeviceModels(deviceModels);
|
|
client->getFilteredDevices(
|
|
false,
|
|
0.00,
|
|
std::numeric_limits<double>::max(),
|
|
false,
|
|
false,
|
|
-1,
|
|
-1,
|
|
"",
|
|
"Сначала новые"
|
|
);
|
|
}
|
|
|
|
void Presenter::onDevicesReceived(const QList<Device> &devices)
|
|
{
|
|
disconnect(client, &ApiClient::devicesReceived, this, &Presenter::onDevicesReceived);
|
|
|
|
QMap<int, Device> devicesMap;
|
|
QMap<int, DeviceModel> 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();
|
|
}
|