diff --git a/sources/ui/formulaassistantdialog.cpp b/sources/ui/formulaassistantdialog.cpp new file mode 100644 index 000000000..ab7489314 --- /dev/null +++ b/sources/ui/formulaassistantdialog.cpp @@ -0,0 +1,63 @@ +/* + Copyright 2006-2017 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "formulaassistantdialog.h" +#include "ui_formulaassistantdialog.h" + +#include + +FormulaAssistantDialog::FormulaAssistantDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::FormulaAssistantDialog) +{ + ui->setupUi(this); +} + +FormulaAssistantDialog::~FormulaAssistantDialog() +{ + delete ui; +} + +void FormulaAssistantDialog::setForbiddenVariables(QStringList list) +{ + m_rx.setPattern(list.join("|")); +} + +void FormulaAssistantDialog::setText(QString text) +{ + ui->m_label->setText(text); +} + +void FormulaAssistantDialog::setFormula(QString text) +{ + ui->m_line_edit->setText(text); +} + +QString FormulaAssistantDialog::formula() const +{ + return ui->m_line_edit->text(); +} + +void FormulaAssistantDialog::on_m_line_edit_textChanged(const QString &arg1) +{ + QPushButton *b = ui->m_button_box->button(QDialogButtonBox::Ok); + + if (arg1.contains(m_rx)) + b->setDisabled(true); + else + b->setEnabled(true); +} diff --git a/sources/ui/formulaassistantdialog.h b/sources/ui/formulaassistantdialog.h new file mode 100644 index 000000000..b87792046 --- /dev/null +++ b/sources/ui/formulaassistantdialog.h @@ -0,0 +1,50 @@ +/* + Copyright 2006-2017 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef FORMULAASSISTANTDIALOG_H +#define FORMULAASSISTANTDIALOG_H + +#include +#include + +namespace Ui { + class FormulaAssistantDialog; +} + +class FormulaAssistantDialog : public QDialog +{ + Q_OBJECT + + public: + FormulaAssistantDialog(QWidget *parent = 0); + ~FormulaAssistantDialog(); + + void setForbiddenVariables(QStringList list); + void setText(QString text); + void setFormula(QString text); + QString formula() const; + + private slots: + void on_m_line_edit_textChanged(const QString &arg1); + + private: + Ui::FormulaAssistantDialog *ui; + QRegularExpression m_rx; + QString m_formula; +}; + +#endif // FORMULAASSISTANTDIALOG_H diff --git a/sources/ui/formulaassistantdialog.ui b/sources/ui/formulaassistantdialog.ui new file mode 100644 index 000000000..c284619e8 --- /dev/null +++ b/sources/ui/formulaassistantdialog.ui @@ -0,0 +1,91 @@ + + + FormulaAssistantDialog + + + + 0 + 0 + 184 + 94 + + + + Assistant de formule + + + + + + TextLabel + + + + + + + Formule + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + m_button_box + accepted() + FormulaAssistantDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_button_box + rejected() + FormulaAssistantDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/ui/potentialselectordialog.cpp b/sources/ui/potentialselectordialog.cpp index f1b4e50b4..94c022ba5 100644 --- a/sources/ui/potentialselectordialog.cpp +++ b/sources/ui/potentialselectordialog.cpp @@ -25,6 +25,7 @@ #include "element.h" #include "reportelement.h" #include "assignvariables.h" +#include "formulaassistantdialog.h" //### BEGIN PRIVATE CLASS ###// @@ -251,6 +252,7 @@ void PotentialSelectorDialog::buildWidget() rb2->setChecked(true); } } +#include /** * @brief PotentialSelectorDialog::on_buttonBox_accepted @@ -291,8 +293,42 @@ void PotentialSelectorDialog::on_buttonBox_accepted() new QPropertyUndoCommand(cond, "sequenceNum", old_seq, new_seq, undo); new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo); } + + //Check if formula of the new potential have incompatible variable with folio report + QRegularExpression rx ("%sequf_|%seqtf_|%seqhf_|%id|%F|%M|%LM"); + foreach(ConductorProperties cp, m_properties_list) + { + if (cp.m_formula.contains(rx)) + { + QStringList forbidden_str; + forbidden_str << "%sequf_" << "%seqtf_" << "%seqhf_" << "%id" << "%F" << "%M" << "%LM"; + + QString text(tr("La formule du nouveau potentiel contient des variables incompatible avec les reports de folio.\n" + "Veuillez saisir une formule compatible pour ce potentiel.\n" + "Les variables suivante sont incompatible :\n" + "%sequf_ %seqtf_ %seqhf_ %id %F %M %LM")); + FormulaAssistantDialog fag(this); + fag.setForbiddenVariables(forbidden_str); + fag.setText(text); + fag.setFormula(cp.m_formula); + fag.exec(); + + QString new_formula = fag.formula(); + QSet c_list = m_report->conductors().first()->relatedPotentialConductors(); + c_list.insert(m_report->conductors().first()); + foreach(Conductor *cond, c_list) + { + old_value.setValue(cond->properties()); + ConductorProperties new_properties = cond->properties(); + new_properties.m_formula = new_formula; + new_value.setValue(new_properties); + new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo); + } + + break; + } + } } - } else if (m_conductor)