Add initial project structure with essential files including .gitignore, application resources, and various model and view components for the application. Implemented asynchronous parsing support and database structure checks.
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "pcbmaterialpreview.h"
|
||||
#include <QDebug>
|
||||
|
||||
PCBMaterialPreview::PCBMaterialPreview(PCBMaterialModel* model, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_tableModel(model)
|
||||
{
|
||||
setUp();
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::setUp()
|
||||
{
|
||||
setWidgets();
|
||||
setUpLayout();
|
||||
setUpConnections();
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::setWidgets()
|
||||
{
|
||||
// Если модель не передана, создаем новую
|
||||
if (!m_tableModel) {
|
||||
m_tableModel = new PCBMaterialModel(this);
|
||||
}
|
||||
|
||||
m_tableView = new QTableView(this);
|
||||
m_layerCountLabel = new QLabel("Количество слоев: 0", this);
|
||||
|
||||
// Настраиваем таблицу
|
||||
m_tableView->setModel(m_tableModel);
|
||||
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_tableView->setAlternatingRowColors(true);
|
||||
m_tableView->setSortingEnabled(true);
|
||||
|
||||
// Настраиваем заголовки
|
||||
m_tableView->horizontalHeader()->setStretchLastSection(true);
|
||||
m_tableView->horizontalHeader()->setSectionsClickable(true);
|
||||
m_tableView->verticalHeader()->setVisible(false);
|
||||
|
||||
qDebug() << "PCBMaterialPreview: Виджет создан";
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::setUpLayout()
|
||||
{
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
||||
|
||||
// Добавляем информацию о количестве слоев
|
||||
mainLayout->addWidget(m_layerCountLabel);
|
||||
|
||||
// Добавляем таблицу
|
||||
mainLayout->addWidget(m_tableView);
|
||||
|
||||
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::setUpConnections()
|
||||
{
|
||||
// Подключаем сигналы выбора строк
|
||||
if (m_tableView) {
|
||||
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
[this](const QItemSelection &selected, const QItemSelection &deselected) {
|
||||
if (!selected.isEmpty()) {
|
||||
int row = selected.indexes().first().row();
|
||||
emit materialSelected(row);
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_tableView, &QTableView::doubleClicked,
|
||||
[this](const QModelIndex &index) {
|
||||
emit materialDoubleClicked(index.row());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::updateView()
|
||||
{
|
||||
if (m_tableModel) {
|
||||
m_tableModel->loadMaterials();
|
||||
int layerCount = m_tableModel->getLayerCount();
|
||||
int materialCount = m_tableModel->getMaterialCount();
|
||||
|
||||
m_layerCountLabel->setText(QString("Количество слоев: %1 | Материалов: %2")
|
||||
.arg(layerCount).arg(materialCount));
|
||||
|
||||
qDebug() << "PCBMaterialPreview: Обновлено отображение - слоев:" << layerCount
|
||||
<< "материалов:" << materialCount;
|
||||
} else {
|
||||
qDebug() << "PCBMaterialPreview: m_tableModel равен nullptr";
|
||||
}
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::setPCBMaterials(const QList<PCBMaterialData> &materials)
|
||||
{
|
||||
if (m_tableModel) {
|
||||
// Этот метод может быть использован для программной установки данных
|
||||
// В текущей реализации данные загружаются из БД через loadMaterials()
|
||||
qDebug() << "PCBMaterialPreview: Установлено материалов:" << materials.size();
|
||||
}
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::setLayerCount(int layerCount)
|
||||
{
|
||||
if (m_layerCountLabel) {
|
||||
m_layerCountLabel->setText(QString("Количество слоев: %1").arg(layerCount));
|
||||
}
|
||||
}
|
||||
|
||||
void PCBMaterialPreview::clear()
|
||||
{
|
||||
if (m_tableModel) {
|
||||
m_tableModel->clearMaterials();
|
||||
m_layerCountLabel->setText("Количество слоев: 0");
|
||||
}
|
||||
}
|
||||
|
||||
PCBMaterialModel* PCBMaterialPreview::tableModel() const
|
||||
{
|
||||
return m_tableModel;
|
||||
}
|
||||
Reference in New Issue
Block a user