Conductor: add option one text per potential in the same diagram (work in progress)

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3341 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-10-03 17:02:01 +00:00
parent 7ebdf8cf00
commit 22c13f29ee
10 changed files with 124 additions and 32 deletions

View File

@@ -224,7 +224,9 @@ ConductorProperties::ConductorProperties() :
verti_rotate_text(270), verti_rotate_text(270),
horiz_rotate_text(0), horiz_rotate_text(0),
style(Qt::SolidLine), style(Qt::SolidLine),
m_show_text(true) m_show_text(true),
m_one_text_per_folio(false),
m_no_one_text_per_folio(false)
{ {
} }
@@ -254,6 +256,8 @@ void ConductorProperties::toXml(QDomElement &e) const {
e.setAttribute("num", text); e.setAttribute("num", text);
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("noonetextperfolio", m_no_one_text_per_folio);
e.setAttribute("vertirotatetext", verti_rotate_text); e.setAttribute("vertirotatetext", verti_rotate_text);
e.setAttribute("horizrotatetext", horiz_rotate_text); e.setAttribute("horizrotatetext", horiz_rotate_text);
@@ -292,6 +296,8 @@ void ConductorProperties::fromXml(QDomElement &e) {
text = e.attribute("num"); text = e.attribute("num");
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_no_one_text_per_folio = e.attribute("noonetextperfolio", QString::number(0)).toInt();
verti_rotate_text = e.attribute("vertirotatetext").toDouble(); verti_rotate_text = e.attribute("vertirotatetext").toDouble();
horiz_rotate_text = e.attribute("horizrotatetext").toDouble(); horiz_rotate_text = e.attribute("horizrotatetext").toDouble();
@@ -311,6 +317,7 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix)
settings.setValue(prefix + "text", text); settings.setValue(prefix + "text", text);
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 + "vertirotatetext", QString::number(verti_rotate_text)); settings.setValue(prefix + "vertirotatetext", QString::number(verti_rotate_text));
settings.setValue(prefix + "horizrotatetext", QString::number(horiz_rotate_text)); settings.setValue(prefix + "horizrotatetext", QString::number(horiz_rotate_text));
singleLineProperties.toSettings(settings, prefix); singleLineProperties.toSettings(settings, prefix);
@@ -339,6 +346,7 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi
text = settings.value(prefix + "text", "_").toString(); text = settings.value(prefix + "text", "_").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();
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();
@@ -371,7 +379,9 @@ bool ConductorProperties::operator==(const ConductorProperties &other) const{
other.text_size == text_size &&\ other.text_size == text_size &&\
other.verti_rotate_text == verti_rotate_text &&\ other.verti_rotate_text == verti_rotate_text &&\
other.horiz_rotate_text == horiz_rotate_text &&\ other.horiz_rotate_text == horiz_rotate_text &&\
other.singleLineProperties == singleLineProperties other.singleLineProperties == singleLineProperties &&\
other.m_one_text_per_folio == m_one_text_per_folio &&\
other.m_no_one_text_per_folio == m_no_one_text_per_folio
); );
} }

View File

@@ -85,6 +85,8 @@ class ConductorProperties {
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_no_one_text_per_folio;
/// conducteur style (Qt::SolidLine or Qt::DashLine) /// conducteur style (Qt::SolidLine or Qt::DashLine)
Qt::PenStyle style; Qt::PenStyle style;

View File

@@ -47,6 +47,7 @@ NewDiagramPage::NewDiagramPage(QETProject *project, QWidget *parent) :
ipw = new TitleBlockPropertiesWidget(QETDiagramEditor::defaultTitleBlockProperties(), true); ipw = new TitleBlockPropertiesWidget(QETDiagramEditor::defaultTitleBlockProperties(), true);
// default conductor properties // default conductor properties
cpw = new ConductorPropertiesWidget(QETDiagramEditor::defaultConductorProperties()); cpw = new ConductorPropertiesWidget(QETDiagramEditor::defaultConductorProperties());
cpw -> setHiddenNoOneTextPerFolio(true);
// default propertie of report label // default propertie of report label
rpw = new ReportPropertieWidget(QETDiagramEditor::defaultReportProperties()); rpw = new ReportPropertieWidget(QETDiagramEditor::defaultReportProperties());
// default properties of xref // default properties of xref

View File

@@ -1188,7 +1188,35 @@ QPointF Conductor::posForText(Qt::Orientations &flag) {
* If text was moved by user, this function do nothing, except check if text is near conductor. * If text was moved by user, this function do nothing, except check if text is near conductor.
*/ */
void Conductor::calculateTextItemPosition() { void Conductor::calculateTextItemPosition() {
if (!text_item) return; if (!text_item || !diagram()) return;
if (diagram() -> defaultConductorProperties.m_one_text_per_folio == true) {
QSet<Conductor *> conductor_list = relatedPotentialConductors(false);
Conductor *longuest_conductor = this;
//Search the longuest conductor
foreach (Conductor *c, conductor_list) {
if (c -> length() > longuest_conductor -> length()) {
longuest_conductor = c;
}
}
//The longuest conductor isn't this conductor
//we call calculateTextItemPosition of the longuest conductor
if(longuest_conductor != this) {
longuest_conductor -> calculateTextItemPosition();
return;
}
//At this point this conductor is the longuest conductor
//we hide all text of conductor_list
foreach (Conductor *c, conductor_list) {
c -> textItem() -> setVisible(false);
}
}
//Make sure text item is visible
text_item -> setVisible(true);
//position //position
if (text_item -> wasMovedByUser()) { if (text_item -> wasMovedByUser()) {
@@ -1405,10 +1433,12 @@ QSet<Conductor *> Conductor::relatedConductors() const {
* @brief Conductor::relatedPotentialConductors * @brief Conductor::relatedPotentialConductors
* Return all conductors at the same potential of this conductor, this conductor isn't * Return all conductors at the same potential of this conductor, this conductor isn't
* part of the returned QSet. * part of the returned QSet.
* @param all_diagram : if true search in all diagram of the project,
* false search only in the parent diagram of this conductor
* @param t_list, a list of terminal already cheched for the serach of potential. * @param t_list, a list of terminal already cheched for the serach of potential.
* @return a QSet of conductor at the same potential. * @return a QSet of conductor at the same potential.
*/ */
QSet<Conductor *> Conductor::relatedPotentialConductors(QList <Terminal *> *t_list) { QSet<Conductor *> Conductor::relatedPotentialConductors(const bool all_diagram, QList <Terminal *> *t_list) {
bool declar_t_list = false; bool declar_t_list = false;
if (t_list == 0) { if (t_list == 0) {
declar_t_list = true; declar_t_list = true;
@@ -1426,7 +1456,7 @@ QSet<Conductor *> Conductor::relatedPotentialConductors(QList <Terminal *> *t_li
QList <Conductor *> other_conductors_list_t = terminal -> conductors(); QList <Conductor *> other_conductors_list_t = terminal -> conductors();
//get terminal share the same potential of @terminal, of parent element //get terminal share the same potential of @terminal, of parent element
Terminal *t1_bis = relatedPotentialTerminal(terminal); Terminal *t1_bis = relatedPotentialTerminal(terminal, all_diagram);
if (t1_bis && !t_list->contains(t1_bis)) { if (t1_bis && !t_list->contains(t1_bis)) {
t_list -> append(t1_bis); t_list -> append(t1_bis);
other_conductors_list_t += t1_bis->conductors(); other_conductors_list_t += t1_bis->conductors();
@@ -1435,7 +1465,7 @@ QSet<Conductor *> Conductor::relatedPotentialConductors(QList <Terminal *> *t_li
other_conductors_list_t.removeAll(this); other_conductors_list_t.removeAll(this);
// Research the conductors connected to conductors already found // Research the conductors connected to conductors already found
foreach (Conductor *c, other_conductors_list_t) { foreach (Conductor *c, other_conductors_list_t) {
other_conductors += c -> relatedPotentialConductors(t_list); other_conductors += c -> relatedPotentialConductors(all_diagram, t_list);
} }
other_conductors += other_conductors_list_t.toSet(); other_conductors += other_conductors_list_t.toSet();
} }
@@ -1454,11 +1484,13 @@ QSet<Conductor *> Conductor::relatedPotentialConductors(QList <Terminal *> *t_li
* For folio report, return the terminal of linked other report. * For folio report, return the terminal of linked other report.
* For Terminal element, return the other terminal of terminal element. * For Terminal element, return the other terminal of terminal element.
* @param t terminal to start search * @param t terminal to start search
* @param all_diagram :if true return all related terminal,
* false return only terminal in the same diagram of @t
* @return * @return
*/ */
Terminal * Conductor::relatedPotentialTerminal (Terminal *t) { Terminal * Conductor::relatedPotentialTerminal (Terminal *t, const bool all_diagram) {
// If terminal parent element is a folio report. // If terminal parent element is a folio report.
if (t->parentElement()->linkType() & Element::AllReport) { if (all_diagram && t->parentElement()->linkType() & Element::AllReport) {
QList <Element *> elmt_list = t->parentElement()->linkedElements(); QList <Element *> elmt_list = t->parentElement()->linkedElements();
if (!elmt_list.isEmpty()) { if (!elmt_list.isEmpty()) {
return (elmt_list.first()->terminals().first()); return (elmt_list.first()->terminals().first());

View File

@@ -107,7 +107,7 @@ class Conductor : public QObject, public QGraphicsPathItem {
virtual Highlight highlight() const; virtual Highlight highlight() const;
virtual void setHighlighted(Highlight); virtual void setHighlighted(Highlight);
void autoText(); void autoText();
QSet<Conductor *> relatedPotentialConductors(QList <Terminal *> *t_list=0); QSet<Conductor *> relatedPotentialConductors(const bool all_diagram = true, QList <Terminal *> *t_list=0);
QETDiagramEditor* diagramEditor() const; QETDiagramEditor* diagramEditor() const;
void editProperty (); void editProperty ();
@@ -181,6 +181,6 @@ class Conductor : public QObject, public QGraphicsPathItem {
static qreal conductor_bound(qreal, qreal, bool); static qreal conductor_bound(qreal, qreal, bool);
static Qt::Corner movementType(const QPointF &, const QPointF &); static Qt::Corner movementType(const QPointF &, const QPointF &);
static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &); static QPointF movePointIntoPolygon(const QPointF &, const QPainterPath &);
Terminal * relatedPotentialTerminal (Terminal *); Terminal * relatedPotentialTerminal (Terminal *, const bool all_diagram = true);
}; };
#endif #endif

View File

@@ -36,6 +36,7 @@ ConductorPropertiesDialog::ConductorPropertiesDialog(Conductor *conductor, QWidg
{ {
ui->setupUi(this); ui->setupUi(this);
m_cpw = new ConductorPropertiesWidget(conductor->properties()); m_cpw = new ConductorPropertiesWidget(conductor->properties());
m_cpw -> setHiddenOneTextPerFolio(true);
ui -> main_layout -> insertWidget(1, m_cpw); ui -> main_layout -> insertWidget(1, m_cpw);
} }

View File

@@ -70,16 +70,20 @@ void ConductorPropertiesWidget::setProperties(const ConductorProperties &propert
setColorButton(m_properties.color); setColorButton(m_properties.color);
int index = ui -> m_line_style_cb->findData(m_properties.style); int index = ui -> m_line_style_cb->findData(m_properties.style);
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_size_sb -> setValue (m_properties.text_size); ui -> m_text_le -> setText (m_properties.text);
ui -> m_show_text_cb -> setChecked (m_properties.m_show_text); ui -> m_text_size_sb -> setValue (m_properties.text_size);
ui -> m_earth_cb -> setChecked (m_properties.singleLineProperties.hasGround); ui -> m_show_text_cb -> setChecked (m_properties.m_show_text);
ui -> m_neutral_cb -> setChecked (m_properties.singleLineProperties.hasNeutral); ui -> m_one_text_per_folio_cb -> setChecked (m_properties.m_one_text_per_folio);
ui -> m_pen_cb -> setChecked (m_properties.singleLineProperties.isPen()); ui -> m_no_one_text_per_folio_cb -> setChecked (m_properties.m_no_one_text_per_folio);
ui -> m_phase_cb -> setChecked (m_properties.singleLineProperties.phasesCount()); ui -> m_earth_cb -> setChecked (m_properties.singleLineProperties.hasGround);
ui -> m_phase_slider -> setValue (m_properties.singleLineProperties.phasesCount()); ui -> m_neutral_cb -> setChecked (m_properties.singleLineProperties.hasNeutral);
m_verti_select -> setValue (m_properties.verti_rotate_text); ui -> m_pen_cb -> setChecked (m_properties.singleLineProperties.isPen());
m_horiz_select -> setValue (m_properties.horiz_rotate_text); 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);
setConductorType(m_properties.type); setConductorType(m_properties.type);
updatePreview(false); updatePreview(false);
@@ -93,16 +97,20 @@ ConductorProperties ConductorPropertiesWidget::properties() const {
ConductorProperties properties_; ConductorProperties properties_;
if (ui -> m_multi_rb -> isChecked()) properties_.type = ConductorProperties::Multi; if (ui -> m_multi_rb -> isChecked()) properties_.type = ConductorProperties::Multi;
else if (ui -> m_single_rb -> isChecked()) properties_.type = ConductorProperties::Single; else if (ui -> m_single_rb -> isChecked()) properties_.type = ConductorProperties::Single;
properties_.color = ui->m_color_pb->palette().color(QPalette::Button);
properties_.style = static_cast<Qt::PenStyle>(ui->m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).toInt()); properties_.color = ui->m_color_pb->palette().color(QPalette::Button);
properties_.text = ui -> m_text_le -> text(); properties_.style = static_cast<Qt::PenStyle>(ui->m_line_style_cb->itemData(ui->m_line_style_cb->currentIndex()).toInt());
properties_.text_size = ui -> m_text_size_sb -> value(); properties_.text = ui -> m_text_le -> text();
properties_.m_show_text = ui -> m_show_text_cb -> isChecked(); properties_.text_size = ui -> m_text_size_sb -> value();
properties_.verti_rotate_text = m_verti_select -> value(); properties_.m_show_text = ui -> m_show_text_cb -> isChecked();
properties_.horiz_rotate_text = m_horiz_select -> value(); properties_.m_one_text_per_folio = ui -> m_one_text_per_folio_cb -> isChecked();
properties_.singleLineProperties.hasGround = ui -> m_earth_cb -> isChecked(); properties_.m_no_one_text_per_folio = ui -> m_no_one_text_per_folio_cb -> isChecked();
properties_.verti_rotate_text = m_verti_select -> value();
properties_.horiz_rotate_text = m_horiz_select -> value();
properties_.singleLineProperties.hasGround = ui -> m_earth_cb -> isChecked();
properties_.singleLineProperties.hasNeutral = ui -> m_neutral_cb -> isChecked(); properties_.singleLineProperties.hasNeutral = ui -> m_neutral_cb -> isChecked();
properties_.singleLineProperties.is_pen = ui -> m_pen_cb -> isChecked(); properties_.singleLineProperties.is_pen = ui -> m_pen_cb -> isChecked();
properties_.singleLineProperties.setPhasesCount(ui -> m_phase_cb -> isChecked() ? ui -> m_phase_sb -> value() : 0); properties_.singleLineProperties.setPhasesCount(ui -> m_phase_cb -> isChecked() ? ui -> m_phase_sb -> value() : 0);
return properties_; return properties_;
@@ -116,10 +124,30 @@ void ConductorPropertiesWidget::setReadOnly(const bool &ro) {
this->setDisabled(ro); this->setDisabled(ro);
} }
/**
* @brief ConductorPropertiesWidget::addAutonumWidget
* @param widget
*/
void ConductorPropertiesWidget::addAutonumWidget(QWidget *widget) { void ConductorPropertiesWidget::addAutonumWidget(QWidget *widget) {
ui->m_autonum_layout->addWidget(widget); ui->m_autonum_layout->addWidget(widget);
} }
/**
* @brief ConductorPropertiesWidget::setHiddenOneTextPerFolio
* @param hide
*/
void ConductorPropertiesWidget::setHiddenOneTextPerFolio(const bool &hide) {
ui -> m_one_text_per_folio_cb -> setHidden(hide);
}
/**
* @brief ConductorPropertiesWidget::setHiddenNoOneTextPerFolio
* @param hide
*/
void ConductorPropertiesWidget::setHiddenNoOneTextPerFolio(const bool &hide) {
ui -> m_no_one_text_per_folio_cb -> setHidden(hide);
}
/** /**
* @brief ConductorPropertiesWidget::initWidget * @brief ConductorPropertiesWidget::initWidget
*/ */

View File

@@ -41,6 +41,8 @@ class ConductorPropertiesWidget : public QWidget
void setReadOnly(const bool &ro); void setReadOnly(const bool &ro);
void addAutonumWidget (QWidget *widget); void addAutonumWidget (QWidget *widget);
void setHiddenOneTextPerFolio (const bool &hide);
void setHiddenNoOneTextPerFolio (const bool &hide);
private: private:
void initWidget(); void initWidget();

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>430</width> <width>570</width>
<height>407</height> <height>453</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -94,7 +94,22 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="m_autonum_layout"/> <layout class="QVBoxLayout" name="m_autonum_layout">
<item>
<widget class="QCheckBox" name="m_one_text_per_folio_cb">
<property name="text">
<string>Afficher un seul texte par potentiel présent sur un folio. (expérimental)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="m_no_one_text_per_folio_cb">
<property name="text">
<string>Ne pas subir l'option : afficher un seul texte par potentiel présent sur un folio. (Inactifl)</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">

View File

@@ -64,6 +64,7 @@ DiagramPropertiesDialog::DiagramPropertiesDialog(Diagram *diagram, QWidget *pare
//Conductor widget //Conductor widget
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(conductors, this); ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(conductors, this);
cpw -> setHiddenNoOneTextPerFolio(true);
cpw -> setReadOnly(diagram_is_read_only); cpw -> setReadOnly(diagram_is_read_only);
//Conductor autonum //Conductor autonum