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:
2025-12-08 15:21:18 +03:00
parent 4f8c90c15b
commit 3467003721
110 changed files with 35406 additions and 0 deletions
+215
View File
@@ -0,0 +1,215 @@
#include "designatormappingdialog.h"
#include "adddesignatordialog.h"
#include <QMessageBox>
#include <QInputDialog>
#include <QApplication>
#include <QRegularExpression>
DesignatorMappingDialog::DesignatorMappingDialog(DesignatorMappingModel *mappingModel, QWidget *parent)
: QDialog(parent)
, m_mappingModel(mappingModel)
{
setUp();
}
void DesignatorMappingDialog::setUp()
{
setWindowTitle(tr("Настройки маппинга дезигнаторов"));
setModal(true);
resize(800, 600);
// Создаем модель таблицы
m_tableModel = new DesignatorMappingTableModel(m_mappingModel, this);
setUpLayout();
setUpConnections();
updateButtons();
}
void DesignatorMappingDialog::setUpLayout()
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
// Группа фильтров
m_filterGroupBox = new QGroupBox(tr("Фильтры"), this);
QHBoxLayout *filterLayout = new QHBoxLayout(m_filterGroupBox);
QLabel *filterLabel = new QLabel(tr("Поиск:"), this);
m_filterEdit = new QLineEdit(this);
m_filterEdit->setPlaceholderText(tr("Введите текст для поиска..."));
m_showOnlyCustomCheckBox = new QCheckBox(tr("Только пользовательские"), this);
filterLayout->addWidget(filterLabel);
filterLayout->addWidget(m_filterEdit);
filterLayout->addWidget(m_showOnlyCustomCheckBox);
filterLayout->addStretch();
// Группа таблицы
m_tableGroupBox = new QGroupBox(tr("Маппинг дезигнаторов"), this);
QVBoxLayout *tableLayout = new QVBoxLayout(m_tableGroupBox);
m_tableView = new QTableView(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->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // Дезигнатор
m_tableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); // Единственное число
m_tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); // Множественное число
m_tableView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents); // Пользовательское
tableLayout->addWidget(m_tableView);
// Группа кнопок
m_buttonsGroupBox = new QGroupBox(this);
QHBoxLayout *buttonsLayout = new QHBoxLayout(m_buttonsGroupBox);
m_addButton = new QPushButton(tr("Добавить"), this);
m_removeButton = new QPushButton(tr("Удалить"), this);
m_resetButton = new QPushButton(tr("Сбросить к умолчанию"), this);
m_saveButton = new QPushButton(tr("Сохранить"), this);
buttonsLayout->addWidget(m_addButton);
buttonsLayout->addWidget(m_removeButton);
buttonsLayout->addStretch();
buttonsLayout->addWidget(m_resetButton);
buttonsLayout->addWidget(m_saveButton);
// Кнопки диалога
QHBoxLayout *dialogButtonsLayout = new QHBoxLayout;
m_okButton = new QPushButton(tr("OK"), this);
m_cancelButton = new QPushButton(tr("Отмена"), this);
dialogButtonsLayout->addStretch();
dialogButtonsLayout->addWidget(m_okButton);
dialogButtonsLayout->addWidget(m_cancelButton);
// Добавляем все в основной layout
mainLayout->addWidget(m_filterGroupBox);
mainLayout->addWidget(m_tableGroupBox);
mainLayout->addWidget(m_buttonsGroupBox);
mainLayout->addLayout(dialogButtonsLayout);
setLayout(mainLayout);
}
void DesignatorMappingDialog::setUpConnections()
{
// Соединения для фильтров
connect(m_filterEdit, &QLineEdit::textChanged,
this, &DesignatorMappingDialog::onFilterTextChanged);
connect(m_showOnlyCustomCheckBox, &QCheckBox::toggled,
this, &DesignatorMappingDialog::onShowOnlyCustomChanged);
// Соединения для кнопок
connect(m_addButton, &QPushButton::clicked,
this, &DesignatorMappingDialog::onAddMapping);
connect(m_removeButton, &QPushButton::clicked,
this, &DesignatorMappingDialog::onRemoveMapping);
connect(m_resetButton, &QPushButton::clicked,
this, &DesignatorMappingDialog::onResetToDefaults);
connect(m_saveButton, &QPushButton::clicked,
this, &DesignatorMappingDialog::onSaveSettings);
// Соединения для кнопок диалога
connect(m_okButton, &QPushButton::clicked,
this, &QDialog::accept);
connect(m_cancelButton, &QPushButton::clicked,
this, &QDialog::reject);
// Соединения для выбора в таблице
connect(m_tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &DesignatorMappingDialog::onSelectionChanged);
}
void DesignatorMappingDialog::updateButtons()
{
QModelIndex currentIndex = m_tableView->currentIndex();
bool hasSelection = currentIndex.isValid();
m_removeButton->setEnabled(hasSelection);
}
void DesignatorMappingDialog::onAddMapping()
{
AddDesignatorDialog dialog(this);
if (dialog.exec() == QDialog::Accepted) {
QString designator = dialog.getDesignator();
// Проверяем, не существует ли уже такой дезигнатор
if (m_mappingModel) {
QList<DesignatorMappingItem> mappings = m_mappingModel->mappings();
for (const auto &item : mappings) {
if (item.designator == designator) {
QMessageBox::warning(this, tr("Ошибка"),
tr("Дезигнатор '%1' уже существует.").arg(designator));
return;
}
}
}
DesignatorMappingItem newItem = dialog.getMapping();
m_tableModel->addMapping(newItem);
}
}
void DesignatorMappingDialog::onRemoveMapping()
{
QModelIndex currentIndex = m_tableView->currentIndex();
if (!currentIndex.isValid()) {
return;
}
DesignatorMappingItem item = m_tableModel->getMapping(currentIndex.row());
int result = QMessageBox::question(this, tr("Подтверждение удаления"),
tr("Удалить маппинг для дезигнатора '%1'?").arg(item.designator),
QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::Yes) {
m_tableModel->removeMapping(currentIndex.row());
}
}
void DesignatorMappingDialog::onResetToDefaults()
{
int result = QMessageBox::question(this, tr("Сброс к умолчанию"),
tr("Все пользовательские настройки будут удалены. Продолжить?"),
QMessageBox::Yes | QMessageBox::No);
if (result == QMessageBox::Yes) {
if (m_mappingModel) {
m_mappingModel->resetToDefaults();
}
}
}
void DesignatorMappingDialog::onSaveSettings()
{
if (m_mappingModel) {
m_mappingModel->saveToDatabase();
QMessageBox::information(this, tr("Сохранение"),
tr("Настройки успешно сохранены в базе данных."));
}
}
void DesignatorMappingDialog::onFilterTextChanged(const QString &text)
{
m_tableModel->setFilterText(text);
}
void DesignatorMappingDialog::onShowOnlyCustomChanged(bool checked)
{
m_tableModel->setShowOnlyCustom(checked);
}
void DesignatorMappingDialog::onSelectionChanged()
{
updateButtons();
}