2024-12-24 18:13:22 +04:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
setWindowIcon(QIcon(":/images/mw-icon.png"));
|
|
|
|
|
|
|
|
|
|
int width = frameGeometry().width();
|
|
|
|
|
int height = frameGeometry().height();
|
|
|
|
|
QScreen *screen = qApp->primaryScreen();
|
|
|
|
|
int screenWidth = screen->geometry().width();
|
|
|
|
|
int screenHeight = screen->geometry().height();
|
|
|
|
|
setGeometry((screenWidth/2)-(width/2), (screenHeight/2)-(height/2), width, height);
|
|
|
|
|
|
|
|
|
|
QStringList filterItems = {
|
|
|
|
|
"Все устройства",
|
|
|
|
|
"Типы устройств",
|
|
|
|
|
"Помещения",
|
|
|
|
|
"Отделы",
|
|
|
|
|
"Производители",
|
|
|
|
|
"Модели устройств"
|
|
|
|
|
};
|
|
|
|
|
ui->comboBoxFilters->addItems(filterItems);
|
|
|
|
|
|
|
|
|
|
QStringList sortItems = {
|
|
|
|
|
"Сначала новые",
|
|
|
|
|
"Сначала старые",
|
|
|
|
|
"Сначала дешевые",
|
|
|
|
|
"Сначала дорогие",
|
|
|
|
|
"Сначала с лайком"
|
|
|
|
|
};
|
|
|
|
|
ui->comboBoxSort->addItems(sortItems);
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
ui->tableWidget->verticalHeader()->setVisible(false);
|
|
|
|
|
ui->tableWidget->setColumnCount(2);
|
|
|
|
|
QStringList headers = {"ID", "Название"};
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
|
QHeaderView *header = ui->tableWidget->horizontalHeader();
|
|
|
|
|
QFont headerFont = header->font();
|
|
|
|
|
headerFont.setBold(true);
|
|
|
|
|
header->setFont(headerFont);
|
|
|
|
|
header->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
|
|
|
|
|
ui->listWidgetDevices->setSpacing(10);
|
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
QLineEdit *searchEdit = ui->lineEditSearch;
|
|
|
|
|
QPushButton *searchButton = new QPushButton(this);
|
|
|
|
|
ButtonHoverWatcher *watcher = new ButtonHoverWatcher(this);
|
|
|
|
|
searchButton->installEventFilter(watcher);
|
|
|
|
|
searchButton->setCursor(Qt::PointingHandCursor);
|
|
|
|
|
searchButton->setStyleSheet("background: transparent; border: none;");
|
|
|
|
|
searchButton->setIcon(QIcon(":/images/search.png"));
|
|
|
|
|
searchButton->setFixedSize(22, 22);
|
|
|
|
|
QMargins margins = searchEdit->textMargins();
|
|
|
|
|
searchEdit->setTextMargins(margins.left(), margins.top(), searchButton->width(), margins.bottom());
|
|
|
|
|
searchEdit->setPlaceholderText(QStringLiteral("Поиск устройств по модели, типу или серийному номеру..."));
|
|
|
|
|
searchEdit->setMaxLength(200);
|
|
|
|
|
QHBoxLayout *searchLayout = new QHBoxLayout();
|
|
|
|
|
searchLayout->addStretch();
|
|
|
|
|
searchLayout->addWidget(searchButton);
|
|
|
|
|
searchLayout->setSpacing(0);
|
|
|
|
|
searchLayout->setContentsMargins(3, 2, 3, 2);
|
|
|
|
|
searchEdit->setLayout(searchLayout);
|
|
|
|
|
|
|
|
|
|
QButtonGroup *buttonGroup = new QButtonGroup(this);
|
|
|
|
|
buttonGroup->addButton(ui->radioButtonWorking);
|
|
|
|
|
buttonGroup->addButton(ui->radioButtonNotWorking);
|
|
|
|
|
buttonGroup->addButton(ui->radioButtonDisregard);
|
|
|
|
|
ui->radioButtonWorking->setChecked(true);
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
ui->checkBoxIsWorking->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
ui->checkBoxIsWorking->setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
|
|
|
|
ui->pushButtonDisregardPrice->setToolTip("Цена не учитывается при том условии, если оба значения из диапазона равны нулю");
|
|
|
|
|
|
|
|
|
|
QFile *styleFile = new QFile(":/styles.qss");
|
|
|
|
|
if (styleFile->open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream ts(styleFile);
|
|
|
|
|
QString style = ts.readAll();
|
|
|
|
|
qApp->setStyleSheet(style);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
connect(ui->comboBoxFilters, SIGNAL(activated(int)), this, SLOT(updateTableWidget(int)));
|
|
|
|
|
connect(ui->comboBoxSort, SIGNAL(activated(int)), this, SLOT(changeSortOrder()));
|
|
|
|
|
connect(ui->tableWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateListWidget()));
|
|
|
|
|
connect(ui->listWidgetDevices, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showItemInfo(QListWidgetItem*)));
|
|
|
|
|
connect(ui->pushButtonBack, SIGNAL(clicked()), this, SLOT(pushButtonBackClicked()));
|
|
|
|
|
connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(pushButtonClearClicked()));
|
|
|
|
|
connect(searchEdit, SIGNAL(returnPressed()), this, SLOT(pushButtonSearchClicked()));
|
|
|
|
|
connect(searchButton, SIGNAL(clicked()), this, SLOT(pushButtonSearchClicked()));
|
2025-01-14 21:33:47 +04:00
|
|
|
|
connect(ui->pushButtonDisregardPrice, SIGNAL(clicked()), this, SLOT(pushButtonDisregardPriceClicked()));
|
2024-12-24 18:13:22 +04:00
|
|
|
|
connect(ui->pushButtonApplyFilters, SIGNAL(clicked()), this, SLOT(pushButtonApplyFiltersClicked()));
|
|
|
|
|
connect(ui->pushButtonCancelFilters, SIGNAL(clicked()), this, SLOT(pushButtonCancelFiltersClicked()));
|
|
|
|
|
connect(ui->pushButtonDefault, SIGNAL(clicked()), this, SLOT(pushButtonDefaultClicked()));
|
|
|
|
|
connect(ui->pushButtonStructure, SIGNAL(clicked()), this, SLOT(pushButtonStructureClicked()));
|
|
|
|
|
connect(ui->pushButtonCharacteristics, SIGNAL(clicked()), this, SLOT(pushButtonCharacteristicsClicked()));
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
returnToDeviceList();
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateTableWidget(int index)
|
|
|
|
|
{
|
|
|
|
|
returnToDeviceList();
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->clearContents();
|
|
|
|
|
ui->tableWidget->setRowCount(0);
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
case 0: // Все устройства
|
|
|
|
|
clearDevicesOutputSettings();
|
2025-01-14 21:33:47 +04:00
|
|
|
|
updateDevices(-1);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
break;
|
|
|
|
|
case 1: // Типы устройств
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_client->getEntities("/api/devicetypes");
|
2024-12-24 18:13:22 +04:00
|
|
|
|
break;
|
|
|
|
|
case 2: // Помещения
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_client->getEntities("/api/locations");
|
2024-12-24 18:13:22 +04:00
|
|
|
|
break;
|
|
|
|
|
case 3: // Отделы
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_client->getEntities("/api/departments");
|
2024-12-24 18:13:22 +04:00
|
|
|
|
break;
|
|
|
|
|
case 4: // Производители
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_client->getEntities("/api/manufacturers");
|
2024-12-24 18:13:22 +04:00
|
|
|
|
break;
|
|
|
|
|
case 5: // Модели устройств
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_client->getEntities("/api/devicemodels");
|
2024-12-24 18:13:22 +04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateListWidget()
|
|
|
|
|
{
|
|
|
|
|
returnToDeviceList();
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
int selectedElementId = getSelectedElementId();
|
2024-12-24 18:13:22 +04:00
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
if (selectedElementId == -1)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
clearDevicesOutputSettings();
|
2025-01-14 21:33:47 +04:00
|
|
|
|
updateDevices(selectedElementId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::changeSortOrder()
|
|
|
|
|
{
|
|
|
|
|
updateDevices(getSelectedElementId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateDevices(int entityId)
|
|
|
|
|
{
|
|
|
|
|
_client->getFilteredDevices(
|
|
|
|
|
_filterParams.isWorking(),
|
|
|
|
|
_filterParams.priceFrom(),
|
|
|
|
|
_filterParams.priceTo(),
|
|
|
|
|
_filterParams.apllyFilters(),
|
|
|
|
|
_filterParams.disregardState(),
|
|
|
|
|
entityId,
|
|
|
|
|
ui->comboBoxFilters->currentIndex(),
|
|
|
|
|
_searchInfo,
|
|
|
|
|
ui->comboBoxSort->currentText()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MainWindow::getSelectedElementId()
|
|
|
|
|
{
|
|
|
|
|
QModelIndexList selectedIndexes = ui->tableWidget->selectionModel()->selectedRows();
|
|
|
|
|
|
|
|
|
|
if (selectedIndexes.isEmpty()) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rowIndex = selectedIndexes.first().row();
|
|
|
|
|
|
|
|
|
|
return ui->tableWidget->item(rowIndex, 0)->text().toInt();
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
void MainWindow::fillTable(const QMap<int, T> &map)
|
|
|
|
|
{
|
|
|
|
|
int row = 0;
|
|
|
|
|
for (auto &item : map) {
|
|
|
|
|
ui->tableWidget->insertRow(row);
|
|
|
|
|
|
|
|
|
|
QTableWidgetItem *idItem = new QTableWidgetItem(QString::number(item.id()));
|
|
|
|
|
QTableWidgetItem *nameItem = new QTableWidgetItem(item.name());
|
|
|
|
|
|
|
|
|
|
idItem->setFlags(idItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->setItem(row, 0, idItem);
|
|
|
|
|
ui->tableWidget->setItem(row, 1, nameItem);
|
|
|
|
|
|
|
|
|
|
idItem->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
nameItem->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
|
|
|
|
|
row++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::fillListWidget(const QList<Device> &devices)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
ui->listWidgetDevices->clear();
|
|
|
|
|
|
|
|
|
|
if (devices.isEmpty()) {
|
|
|
|
|
addMessageEmptyToList();
|
|
|
|
|
} else {
|
|
|
|
|
for (const auto &device : devices) {
|
|
|
|
|
addDeviceToList(device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::addMessageEmptyToList()
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(ui->listWidgetDevices);
|
|
|
|
|
ui->listWidgetDevices->addItem(item);
|
|
|
|
|
|
|
|
|
|
QWidget *cardWidget = createMessageEmptyCard();
|
|
|
|
|
|
|
|
|
|
item->setSizeHint(cardWidget->minimumSizeHint());
|
|
|
|
|
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
|
|
ui->listWidgetDevices->setItemWidget(item, cardWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::addDeviceToList(const Device &device)
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(ui->listWidgetDevices);
|
|
|
|
|
ui->listWidgetDevices->addItem(item);
|
|
|
|
|
|
|
|
|
|
QWidget *cardWidget = createDeviceCard(device);
|
|
|
|
|
|
|
|
|
|
item->setSizeHint(cardWidget->minimumSizeHint());
|
|
|
|
|
ui->listWidgetDevices->setItemWidget(item, cardWidget);
|
|
|
|
|
|
|
|
|
|
item->setData(Qt::UserRole, device.id());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createMessageEmptyCard()
|
|
|
|
|
{
|
|
|
|
|
QWidget *cardWidget = new QWidget(ui->listWidgetDevices);
|
|
|
|
|
QVBoxLayout *cardLayout = new QVBoxLayout(cardWidget);
|
|
|
|
|
|
|
|
|
|
QLabel *titleLabel = new QLabel("По заданным параметрам ничего не найдено", cardWidget);
|
|
|
|
|
QFont titleFont("Arial", 17, QFont::Bold);
|
|
|
|
|
titleLabel->setFont(titleFont);
|
|
|
|
|
|
|
|
|
|
cardLayout->addWidget(titleLabel, 0, Qt::AlignCenter);
|
|
|
|
|
|
|
|
|
|
cardLayout->setSpacing(12);
|
|
|
|
|
|
|
|
|
|
QLabel *imageLabel = new QLabel(cardWidget);
|
|
|
|
|
QPixmap pixmap(":/images/question.png");
|
|
|
|
|
imageLabel->setPixmap(pixmap.scaled(256, 256, Qt::KeepAspectRatio));
|
|
|
|
|
|
|
|
|
|
cardLayout->addWidget(imageLabel, 0, Qt::AlignCenter);
|
|
|
|
|
|
|
|
|
|
return cardWidget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *MainWindow::createDeviceCard(const Device &device)
|
|
|
|
|
{
|
|
|
|
|
QWidget *cardWidget = new QWidget(ui->listWidgetDevices);
|
|
|
|
|
QVBoxLayout *cardLayout = new QVBoxLayout(cardWidget);
|
|
|
|
|
|
|
|
|
|
QFrame *topBorder = new QFrame(cardWidget);
|
|
|
|
|
topBorder->setFrameShape(QFrame::HLine);
|
|
|
|
|
topBorder->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
|
|
|
|
|
cardLayout->addWidget(topBorder);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *iconTextlayout = new QHBoxLayout();
|
|
|
|
|
|
|
|
|
|
QLabel *imageLabel = new QLabel(cardWidget);
|
2025-01-14 21:33:47 +04:00
|
|
|
|
QString imagePath = _deviceTypeImages[device.deviceModel().idType()];
|
2024-12-24 18:13:22 +04:00
|
|
|
|
QPixmap pixmap(imagePath);
|
|
|
|
|
imageLabel->setPixmap(pixmap.scaled(100, 100, Qt::KeepAspectRatio));
|
|
|
|
|
|
|
|
|
|
iconTextlayout->addWidget(imageLabel);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *textLayout = new QVBoxLayout();
|
|
|
|
|
|
|
|
|
|
QLabel *serialNumberLabel = new QLabel(device.serialNumber(), cardWidget);
|
|
|
|
|
QFont serialNumberFont("Arial", 14, QFont::Bold);
|
|
|
|
|
serialNumberLabel->setFont(serialNumberFont);
|
2025-01-14 21:33:47 +04:00
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
textLayout->addWidget(serialNumberLabel);
|
|
|
|
|
|
|
|
|
|
QFont generalFont("Arial", 11);
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
QString typeName = normalizeTypeName(device.deviceModel().nameType());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
QLabel *typeNameLabel = new QLabel(typeName + ": " + device.deviceModel().name(), cardWidget);
|
|
|
|
|
typeNameLabel->setFont(generalFont);
|
2025-01-14 21:33:47 +04:00
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
textLayout->addWidget(typeNameLabel);
|
|
|
|
|
|
|
|
|
|
QLabel *statusLabel = new QLabel(device.isWorking() ? "Работает" : "Сломано", cardWidget);
|
|
|
|
|
statusLabel->setFont(generalFont);
|
2025-01-14 21:33:47 +04:00
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
textLayout->addWidget(statusLabel);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *priceLikeLayout = new QHBoxLayout();
|
|
|
|
|
priceLikeLayout->setSpacing(100);
|
|
|
|
|
|
|
|
|
|
QLabel *priceLabel = new QLabel(QString::number(device.price()) + " ₽", cardWidget);
|
|
|
|
|
priceLabel->setFont(generalFont);
|
|
|
|
|
priceLabel->setFixedWidth(100);
|
2025-01-14 21:33:47 +04:00
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
priceLikeLayout->addWidget(priceLabel);
|
|
|
|
|
|
|
|
|
|
priceLikeLayout->addSpacerItem(new QSpacerItem(40, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
|
|
|
|
|
|
QCheckBox *likeCheckBox = new QCheckBox("Нравится", cardWidget);
|
|
|
|
|
likeCheckBox->setChecked(device.isLiked());
|
|
|
|
|
likeCheckBox->setFont(generalFont);
|
|
|
|
|
likeCheckBox->setStyleSheet(likeCheckBox->isChecked() ? "color: green;" : "color: black;");
|
|
|
|
|
connect(likeCheckBox, &QCheckBox::toggled, this, [this, device, likeCheckBox](bool checked) {
|
2025-01-14 21:33:47 +04:00
|
|
|
|
Device updatedDevice = device;
|
|
|
|
|
updatedDevice.setIsLiked(checked);
|
|
|
|
|
_client->updateDevice(updatedDevice.id(), updatedDevice);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
connect(_client, &ApiClient::deviceUpdated, this, [this, checked, device, likeCheckBox](bool success) {
|
|
|
|
|
disconnect(_client, &ApiClient::deviceUpdated, this, nullptr);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
QString message = checked ? "Устройство добавлено в избранное." : "Устройство удалено из избранного.";
|
|
|
|
|
QMessageBox::information(this, "Обновление", message);
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
Device& deviceRef = _mapDevices[device.id()];
|
2024-12-24 18:13:22 +04:00
|
|
|
|
deviceRef.setIsLiked(checked);
|
|
|
|
|
|
|
|
|
|
likeCheckBox->setStyleSheet(checked ? "color: green;" : "color: black;");
|
|
|
|
|
} else {
|
|
|
|
|
QMessageBox::critical(this, "Ошибка", "Не удалось изменить состояние устройства.");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
priceLikeLayout->addWidget(likeCheckBox);
|
|
|
|
|
|
|
|
|
|
textLayout->addLayout(priceLikeLayout);
|
|
|
|
|
|
|
|
|
|
iconTextlayout->addSpacerItem(new QSpacerItem(40, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
|
|
|
|
iconTextlayout->addLayout(textLayout);
|
|
|
|
|
|
|
|
|
|
cardLayout->addLayout(iconTextlayout);
|
|
|
|
|
|
|
|
|
|
QFrame *bottomBorder = new QFrame(cardWidget);
|
|
|
|
|
bottomBorder->setFrameShape(QFrame::HLine);
|
|
|
|
|
bottomBorder->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
cardLayout->addWidget(bottomBorder);
|
|
|
|
|
|
|
|
|
|
cardLayout->setContentsMargins(2, 0, 2, 0);
|
|
|
|
|
|
|
|
|
|
return cardWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
QString MainWindow::normalizeTypeName(const QString &name)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
QString typeName = name.left(name.length() - 1);
|
|
|
|
|
if (typeName == "Персональные компьютер")
|
|
|
|
|
typeName = "Персональный компьютер";
|
|
|
|
|
return typeName;
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::showItemInfo(QListWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
ui->listWidgetDevices->scrollToItem(item, QAbstractItemView::PositionAtCenter);
|
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
int deviceId = item->data(Qt::UserRole).toInt();
|
2025-01-14 21:33:47 +04:00
|
|
|
|
Device device = _mapDevices[deviceId];
|
2024-12-24 18:13:22 +04:00
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_idCard = deviceId;
|
2024-12-24 18:13:22 +04:00
|
|
|
|
|
|
|
|
|
ui->lineEditId->setText(QString::number(device.id()));
|
|
|
|
|
ui->lineEditSerialNum->setText(device.serialNumber());
|
|
|
|
|
ui->lineEditPurchaseDate->setText(device.purchaseDate().toString("dd.MM.yyyy HH:mm:ss"));
|
|
|
|
|
ui->lineEditPrice->setText(QString::number(device.price(), 'f', 2));
|
|
|
|
|
ui->lineEditWarranty->setText(device.warrantyExpireDate().toString("dd.MM.yyyy HH:mm:ss"));
|
|
|
|
|
ui->lineEditLocation->setText(device.nameLocation());
|
|
|
|
|
ui->lineEditEmployee->setText(device.nameEmployee());
|
|
|
|
|
ui->lineEditDepartment->setText(device.nameDepartment());
|
|
|
|
|
ui->lineEditModel->setText(device.deviceModel().name());
|
|
|
|
|
ui->lineEditType->setText(device.deviceModel().nameType());
|
|
|
|
|
ui->lineEditManuf->setText(device.deviceModel().nameManuf());
|
|
|
|
|
ui->textEditFurtherInformation->setPlainText(device.furtherInformation());
|
|
|
|
|
ui->checkBoxIsWorking->setChecked(device.isWorking());
|
|
|
|
|
|
|
|
|
|
ui->stackedWidget->setCurrentIndex(1);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::returnToDeviceList()
|
|
|
|
|
{
|
|
|
|
|
_idCard = 0;
|
|
|
|
|
ui->stackedWidget->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 18:13:22 +04:00
|
|
|
|
void MainWindow::showTableWithStructureElements(const QList<DeviceStructureElement> &elements)
|
|
|
|
|
{
|
|
|
|
|
QDialog* dialog = new QDialog(this);
|
|
|
|
|
dialog->setWindowTitle("Элементы структуры устройства");
|
|
|
|
|
dialog->resize(1100, 600);
|
|
|
|
|
|
|
|
|
|
QTableWidget* tableWidget = new QTableWidget(dialog);
|
|
|
|
|
tableWidget->setColumnCount(5);
|
|
|
|
|
|
|
|
|
|
QFont font("Arial", 12);
|
|
|
|
|
tableWidget->setFont(font);
|
|
|
|
|
|
|
|
|
|
QStringList headers = {"Название модели", "Производитель", "Описание элемента", "Тип элемента", "Количество"};
|
|
|
|
|
tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
|
|
|
|
|
|
QFont headerFont("Arial", 12, QFont::Bold);
|
|
|
|
|
for (int i = 0; i < tableWidget->columnCount(); i++) {
|
|
|
|
|
tableWidget->horizontalHeaderItem(i)->setFont(headerFont);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tableWidget->setRowCount(elements.size());
|
|
|
|
|
for (int row = 0; row < elements.size(); row++) {
|
|
|
|
|
const DeviceStructureElement& element = elements[row];
|
|
|
|
|
|
|
|
|
|
tableWidget->setItem(row, 0, new QTableWidgetItem(element.nameModel()));
|
|
|
|
|
tableWidget->setItem(row, 1, new QTableWidgetItem(element.nameManuf()));
|
|
|
|
|
tableWidget->setItem(row, 2, new QTableWidgetItem(element.description()));
|
|
|
|
|
tableWidget->setItem(row, 3, new QTableWidgetItem(element.nameType()));
|
|
|
|
|
tableWidget->setItem(row, 4, new QTableWidgetItem(QString::number(element.count())));
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < tableWidget->columnCount(); col++) {
|
|
|
|
|
tableWidget->item(row, col)->setFlags(tableWidget->item(row, col)->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(tableWidget, &QTableWidget::cellClicked, [tableWidget](int row, int col) {
|
|
|
|
|
QString text = tableWidget->item(row, col)->text();
|
|
|
|
|
QToolTip::showText(QCursor::pos(), text);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Interactive);
|
|
|
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch);
|
|
|
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
|
|
|
|
tableWidget->setColumnWidth(2, tableWidget->columnWidth(0) * 2);
|
|
|
|
|
|
|
|
|
|
tableWidget->setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(dialog);
|
|
|
|
|
layout->addWidget(tableWidget);
|
|
|
|
|
|
|
|
|
|
dialog->setLayout(layout);
|
|
|
|
|
dialog->exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::showTableWithDeviceModelCharacteristics(const DeviceModel &model)
|
|
|
|
|
{
|
|
|
|
|
QDialog* dialog = new QDialog(this);
|
|
|
|
|
dialog->setWindowTitle("Характеристики устройства");
|
|
|
|
|
dialog->setFixedSize(1200, 75);
|
|
|
|
|
|
|
|
|
|
QTableWidget* tableWidget = new QTableWidget(dialog);
|
|
|
|
|
tableWidget->setColumnCount(6);
|
|
|
|
|
|
|
|
|
|
QFont font("Arial", 11);
|
|
|
|
|
tableWidget->setFont(font);
|
|
|
|
|
|
|
|
|
|
QStringList headers = {"Эффективность работы", "Надежность", "Энергоэффективность", "Удобство использования", "Долговечность", "Эстетические качества"};
|
|
|
|
|
tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
|
|
|
|
|
|
QFont headerFont("Arial", 11, QFont::Bold);
|
|
|
|
|
for (int i = 0; i < tableWidget->columnCount(); i++) {
|
|
|
|
|
tableWidget->horizontalHeaderItem(i)->setFont(headerFont);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tableWidget->setRowCount(1);
|
|
|
|
|
tableWidget->setItem(0, 0, new QTableWidgetItem(QString::number(model.workEfficiency())));
|
|
|
|
|
tableWidget->setItem(0, 1, new QTableWidgetItem(QString::number(model.reliability())));
|
|
|
|
|
tableWidget->setItem(0, 2, new QTableWidgetItem(QString::number(model.energyEfficiency())));
|
|
|
|
|
tableWidget->setItem(0, 3, new QTableWidgetItem(QString::number(model.userFriendliness())));
|
|
|
|
|
tableWidget->setItem(0, 4, new QTableWidgetItem(QString::number(model.durability())));
|
|
|
|
|
tableWidget->setItem(0, 5, new QTableWidgetItem(QString::number(model.aestheticQualities())));
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < tableWidget->columnCount(); col++) {
|
|
|
|
|
tableWidget->item(0, col)->setFlags(tableWidget->item(0, col)->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
tableWidget->item(0, col)->setTextAlignment(Qt::AlignCenter);
|
|
|
|
|
tableWidget->horizontalHeader()->setSectionResizeMode(col, QHeaderView::Stretch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tableWidget->verticalHeader()->setVisible(false);
|
|
|
|
|
tableWidget->setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(dialog);
|
|
|
|
|
layout->addWidget(tableWidget);
|
|
|
|
|
|
|
|
|
|
dialog->setLayout(layout);
|
|
|
|
|
dialog->exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonBackClicked()
|
|
|
|
|
{
|
|
|
|
|
returnToDeviceList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonClearClicked()
|
|
|
|
|
{
|
|
|
|
|
ui->lineEditSearch->setText("");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonSearchClicked()
|
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_searchInfo = ui->lineEditSearch->text();
|
|
|
|
|
if (_searchInfo.isEmpty()) {
|
2024-12-24 18:13:22 +04:00
|
|
|
|
QMessageBox::warning(this, "Ошибка", "Пожалуйста, введите текст для поиска.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ui->comboBoxSort->setCurrentIndex(0);
|
|
|
|
|
clearFilters();
|
2025-01-14 21:33:47 +04:00
|
|
|
|
updateDevices(getSelectedElementId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonDisregardPriceClicked()
|
|
|
|
|
{
|
|
|
|
|
clearSpinBoxes();
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonApplyFiltersClicked()
|
|
|
|
|
{
|
|
|
|
|
double priceFrom = ui->doubleSpinBoxFrom->value();
|
|
|
|
|
double priceTo = ui->doubleSpinBoxTo->value();
|
|
|
|
|
if (priceFrom > priceTo) {
|
|
|
|
|
QMessageBox::warning(this, "Ошибка", "Начальное значение диапазона не может быть больше конечного значения.");
|
2025-01-14 21:33:47 +04:00
|
|
|
|
clearSpinBoxes();
|
2024-12-24 18:13:22 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_filterParams.setApllyFilters(true);
|
|
|
|
|
_filterParams.setDisregardState(ui->radioButtonDisregard->isChecked());
|
|
|
|
|
_filterParams.setIsWorking(ui->radioButtonWorking->isChecked());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
|
|
|
|
|
if (priceFrom == 0.00 && priceTo == 0.00) {
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_filterParams.setPriceFrom(0.00);
|
|
|
|
|
_filterParams.setPriceTo(std::numeric_limits<double>::max());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
} else {
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_filterParams.setPriceFrom(priceFrom);
|
|
|
|
|
_filterParams.setPriceTo(priceTo);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
updateDevices(getSelectedElementId());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonCancelFiltersClicked()
|
|
|
|
|
{
|
|
|
|
|
clearFilters();
|
2025-01-14 21:33:47 +04:00
|
|
|
|
updateDevices(getSelectedElementId());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonStructureClicked()
|
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
showTableWithStructureElements(_mapDevices[_idCard].deviceModel().structureElements());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonCharacteristicsClicked()
|
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
showTableWithDeviceModelCharacteristics(_mapDevices[_idCard].deviceModel());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonDefaultClicked()
|
|
|
|
|
{
|
|
|
|
|
clearDevicesOutputSettings();
|
2025-01-14 21:33:47 +04:00
|
|
|
|
updateDevices(getSelectedElementId());
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::clearDevicesOutputSettings()
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
ui->comboBoxSort->setCurrentIndex(0);
|
|
|
|
|
|
|
|
|
|
ui->lineEditSearch->setText("");
|
|
|
|
|
_searchInfo = "";
|
|
|
|
|
|
|
|
|
|
clearFilters();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::clearFilters()
|
|
|
|
|
{
|
|
|
|
|
ui->radioButtonWorking->setChecked(true);
|
|
|
|
|
clearSpinBoxes();
|
|
|
|
|
_filterParams.setIsWorking(true);
|
|
|
|
|
_filterParams.setPriceFrom(-1);
|
|
|
|
|
_filterParams.setPriceTo(-1);
|
|
|
|
|
_filterParams.setDisregardState(false);
|
|
|
|
|
_filterParams.setApllyFilters(false);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::clearSpinBoxes()
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
ui->doubleSpinBoxFrom->setValue(0.00);
|
|
|
|
|
ui->doubleSpinBoxTo->setValue(0.00);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::setClient(ApiClient *newClient)
|
|
|
|
|
{
|
|
|
|
|
_client = newClient;
|
|
|
|
|
connect(_client, &ApiClient::devicesReceived, this, &MainWindow::onDevicesReceived);
|
|
|
|
|
connect(_client, &ApiClient::departmentsReceived, this, &MainWindow::onDepartmentsReceived);
|
|
|
|
|
connect(_client, &ApiClient::deviceModelsReceived, this, &MainWindow::onDeviceModelsReceived);
|
|
|
|
|
connect(_client, &ApiClient::deviceTypesReceived, this, &MainWindow::onDeviceTypesReceived);
|
|
|
|
|
connect(_client, &ApiClient::locationsReceived, this, &MainWindow::onLocationsReceived);
|
|
|
|
|
connect(_client, &ApiClient::manufacturersReceived, this, &MainWindow::onManufacturersReceived);
|
|
|
|
|
_client->getEntities("/api/devicetypes");
|
2024-12-24 18:13:22 +04:00
|
|
|
|
updateTableWidget(0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::onDevicesReceived(const QList<Device> &devices)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
_mapDevices = getDevicesMap(devices);
|
|
|
|
|
|
|
|
|
|
fillListWidget(devices);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::onDepartmentsReceived(const QMap<int, Department> &departments)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
fillTable<Department>(departments);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::onDeviceModelsReceived(const QMap<int, DeviceModel> &deviceModels)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
fillTable<DeviceModel>(deviceModels);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::onDeviceTypesReceived(const QMap<int, DeviceType> &deviceTypes)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
if (_initialTypesLoad) {
|
|
|
|
|
_initialTypesLoad = false;
|
|
|
|
|
} else {
|
|
|
|
|
fillTable<DeviceType>(deviceTypes);
|
|
|
|
|
}
|
|
|
|
|
for (const DeviceType &type : deviceTypes) {
|
|
|
|
|
QString imagePath = QString(":/images/device-type-%1.png").arg(type.name());
|
|
|
|
|
|
|
|
|
|
if (QFile::exists(imagePath)) {
|
|
|
|
|
_deviceTypeImages[type.id()] = imagePath;
|
|
|
|
|
} else {
|
|
|
|
|
_deviceTypeImages[type.id()] = ":/images/placeholder.png";
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::onManufacturersReceived(const QMap<int, Manufacturer> &manufacturers)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
fillTable<Manufacturer>(manufacturers);
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 21:33:47 +04:00
|
|
|
|
void MainWindow::onLocationsReceived(const QMap<int, Location> &locations)
|
2024-12-24 18:13:22 +04:00
|
|
|
|
{
|
2025-01-14 21:33:47 +04:00
|
|
|
|
fillTable<Location>(locations);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<int, Device> MainWindow::getDevicesMap(const QList<Device> &devices)
|
|
|
|
|
{
|
|
|
|
|
QMap<int, Device> devicesMap;
|
|
|
|
|
|
|
|
|
|
for (const Device &device : devices) {
|
|
|
|
|
devicesMap.insert(device.id(), device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return devicesMap;
|
2024-12-24 18:13:22 +04:00
|
|
|
|
}
|