/** * @RDE_HEADER@ * HMI Plugin for ParticipantManagement - Name Template Unit Frameless Dialog * $Id$ * $HeadURL$ * $Author$ * Created by Patric Karwat, SLSE, 2016-11-07 */ #include "template_unit_namer.h" #include "ui_template_unit_namer.h" #include namespace ParticipantManagement { TemplateUnitNamer::TemplateUnitNamer(bool asSupportService, const std::shared_ptr &dtc, const std::shared_ptr &ppmGuiCbxIfc, QWidget *parent) : LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal) , m_asSupportService(asSupportService) , m_dtc(dtc) , m_ppmGuiCbxIfc(ppmGuiCbxIfc) , m_ui(new Ui::TemplateUnitNamer) , m_validator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("[^,;\"'ยด`]*")), this)) , m_logger(getLogger("TemplateTemplateChooser")) { m_ui->setupUi(this); if (!m_ppmGuiCbxIfc || !m_dtc) return; m_ui->leDesignator->setValidator(m_validator); m_ui->leTactIdentifier->setValidator(m_validator); connect(m_ui->cbxTypeClass, static_cast(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &TemplateUnitNamer::onTypeClassChanged); m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Ok)->setVisible(false); m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Apply)->setVisible(false); m_ui->ltsDialogButtonBox->connectButton(LtsWidgets::DialogButton::Add, this, &TemplateUnitNamer::onSetUnitName); m_ui->ltsDialogButtonBox->setText(LtsWidgets::DialogButton::Add, tr("Add")); connect(m_ui->leTactIdentifier, &QLineEdit::textChanged, this, &TemplateUnitNamer::enaDisa); //HACK as close is not allowed directly connect(m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &TemplateUnitNamer::close); const int filter = m_asSupportService ? ForeignGuiComboboxInterface::eOcUnits : ForeignGuiComboboxInterface::eUnits; m_ppmGuiCbxIfc->fillTypeClassComboBox(m_ui->cbxTypeClass, filter); onTypeClassChanged(); } TemplateUnitNamer::~TemplateUnitNamer() { delete m_ui; } //SLOTS void ParticipantManagement::TemplateUnitNamer::onSetUnitName() { ParticipantManagement::TemplateData templateData; templateData.modId(1); templateData.hierarchyNumber(1); templateData.designator(m_ui->leDesignator->text().toStdString()); templateData.tacticalIdentifier(m_ui->leTactIdentifier->text().toStdString()); templateData.typeId(m_ui->cbxType->currentData().toInt()); templateData.symbol(m_dtc->type(templateData.typeId()).symbol()); emit newUnitTemplateRoot(templateData); close(); } void TemplateUnitNamer::onTypeClassChanged() { TypeClass currentClass(static_cast(m_ui->cbxTypeClass->currentData().toInt())); m_ppmGuiCbxIfc->fillTypeComboBox(m_ui->cbxType, currentClass); enaDisa(); } void TemplateUnitNamer::enaDisa() { m_ui->ltsDialogButtonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, (!m_ui->leTactIdentifier->text().isEmpty() && m_ui->cbxType->count())); } } //namespace ParticipantManagement