diff --git a/sources/conductorautonumerotation.cpp b/sources/conductorautonumerotation.cpp index eef9452ca..8538360e8 100644 --- a/sources/conductorautonumerotation.cpp +++ b/sources/conductorautonumerotation.cpp @@ -20,9 +20,9 @@ #include "qetdiagrameditor.h" #include "conductor.h" #include "diagram.h" -#include "potentialtextsdialog.h" #include "qet.h" #include "QPropertyUndoCommand/qpropertyundocommand.h" +#include "potentialselectordialog.h" /** * @brief ConductorAutoNumerotation::ConductorAutoNumerotation @@ -51,31 +51,6 @@ void ConductorAutoNumerotation::numerate() { else if (conductor_ -> properties().type == ConductorProperties::Multi) numerateNewConductor(); } -/** - * @brief ConductorAutoNumerotation::checkPotential - * Check if eah texts of this potential is identical. - * If not, ask user how to numerate - * @param conductor - * A conductor of the potential to check. - */ -void ConductorAutoNumerotation::checkPotential(Conductor *conductor, QUndoCommand *parent) { - //fill list of potential - QSet c_list = conductor->relatedPotentialConductors(); - c_list << conductor; - //fill list of text - QStringList strl; - foreach (const Conductor *c, c_list) strl<<(c->text()); - - //check text list, isn't same in potential, ask user what to do - if (!QET::eachStrIsEqual(strl)) { - PotentialTextsDialog ptd(conductor, conductor->diagramEditor()); - if ( ptd.exec() == QDialog::Accepted ) { - ConductorAutoNumerotation can(conductor, conductor -> diagram(), parent); - can.applyText(ptd.selectedText()); - } - } -} - /** * @brief ConductorAutoNumerotation::applyText * apply the text @t to @conductor_ and all conductors at the same potential @@ -130,9 +105,8 @@ void ConductorAutoNumerotation::numeratePotential() //the texts isn't identicals else { - PotentialTextsDialog ptd (conductor_, conductor_ -> diagramEditor()); - ptd.exec(); - applyText(ptd.selectedText()); + PotentialSelectorDialog psd(conductor_, m_parent_undo, conductor_->diagramEditor()); + psd.exec(); } } diff --git a/sources/conductorautonumerotation.h b/sources/conductorautonumerotation.h index 75c49f39f..2bb3b58aa 100644 --- a/sources/conductorautonumerotation.h +++ b/sources/conductorautonumerotation.h @@ -32,7 +32,6 @@ class ConductorAutoNumerotation //methods void numerate (); - static void checkPotential (Conductor *conductor, QUndoCommand *parent = nullptr); void applyText (QString); private: diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index 34fd42449..ecab2d647 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -241,18 +241,19 @@ ConductorProperties::~ConductorProperties() { * Export conductor propertie, in the XML element 'e' * @param e the xml element */ -void ConductorProperties::toXml(QDomElement &e) const { +void ConductorProperties::toXml(QDomElement &e) const +{ e.setAttribute("type", typeToString(type)); - - if (color != QColor(Qt::black)) { + if (color != QColor(Qt::black)) e.setAttribute("color", color.name()); - } - if (type == Single) { + if (type == Single) singleLineProperties.toXml(e); - } + e.setAttribute("num", text); + e.setAttribute("function", m_function); + e.setAttribute("tension-protocol", m_tension_protocol); e.setAttribute("numsize", text_size); e.setAttribute("displaytext", m_show_text); e.setAttribute("onetextperfolio", m_one_text_per_folio); @@ -260,9 +261,8 @@ void ConductorProperties::toXml(QDomElement &e) const { e.setAttribute("horizrotatetext", horiz_rotate_text); QString conductor_style = writeStyle(); - if (!conductor_style.isEmpty()) { + if (!conductor_style.isEmpty()) e.setAttribute("style", conductor_style); - } } @@ -271,35 +271,36 @@ void ConductorProperties::toXml(QDomElement &e) const { * Import conductor propertie, from the attribute of the xml element 'e' * @param e the xml document */ -void ConductorProperties::fromXml(QDomElement &e) { - // get conductor color +void ConductorProperties::fromXml(QDomElement &e) +{ + // get conductor color QColor xml_color= QColor(e.attribute("color")); - if (xml_color.isValid()) { - color = xml_color; - } else { - color = QColor(Qt::black); - } + color = (xml_color.isValid()? xml_color : QColor(Qt::black)); - // read style of conductor + // read style of conductor readStyle(e.attribute("style")); - if (e.attribute("type") == typeToString(Single)) { - // get specific properties for single conductor + if (e.attribute("type") == typeToString(Single)) + { + // get specific properties for single conductor singleLineProperties.fromXml(e); type = Single; - } else { - type = Multi; } - // get text field - text = e.attribute("num"); - text_size = e.attribute("numsize", QString::number(9)).toInt(); - m_show_text = e.attribute("displaytext", QString::number(1)).toInt(); - m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt(); - verti_rotate_text = e.attribute("vertirotatetext").toDouble(); - horiz_rotate_text = e.attribute("horizrotatetext").toDouble(); + else + type = Multi; - //Keep retrocompatible with version older than 0,4 - //If the propertie @type is simple (removed since QET 0,4), we set text no visible. + text = e.attribute("num"); + m_function = e.attribute("function"); + m_tension_protocol = e.attribute("tension-protocol"); + text_size = e.attribute("numsize", QString::number(9)).toInt(); + m_show_text = e.attribute("displaytext", QString::number(1)).toInt(); + m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt(); + verti_rotate_text = e.attribute("vertirotatetext").toDouble(); + horiz_rotate_text = e.attribute("horizrotatetext").toDouble(); + + //Keep retrocompatible with version older than 0,4 + //If the propertie @type is simple (removed since QET 0,4), we set text no visible. + //@TODO remove this code for qet 0.6 or later if (e.attribute("type") == "simple") m_show_text = false; } @@ -307,11 +308,14 @@ void ConductorProperties::fromXml(QDomElement &e) { @param settings Parametres a ecrire @param prefix prefixe a ajouter devant les noms des parametres */ -void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const { +void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const +{ settings.setValue(prefix + "color", color.name()); settings.setValue(prefix + "style", writeStyle()); settings.setValue(prefix + "type", typeToString(type)); settings.setValue(prefix + "text", text); + settings.setValue(prefix + "function", m_function); + settings.setValue(prefix + "tension-protocol", m_tension_protocol); settings.setValue(prefix + "textsize", QString::number(text_size)); settings.setValue(prefix + "displaytext", m_show_text); settings.setValue(prefix + "onetextperfolio", m_one_text_per_folio); @@ -324,30 +328,25 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) @param settings Parametres a lire @param prefix prefixe a ajouter devant les noms des parametres */ -void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) { - // recupere la couleur dans les parametres +void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) +{ QColor settings_color = QColor(settings.value(prefix + "color").toString()); - if (settings_color.isValid()) { - color = settings_color; - } else { - color = QColor(Qt::black); - } + color = (settings_color.isValid()? settings_color : QColor(Qt::black)); QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString(); - if (setting_type == typeToString(Single)) { - type = Single; - } else { - type = Multi; - } - singleLineProperties.fromSettings(settings, prefix); - text = settings.value(prefix + "text", "_").toString(); - text_size = settings.value(prefix + "textsize", "7").toInt(); - m_show_text = settings.value(prefix + "displaytext", true).toBool(); - m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool(); - verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble(); - horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble(); + type = (setting_type == typeToString(Single)? Single : Multi); + + singleLineProperties.fromSettings(settings, prefix); + + text = settings.value(prefix + "text", "_").toString(); + m_function = settings.value(prefix + "function", "").toString(); + m_tension_protocol = settings.value(prefix + "tension-protocol", "").toString(); + text_size = settings.value(prefix + "textsize", "7").toInt(); + m_show_text = settings.value(prefix + "displaytext", true).toBool(); + m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool(); + verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble(); + horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble(); - // lit le style du conducteur readStyle(settings.value(prefix + "style").toString()); } @@ -385,6 +384,8 @@ bool ConductorProperties::operator==(const ConductorProperties &other) const{ other.color == color &&\ other.style == style &&\ other.text == text &&\ + other.m_function == m_function &&\ + other.m_tension_protocol == m_tension_protocol &&\ other.m_show_text == m_show_text &&\ other.text_size == text_size &&\ other.verti_rotate_text == verti_rotate_text &&\ diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index 91ce40582..f8681047f 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -61,56 +61,50 @@ class SingleLineProperties { This class represents the functional properties of a particular conductor, i.e. properties other than path and terminals. */ -class ConductorProperties { - // constructors, destructor +class ConductorProperties +{ public: - ConductorProperties(); - virtual ~ConductorProperties(); + ConductorProperties(); + virtual ~ConductorProperties(); - /** - Represents the kind of a particular conductor: - * Simple: no symbols, no text input - * Single: singleline symbols, no text input - * Multi: text input, no symbol - */ - enum ConductorType { Single, Multi }; - - // attributes - /// Conductor type - ConductorType type; - /// Conductor color - QColor color; - /// Texte displayed for multiline conductors - QString text; - /// size of text - int text_size; - /// rotation angle texte - double verti_rotate_text; - double horiz_rotate_text; - bool m_show_text; - bool m_one_text_per_folio; - /// conducteur style (Qt::SolidLine or Qt::DashLine) - Qt::PenStyle style; - - /// properties for singleline conductors - SingleLineProperties singleLineProperties; - - // methods - void toXml(QDomElement &) const; - void fromXml(QDomElement &); - void toSettings(QSettings &, const QString & = QString()) const; - void fromSettings(QSettings &, const QString & = QString()); - static QString typeToString(ConductorType); + /** + * @brief The ConductorType enum Represents the kind of a particular conductor: + * Single: singleline symbols, no text input + * Multi: text input, no symbol + */ + enum ConductorType { Single, Multi }; - static ConductorProperties defaultProperties(); + + //Attributes + ConductorType type; + QColor color; + QString text, + m_function, + m_tension_protocol; + int text_size; + double verti_rotate_text; + double horiz_rotate_text; + bool m_show_text; + bool m_one_text_per_folio; + Qt::PenStyle style; + SingleLineProperties singleLineProperties; - // operators - bool operator==(const ConductorProperties &) const; - bool operator!=(const ConductorProperties &) const; + // methods + void toXml(QDomElement &) const; + void fromXml(QDomElement &); + void toSettings(QSettings &, const QString & = QString()) const; + void fromSettings(QSettings &, const QString & = QString()); + static QString typeToString(ConductorType); + + static ConductorProperties defaultProperties(); + + // operators + bool operator==(const ConductorProperties &) const; + bool operator!=(const ConductorProperties &) const; private: - void readStyle(const QString &); - QString writeStyle() const; + void readStyle(const QString &); + QString writeStyle() const; }; Q_DECLARE_METATYPE(ConductorProperties) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 4710cdd00..a1fa53f10 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -35,12 +35,13 @@ bool Conductor::pen_and_brush_initialized = false; QPen Conductor::conductor_pen = QPen(); QBrush Conductor::conductor_brush = QBrush(); QBrush Conductor::square_brush = QBrush(Qt::darkGreen); + /** - Constructeur - @param p1 Premiere Borne a laquelle le conducteur est lie - @param p2 Seconde Borne a laquelle le conducteur est lie - @param parent_diagram QGraphicsScene a laquelle appartient le conducteur -*/ + * @brief Conductor::Conductor + * Default constructor. + * @param p1 : first terminal of this conductor. + * @param p2 : second terminal of this conductor. + */ Conductor::Conductor(Terminal *p1, Terminal* p2) : QObject(), QGraphicsPathItem(0), @@ -57,7 +58,13 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) : segments_squares_scale_(1.0), must_highlight_(Conductor::None) { - //set Zvalue at 9 to be upper than the DiagramImageItem and bottom of element(10) + //Set the default conductor properties. + if (p1->diagram()) + properties_ = p1->diagram()->defaultConductorProperties; + else if (p2->diagram()) + properties_ = p2->diagram()->defaultConductorProperties; + + //set Zvalue at 9 to be upper than the DiagramImageItem and bottom of element(10) setZValue(9); previous_z_value = zValue(); @@ -67,8 +74,9 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) : //m_valid become false if the conductor can't be added to terminal (conductor already exist) m_valid = (!ajout_p1 || !ajout_p2) ? false : true; - // attributs de dessin par defaut (communs a tous les conducteurs) - if (!pen_and_brush_initialized) { + //Default attribut for paint a conductor + if (!pen_and_brush_initialized) + { conductor_pen.setJoinStyle(Qt::MiterJoin); conductor_pen.setCapStyle(Qt::SquareCap); conductor_pen.setColor(Qt::black); @@ -79,13 +87,13 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) : pen_and_brush_initialized = true; } - // par defaut, les 4 profils sont des profils nuls = il faut utiliser priv_calculeConductor + //By default, the 4 profils are nuls -> we must to use priv_calculeConductor conductor_profiles.insert(Qt::TopLeftCorner, ConductorProfile()); conductor_profiles.insert(Qt::TopRightCorner, ConductorProfile()); conductor_profiles.insert(Qt::BottomLeftCorner, ConductorProfile()); conductor_profiles.insert(Qt::BottomRightCorner, ConductorProfile()); - // calcul du rendu du conducteur + //Generate the path of this conductor. generateConductorPath(terminal1 -> dockConductor(), terminal1 -> orientation(), terminal2 -> dockConductor(), terminal2 -> orientation()); setFlags(QGraphicsItem::ItemIsSelectable); setAcceptHoverEvents(true); @@ -1338,14 +1346,26 @@ void Conductor::setText(const QString &t) { /** * @brief Conductor::setProperties * Set new properties for this conductor - * @param p : properties + * Also change the common properties for every conductors at the same potential. + * (text, function and tension/protocol) other value of properties isn't changed. + * @param properties : properties */ -void Conductor::setProperties(const ConductorProperties &p) { - if (properties_ != p) +void Conductor::setProperties(const ConductorProperties &properties) +{ + if (properties_ == properties) return; + + properties_ = properties; + + foreach(Conductor *other_conductor, relatedPotentialConductors()) { - properties_ = p; - readProperties(); + ConductorProperties other_properties = other_conductor->properties(); + other_properties.text = properties_.text; + other_properties.m_function = properties_.m_function; + other_properties.m_tension_protocol = properties_.m_tension_protocol; + other_conductor->setProperties(other_properties); } + + readProperties(); } /** diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index ad6cbbb06..15ecfd8dd 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -105,20 +105,20 @@ class Conductor : public QObject, public QGraphicsPathItem bool pathFromXml(const QDomElement &); public: - const QList segmentsList() const; - void setProperties(const ConductorProperties &); - ConductorProperties properties() const; - void setProfile(const ConductorProfile &, Qt::Corner); - ConductorProfile profile(Qt::Corner) const; - void setProfiles(const ConductorProfilesGroup &); - ConductorProfilesGroup profiles() const; - void readProperties(); - void calculateTextItemPosition(); - virtual Highlight highlight() const; - virtual void setHighlighted(Highlight); - QSet relatedPotentialConductors(const bool all_diagram = true, QList *t_list=0); - QETDiagramEditor* diagramEditor() const; - void editProperty (); + const QList segmentsList() const; + void setProperties(const ConductorProperties &properties); + ConductorProperties properties() const; + void setProfile(const ConductorProfile &, Qt::Corner); + ConductorProfile profile(Qt::Corner) const; + void setProfiles(const ConductorProfilesGroup &); + ConductorProfilesGroup profiles() const; + void readProperties(); + void calculateTextItemPosition(); + virtual Highlight highlight() const; + virtual void setHighlighted(Highlight); + QSet relatedPotentialConductors(const bool all_diagram = true, QList *t_list=0); + QETDiagramEditor* diagramEditor() const; + void editProperty (); public slots: void displayedTextChanged(); diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index c03e6c64d..2ed100835 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -627,7 +627,6 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) new_conductor->setProperties(others_properties); else { - new_conductor -> setProperties(diagram() -> defaultConductorProperties); //Autonum it ConductorAutoNumerotation can (new_conductor, diagram(), undo); can.numerate(); diff --git a/sources/ui/conductorpropertiesdialog.cpp b/sources/ui/conductorpropertiesdialog.cpp index 34487c0fe..d94de69d8 100644 --- a/sources/ui/conductorpropertiesdialog.cpp +++ b/sources/ui/conductorpropertiesdialog.cpp @@ -70,31 +70,14 @@ void ConductorPropertiesDialog::PropertiesDialog(Conductor *conductor, QWidget * QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value); undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption")); - if (!conductor->relatedPotentialConductors().isEmpty()) + if (!conductor->relatedPotentialConductors().isEmpty() && cpd.applyAll()) { undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption")); - QString old_text = conductor->properties().text; - QString new_text = cpd.properties().text; foreach (Conductor *potential_conductor, conductor->relatedPotentialConductors()) { - //"Apply to all conductors of potential" is checked, - //we apply the new properties for every conductors in the same potential. - if (cpd.applyAll()) - { - old_value.setValue(potential_conductor->properties()); - new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo); - } - //The num of conductor isn't affected by "Apply to all conductors of potential" - //we always apply it to the potential if he change. - else if(old_text != new_text) - { - old_value.setValue(potential_conductor->properties()); - ConductorProperties new_properties = potential_conductor->properties(); - new_properties.text = new_text; - new_value.setValue(new_properties); - new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo); - } + old_value.setValue(potential_conductor->properties()); + new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo); } } diff --git a/sources/ui/conductorpropertieswidget.cpp b/sources/ui/conductorpropertieswidget.cpp index ef2fcb34d..1238b9b4e 100644 --- a/sources/ui/conductorpropertieswidget.cpp +++ b/sources/ui/conductorpropertieswidget.cpp @@ -66,7 +66,8 @@ ConductorPropertiesWidget::~ConductorPropertiesWidget() * Set the properties * @param properties */ -void ConductorPropertiesWidget::setProperties(const ConductorProperties &properties) { +void ConductorPropertiesWidget::setProperties(const ConductorProperties &properties) +{ if (m_properties == properties) return; m_properties = properties; @@ -74,18 +75,20 @@ void ConductorPropertiesWidget::setProperties(const ConductorProperties &propert int index = ui -> m_line_style_cb -> findData(QPen(m_properties.style)); if (index != -1) ui -> m_line_style_cb -> setCurrentIndex(index); - ui -> m_text_le -> setText (m_properties.text); - ui -> m_text_size_sb -> setValue (m_properties.text_size); - ui -> m_show_text_cb -> setChecked (m_properties.m_show_text); - ui -> m_one_text_per_folio_cb -> setChecked (m_properties.m_one_text_per_folio); - ui -> m_earth_cb -> setChecked (m_properties.singleLineProperties.hasGround); - ui -> m_neutral_cb -> setChecked (m_properties.singleLineProperties.hasNeutral); - ui -> m_pen_cb -> setChecked (m_properties.singleLineProperties.isPen()); - ui -> m_phase_cb -> setChecked (m_properties.singleLineProperties.phasesCount()); - ui -> m_phase_slider -> setValue (m_properties.singleLineProperties.phasesCount()); + ui->m_text_le -> setText (m_properties.text); + ui->m_function_le ->setText (m_properties.m_function); + ui->m_tension_protocol_le ->setText (m_properties.m_tension_protocol); + ui->m_text_size_sb -> setValue (m_properties.text_size); + ui->m_show_text_cb -> setChecked (m_properties.m_show_text); + ui->m_one_text_per_folio_cb -> setChecked (m_properties.m_one_text_per_folio); + ui->m_earth_cb -> setChecked (m_properties.singleLineProperties.hasGround); + ui->m_neutral_cb -> setChecked (m_properties.singleLineProperties.hasNeutral); + ui->m_pen_cb -> setChecked (m_properties.singleLineProperties.isPen()); + ui->m_phase_cb -> setChecked (m_properties.singleLineProperties.phasesCount()); + ui->m_phase_slider -> setValue (m_properties.singleLineProperties.phasesCount()); - m_verti_select -> setValue (m_properties.verti_rotate_text); - m_horiz_select -> setValue (m_properties.horiz_rotate_text); + m_verti_select -> setValue (m_properties.verti_rotate_text); + m_horiz_select -> setValue (m_properties.horiz_rotate_text); setConductorType(m_properties.type); updatePreview(false); @@ -95,7 +98,8 @@ void ConductorPropertiesWidget::setProperties(const ConductorProperties &propert * @brief ConductorPropertiesWidget::properties * @return the edited properties */ -ConductorProperties ConductorPropertiesWidget::properties() const { +ConductorProperties ConductorPropertiesWidget::properties() const +{ ConductorProperties properties_; if (ui -> m_multiwires_gb -> isChecked()) properties_.type = ConductorProperties::Multi; else if (ui -> m_singlewire_gb -> isChecked()) properties_.type = ConductorProperties::Single; @@ -103,6 +107,8 @@ ConductorProperties ConductorPropertiesWidget::properties() const { properties_.color = ui -> m_color_pb->palette().color(QPalette::Button); properties_.style = ui -> m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).value().style(); properties_.text = ui -> m_text_le -> text(); + properties_.m_function = ui -> m_function_le->text(); + properties_.m_tension_protocol = ui -> m_tension_protocol_le->text(); properties_.text_size = ui -> m_text_size_sb -> value(); properties_.m_show_text = ui -> m_show_text_cb -> isChecked(); properties_.m_one_text_per_folio = ui -> m_one_text_per_folio_cb -> isChecked(); diff --git a/sources/ui/conductorpropertieswidget.ui b/sources/ui/conductorpropertieswidget.ui index 72e782837..abcc2c295 100644 --- a/sources/ui/conductorpropertieswidget.ui +++ b/sources/ui/conductorpropertieswidget.ui @@ -6,8 +6,8 @@ 0 0 - 354 - 329 + 504 + 420 @@ -33,23 +33,35 @@ true - false + true - + - Texte : + Taille du texte : - + + + + Taille du texte + + false + + + QAbstractSpinBox::UpDownArrows + + + + 5 @@ -58,14 +70,31 @@ - - + + + + + - Taille : + Tension / Protocole : - + + + + Texte : + + + + + + + Fonction : + + + + Texte @@ -75,13 +104,13 @@ - + Texte visible - Visible + true diff --git a/sources/ui/potentialselectordialog.cpp b/sources/ui/potentialselectordialog.cpp new file mode 100644 index 000000000..862ccd106 --- /dev/null +++ b/sources/ui/potentialselectordialog.cpp @@ -0,0 +1,224 @@ +/* + Copyright 2006-2015 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 "potentialselectordialog.h" +#include "ui_potentialselectordialog.h" +#include "conductor.h" +#include "terminal.h" +#include +#include "QPropertyUndoCommand/qpropertyundocommand.h" +#include "diagram.h" +#include "element.h" +#include "reportelement.h" + +//### PRIVATE CLASS ###// + +/** + * @brief The NewConductorPotentialSelector class + * Use for get the conductor propertie when two potentials is linked by a conductor + */ +class NewConductorPotentialSelector : public AbstractPotentialSelector +{ + public: + NewConductorPotentialSelector(Conductor *conductor) : + m_is_valid(false) + { + Terminal *terminal_1 = conductor->terminal1; + Terminal *terminal_2 = conductor->terminal2; + //We temporarily remove the conductor of his two terminals, to get the two existing potential + terminal_1->removeConductor(conductor); + terminal_2->removeConductor(conductor); + + if (terminal_1->conductors().isEmpty() || terminal_2->conductors().isEmpty()) return; + + m_properties_1 = terminal_1->conductors().first()->properties(); + m_conductor_number_1 = terminal_1->conductors().first()->relatedPotentialConductors().size() + 1; + m_properties_2 = terminal_2->conductors().first()->properties(); + m_conductor_number_2 = terminal_2->conductors().first()->relatedPotentialConductors().size() + 1; + + //Re-add conductor to his terminals. + terminal_1->addConductor(conductor); + terminal_2->addConductor(conductor); + m_is_valid = true; + } + + bool isValid() const {return m_is_valid;} + + ~NewConductorPotentialSelector() {} + + private : + bool m_is_valid; +}; + +/** + * @brief The LinkReportPotentialSelector class + * Use for get the conductor propertie when two potentials is linked with a folio report + */ +class LinkReportPotentialSelector : public AbstractPotentialSelector +{ + public: + LinkReportPotentialSelector(Element *report) : + m_is_valid(false) + { + if (report->linkType() & Element::AllReport) + { + //We temporarily unlink report to get the two existing potential + Element *other_report = report->linkedElements().first(); + report->unlinkAllElements(); + + if (report->conductors().isEmpty() || other_report->conductors().isEmpty()) return; + + m_properties_1 = report->conductors().first()->properties(); + m_conductor_number_1 = report->conductors().first()->relatedPotentialConductors().size() + 1; + m_properties_2 = other_report->conductors().first()->properties(); + m_conductor_number_2 = other_report->conductors().first()->relatedPotentialConductors().size() + 1; + + //We relink the report + report->linkToElement(other_report); + m_is_valid = true; + } + } + + ~LinkReportPotentialSelector() {} + + bool isValid() const {return m_is_valid;} + + private: + bool m_is_valid; +}; + +//### PRIVATE CLASS ###// + +/** + * @brief PotentialSelectorDialog::PotentialSelectorDialog + * Constructor when we link two potentiels together, with a conductor + * @param conductor : the new conductor who connect to existing potential + * @param parent_undo : undo parent to use. + * @param parent : parent widget. + */ +PotentialSelectorDialog::PotentialSelectorDialog(Conductor *conductor, QUndoCommand *parent_undo, QWidget *parent) : + QDialog(parent), + ui(new Ui::PotentialSelectorDialog), + m_conductor(conductor), + m_report(nullptr), + m_parent_undo(parent_undo) +{ + ui->setupUi(this); + m_potential_selector = new NewConductorPotentialSelector(conductor); + buildWidget(); +} + +/** + * @brief PotentialSelectorDialog::PotentialSelectorDialog + * Constructor when we link two potentiels together, with a folio report. + * @param report : one of the report used to link the potentials (report must be linked to another report) + * @param parent_undo : undo parent to use + * @param parent : paren widget + */ +PotentialSelectorDialog::PotentialSelectorDialog(Element *report, QUndoCommand *parent_undo, QWidget *parent) : + QDialog(parent), + ui(new Ui::PotentialSelectorDialog), + m_conductor(nullptr), + m_report(report), + m_parent_undo(parent_undo) +{ + ui->setupUi(this); + m_potential_selector = new LinkReportPotentialSelector(report); + buildWidget(); +} + +PotentialSelectorDialog::~PotentialSelectorDialog() +{ + delete ui; + delete m_potential_selector; +} + +/** + * @brief PotentialSelectorDialog::buildWidget + * Build the dialog + */ +void PotentialSelectorDialog::buildWidget() +{ + QRadioButton *rb1 = new QRadioButton(tr("Le potentiel avec numero de fil %1 est présent %2 fois").arg(m_potential_selector->m_properties_1.text).arg(m_potential_selector->m_conductor_number_1), this); + QRadioButton *rb2 = new QRadioButton(tr("Le potentiel avec numero de fil %1 est présent %2 fois").arg(m_potential_selector->m_properties_2.text).arg(m_potential_selector->m_conductor_number_2), this); + + connect(rb1, &QRadioButton::toggled, [this](bool t){if(t) this->m_selected_properties = this->m_potential_selector->m_properties_1;}); + connect(rb2, &QRadioButton::toggled, [this](bool t){if(t) this->m_selected_properties = this->m_potential_selector->m_properties_2;}); + + //Set the radio button of potential with the bigger number of conductors, + //at first position, and check it + if (m_potential_selector->m_conductor_number_1 >= m_potential_selector->m_conductor_number_2) + { + ui->verticalLayout->insertWidget(1, rb1); + ui->verticalLayout->insertWidget(2, rb2); + rb1->setChecked(true); + } + else + { + ui->verticalLayout->insertWidget(1, rb2); + ui->verticalLayout->insertWidget(2, rb1); + rb2->setChecked(true); + } +} + +/** + * @brief PotentialSelectorDialog::on_buttonBox_accepted + * Action when user click on OK button + */ +void PotentialSelectorDialog::on_buttonBox_accepted() +{ + if (!m_potential_selector->isValid()) return; + + if (!m_conductor) + m_conductor = m_report->conductors().first(); + + ConductorProperties new_properties = m_conductor->properties(); + new_properties.text = m_selected_properties.text; + new_properties.m_function = m_selected_properties.m_function; + new_properties.m_tension_protocol = m_selected_properties.m_tension_protocol; + + QVariant old_value, new_value; + old_value.setValue(m_conductor->properties()); + new_value.setValue(new_properties); + + //Set the properties for the new conductor + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, m_parent_undo); + undo->setText(tr("Modifier les propriétés de plusieurs conducteurs", "undo caption")); + + //Set the new properties for each conductors of the new potential + foreach(Conductor *cond, m_conductor->relatedPotentialConductors()) + { + new_properties = cond->properties(); + new_properties.text = m_selected_properties.text; + new_properties.m_function = m_selected_properties.m_function; + new_properties.m_tension_protocol = m_selected_properties.m_tension_protocol; + old_value.setValue(cond->properties()); + new_value.setValue(new_properties); + new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo); + } + + //There is an undo parent, we stop here, the owner of m_parent_undo will push it to an undo stack + if (m_parent_undo) return; + //There isn't a parent, we push the undo command to diagram undo stack. + if (m_conductor->diagram()) m_conductor->diagram()->undoStack().push(undo); + //We apply the change without undo command + else + { + delete undo; + m_conductor->setProperties(new_properties); + } +} diff --git a/sources/ui/potentialselectordialog.h b/sources/ui/potentialselectordialog.h new file mode 100644 index 000000000..cea80daf6 --- /dev/null +++ b/sources/ui/potentialselectordialog.h @@ -0,0 +1,76 @@ +/* + Copyright 2006-2015 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 POTENTIALSELECTORDIALOG_H +#define POTENTIALSELECTORDIALOG_H + +#include +#include "conductorproperties.h" +class Conductor; +class QUndoCommand; +class Element; + +class AbstractPotentialSelector +{ + public: + virtual ~AbstractPotentialSelector() {} + virtual bool isValid() const = 0; + + ConductorProperties m_properties_1, m_properties_2; + int m_conductor_number_1, m_conductor_number_2; +}; + +namespace Ui { + class PotentialSelectorDialog; +} + +/** + * @brief The PotentialSelectorDialog class + * This dialog is used when user try to connect two existing potential together. + * The dialog ask to user to make a choice between the properties of the two existing potential, + * to apply it for the new potential. + * + * Each constructor have a QUndoCommand @parent_undo for parameter + * If @parent_undo isn't null, when user click on OK button, the dialog will use the parent-undo + * as parent of the undo command that describe the changes. + * If @parent_undo is null, the created undo-command is push to the undo stack of the parent diagram of a conductor in potential. + * else we apply the change without a QUndoCommand. + */ +class PotentialSelectorDialog : public QDialog +{ + Q_OBJECT + + public: + explicit PotentialSelectorDialog(Conductor *conductor, QUndoCommand *parent_undo = nullptr, QWidget *parent = nullptr); + explicit PotentialSelectorDialog(Element *report, QUndoCommand *parent_undo = nullptr, QWidget *parent = nullptr); + ~PotentialSelectorDialog(); + + private slots: + void on_buttonBox_accepted(); + + private: + void buildWidget(); + + private: + Ui::PotentialSelectorDialog *ui; + Conductor *m_conductor; + Element *m_report; + QUndoCommand *m_parent_undo; + ConductorProperties m_selected_properties; + AbstractPotentialSelector *m_potential_selector; +}; +#endif // POTENTIALSELECTORDIALOG_H diff --git a/sources/ui/potentialtextsdialog.ui b/sources/ui/potentialselectordialog.ui similarity index 50% rename from sources/ui/potentialtextsdialog.ui rename to sources/ui/potentialselectordialog.ui index 991da90f4..dd6a31d0a 100644 --- a/sources/ui/potentialtextsdialog.ui +++ b/sources/ui/potentialselectordialog.ui @@ -1,46 +1,53 @@ - PotentialTextsDialog - + PotentialSelectorDialog + 0 0 - 403 - 94 + 425 + 74 - Textes de potentiel + Sélectionner le potentiel éléctrique + + + false + + + true + + QLayout::SetDefaultConstraint + + + 9 + - - - - - Les textes de ce potentiel électrique ne sont pas identiques. -Appliquer un texte à l'ensemble de ces conducteurs. - - - - - - - - - - - - Qt::Vertical + + + QFrame::NoFrame - - - 20 - 40 - + + QFrame::Plain - + + Vous tentez de lier deux potentiels différents ensemble. +Veuillez choisir les propriétées à appliquer au nouveau potentiel. + + + Qt::PlainText + + + false + + + false + + @@ -59,7 +66,7 @@ Appliquer un texte à l'ensemble de ces conducteurs. buttonBox accepted() - PotentialTextsDialog + PotentialSelectorDialog accept() @@ -75,7 +82,7 @@ Appliquer un texte à l'ensemble de ces conducteurs. buttonBox rejected() - PotentialTextsDialog + PotentialSelectorDialog reject() diff --git a/sources/ui/potentialtextsdialog.cpp b/sources/ui/potentialtextsdialog.cpp deleted file mode 100644 index 0c0076f4d..000000000 --- a/sources/ui/potentialtextsdialog.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - Copyright 2006-2015 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 "conductor.h" -#include "potentialtextsdialog.h" -#include "ui_potentialtextsdialog.h" -#include -#include - -/** - * @brief PotentialTextsDialog::PotentialTextsDialog - * Constructor - * @param conductor : A Conductor of the potential to check - * @param parent : parent widget - */ -PotentialTextsDialog::PotentialTextsDialog(Conductor *conductor, QWidget *parent) : - QDialog(parent), - ui(new Ui::PotentialTextsDialog), - m_conductor (conductor) -{ - ui->setupUi(this); - conductorsTextToMap(); - buildRadioList(); -} - -/** - * @brief PotentialTextsDialog::~PotentialTextsDialog - * Destructor - */ -PotentialTextsDialog::~PotentialTextsDialog() -{ - delete ui; -} - -/** - * @brief PotentialTextsDialog::selectedText - * @return the selected text - */ -QString PotentialTextsDialog::selectedText() const { - return m_selected_text; -} - -/** - * @brief PotentialTextsDialog::buildRadioList - * Build the radio list of this dialog, for selected a text - */ -void PotentialTextsDialog::buildRadioList() { - //map the signal for each radio button create in buildRadioList - m_signal_mapper = new QSignalMapper(this); - connect(m_signal_mapper, SIGNAL(mapped(QString)), this, SLOT(setSelectedText(QString))); - - //create a new radio button for each text of @conductorList - for (QMultiMap::ConstIterator it = m_texts.constEnd()-1; it != m_texts.constBegin()-1; --it) { - QRadioButton *rb= new QRadioButton(it.value() + tr(" : est présent ") + QString::number(it.key()) + tr(" fois."), this); - if (it == m_texts.constEnd()-1) { - rb -> setChecked(true); - m_selected_text = it.value(); - } - //connect the button to mapper @m_signal_mapper - connect(rb, SIGNAL(clicked()), m_signal_mapper, SLOT(map())); - m_signal_mapper -> setMapping(rb, it.value()); - ui -> m_buttons_layout -> addWidget(rb); - } -} - -/** - * @brief PotentialTextsDialog::conductorsTextToMap - * Fill the multimap @m_text with all different text found in the same potentil of @m_conductor - * The key "int" of multimap is the number of conductors with the same text. - * The value "QString" of multimap is the text. - */ -void PotentialTextsDialog::conductorsTextToMap() { - QStringList textList; - textList << m_conductor -> text(); - foreach(Conductor *c, m_conductor->relatedPotentialConductors()) textList << c -> text(); - - while (!textList.size() == 0) { - QString t = textList.at(0); - int n = textList.count(t); - textList.removeAll(t); - m_texts.insert(n, t); - } -} - -/** - * @brief PotentialTextsDialog::setSelectedText - * @param text - */ -void PotentialTextsDialog::setSelectedText(QString text) { - m_selected_text = text; -} diff --git a/sources/ui/potentialtextsdialog.h b/sources/ui/potentialtextsdialog.h deleted file mode 100644 index 2d22c0838..000000000 --- a/sources/ui/potentialtextsdialog.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright 2006-2015 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 POTENTIALTEXTSDIALOG_H -#define POTENTIALTEXTSDIALOG_H - -#include -#include -class Conductor; -class QSignalMapper; - -namespace Ui { - class PotentialTextsDialog; -} - -/** - * @brief The PotentialTextsDialog class - * This dialog show all differents conductors texts at the same - * potential of @conductor. - * The user can select a text in the list. - */ -class PotentialTextsDialog : public QDialog -{ - Q_OBJECT - - public: - explicit PotentialTextsDialog(Conductor *conductor, QWidget *parent = 0); - ~PotentialTextsDialog(); - - QString selectedText () const; - - private: - void buildRadioList(); - void conductorsTextToMap(); - - private slots: - void setSelectedText (QString text); - - private: - Ui::PotentialTextsDialog *ui; - Conductor *m_conductor; - QSignalMapper *m_signal_mapper; - QString m_selected_text; - QMultiMap m_texts; -}; - -#endif // POTENTIALTEXTSDIALOG_H diff --git a/sources/undocommand/linkelementcommand.cpp b/sources/undocommand/linkelementcommand.cpp index a9e71a9a7..e74af6d7e 100644 --- a/sources/undocommand/linkelementcommand.cpp +++ b/sources/undocommand/linkelementcommand.cpp @@ -19,6 +19,8 @@ #include "element.h" #include "diagram.h" #include "conductorautonumerotation.h" +#include "conductor.h" +#include "potentialselectordialog.h" /** * @brief LinkElementCommand::LinkElementCommand @@ -211,7 +213,19 @@ void LinkElementCommand::redo() && m_element->conductors().size() \ && m_linked_after.size() && m_linked_after.first()->conductors().size()) { - ConductorAutoNumerotation::checkPotential(m_element->conductors().first(), this); + //fill list of potential + QSet c_list = m_element->conductors().first()->relatedPotentialConductors(); + c_list << m_element->conductors().first(); + //fill list of text + QStringList strl; + foreach (const Conductor *c, c_list) strl<<(c->properties().text); + + //check text list, isn't same in potential, ask user what to do + if (!QET::eachStrIsEqual(strl)) + { + PotentialSelectorDialog psd(m_element, this); + psd.exec(); + } m_first_redo = false; } QUndoCommand::redo();