QElectroTech  0.70
xrefpropertieswidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "xrefpropertieswidget.h"
19 
20 #include <utility>
21 #include "ui_xrefpropertieswidget.h"
22 #include "qdebug.h"
23 
30 XRefPropertiesWidget::XRefPropertiesWidget(QHash <QString, XRefProperties> properties, QWidget *parent) :
31  QWidget(parent),
32  ui(new Ui::XRefPropertiesWidget),
33  m_properties(std::move(properties))
34 {
35  ui->setupUi(this);
36  buildUi();
37  connect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool)));
38  connect(ui->m_type_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged()));
39  connect(ui->m_snap_to_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(enableOffsetSB(int)));
40  updateDisplay();
41 }
42 
48 {
49  disconnect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_cross_properties_gb, SLOT(setEnabled(bool)));
50  disconnect(ui->m_type_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged()));
51  disconnect(ui->m_snap_to_cb, SIGNAL(currentIndexChanged(int)), this, SLOT(enableOffsetSB(int)));
52  delete ui;
53 }
54 
60 void XRefPropertiesWidget::setProperties(const QHash <QString, XRefProperties> &properties) {
62  updateDisplay();
63  m_previous_type_index = ui->m_type_cb->currentIndex();
64 }
65 
70 QHash <QString, XRefProperties> XRefPropertiesWidget::properties(){
71  saveProperties(ui->m_type_cb->currentIndex());
72  return m_properties;
73 }
74 
81  ui->m_type_cb->setDisabled(ro);
82  ui->m_display_gb->setDisabled(ro);
83  ui->m_cross_properties_gb->setDisabled(ro);
84 
85  if (!ro && ui->m_display_has_contacts_rb->isChecked()) {
86  ui->m_cross_properties_gb->setDisabled(true);
87  }
88 }
89 
95 {
96  ui -> m_type_cb -> addItem(tr("Bobine"), "coil");
97  ui -> m_type_cb -> addItem(tr("Organe de protection"), "protection");
98  ui -> m_type_cb -> addItem(tr("Commutateur / bouton"), "commutator");
99 
100  ui -> m_snap_to_cb -> addItem(tr("En bas de page"), "bottom");
101  ui -> m_snap_to_cb -> addItem(tr("Sous le label de l'élément"), "label");
102 
103  m_previous_type_index = ui -> m_type_cb -> currentIndex();
104 }
105 
112  QString type = ui->m_type_cb->itemData(index).toString();
113  XRefProperties xrp = m_properties[type];
114 
115  if (ui->m_display_has_cross_rb->isChecked()) xrp.setDisplayHas(XRefProperties::Cross);
116  else if (ui->m_display_has_contacts_rb->isChecked()) xrp.setDisplayHas(XRefProperties::Contacts);
117  if (ui->m_snap_to_cb->itemData(ui->m_snap_to_cb->currentIndex()).toString() == "bottom")
120  xrp.setShowPowerContac(ui->m_show_power_cb->isChecked());
121  xrp.setPrefix("power", ui->m_power_prefix_le->text());
122  xrp.setPrefix("delay", ui->m_delay_prefix_le->text());
123  xrp.setPrefix("switch", ui->m_switch_prefix_le->text());
124  xrp.setMasterLabel(ui->m_master_le->text());
125  xrp.setSlaveLabel(ui->m_slave_le->text());
126  xrp.setOffset(ui->m_offset_sb->value());
127 
128  m_properties.insert(type, xrp);
129 }
130 
136  QString type = ui->m_type_cb->itemData(ui->m_type_cb->currentIndex()).toString();
137  XRefProperties xrp = m_properties[type];
138 
140  if (dh == XRefProperties::Cross) {
141  ui->m_display_has_cross_rb->setChecked(true);
142  }
143  else if (dh == XRefProperties::Contacts) {
144  ui->m_display_has_contacts_rb->setChecked(true);
145  }
146 
147  QString master = xrp.masterLabel();
148  ui->m_master_le->setText(master);
149 
150  QString slave = xrp.slaveLabel();
151  ui->m_slave_le->setText(slave);
152 
153  int offset = xrp.offset();
154  ui->m_offset_sb->setValue(offset);
155 
156  if (xrp.snapTo() == XRefProperties::Bottom){
157  ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("bottom"));
158  ui->m_offset_sb->setEnabled(true);
159  }
160  else {
161  ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("label"));
162  ui->m_offset_sb->setEnabled(false);
163  }
164  ui->m_show_power_cb->setChecked(xrp.showPowerContact());
165  ui->m_power_prefix_le-> setText(xrp.prefix("power"));
166  ui->m_delay_prefix_le-> setText(xrp.prefix("delay"));
167  ui->m_switch_prefix_le->setText(xrp.prefix("switch"));
168  ui->m_cross_properties_gb->setDisabled(!ui->m_display_has_cross_rb->isChecked());
169 }
170 
177  //save the properties of the previous xref type
179  //update display with the current xref type
180  updateDisplay();
181  //everything is done
182  //previous index is now the current index
183  m_previous_type_index = ui->m_type_cb->currentIndex();
184 }
185 
191  if (i)
192  ui->m_offset_sb->setEnabled(false);
193  else
194  ui->m_offset_sb->setEnabled(true);
195 }
void updateDisplay()
XRefPropertiesWidget::updateDisplay Update display with the curent displayed type.
QHash< QString, XRefProperties > properties()
XRefPropertiesWidget::properties.
void setMasterLabel(const QString master)
QString prefix(const QString &key) const
The XRefProperties class this class store properties used by XrefItem.
DisplayHas displayHas() const
void setSlaveLabel(const QString slave)
void setProperties(const QHash< QString, XRefProperties > &properties)
XRefPropertiesWidget::setProperties set new properties for this widget.
void saveProperties(int index)
XRefPropertiesWidget::saveProperties Save the properties of the type define at of the combo box m_ty...
void setSnapTo(const SnapTo st)
QString slaveLabel() const
The XRefPropertiesWidget class This class provide a widget to edit the XRefProperties.
void enableOffsetSB(int i)
XRefPropertiesWidget::enableOffsetSB Enable Offset SB only if Snap to Footer is selected.
bool showPowerContact() const
void setReadOnly(bool=true)
XRefPropertiesWidget::setReadOnly Set all of this widget disable if true.
XRefPropertiesWidget(QHash< QString, XRefProperties > properties=QHash< QString, XRefProperties >(), QWidget *parent=nullptr)
XRefPropertiesWidget::XRefPropertiesWidget Default constructor.
void typeChanged()
XRefPropertiesWidget::typeChanged manage the save of the current properties, when the combo box of ty...
void buildUi()
XRefPropertiesWidget::buildUi Build some widget of this ui.
QIcon tr
Definition: qeticons.cpp:204
~XRefPropertiesWidget() override
XRefPropertiesWidget::~XRefPropertiesWidget Default destructor.
QString masterLabel() const
int offset() const
SnapTo snapTo() const
void setPrefix(const QString &key, const QString &value)
QHash< QString, XRefProperties > m_properties
QIcon ro
Definition: qeticons.cpp:199
void setDisplayHas(const DisplayHas dh)
void setShowPowerContac(const bool a)
Ui::XRefPropertiesWidget * ui
void setOffset(const int offset)