#include "editpdfwidget.h" #include "../controller/maincontroller.h" #include #include #include EditPDFWidget::EditPDFWidget(QWidget *parent) : QWidget{parent} , m_componentModel(nullptr) , m_projectParamModel(nullptr) , m_controller(nullptr) { setUp(); } EditPDFWidget::EditPDFWidget(MainController *controller, QWidget *parent) : QWidget{parent} , m_componentModel(nullptr) , m_projectParamModel(nullptr) , m_controller(controller) { setUp(); } void EditPDFWidget::setUp(){ setWidgets(); setUpLayout(); setUpConnections(); } void EditPDFWidget::setWidgets(){ m_tabWidget = new QTabWidget(this); // Создаем процессоры документов m_perechenProcessor = new PerechenProcessor(this); m_specificationProcessor = new SpecificationProcessor(this); m_specificationPCBProcessor = new SpecificationPCBProcessor(this); m_vedomostProcessor = new VedomostProcessor(this); m_simpleListProcessor = new SimpleListProcessor(this); // Устанавливаем PerechenTableController из MainController в PerechenProcessor if (m_controller && m_perechenProcessor) { PerechenTableController *perechenController = m_controller->perechenTableController(); if (perechenController) { // Заменяем контроллер в PerechenProcessor на контроллер из MainController // Это обеспечивает единую точку управления данными qDebug() << "EditPDFWidget::setWidgets: Используем PerechenTableController из MainController"; m_perechenProcessor->setController(perechenController); // Также устанавливаем модель из MainController в PerechenProcessor PerechenTableModel *perechenModel = m_controller->perechenTableModel(); if (perechenModel) { qDebug() << "EditPDFWidget::setWidgets: Устанавливаем PerechenTableModel из MainController в PerechenProcessor"; m_perechenProcessor->setModel(perechenModel); } } } // Устанавливаем SpecificationPCBController из MainController в SpecificationPCBProcessor if (m_controller && m_specificationPCBProcessor) { SpecificationPCBController *specPCBController = m_controller->specificationPCBController(); if (specPCBController) { // Заменяем контроллер в SpecificationPCBProcessor на контроллер из MainController qDebug() << "EditPDFWidget::setWidgets: Используем SpecificationPCBController из MainController"; m_specificationPCBProcessor->setController(specPCBController); // Также устанавливаем модель из MainController в SpecificationPCBProcessor SpecificationPCBTableModel *specPCBModel = m_controller->specificationPCBTableModel(); if (specPCBModel) { qDebug() << "EditPDFWidget::setWidgets: Устанавливаем SpecificationPCBTableModel из MainController в SpecificationPCBProcessor"; m_specificationPCBProcessor->setModel(specPCBModel); } } } // Устанавливаем SpecificationController из MainController в SpecificationProcessor if (m_controller && m_specificationProcessor) { SpecificationController *specController = m_controller->specificationController(); if (specController) { // Заменяем контроллер в SpecificationProcessor на контроллер из MainController qDebug() << "EditPDFWidget::setWidgets: Используем SpecificationController из MainController"; m_specificationProcessor->setController(specController); // Также устанавливаем модель из MainController в SpecificationProcessor SpecificationTableModel *specModel = m_controller->specificationTableModel(); if (specModel) { qDebug() << "EditPDFWidget::setWidgets: Устанавливаем SpecificationTableModel из MainController в SpecificationProcessor"; m_specificationProcessor->setModel(specModel); } } } // Устанавливаем VedomostController из MainController в VedomostProcessor if (m_controller && m_vedomostProcessor) { VedomostController *vedomostController = m_controller->vedomostController(); if (vedomostController) { // Заменяем контроллер в VedomostProcessor на контроллер из MainController qDebug() << "EditPDFWidget::setWidgets: Используем VedomostController из MainController"; m_vedomostProcessor->setController(vedomostController); // Также устанавливаем модель из MainController в VedomostProcessor VedomostTableModel *vedomostModel = m_controller->vedomostTableModel(); if (vedomostModel) { qDebug() << "EditPDFWidget::setWidgets: Устанавливаем VedomostTableModel из MainController в VedomostProcessor"; m_vedomostProcessor->setModel(vedomostModel); } } } // Устанавливаем SimpleListTableController из MainController в SimpleListProcessor if (m_controller && m_simpleListProcessor) { SimpleListTableController *simpleListController = m_controller->simpleListTableController(); if (simpleListController) { qDebug() << "EditPDFWidget::setWidgets: Используем SimpleListTableController из MainController"; m_simpleListProcessor->setController(simpleListController); SimpleListTableModel *simpleListModel = m_controller->simpleListTableModel(); if (simpleListModel) { qDebug() << "EditPDFWidget::setWidgets: Устанавливаем SimpleListTableModel из MainController в SimpleListProcessor"; m_simpleListProcessor->setModel(simpleListModel); } } } // Создаем виджеты документов с соответствующими процессорами if (m_controller) { // Используем новый конструктор с контроллером для сохранения настроек m_perechenEditWidget = new DocumentEditWidget(m_perechenProcessor, m_controller, this); m_specificationEditWidget = new DocumentEditWidget(m_specificationProcessor, m_controller, this); m_specificationPCBEditWidget = new DocumentEditWidget(m_specificationPCBProcessor, m_controller, this); m_vedomostEditWidget = new DocumentEditWidget(m_vedomostProcessor, m_controller, this); m_simpleListEditWidget = new DocumentEditWidget(m_simpleListProcessor, m_controller, this); } else { // Используем старый конструктор для обратной совместимости m_perechenEditWidget = new DocumentEditWidget(m_perechenProcessor, this); m_specificationEditWidget = new DocumentEditWidget(m_specificationProcessor, this); m_specificationPCBEditWidget = new DocumentEditWidget(m_specificationPCBProcessor, this); m_vedomostEditWidget = new DocumentEditWidget(m_vedomostProcessor, this); m_simpleListEditWidget = new DocumentEditWidget(m_simpleListProcessor, this); } m_tabWidget->addTab(m_specificationEditWidget, "Спецификация"); m_tabWidget->addTab(m_specificationPCBEditWidget, "Спецификация ПП"); m_tabWidget->addTab(m_vedomostEditWidget, "Ведомость"); m_tabWidget->addTab(m_perechenEditWidget, "Перечень"); m_tabWidget->addTab(m_simpleListEditWidget, "Бланк заказа"); } void EditPDFWidget::setUpLayout(){ QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->addWidget(m_tabWidget); this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } void EditPDFWidget::setUpConnections(){ // Подключаем сигнал изменения таба для синхронизации с PreviewPdfWidget connect(m_tabWidget, QOverload::of(&QTabWidget::currentChanged), this, [this](int index) { QString documentType; switch (index) { case 0: // Спецификация documentType = "Спецификация"; break; case 1: // Спецификация ПП documentType = "Спецификация PCB"; break; case 2: // Ведомость documentType = "Ведомость"; // Пока не поддерживается в PreviewPdfWidget break; case 3: // Перечень documentType = "Перечень элементов"; break; default: documentType = "Перечень элементов"; break; } emit documentTypeChanged(documentType); }); // Пока убираем экспорт, так как методы не реализованы // TODO: Добавить экспорт когда будет реализован } void EditPDFWidget::setData(ComponentTableModel *componentModel, ProjectParamTableModel *projectParamModel) { m_componentModel = componentModel; m_projectParamModel = projectParamModel; // Передаем данные во все виджеты документов m_perechenEditWidget->setData(componentModel, projectParamModel); m_specificationEditWidget->setData(componentModel, projectParamModel); m_specificationPCBEditWidget->setData(componentModel, projectParamModel); m_vedomostEditWidget->setData(componentModel, projectParamModel); m_simpleListEditWidget->setData(componentModel, projectParamModel); } void EditPDFWidget::updateAllViews() { qDebug() << "EditPDFWidget::updateAllViews: Начинаем обновление всех представлений"; if (m_componentModel && m_projectParamModel) { qDebug() << "EditPDFWidget::updateAllViews: Обновляем представление перечня"; m_perechenEditWidget->updateView(); qDebug() << "EditPDFWidget::updateAllViews: Обновляем представление спецификации"; m_specificationEditWidget->updateView(); qDebug() << "EditPDFWidget::updateAllViews: Обновляем представление спецификации ПП"; m_specificationPCBEditWidget->updateView(); qDebug() << "EditPDFWidget::updateAllViews: Обновляем представление ведомости"; m_vedomostEditWidget->updateView(); qDebug() << "EditPDFWidget::updateAllViews: Все представления обновлены"; } else { qDebug() << "EditPDFWidget::updateAllViews: Модели данных недоступны"; } } bool EditPDFWidget::exportCurrentDocument(const QString &filePath) { // TODO: Реализовать экспорт текущего документа Q_UNUSED(filePath) return false; } bool EditPDFWidget::exportAllDocuments(const QString &basePath) { // TODO: Реализовать экспорт всех документов Q_UNUSED(basePath) return false; } TitleInscriptionsModel* EditPDFWidget::getTitleInscriptionsModel() const { // Возвращаем модель надписей из MainController if (m_controller) { return m_controller->titleInscriptionsModel(); } return nullptr; } PerechenTableModel* EditPDFWidget::getPerechenTableModel() const { // Теперь получаем модель напрямую из MainController if (m_controller) { return m_controller->perechenTableModel(); } return nullptr; }