diff --git a/sources/conductorautonumerotation.cpp b/sources/conductorautonumerotation.cpp
index a6918c562..4aabf5c19 100644
--- a/sources/conductorautonumerotation.cpp
+++ b/sources/conductorautonumerotation.cpp
@@ -16,12 +16,12 @@
along with QElectroTech. If not, see .
*/
#include "conductorautonumerotation.h"
-#include "conductorautonumerotationwidget.h"
#include "diagramcommands.h"
#include "numerotationcontextcommands.h"
#include "qetdiagrameditor.h"
#include "conductor.h"
#include "diagram.h"
+#include "potentialtextsdialog.h"
/**
*Constructor
@@ -45,10 +45,10 @@ void ConductorAutoNumerotation::numerate() {
/**
* @brief ConductorAutoNumerotation::checkPotential
- * Check if text of this potential is identical.
+ * Check if eah texts of this potential is identical.
* If not, ask user how to numerate
* @param conductor
- * One conductor of this potential.
+ * A conductor of the potential to check.
*/
void ConductorAutoNumerotation::checkPotential(Conductor *conductor) {
//fill list of potential
@@ -60,10 +60,11 @@ void ConductorAutoNumerotation::checkPotential(Conductor *conductor) {
//check text list, isn't same in potential, ask user what to do
if (!eachIsEqual(strl)) {
- ConductorAutoNumerotationWidget canw(c_list, conductor -> diagramEditor());
- ConductorAutoNumerotation can(conductor);
- //connect(&canw, SIGNAL(textIsSelected(QString)), &can, SLOT(applyText(QString)));
- canw.exec();
+ PotentialTextsDialog ptd(conductor, conductor->diagramEditor());
+ if ( ptd.exec() == QDialog::Accepted ) {
+ ConductorAutoNumerotation can(conductor);
+ can.applyText(ptd.selectedText());
+ }
}
}
@@ -118,10 +119,10 @@ void ConductorAutoNumerotation::numeratePotential() {
}
//the texts isn't identicals
else {
- ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_list, conductor_ -> diagramEditor());
- /*connect(canw, SIGNAL(textIsSelected(QString)),
- this, SLOT(applyText(QString)));*/
- canw -> exec();
+ PotentialTextsDialog ptd (conductor_, conductor_ -> diagramEditor());
+ if (ptd.exec() == QDialog::Accepted) {
+ applyText(ptd.selectedText());
+ }
}
}
diff --git a/sources/conductorautonumerotationwidget.cpp b/sources/conductorautonumerotationwidget.cpp
deleted file mode 100644
index 1931f4d7c..000000000
--- a/sources/conductorautonumerotationwidget.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- Copyright 2006-2014 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 "conductorautonumerotationwidget.h"
-
-/**
- * constructor
- */
-ConductorAutoNumerotationWidget::ConductorAutoNumerotationWidget(QSet cl, QWidget *parent) :
- QDialog (parent),
- c_list(cl)
-{
-#ifdef Q_WS_MAC
- setWindowFlags(Qt::Sheet);
-#endif
- buildInterface();
-}
-
-/**
- * @brief ConductorAutoNumerotationWidget::buildInterface
- */
-void ConductorAutoNumerotationWidget::buildInterface() {
- QVBoxLayout *mainlayout = new QVBoxLayout;
- QGroupBox *potential_groupbox = new QGroupBox(tr("Textes de potentiel"), this);
- QVBoxLayout *vlayout = new QVBoxLayout;
-
- QLabel *label= new QLabel(tr("Les textes de ce potentiel \351lectrique ne sont pas identiques.\n"
- "Appliquer un texte \340 l'ensemble de ces conducteurs?"), this);
- vlayout -> addWidget(label);
-
- //map the signal for each radio button create in buildRadioList
- sm_ = new QSignalMapper(this);
- connect(sm_, SIGNAL(mapped(QString)), this, SLOT(setText(QString)));
- vlayout -> addLayout(buildRadioList());
-
- potential_groupbox -> setLayout(vlayout);
- mainlayout -> addWidget(potential_groupbox);
-
- QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Yes, Qt::Horizontal, this);
- connect(dbb, SIGNAL(rejected()),
- this, SLOT(reject()));
- connect(dbb, SIGNAL(accepted()),
- this, SLOT(accept()));
-
- mainlayout->addWidget(dbb);
- setLayout(mainlayout);
-}
-
-/**
- * @brief ConductorAutoNumerotationWidget::buildRadioList
- *construit toute la partie de l'interface contenant les boutons radio permetant le choix du texte a appliquer
- * @return un layout contenant les boutons radio
- */
-QVBoxLayout* ConductorAutoNumerotationWidget::buildRadioList() {
- QVBoxLayout *radioLayout = new QVBoxLayout;
- QHBoxLayout *otherLayout = new QHBoxLayout;
-
- //create a new radio button for each text of @conductorList
- QMultiMap conductorlist = conductorsTextToMap(c_list);
- for (QMultiMap::ConstIterator it = conductorlist.constEnd()-1; it != conductorlist.constBegin()-1; --it) {
- QRadioButton *rb= new QRadioButton(it.value() + tr(" : est pr\351sent ") + QString::number(it.key()) + tr(" fois."), this);
- if (it == conductorlist.constEnd()-1) {
- rb -> setChecked(true);
- text_ = it.value();
- }
- //connect the button to mapper @sm_
- connect(rb, SIGNAL(clicked()),
- sm_, SLOT(map()));
- sm_ -> setMapping(rb, it.value());
- radioLayout -> addWidget(rb);
- }
-
- //create the "other" radio button and is text field
- QRadioButton *other= new QRadioButton(tr("Autre"), this);
- text_field = new QLineEdit(this);
- text_field -> setEnabled(false);
- connect(other, SIGNAL(toggled(bool)), text_field, SLOT(setEnabled(bool)));
- otherLayout -> addWidget(other);
- otherLayout -> addWidget(text_field);
- radioLayout -> addLayout(otherLayout);
- return radioLayout;
-}
-
-/**
- * @param csl liste des conducteurs a analyser
- * @return QMultiMap avec le nombre de conducteurs possedant le même texte en clee et le texte en question comme valeur
- */
-QMultiMap ConductorAutoNumerotationWidget::conductorsTextToMap(QSet csl) {
- QStringList textList;
- foreach(Conductor *c, csl) textList << c -> text();
-
- QMultiMap conductorlist;
- while (!textList.size() == 0) {
- QString t = textList.at(0);
- int n = textList.count(t);
- textList.removeAll(t);
- conductorlist.insert(n, t);
- }
- return conductorlist;
-}
-
-/**
- * @brief ConductorAutoNumerotationWidget::setText
- * enregistre le texte @t passé en parametre
- */
-void ConductorAutoNumerotationWidget::setText(QString t) {
- text_ = t;
-}
-
-/**
- * @brief ConductorAutoNumerotationWidget::accept
- *action executé lors de l'appuis sur le bouton 'oui'
- */
-void ConductorAutoNumerotationWidget::accept() {
- if (text_field -> isEnabled()) {
- emit textIsSelected(text_field -> text());
- }
- else
- emit textIsSelected(text_);
- close();
-}
diff --git a/sources/conductorautonumerotationwidget.h b/sources/conductorautonumerotationwidget.h
deleted file mode 100644
index 21f48c031..000000000
--- a/sources/conductorautonumerotationwidget.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef CONDUCTORAUTONUMEROTATIONWIDGET_H
-#define CONDUCTORAUTONUMEROTATIONWIDGET_H
-
-#include
-#include
-#include
-#include
-#include "qetgraphicsitem/conductor.h"
-#include "diagram.h"
-
-class ConductorAutoNumerotationWidget : public QDialog
-{
- Q_OBJECT
- public:
- explicit ConductorAutoNumerotationWidget(QSet , QWidget *parent = 0);
- QMultiMap conductorsTextToMap (QSet );
-
- public slots:
- void setText (QString);
- void accept();
-
- signals:
- void textIsSelected (QString);
-
- private:
- //methods
- void buildInterface();
- QVBoxLayout* buildRadioList();
-
- //attributes
- QSet c_list; //liste des conducteurs au même potentiel
- QLineEdit *text_field;
- QString text_;
- QSignalMapper *sm_;
-
-};
-
-#endif // CONDUCTORAUTONUMEROTATIONWIDGET_H
diff --git a/sources/diagram.cpp b/sources/diagram.cpp
index 0c7284dfe..0fbc741d3 100644
--- a/sources/diagram.cpp
+++ b/sources/diagram.cpp
@@ -339,10 +339,15 @@ QDomDocument Diagram::toXml(bool whole_content) {
border_and_titleblock.titleBlockToXml(racine);
border_and_titleblock.borderToXml(racine);
- // type de conducteur par defaut
+ // Default conductor properties
QDomElement default_conductor = document.createElement("defaultconductor");
defaultConductorProperties.toXml(default_conductor);
racine.appendChild(default_conductor);
+
+ // Conductor autonum
+ if (!m_conductors_autonum_name.isEmpty()) {
+ racine.setAttribute("conductorAutonum", m_conductors_autonum_name);
+ }
}
document.appendChild(racine);
@@ -494,28 +499,34 @@ bool Diagram::initFromXml(QDomElement &document, QPointF position, bool consider
*/
bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_informations, DiagramContent *content_ptr) {
QDomElement root = document;
- // le premier element doit etre un schema
+ // The first element must be a diagram
if (root.tagName() != "diagram") return(false);
- // lecture des attributs de ce schema
+ // Read attributes of this diagram
if (consider_informations) {
+ // Version of diagram
bool conv_ok;
qreal version_value = root.attribute("version").toDouble(&conv_ok);
if (conv_ok) {
diagram_qet_version_ = version_value;
}
+ // Load border and titleblock
border_and_titleblock.titleBlockFromXml(root);
border_and_titleblock.borderFromXml(root);
- // repere le permier element "defaultconductor"
+ // Find the element "defaultconductor".
+ // If found, load default conductor properties.
QDomElement default_conductor_elmt = root.firstChildElement("defaultconductor");
if (!default_conductor_elmt.isNull()) {
defaultConductorProperties.fromXml(default_conductor_elmt);
}
+
+ // Load the autonum
+ m_conductors_autonum_name = root.attribute("conductorAutonum");
}
- // si la racine n'a pas d'enfant : le chargement est fini (schema vide)
+ // if child haven't got a child, loading is finish (diagram is empty)
if (root.firstChild().isNull()) {
write(document);
return(true);
diff --git a/sources/ui/potentialtextsdialog.cpp b/sources/ui/potentialtextsdialog.cpp
new file mode 100644
index 000000000..68277d688
--- /dev/null
+++ b/sources/ui/potentialtextsdialog.cpp
@@ -0,0 +1,104 @@
+/*
+ Copyright 2006-2014 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
+
+/**
+ * @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\351sent ") + 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
new file mode 100644
index 000000000..2a45394a8
--- /dev/null
+++ b/sources/ui/potentialtextsdialog.h
@@ -0,0 +1,61 @@
+/*
+ Copyright 2006-2014 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/ui/potentialtextsdialog.ui b/sources/ui/potentialtextsdialog.ui
new file mode 100644
index 000000000..5108a809c
--- /dev/null
+++ b/sources/ui/potentialtextsdialog.ui
@@ -0,0 +1,92 @@
+
+
+ PotentialTextsDialog
+
+
+
+ 0
+ 0
+ 400
+ 94
+
+
+
+ Textes de potentiel
+
+
+ -
+
+
-
+
+
+ Les textes de ce potentiel électrique ne sont pas identiques.
+Appliquer un texte à l'ensemble de ces conducteurs?
+
+
+
+
+
+ -
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ PotentialTextsDialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ PotentialTextsDialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+