xref properties widget: user can define the behavior of xref for coil and protection.

They don't work now with official collection, because we must to update the information of element (type coil or protection).
You can test it by creating new master element (dont forget to define the master type, coil or protection).


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3185 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2014-07-03 08:52:14 +00:00
parent 8c5f953897
commit 68e9d33e88
14 changed files with 180 additions and 75 deletions

View File

@ -87,7 +87,12 @@ void NewDiagramPage::applyConf() {
rpw->toSettings(settings, "diagrameditor/defaultreport");
// default xref properties
xrefpw -> properties().toSettings(settings, "diagrameditor/defaultxref");
QHash <QString, XRefProperties> 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

View File

@ -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()));
}
}

View File

@ -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 *)

View File

@ -262,8 +262,8 @@ void ProjectNewDiagramConfigPage::applyProjectConf() {
modified_project = true;
}
XRefProperties new_xref_properties = xref_ -> properties();
if (project_ -> defaultXrefProperties() != new_xref_properties) {
QHash<QString, XRefProperties> 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());
}
/**

View File

@ -22,7 +22,11 @@
* Default Constructor
*/
XRefProperties::XRefProperties()
{}
{
m_show_power_ctc = true;
m_display = Cross;
m_snap_to = Bottom;
}
/**
* @brief XRefProperties::toSettings

View File

@ -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 <QString, XRefProperties> QETDiagramEditor::defaultXRefProperties() {
QHash <QString, XRefProperties> 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;
}

View File

@ -59,13 +59,13 @@ class QETDiagramEditor : public QETMainWindow {
QList<DiagramView *> projectViews() const;
QList<QString> 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<QString, XRefProperties> defaultXRefProperties();
protected:
void actions();

View File

@ -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) {

View File

@ -61,7 +61,7 @@ class CrossRefItem : public QGraphicsObject
signals:
public slots:
void setProperties (const XRefProperties &xrp);
void updateProperties ();
void updateLabel ();
void autoPos ();

View File

@ -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<QString, XRefProperties> 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);
}
/**

View File

@ -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 <QString, XRefProperties> defaultXRefProperties() const {return m_default_xref_properties;}
void setDefaultXRefProperties(const QString type, const XRefProperties &properties);
void setDefaultXRefProperties(QHash <QString, XRefProperties> 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 <QString, XRefProperties> m_default_xref_properties;
/// Embedded title block templates collection
TitleBlockTemplatesProjectCollection titleblocks_;
/// project-wide variables that will be made available to child diagrams

View File

@ -25,16 +25,15 @@
* @param properties: properties to use
* @param parent: parent widget
*/
XRefPropertiesWidget::XRefPropertiesWidget(XRefProperties properties, QWidget *parent) :
XRefPropertiesWidget::XRefPropertiesWidget(QHash <QString, XRefProperties> 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 <QString, XRefProperties> &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 <QString, XRefProperties> 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();
}

View File

@ -34,20 +34,27 @@ class XRefPropertiesWidget : public QWidget
Q_OBJECT
public:
XRefPropertiesWidget(XRefProperties properties = XRefProperties(), QWidget *parent = 0);
XRefPropertiesWidget(QHash <QString, XRefProperties> properties = QHash <QString, XRefProperties>(), QWidget *parent = 0);
~XRefPropertiesWidget();
void setProperties (const XRefProperties &properties);
XRefProperties properties();
void setProperties (const QHash <QString, XRefProperties> &properties);
QHash <QString, XRefProperties> 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 <QString, XRefProperties> m_properties;
int m_previous_type_index;
};
#endif // XREFPROPERTIESWIDGET_H

View File

@ -6,14 +6,28 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>484</width>
<height>470</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Type :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_type_cb"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="m_display_gb">
<property name="title">