Files
GostGenerator/model/projectsettingsmodel.cpp
T

221 lines
7.9 KiB
C++

#include "projectsettingsmodel.h"
#include <QDebug>
// Статические константы
const QStringList ProjectSettingsModel::DEFAULT_COLUMN_MAPPINGS = QStringList()
<< "Designator" << "<Пусто>" << "<Пусто>" << "<Пусто>";
const QString ProjectSettingsModel::DEFAULT_VARIANT = "No Variations";
ProjectSettingsModel::ProjectSettingsModel(QObject *parent)
: QObject{parent}
, m_currentVariant(DEFAULT_VARIANT)
, m_columnMappings(DEFAULT_COLUMN_MAPPINGS)
, m_isModified(false)
, m_databaseController(nullptr)
{
qDebug() << "ProjectSettingsModel: Инициализация модели настроек проекта";
}
QString ProjectSettingsModel::currentVariant() const
{
return m_currentVariant;
}
void ProjectSettingsModel::setCurrentVariant(const QString &newCurrentVariant)
{
if (m_currentVariant == newCurrentVariant)
return;
qDebug() << "ProjectSettingsModel: Устанавливаем текущий вариант:" << newCurrentVariant;
m_currentVariant = newCurrentVariant;
setModified(true);
emit currentVariantChanged();
}
QStringList ProjectSettingsModel::columnMappings() const
{
return m_columnMappings;
}
void ProjectSettingsModel::setColumnMappings(const QStringList &newColumnMappings)
{
if (m_columnMappings == newColumnMappings)
return;
qDebug() << "ProjectSettingsModel: Устанавливаем настройки столбцов:" << newColumnMappings;
m_columnMappings = newColumnMappings;
setModified(true);
emit columnMappingsChanged();
}
QStringList ProjectSettingsModel::availableVariants() const
{
return m_availableVariants;
}
void ProjectSettingsModel::setAvailableVariants(const QStringList &newAvailableVariants)
{
if (m_availableVariants == newAvailableVariants)
return;
qDebug() << "ProjectSettingsModel: Устанавливаем доступные варианты:" << newAvailableVariants;
m_availableVariants = newAvailableVariants;
emit availableVariantsChanged();
}
QStringList ProjectSettingsModel::availableProperties() const
{
return m_availableProperties;
}
void ProjectSettingsModel::setAvailableProperties(const QStringList &newAvailableProperties)
{
if (m_availableProperties == newAvailableProperties)
return;
qDebug() << "ProjectSettingsModel: Устанавливаем доступные свойства:" << newAvailableProperties;
m_availableProperties = newAvailableProperties;
emit availablePropertiesChanged();
}
void ProjectSettingsModel::resetToDefaults()
{
qDebug() << "ProjectSettingsModel: Сброс настроек к значениям по умолчанию";
setCurrentVariant(DEFAULT_VARIANT);
setColumnMappings(DEFAULT_COLUMN_MAPPINGS);
setModified(false);
}
bool ProjectSettingsModel::isModified() const
{
return m_isModified;
}
void ProjectSettingsModel::setModified(bool modified)
{
if (m_isModified == modified)
return;
m_isModified = modified;
if (modified) {
emit settingsModified();
}
}
// Методы для работы с настройками маппинга для разных типов документов
void ProjectSettingsModel::setColumnMapping(const QString &documentType, int columnIndex, const QString &propertyName)
{
QString key = QString("%1_%2").arg(documentType).arg(columnIndex);
if (m_columnMappingSettings.value(key) != propertyName) {
qDebug() << "ProjectSettingsModel::setColumnMapping: Устанавливаем маппинг" << key << "=" << propertyName;
m_columnMappingSettings[key] = propertyName;
setModified(true);
}
}
QString ProjectSettingsModel::getColumnMapping(const QString &documentType, int columnIndex) const
{
QString key = QString("%1_%2").arg(documentType).arg(columnIndex);
QString value = m_columnMappingSettings.value(key);
qDebug() << "ProjectSettingsModel::getColumnMapping: Получаем маппинг" << key << "=" << value;
return value;
}
QStringList ProjectSettingsModel::getColumnMappings(const QString &documentType) const
{
QStringList mappings;
QString prefix = QString("%1_").arg(documentType);
// Собираем все маппинги для данного типа документа
QMap<int, QString> tempMappings;
for (auto it = m_columnMappingSettings.begin(); it != m_columnMappingSettings.end(); ++it) {
if (it.key().startsWith(prefix)) {
// Извлекаем индекс колонки из ключа
QString suffix = it.key().mid(prefix.length());
bool ok;
int columnIndex = suffix.toInt(&ok);
if (ok) {
tempMappings[columnIndex] = it.value();
}
}
}
// Сортируем по индексу колонки и формируем список
for (auto it = tempMappings.begin(); it != tempMappings.end(); ++it) {
while (mappings.size() <= it.key()) {
mappings.append(QString()); // Добавляем пустые строки для пропущенных индексов
}
mappings[it.key()] = it.value();
}
qDebug() << "ProjectSettingsModel::getColumnMappings: Получены маппинги для" << documentType << ":" << mappings;
return mappings;
}
void ProjectSettingsModel::clearColumnMappings(const QString &documentType)
{
QString prefix = QString("%1_").arg(documentType);
// Удаляем все маппинги для данного типа документа
QList<QString> keysToRemove;
for (auto it = m_columnMappingSettings.begin(); it != m_columnMappingSettings.end(); ++it) {
if (it.key().startsWith(prefix)) {
keysToRemove.append(it.key());
}
}
for (const QString &key : keysToRemove) {
m_columnMappingSettings.remove(key);
}
if (!keysToRemove.isEmpty()) {
qDebug() << "ProjectSettingsModel::clearColumnMappings: Удалены маппинги для" << documentType;
setModified(true);
}
}
void ProjectSettingsModel::setDatabaseController(DataBaseController *controller)
{
m_databaseController = controller;
qDebug() << "ProjectSettingsModel::setDatabaseController: Установлен контроллер БД";
}
// Методы для работы с размером шрифта для разных типов документов
void ProjectSettingsModel::setFontSize(const QString &documentType, int fontSize)
{
if (m_fontSizes.value(documentType, 12) != fontSize) {
qDebug() << "ProjectSettingsModel::setFontSize: Устанавливаем размер шрифта для" << documentType << "=" << fontSize;
m_fontSizes[documentType] = fontSize;
setModified(true);
}
}
int ProjectSettingsModel::getFontSize(const QString &documentType) const
{
int fontSize = m_fontSizes.value(documentType, 12); // По умолчанию 12
qDebug() << "ProjectSettingsModel::getFontSize: Размер шрифта для" << documentType << "=" << fontSize;
return fontSize;
}
// Методы для работы с поджимом по ширине
void ProjectSettingsModel::setFontStretch(const QString &documentType, int stretch)
{
if (m_fontStretches.value(documentType, 100) != stretch) {
qDebug() << "ProjectSettingsModel::setFontStretch: Устанавливаем поджим для" << documentType << "=" << stretch;
m_fontStretches[documentType] = stretch;
setModified(true);
}
}
int ProjectSettingsModel::getFontStretch(const QString &documentType) const
{
int stretch = m_fontStretches.value(documentType, 100); // По умолчанию 100 (нормальный)
qDebug() << "ProjectSettingsModel::getFontStretch: Поджим для" << documentType << "=" << stretch;
return stretch;
}