1
0
forked from BRT/arc
arc/views/AccountWindow.cpp
slava c3fed927fc Remove macOS-specific Scrcpy embedding and cleanup debug logs
Removed Scrcpy embedding code and related configurations for macOS. Commented out excessive debug logging in multiple files to reduce console noise. Simplified CMakeLists.txt by unifying platform-specific sections for improved build system clarity.
2025-04-26 15:16:42 +07:00

101 lines
4.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "AccountWindow.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QTableWidget>
#include <QHeaderView>
#include <QScrollArea>
#include "TransactionWindow.h"
#include "dao/AccountDAO.h"
#include "dao/DeviceDAO.h"
AccountWindow::AccountWindow(QWidget *parent): QWidget(parent) {
auto *mainLayout = new QVBoxLayout(this);
// Скролл-область
auto *scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
// Виджет-контейнер, в котором будет layout с таблицами и лейблами
auto *contentWidget = new QWidget;
auto *layout = new QVBoxLayout(contentWidget);
// Убираем отступы и рамку
contentWidget->setContentsMargins(0, 0, 0, 0); // Убираем отступы
layout->setContentsMargins(0, 0, 0, 0); // Убираем отступы у layout
scrollArea->setStyleSheet("border: none;"); // Убираем рамку
layout->setAlignment(Qt::AlignTop);
QList<DeviceInfo> devices = DeviceDAO::getAllDevices(false);
for (int i = 0; i < devices.size(); ++i) {
DeviceInfo device = devices[i];
QList<AccountInfo> accounts = AccountDAO::getAccounts(device.id, "bank");
// Текст перед первой таблицей
QString title = QString("%1 [%2] | %3").arg(device.name, device.id, device.status);
QLabel *label = new QLabel(title, this);
layout->addWidget(label);
if (accounts.length() > 0) {
QTableWidget *tableWidget = new QTableWidget(this);
tableWidget->setStyleSheet("QTableWidget {"
"border: 1px solid grey;"
"}");
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(tableWidget, &QTableWidget::itemDoubleClicked, this, &AccountWindow::onItemDoubleClicked);
tableWidget->setRowCount(accounts.length()); // Устанавливаем количество строк
tableWidget->setColumnCount(5); // Устанавливаем количество столбцов
tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
tableWidget->setHorizontalHeaderLabels({"Карта", "Сумма", "Время обновления", "Описание", "Статус"});
tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
int totalHeight = tableWidget->horizontalHeader()->height();
for (int k = 0; k < accounts.size(); ++k) {
AccountInfo account = accounts[k];
QTableWidgetItem *item = new QTableWidgetItem("*" + account.cardName);
item->setData(Qt::UserRole, account.id);
tableWidget->setItem(k, 0, item);
tableWidget->setItem(k, 1, new QTableWidgetItem(QString::number(account.amount)));
tableWidget->setItem(k, 2, new QTableWidgetItem(account.updateTime.toString("dd.MM.yyyy HH:mm:ss")));
tableWidget->setItem(k, 3, new QTableWidgetItem(account.description));
tableWidget->setItem(k, 4, new QTableWidgetItem(account.status));
totalHeight += tableWidget->rowHeight(k);
}
tableWidget->setFixedHeight(totalHeight + 2);
layout->addWidget(tableWidget);
}
if (i < devices.size() - 1) {
QFrame *separator = new QFrame(this);
separator->setFrameShape(QFrame::VLine);
separator->setStyleSheet("background-color: black;"); // Цвет разделителя
separator->setFixedHeight(1);
separator->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->addWidget(separator);
}
}
// Добавим вертикальный Spacer в конец, чтобы прокручиваемая область не растягивала контент
QSpacerItem *spacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout->addItem(spacer);
contentWidget->setLayout(layout);
scrollArea->setWidget(contentWidget);
mainLayout->addWidget(scrollArea);
setLayout(mainLayout);
setWindowTitle("Таблица устройств");
}
void AccountWindow::onItemDoubleClicked(QTableWidgetItem *item) {
int column = item->column();
if (column == 0) {
int accountId = item->data(Qt::UserRole).toInt();
// qDebug() << accountId;
TransactionWindow *detailWindow = new TransactionWindow(accountId, this);
detailWindow->exec(); // Ожидаем закрытия окна
}
}