Conductor properties : Add two value, function and tension/protocol.

Revamp some widget to edit it.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4172 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2015-08-29 14:18:30 +00:00
parent bda6d607b3
commit 1bdb13594b
16 changed files with 557 additions and 397 deletions

View File

@ -20,9 +20,9 @@
#include "qetdiagrameditor.h" #include "qetdiagrameditor.h"
#include "conductor.h" #include "conductor.h"
#include "diagram.h" #include "diagram.h"
#include "potentialtextsdialog.h"
#include "qet.h" #include "qet.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h" #include "QPropertyUndoCommand/qpropertyundocommand.h"
#include "potentialselectordialog.h"
/** /**
* @brief ConductorAutoNumerotation::ConductorAutoNumerotation * @brief ConductorAutoNumerotation::ConductorAutoNumerotation
@ -51,31 +51,6 @@ void ConductorAutoNumerotation::numerate() {
else if (conductor_ -> properties().type == ConductorProperties::Multi) numerateNewConductor(); 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 <Conductor *> 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 * @brief ConductorAutoNumerotation::applyText
* apply the text @t to @conductor_ and all conductors at the same potential * 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 //the texts isn't identicals
else else
{ {
PotentialTextsDialog ptd (conductor_, conductor_ -> diagramEditor()); PotentialSelectorDialog psd(conductor_, m_parent_undo, conductor_->diagramEditor());
ptd.exec(); psd.exec();
applyText(ptd.selectedText());
} }
} }

View File

@ -32,7 +32,6 @@ class ConductorAutoNumerotation
//methods //methods
void numerate (); void numerate ();
static void checkPotential (Conductor *conductor, QUndoCommand *parent = nullptr);
void applyText (QString); void applyText (QString);
private: private:

View File

@ -241,18 +241,19 @@ ConductorProperties::~ConductorProperties() {
* Export conductor propertie, in the XML element 'e' * Export conductor propertie, in the XML element 'e'
* @param e the xml element * @param e the xml element
*/ */
void ConductorProperties::toXml(QDomElement &e) const { void ConductorProperties::toXml(QDomElement &e) const
{
e.setAttribute("type", typeToString(type)); e.setAttribute("type", typeToString(type));
if (color != QColor(Qt::black))
if (color != QColor(Qt::black)) {
e.setAttribute("color", color.name()); e.setAttribute("color", color.name());
}
if (type == Single) { if (type == Single)
singleLineProperties.toXml(e); singleLineProperties.toXml(e);
}
e.setAttribute("num", text); e.setAttribute("num", text);
e.setAttribute("function", m_function);
e.setAttribute("tension-protocol", m_tension_protocol);
e.setAttribute("numsize", text_size); e.setAttribute("numsize", text_size);
e.setAttribute("displaytext", m_show_text); e.setAttribute("displaytext", m_show_text);
e.setAttribute("onetextperfolio", m_one_text_per_folio); e.setAttribute("onetextperfolio", m_one_text_per_folio);
@ -260,10 +261,9 @@ void ConductorProperties::toXml(QDomElement &e) const {
e.setAttribute("horizrotatetext", horiz_rotate_text); e.setAttribute("horizrotatetext", horiz_rotate_text);
QString conductor_style = writeStyle(); QString conductor_style = writeStyle();
if (!conductor_style.isEmpty()) { if (!conductor_style.isEmpty())
e.setAttribute("style", conductor_style); e.setAttribute("style", conductor_style);
} }
}
/** /**
@ -271,27 +271,27 @@ void ConductorProperties::toXml(QDomElement &e) const {
* Import conductor propertie, from the attribute of the xml element 'e' * Import conductor propertie, from the attribute of the xml element 'e'
* @param e the xml document * @param e the xml document
*/ */
void ConductorProperties::fromXml(QDomElement &e) { void ConductorProperties::fromXml(QDomElement &e)
{
// get conductor color // get conductor color
QColor xml_color= QColor(e.attribute("color")); QColor xml_color= QColor(e.attribute("color"));
if (xml_color.isValid()) { color = (xml_color.isValid()? xml_color : QColor(Qt::black));
color = xml_color;
} else {
color = QColor(Qt::black);
}
// read style of conductor // read style of conductor
readStyle(e.attribute("style")); readStyle(e.attribute("style"));
if (e.attribute("type") == typeToString(Single)) { if (e.attribute("type") == typeToString(Single))
{
// get specific properties for single conductor // get specific properties for single conductor
singleLineProperties.fromXml(e); singleLineProperties.fromXml(e);
type = Single; type = Single;
} else {
type = Multi;
} }
// get text field else
type = Multi;
text = e.attribute("num"); 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(); text_size = e.attribute("numsize", QString::number(9)).toInt();
m_show_text = e.attribute("displaytext", QString::number(1)).toInt(); m_show_text = e.attribute("displaytext", QString::number(1)).toInt();
m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt(); m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt();
@ -300,6 +300,7 @@ void ConductorProperties::fromXml(QDomElement &e) {
//Keep retrocompatible with version older than 0,4 //Keep retrocompatible with version older than 0,4
//If the propertie @type is simple (removed since QET 0,4), we set text no visible. //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; if (e.attribute("type") == "simple") m_show_text = false;
} }
@ -307,11 +308,14 @@ void ConductorProperties::fromXml(QDomElement &e) {
@param settings Parametres a ecrire @param settings Parametres a ecrire
@param prefix prefixe a ajouter devant les noms des parametres @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 + "color", color.name());
settings.setValue(prefix + "style", writeStyle()); settings.setValue(prefix + "style", writeStyle());
settings.setValue(prefix + "type", typeToString(type)); settings.setValue(prefix + "type", typeToString(type));
settings.setValue(prefix + "text", text); 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 + "textsize", QString::number(text_size));
settings.setValue(prefix + "displaytext", m_show_text); settings.setValue(prefix + "displaytext", m_show_text);
settings.setValue(prefix + "onetextperfolio", m_one_text_per_folio); 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 settings Parametres a lire
@param prefix prefixe a ajouter devant les noms des parametres @param prefix prefixe a ajouter devant les noms des parametres
*/ */
void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) { void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix)
// recupere la couleur dans les parametres {
QColor settings_color = QColor(settings.value(prefix + "color").toString()); QColor settings_color = QColor(settings.value(prefix + "color").toString());
if (settings_color.isValid()) { color = (settings_color.isValid()? settings_color : QColor(Qt::black));
color = settings_color;
} else {
color = QColor(Qt::black);
}
QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString(); QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString();
if (setting_type == typeToString(Single)) { type = (setting_type == typeToString(Single)? Single : Multi);
type = Single;
} else {
type = Multi;
}
singleLineProperties.fromSettings(settings, prefix); singleLineProperties.fromSettings(settings, prefix);
text = settings.value(prefix + "text", "_").toString(); 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(); text_size = settings.value(prefix + "textsize", "7").toInt();
m_show_text = settings.value(prefix + "displaytext", true).toBool(); m_show_text = settings.value(prefix + "displaytext", true).toBool();
m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool(); m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool();
verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble(); verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble();
horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble(); horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble();
// lit le style du conducteur
readStyle(settings.value(prefix + "style").toString()); readStyle(settings.value(prefix + "style").toString());
} }
@ -385,6 +384,8 @@ bool ConductorProperties::operator==(const ConductorProperties &other) const{
other.color == color &&\ other.color == color &&\
other.style == style &&\ other.style == style &&\
other.text == text &&\ other.text == text &&\
other.m_function == m_function &&\
other.m_tension_protocol == m_tension_protocol &&\
other.m_show_text == m_show_text &&\ other.m_show_text == m_show_text &&\
other.text_size == text_size &&\ other.text_size == text_size &&\
other.verti_rotate_text == verti_rotate_text &&\ other.verti_rotate_text == verti_rotate_text &&\

View File

@ -61,38 +61,32 @@ class SingleLineProperties {
This class represents the functional properties of a particular conductor, This class represents the functional properties of a particular conductor,
i.e. properties other than path and terminals. i.e. properties other than path and terminals.
*/ */
class ConductorProperties { class ConductorProperties
// constructors, destructor {
public: public:
ConductorProperties(); ConductorProperties();
virtual ~ConductorProperties(); virtual ~ConductorProperties();
/** /**
Represents the kind of a particular conductor: * @brief The ConductorType enum Represents the kind of a particular conductor:
* Simple: no symbols, no text input
* Single: singleline symbols, no text input * Single: singleline symbols, no text input
* Multi: text input, no symbol * Multi: text input, no symbol
*/ */
enum ConductorType { Single, Multi }; enum ConductorType { Single, Multi };
// attributes
/// Conductor type //Attributes
ConductorType type; ConductorType type;
/// Conductor color
QColor color; QColor color;
/// Texte displayed for multiline conductors QString text,
QString text; m_function,
/// size of text m_tension_protocol;
int text_size; int text_size;
/// rotation angle texte
double verti_rotate_text; double verti_rotate_text;
double horiz_rotate_text; double horiz_rotate_text;
bool m_show_text; bool m_show_text;
bool m_one_text_per_folio; bool m_one_text_per_folio;
/// conducteur style (Qt::SolidLine or Qt::DashLine)
Qt::PenStyle style; Qt::PenStyle style;
/// properties for singleline conductors
SingleLineProperties singleLineProperties; SingleLineProperties singleLineProperties;
// methods // methods

View File

@ -35,11 +35,12 @@ bool Conductor::pen_and_brush_initialized = false;
QPen Conductor::conductor_pen = QPen(); QPen Conductor::conductor_pen = QPen();
QBrush Conductor::conductor_brush = QBrush(); QBrush Conductor::conductor_brush = QBrush();
QBrush Conductor::square_brush = QBrush(Qt::darkGreen); QBrush Conductor::square_brush = QBrush(Qt::darkGreen);
/** /**
Constructeur * @brief Conductor::Conductor
@param p1 Premiere Borne a laquelle le conducteur est lie * Default constructor.
@param p2 Seconde Borne a laquelle le conducteur est lie * @param p1 : first terminal of this conductor.
@param parent_diagram QGraphicsScene a laquelle appartient le conducteur * @param p2 : second terminal of this conductor.
*/ */
Conductor::Conductor(Terminal *p1, Terminal* p2) : Conductor::Conductor(Terminal *p1, Terminal* p2) :
QObject(), QObject(),
@ -57,6 +58,12 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
segments_squares_scale_(1.0), segments_squares_scale_(1.0),
must_highlight_(Conductor::None) must_highlight_(Conductor::None)
{ {
//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) //set Zvalue at 9 to be upper than the DiagramImageItem and bottom of element(10)
setZValue(9); setZValue(9);
previous_z_value = zValue(); 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 become false if the conductor can't be added to terminal (conductor already exist)
m_valid = (!ajout_p1 || !ajout_p2) ? false : true; m_valid = (!ajout_p1 || !ajout_p2) ? false : true;
// attributs de dessin par defaut (communs a tous les conducteurs) //Default attribut for paint a conductor
if (!pen_and_brush_initialized) { if (!pen_and_brush_initialized)
{
conductor_pen.setJoinStyle(Qt::MiterJoin); conductor_pen.setJoinStyle(Qt::MiterJoin);
conductor_pen.setCapStyle(Qt::SquareCap); conductor_pen.setCapStyle(Qt::SquareCap);
conductor_pen.setColor(Qt::black); conductor_pen.setColor(Qt::black);
@ -79,13 +87,13 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
pen_and_brush_initialized = true; 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::TopLeftCorner, ConductorProfile());
conductor_profiles.insert(Qt::TopRightCorner, ConductorProfile()); conductor_profiles.insert(Qt::TopRightCorner, ConductorProfile());
conductor_profiles.insert(Qt::BottomLeftCorner, ConductorProfile()); conductor_profiles.insert(Qt::BottomLeftCorner, ConductorProfile());
conductor_profiles.insert(Qt::BottomRightCorner, 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()); generateConductorPath(terminal1 -> dockConductor(), terminal1 -> orientation(), terminal2 -> dockConductor(), terminal2 -> orientation());
setFlags(QGraphicsItem::ItemIsSelectable); setFlags(QGraphicsItem::ItemIsSelectable);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
@ -1338,14 +1346,26 @@ void Conductor::setText(const QString &t) {
/** /**
* @brief Conductor::setProperties * @brief Conductor::setProperties
* Set new properties for this conductor * 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) { void Conductor::setProperties(const ConductorProperties &properties)
if (properties_ != p)
{ {
properties_ = p; if (properties_ == properties) return;
readProperties();
properties_ = properties;
foreach(Conductor *other_conductor, relatedPotentialConductors())
{
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();
} }
/** /**

View File

@ -106,7 +106,7 @@ class Conductor : public QObject, public QGraphicsPathItem
public: public:
const QList<ConductorSegment *> segmentsList() const; const QList<ConductorSegment *> segmentsList() const;
void setProperties(const ConductorProperties &); void setProperties(const ConductorProperties &properties);
ConductorProperties properties() const; ConductorProperties properties() const;
void setProfile(const ConductorProfile &, Qt::Corner); void setProfile(const ConductorProfile &, Qt::Corner);
ConductorProfile profile(Qt::Corner) const; ConductorProfile profile(Qt::Corner) const;

View File

@ -627,7 +627,6 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
new_conductor->setProperties(others_properties); new_conductor->setProperties(others_properties);
else else
{ {
new_conductor -> setProperties(diagram() -> defaultConductorProperties);
//Autonum it //Autonum it
ConductorAutoNumerotation can (new_conductor, diagram(), undo); ConductorAutoNumerotation can (new_conductor, diagram(), undo);
can.numerate(); can.numerate();

View File

@ -70,32 +70,15 @@ void ConductorPropertiesDialog::PropertiesDialog(Conductor *conductor, QWidget *
QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value); QPropertyUndoCommand *undo = new QPropertyUndoCommand(conductor, "properties", old_value, new_value);
undo->setText(tr("Modifier les propriétés d'un conducteur", "undo caption")); 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")); 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()) 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()); old_value.setValue(potential_conductor->properties());
new QPropertyUndoCommand (potential_conductor, "properties", old_value, new_value, undo); 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);
}
}
} }
conductor->diagram()->undoStack().push(undo); conductor->diagram()->undoStack().push(undo);

View File

@ -66,7 +66,8 @@ ConductorPropertiesWidget::~ConductorPropertiesWidget()
* Set the properties * Set the properties
* @param properties * @param properties
*/ */
void ConductorPropertiesWidget::setProperties(const ConductorProperties &properties) { void ConductorPropertiesWidget::setProperties(const ConductorProperties &properties)
{
if (m_properties == properties) return; if (m_properties == properties) return;
m_properties = properties; m_properties = properties;
@ -75,6 +76,8 @@ void ConductorPropertiesWidget::setProperties(const ConductorProperties &propert
if (index != -1) ui -> m_line_style_cb -> setCurrentIndex(index); if (index != -1) ui -> m_line_style_cb -> setCurrentIndex(index);
ui->m_text_le -> setText (m_properties.text); 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_text_size_sb -> setValue (m_properties.text_size);
ui->m_show_text_cb -> setChecked (m_properties.m_show_text); 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_one_text_per_folio_cb -> setChecked (m_properties.m_one_text_per_folio);
@ -95,7 +98,8 @@ void ConductorPropertiesWidget::setProperties(const ConductorProperties &propert
* @brief ConductorPropertiesWidget::properties * @brief ConductorPropertiesWidget::properties
* @return the edited properties * @return the edited properties
*/ */
ConductorProperties ConductorPropertiesWidget::properties() const { ConductorProperties ConductorPropertiesWidget::properties() const
{
ConductorProperties properties_; ConductorProperties properties_;
if (ui -> m_multiwires_gb -> isChecked()) properties_.type = ConductorProperties::Multi; if (ui -> m_multiwires_gb -> isChecked()) properties_.type = ConductorProperties::Multi;
else if (ui -> m_singlewire_gb -> isChecked()) properties_.type = ConductorProperties::Single; 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_.color = ui -> m_color_pb->palette().color(QPalette::Button);
properties_.style = ui -> m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).value<QPen>().style(); properties_.style = ui -> m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).value<QPen>().style();
properties_.text = ui -> m_text_le -> text(); 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_.text_size = ui -> m_text_size_sb -> value();
properties_.m_show_text = ui -> m_show_text_cb -> isChecked(); properties_.m_show_text = ui -> m_show_text_cb -> isChecked();
properties_.m_one_text_per_folio = ui -> m_one_text_per_folio_cb -> isChecked(); properties_.m_one_text_per_folio = ui -> m_one_text_per_folio_cb -> isChecked();

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>354</width> <width>504</width>
<height>329</height> <height>420</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -33,23 +33,35 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Texte :</string> <string>Taille du texte :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="2" column="2">
<widget class="QLineEdit" name="m_function_le"/>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="m_text_size_sb"> <widget class="QSpinBox" name="m_text_size_sb">
<property name="toolTip"> <property name="toolTip">
<string>Taille du texte</string> <string>Taille du texte</string>
</property> </property>
<property name="wrapping">
<bool>false</bool>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::UpDownArrows</enum>
</property>
<property name="prefix">
<string/>
</property>
<property name="minimum"> <property name="minimum">
<number>5</number> <number>5</number>
</property> </property>
@ -58,14 +70,31 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="3" column="2">
<widget class="QLabel" name="label_2"> <widget class="QLineEdit" name="m_tension_protocol_le"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_9">
<property name="text"> <property name="text">
<string>Taille :</string> <string>Tension / Protocole :</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Texte :</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Fonction :</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="m_text_le"> <widget class="QLineEdit" name="m_text_le">
<property name="toolTip"> <property name="toolTip">
<string>Texte</string> <string>Texte</string>
@ -75,13 +104,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="1" column="3">
<widget class="QCheckBox" name="m_show_text_cb"> <widget class="QCheckBox" name="m_show_text_cb">
<property name="toolTip"> <property name="toolTip">
<string>Texte visible</string> <string>Texte visible</string>
</property> </property>
<property name="text"> <property name="text">
<string>Visible</string> <string/>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "potentialselectordialog.h"
#include "ui_potentialselectordialog.h"
#include "conductor.h"
#include "terminal.h"
#include <QRadioButton>
#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);
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef POTENTIALSELECTORDIALOG_H
#define POTENTIALSELECTORDIALOG_H
#include <QDialog>
#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

View File

@ -1,47 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>PotentialTextsDialog</class> <class>PotentialSelectorDialog</class>
<widget class="QDialog" name="PotentialTextsDialog"> <widget class="QDialog" name="PotentialSelectorDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>403</width> <width>425</width>
<height>94</height> <height>74</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Textes de potentiel</string> <string>Sélectionner le potentiel éléctrique</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<property name="modal">
<bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <property name="sizeConstraint">
<layout class="QVBoxLayout" name="verticalLayout_3"> <enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="topMargin">
<number>9</number>
</property>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="text"> <property name="text">
<string>Les textes de ce potentiel électrique ne sont pas identiques. <string>Vous tentez de lier deux potentiels différents ensemble.
Appliquer un texte à l'ensemble de ces conducteurs.</string> Veuillez choisir les propriétées à appliquer au nouveau potentiel.</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="m_buttons_layout"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
@ -59,7 +66,7 @@ Appliquer un texte à l'ensemble de ces conducteurs.</string>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>accepted()</signal> <signal>accepted()</signal>
<receiver>PotentialTextsDialog</receiver> <receiver>PotentialSelectorDialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
@ -75,7 +82,7 @@ Appliquer un texte à l'ensemble de ces conducteurs.</string>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>rejected()</signal> <signal>rejected()</signal>
<receiver>PotentialTextsDialog</receiver> <receiver>PotentialSelectorDialog</receiver>
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "conductor.h"
#include "potentialtextsdialog.h"
#include "ui_potentialtextsdialog.h"
#include <QSignalMapper>
#include <QRadioButton>
/**
* @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<int, QString>::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;
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef POTENTIALTEXTSDIALOG_H
#define POTENTIALTEXTSDIALOG_H
#include <QDialog>
#include <QMultiMap>
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 <int, QString> m_texts;
};
#endif // POTENTIALTEXTSDIALOG_H

View File

@ -19,6 +19,8 @@
#include "element.h" #include "element.h"
#include "diagram.h" #include "diagram.h"
#include "conductorautonumerotation.h" #include "conductorautonumerotation.h"
#include "conductor.h"
#include "potentialselectordialog.h"
/** /**
* @brief LinkElementCommand::LinkElementCommand * @brief LinkElementCommand::LinkElementCommand
@ -211,7 +213,19 @@ void LinkElementCommand::redo()
&& m_element->conductors().size() \ && m_element->conductors().size() \
&& m_linked_after.size() && m_linked_after.first()->conductors().size()) && m_linked_after.size() && m_linked_after.first()->conductors().size())
{ {
ConductorAutoNumerotation::checkPotential(m_element->conductors().first(), this); //fill list of potential
QSet <Conductor *> 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; m_first_redo = false;
} }
QUndoCommand::redo(); QUndoCommand::redo();