diff --git a/sources/configpages.cpp b/sources/configpages.cpp index 5bfac716a..ffcd965d1 100644 --- a/sources/configpages.cpp +++ b/sources/configpages.cpp @@ -87,7 +87,12 @@ void NewDiagramPage::applyConf() { rpw->toSettings(settings, "diagrameditor/defaultreport"); // default xref properties - xrefpw -> properties().toSettings(settings, "diagrameditor/defaultxref"); + QHash hash_xrp = xrefpw -> properties(); + foreach (QString key, hash_xrp.keys()) { + XRefProperties xrp = hash_xrp[key]; + QString str("diagrameditor/defaultxref"); + xrp.toSettings(settings, str += key); + } } /// @return l'icone de cette page diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 7dabfecff..fa0260c7d 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1203,12 +1203,12 @@ QETProject *Diagram::project() const { void Diagram::setProject(QETProject *project) { if (project_) { disconnect (project_, SIGNAL(reportPropertiesChanged(QString)), this, SIGNAL(reportPropertiesChanged(QString))); - disconnect (project_, SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SIGNAL(XRefPropertiesChanged(XRefProperties))); + disconnect (project_, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged())); } project_ = project; if (project_) { connect (project_, SIGNAL(reportPropertiesChanged(QString)), this, SIGNAL(reportPropertiesChanged(QString))); - connect (project_, SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SIGNAL(XRefPropertiesChanged(XRefProperties))); + connect (project_, SIGNAL(XRefPropertiesChanged()), this, SIGNAL(XRefPropertiesChanged())); } } diff --git a/sources/diagram.h b/sources/diagram.h index 2bdf34cb7..e9396004b 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -104,7 +104,7 @@ class Diagram : public QGraphicsScene { public: QString defaultReportProperties () const {return project_ -> defaultReportProperties();} - XRefProperties defaultXRefProperties () const {return project_ -> defaultXrefProperties();} + XRefProperties defaultXRefProperties (const QString &str) const {return project_ -> defaultXRefProperties(str);} static bool clipboardMayContainDiagram(); bool setNumerotation (NumerotationType, NumerotationContext); NumerotationContext getNumerotation (NumerotationType) const; @@ -213,7 +213,7 @@ class Diagram : public QGraphicsScene { /// Signal emitted when users wish to edit an element from the diagram void editElementRequired(const ElementsLocation &); void reportPropertiesChanged(QString); - void XRefPropertiesChanged(XRefProperties); + void XRefPropertiesChanged(); }; Q_DECLARE_METATYPE(Diagram *) diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index 211166cd3..e23f4ac34 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -262,8 +262,8 @@ void ProjectNewDiagramConfigPage::applyProjectConf() { modified_project = true; } - XRefProperties new_xref_properties = xref_ -> properties(); - if (project_ -> defaultXrefProperties() != new_xref_properties) { + QHash new_xref_properties = xref_ -> properties(); + if (project_ -> defaultXRefProperties() != new_xref_properties) { project_ -> setDefaultXRefProperties(new_xref_properties); modified_project = true; } @@ -288,7 +288,7 @@ void ProjectNewDiagramConfigPage::initWidgets() { conductor_ = new ConductorPropertiesWidget(); conductor_ -> setContentsMargins(0, 0, 0, 0); report_ = new ReportPropertieWidget("_"); - xref_ = new XRefPropertiesWidget(XRefProperties()); + xref_ = new XRefPropertiesWidget(); } /** @@ -322,7 +322,7 @@ void ProjectNewDiagramConfigPage::readValuesFromProject() { conductor_ -> setConductorProperties (project_ -> defaultConductorProperties()); titleblock_ -> setTitleBlockProperties (project_ -> defaultTitleBlockProperties()); report_ -> setReportProperties (project_ -> defaultReportProperties()); - xref_ -> setProperties (project_ -> defaultXrefProperties()); + xref_ -> setProperties (project_ -> defaultXRefProperties()); } /** diff --git a/sources/properties/xrefproperties.cpp b/sources/properties/xrefproperties.cpp index c4bb70924..5df154497 100644 --- a/sources/properties/xrefproperties.cpp +++ b/sources/properties/xrefproperties.cpp @@ -22,7 +22,11 @@ * Default Constructor */ XRefProperties::XRefProperties() -{} +{ + m_show_power_ctc = true; + m_display = Cross; + m_snap_to = Bottom; +} /** * @brief XRefProperties::toSettings diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 4072ceb1d..25bba28d5 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -2076,8 +2076,15 @@ QString QETDiagramEditor::defaultReportProperties() { * @brief QETDiagramEditor::defaultXRefProperties * @return the default setting for Xref */ -XRefProperties QETDiagramEditor::defaultXRefProperties() { - XRefProperties properties; - properties.fromSettings(QETApp::settings(), "diagrameditor/defaultxref"); - return properties; +QHash QETDiagramEditor::defaultXRefProperties() { + QHash hash; + QStringList keys; + keys << "coil" << "protection"; + foreach (QString key, keys) { + XRefProperties properties; + QString str("diagrameditor/defaultxref"); + properties.fromSettings(QETApp::settings(), str += key); + hash.insert(key, properties); + } + return hash; } diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 9139c9c15..6e6995fef 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -59,13 +59,13 @@ class QETDiagramEditor : public QETMainWindow { QList projectViews() const; QList editedFiles() const; ProjectView *viewForFile(const QString &) const; - static TitleBlockProperties defaultTitleBlockProperties(); - static BorderProperties defaultBorderProperties(); - static ConductorProperties defaultConductorProperties(); - static ExportProperties defaultExportProperties(); - static ExportProperties defaultPrintProperties(); - static QString defaultReportProperties(); - static XRefProperties defaultXRefProperties(); + static TitleBlockProperties defaultTitleBlockProperties(); + static BorderProperties defaultBorderProperties(); + static ConductorProperties defaultConductorProperties(); + static ExportProperties defaultExportProperties(); + static ExportProperties defaultPrintProperties(); + static QString defaultReportProperties(); + static QHash defaultXRefProperties(); protected: void actions(); diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 502c8c0d1..67448a3d1 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -35,10 +35,10 @@ CrossRefItem::CrossRefItem(Element *elmt) : QGraphicsObject(elmt), m_element (elmt) { - m_properties = elmt->diagram()->defaultXRefProperties(); + m_properties = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString()); connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); connect(elmt->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); - connect(elmt->diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(setProperties(XRefProperties))); + connect(elmt->diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties())); //set specific behavior related to the parent item. if(m_properties.snapTo() == XRefProperties::Bottom) { @@ -61,7 +61,7 @@ CrossRefItem::~CrossRefItem() { } disconnect(m_element, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel())); disconnect(m_element->diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel())); - disconnect(m_element->diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(setProperties(XRefProperties))); + disconnect(m_element->diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateProperties())); } /** @@ -119,7 +119,13 @@ void CrossRefItem::allElementsPositionText(QString &no_str, QString &nc_str, con } } -void CrossRefItem::setProperties(const XRefProperties &xrp) { +/** + * @brief CrossRefItem::updateProperties + * update the curent properties + */ +void CrossRefItem::updateProperties() { + XRefProperties xrp = m_element->diagram()->defaultXRefProperties(m_element->kindInformations()["type"].toString()); + if (m_properties != xrp) { if (m_properties.snapTo() != xrp.snapTo()) { if (xrp.snapTo() == XRefProperties::Bottom) { diff --git a/sources/qetgraphicsitem/crossrefitem.h b/sources/qetgraphicsitem/crossrefitem.h index caf9e2c65..def3078ac 100644 --- a/sources/qetgraphicsitem/crossrefitem.h +++ b/sources/qetgraphicsitem/crossrefitem.h @@ -61,7 +61,7 @@ class CrossRefItem : public QGraphicsObject signals: public slots: - void setProperties (const XRefProperties &xrp); + void updateProperties (); void updateLabel (); void autoPos (); diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index b8ef9061b..5dc92d7a6 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -451,13 +451,14 @@ void QETProject::setDefaultReportProperties(const QString &properties) { emit reportPropertiesChanged(properties); } -XRefProperties QETProject::defaultXrefProperties() const{ - return m_default_xref_properties; +void QETProject::setDefaultXRefProperties(const QString type, const XRefProperties &properties) { + m_default_xref_properties.insert(type, properties); + emit XRefPropertiesChanged(); } -void QETProject::setDefaultXRefProperties(const XRefProperties &properties) { - m_default_xref_properties = properties; - emit XRefPropertiesChanged(properties); +void QETProject::setDefaultXRefProperties(QHash hash) { + m_default_xref_properties.swap(hash); + emit XRefPropertiesChanged(); } /** @@ -1179,7 +1180,7 @@ void QETProject::readDefaultPropertiesXml() { conductors_elmt = child_elmt; } else if (child_elmt.tagName() == "report") { report_elmt = child_elmt; - } else if (child_elmt.tagName() == "xref") { + } else if (child_elmt.tagName() == "xrefs") { xref_elmt = child_elmt; } } @@ -1189,7 +1190,13 @@ void QETProject::readDefaultPropertiesXml() { if (!titleblock_elmt.isNull()) default_titleblock_properties_.fromXml(titleblock_elmt); if (!conductors_elmt.isNull()) default_conductor_properties_.fromXml(conductors_elmt); if (!report_elmt.isNull()) setDefaultReportProperties(report_elmt.attribute("label")); - if (!xref_elmt.isNull()) m_default_xref_properties.fromXml(xref_elmt); + if (!xref_elmt.isNull()) { + foreach(QDomElement elmt, QET::findInDomElement(xref_elmt, "xref")) { + XRefProperties xrp; + xrp.fromXml(elmt); + m_default_xref_properties.insert(elmt.attribute("type"), xrp); + } + } } @@ -1227,9 +1234,15 @@ void QETProject::writeDefaultPropertiesXml(QDomElement &xml_element) { xml_element.appendChild(report_elmt); // export default XRef properties - QDomElement xref_elmt = xml_document.createElement("xref"); - defaultXrefProperties().toXml(xref_elmt); - xml_element.appendChild(xref_elmt); + QDomElement xrefs_elmt = xml_document.createElement("xrefs"); + foreach (QString key, defaultXRefProperties().keys()) { + QDomElement xref_elmt = xml_document.createElement("xref"); + xref_elmt.setAttribute("type", key); + defaultXRefProperties()[key].toXml(xref_elmt); + xrefs_elmt.appendChild(xref_elmt); + } + + xml_element.appendChild(xrefs_elmt); } /** diff --git a/sources/qetproject.h b/sources/qetproject.h index 040712410..b9d204213 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -92,6 +92,8 @@ class QETProject : public QObject { QDomElement getTemplateXmlDescriptionByName(const QString &); bool setTemplateXmlDescription(const QString &, const QDomElement &); void removeTemplateByName(const QString &); + + ///DEFAULT PROPERTIES BorderProperties defaultBorderProperties() const; void setDefaultBorderProperties(const BorderProperties &); TitleBlockProperties defaultTitleBlockProperties() const; @@ -100,8 +102,11 @@ class QETProject : public QObject { void setDefaultConductorProperties(const ConductorProperties &); QString defaultReportProperties() const; void setDefaultReportProperties (const QString &properties); - XRefProperties defaultXrefProperties () const; - void setDefaultXRefProperties(const XRefProperties &properties); + XRefProperties defaultXRefProperties (const QString &type) const {return m_default_xref_properties[type];} + QHash defaultXRefProperties() const {return m_default_xref_properties;} + void setDefaultXRefProperties(const QString type, const XRefProperties &properties); + void setDefaultXRefProperties(QHash hash); + QDomDocument toXml(); bool close(); QETResult write(); @@ -147,7 +152,7 @@ class QETProject : public QObject { void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &); void readOnlyChanged(QETProject *, bool); void reportPropertiesChanged(QString); - void XRefPropertiesChanged (XRefProperties); + void XRefPropertiesChanged (); private slots: void updateDiagramsFolioData(); @@ -206,7 +211,7 @@ class QETProject : public QObject { /// Default report properties QString default_report_properties_; /// Default xref properties - XRefProperties m_default_xref_properties; + QHash m_default_xref_properties; /// Embedded title block templates collection TitleBlockTemplatesProjectCollection titleblocks_; /// project-wide variables that will be made available to child diagrams diff --git a/sources/ui/xrefpropertieswidget.cpp b/sources/ui/xrefpropertieswidget.cpp index 42a1269f5..da77c030c 100644 --- a/sources/ui/xrefpropertieswidget.cpp +++ b/sources/ui/xrefpropertieswidget.cpp @@ -25,16 +25,15 @@ * @param properties: properties to use * @param parent: parent widget */ -XRefPropertiesWidget::XRefPropertiesWidget(XRefProperties properties, QWidget *parent) : +XRefPropertiesWidget::XRefPropertiesWidget(QHash properties, QWidget *parent) : QWidget(parent), ui(new Ui::XRefPropertiesWidget), m_properties(properties) { ui->setupUi(this); - - ui->m_snap_to_cb->addItem(tr("En bas de page"), "bottom"); - ui->m_snap_to_cb->addItem(tr("Sous le label de l'\351l\351ment"), "label"); - connect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool))); + buildUi(); + connect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool))); + connect(ui->m_type_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged())); updateDisplay(); } @@ -44,7 +43,8 @@ XRefPropertiesWidget::XRefPropertiesWidget(XRefProperties properties, QWidget *p */ XRefPropertiesWidget::~XRefPropertiesWidget() { - disconnect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool))); + disconnect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool))); + disconnect(ui->m_type_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged())); delete ui; } @@ -53,25 +53,18 @@ XRefPropertiesWidget::~XRefPropertiesWidget() * set new properties for this widget * @param properties */ -void XRefPropertiesWidget::setProperties(const XRefProperties &properties) { +void XRefPropertiesWidget::setProperties(const QHash &properties) { m_properties = properties; updateDisplay(); + m_previous_type_index = ui->m_type_cb->currentIndex(); } /** * @brief XRefPropertiesWidget::properties - * @return the propertie edited by this widget + * @return the properties edited by this widget */ -XRefProperties XRefPropertiesWidget::properties() { - if (ui->m_display_has_cross_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Cross); - else if (ui->m_display_has_contacts_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Contacts); - if (ui->m_snap_to_cb->itemData(ui->m_snap_to_cb->currentIndex()).toString() == "bottom") - m_properties.setSnapTo(XRefProperties::Bottom); - else m_properties.setSnapTo(XRefProperties::Label); - m_properties.setShowPowerContac(ui->m_show_power_cb->isChecked()); - m_properties.setPrefix("power", ui->m_power_prefix_le->text()); - m_properties.setPrefix("delay", ui->m_delay_prefix_le->text()); - +QHash XRefPropertiesWidget::properties(){ + saveProperties(ui->m_type_cb->currentIndex()); return m_properties; } @@ -81,21 +74,57 @@ XRefProperties XRefPropertiesWidget::properties() { * @param ro */ void XRefPropertiesWidget::setReadOnly(bool ro) { - ui->m_display_has_cross_rb->setDisabled(ro); - ui->m_display_has_contacts_rb->setDisabled(ro); + ui->m_type_cb->setDisabled(ro); + ui->m_display_gb->setDisabled(ro); + ui->m_cross_properties_gb->setDisabled(ro); - if (m_properties.displayHas() != XRefProperties::Cross) + if (!ro && ui->m_display_has_contacts_rb->isChecked()) { ui->m_cross_properties_gb->setDisabled(true); - else - ui->m_cross_properties_gb->setDisabled(ro); + } +} + +/** + * @brief XRefPropertiesWidget::buildUi + * Build some widget of this ui. + */ +void XRefPropertiesWidget::buildUi() { + ui -> m_type_cb -> addItem(tr("Bobine"), "coil"); + ui -> m_type_cb -> addItem(tr("Organe de protection"), "protection"); + ui -> m_snap_to_cb -> addItem(tr("En bas de page"), "bottom"); + ui -> m_snap_to_cb -> addItem(tr("Sous le label de l'\351l\351ment"), "label"); + m_previous_type_index = ui -> m_type_cb -> currentIndex(); +} + +/** + * @brief XRefPropertiesWidget::saveProperties + * Save the properties of the type define at @index of the combo box m_type_cb + * @param index + */ +void XRefPropertiesWidget::saveProperties(int index) { + QString type = ui->m_type_cb->itemData(index).toString(); + XRefProperties xrp = m_properties[type]; + + if (ui->m_display_has_cross_rb->isChecked()) xrp.setDisplayHas(XRefProperties::Cross); + else if (ui->m_display_has_contacts_rb->isChecked()) xrp.setDisplayHas(XRefProperties::Contacts); + if (ui->m_snap_to_cb->itemData(ui->m_snap_to_cb->currentIndex()).toString() == "bottom") + xrp.setSnapTo(XRefProperties::Bottom); + else xrp.setSnapTo(XRefProperties::Label); + xrp.setShowPowerContac(ui->m_show_power_cb->isChecked()); + xrp.setPrefix("power", ui->m_power_prefix_le->text()); + xrp.setPrefix("delay", ui->m_delay_prefix_le->text()); + + m_properties.insert(type, xrp); } /** * @brief XRefPropertiesWidget::updateDisplay - * Update display with the content of the properties + * Update display with the curent displayed type. */ void XRefPropertiesWidget::updateDisplay() { - XRefProperties::DisplayHas dh = m_properties.displayHas(); + QString type = ui->m_type_cb->itemData(ui->m_type_cb->currentIndex()).toString(); + XRefProperties xrp = m_properties[type]; + + XRefProperties::DisplayHas dh = xrp.displayHas(); if (dh == XRefProperties::Cross) { ui->m_display_has_cross_rb->setChecked(true); } @@ -103,11 +132,26 @@ void XRefPropertiesWidget::updateDisplay() { ui->m_display_has_contacts_rb->setChecked(true); } - if (m_properties.snapTo() == XRefProperties::Bottom) + if (xrp.snapTo() == XRefProperties::Bottom) ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("bottom")); else ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("label")); - ui->m_show_power_cb->setChecked(m_properties.showPowerContact()); - ui->m_power_prefix_le->setText(m_properties.prefix("power")); - ui->m_delay_prefix_le->setText(m_properties.prefix("delay")); + ui->m_show_power_cb->setChecked(xrp.showPowerContact()); + ui->m_power_prefix_le->setText(xrp.prefix("power")); + ui->m_delay_prefix_le->setText(xrp.prefix("delay")); ui->m_cross_properties_gb->setDisabled(!ui->m_display_has_cross_rb->isChecked()); } + +/** + * @brief XRefPropertiesWidget::typeChanged + * manage the save of the current properties, + * when the combo box of type change. + */ +void XRefPropertiesWidget::typeChanged() { + //save the properties of the previous xref type + saveProperties(m_previous_type_index); + //update display with the current xref type + updateDisplay(); + //everything is done + //previous index is now the current index + m_previous_type_index = ui->m_type_cb->currentIndex(); +} diff --git a/sources/ui/xrefpropertieswidget.h b/sources/ui/xrefpropertieswidget.h index 8bdc776dc..893f8017a 100644 --- a/sources/ui/xrefpropertieswidget.h +++ b/sources/ui/xrefpropertieswidget.h @@ -34,20 +34,27 @@ class XRefPropertiesWidget : public QWidget Q_OBJECT public: - XRefPropertiesWidget(XRefProperties properties = XRefProperties(), QWidget *parent = 0); + XRefPropertiesWidget(QHash properties = QHash (), QWidget *parent = 0); ~XRefPropertiesWidget(); - void setProperties (const XRefProperties &properties); - XRefProperties properties(); + void setProperties (const QHash &properties); + QHash properties(); void setReadOnly (bool = true); private: + void buildUi(); + void saveProperties(int index); + + private slots: void updateDisplay(); + void typeChanged(); + private: Ui::XRefPropertiesWidget *ui; - XRefProperties m_properties; + QHash m_properties; + int m_previous_type_index; }; #endif // XREFPROPERTIESWIDGET_H diff --git a/sources/ui/xrefpropertieswidget.ui b/sources/ui/xrefpropertieswidget.ui index 3545ca849..09fefb571 100644 --- a/sources/ui/xrefpropertieswidget.ui +++ b/sources/ui/xrefpropertieswidget.ui @@ -6,14 +6,28 @@ 0 0 - 400 - 300 + 484 + 470 Form + + + + + + Type : + + + + + + + +