QElectroTech  0.70
elementpropertieseditorwidget.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 */
19 #include "ui_elementpropertieseditorwidget.h"
20 #include "qetapp.h"
21 
22 #include <QItemDelegate>
23 
29 class EditorDelegate : public QItemDelegate
30 {
31  public:
32  EditorDelegate(QObject *parent) :
33  QItemDelegate(parent)
34  {}
35 
36  QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
37  {
38  if(index.column() == 1)
39  {
40  return QItemDelegate::createEditor(parent, option, index);
41  }
42  return nullptr;
43  }
44 };
45 
54 ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &kind_info, DiagramContext &elmt_info, QWidget *parent) :
55  QDialog(parent),
57  m_basic_type(basic_type),
58  m_kind_info (kind_info),
59  m_elmt_info (elmt_info)
60 {
61  ui->setupUi(this);
64 }
65 
71 {
72  delete ui;
73 }
74 
80 {
81  ui->m_base_type_cb->setCurrentIndex(ui->m_base_type_cb->findData(QVariant(m_basic_type)));
82 
83  if (m_basic_type == "slave")
84  {
85  ui->m_state_cb->setCurrentIndex(ui->m_state_cb->findData(m_kind_info["state"].toString()));
86  ui->m_type_cb->setCurrentIndex (ui->m_type_cb->findData(m_kind_info["type"].toString()));
87  ui->m_number_ctc->setValue(m_kind_info["number"].toInt());
88  }
89  else if (m_basic_type == "master") {
90  ui->m_master_type_cb->setCurrentIndex(ui->m_master_type_cb->findData (m_kind_info["type"]));
91  }
92 
93  on_m_base_type_cb_currentIndexChanged(ui->m_base_type_cb->currentIndex());
94 }
95 
100 {
101  // Type combo box
102  ui->m_base_type_cb->addItem (tr("Simple"), QVariant("simple"));
103  ui->m_base_type_cb->addItem (tr("Maître"), QVariant("master"));
104  ui->m_base_type_cb->addItem (tr("Esclave"), QVariant("slave"));
105  ui->m_base_type_cb->addItem (tr("Renvoi de folio suivant"), QVariant("next_report"));
106  ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"), QVariant("previous_report"));
107  ui->m_base_type_cb->addItem (tr("Bornier"), QVariant("terminal"));
108 
109  // Slave option
110  ui->m_state_cb->addItem(tr("Normalement ouvert"),QVariant("NO"));
111  ui->m_state_cb->addItem(tr("Normalement fermé"), QVariant("NC"));
112  ui->m_state_cb->addItem(tr("Inverseur"), QVariant("SW"));
113  ui->m_type_cb->addItem(tr("Simple"), QVariant("simple"));
114  ui->m_type_cb->addItem(tr("Puissance"), QVariant("power"));
115  ui->m_type_cb->addItem(tr("Temporisé travail"), QVariant("delayOn"));
116  ui->m_type_cb->addItem(tr("Temporisé repos"), QVariant("delayOff"));
117  ui->m_type_cb->addItem(tr("Temporisé travail & repos"), QVariant("delayOnOff"));
118 
119  //Master option
120  ui->m_master_type_cb->addItem(tr("Bobine"), QVariant("coil"));
121  ui->m_master_type_cb->addItem(tr("Organe de protection"), QVariant("protection"));
122  ui->m_master_type_cb->addItem(tr("Commutateur / bouton"), QVariant("commutator"));
123 
124  //Disable the edition of the first column of the information tree
125  //by this little workaround
126  ui->m_tree->setItemDelegate(new EditorDelegate(this));
127  ui->m_tree->header()->resizeSection(0, 150);
128  populateTree();
129 }
130 
132 {
133  QString type = ui->m_base_type_cb->itemData(ui->m_base_type_cb->currentIndex()).toString();
134 
135  if (type == "master")
136  ui->m_tree->setEnabled(true);
137  else if (type == "slave")
138  ui->m_tree->setDisabled(true);
139  else if (type == "simple")
140  ui->m_tree->setEnabled(true);
141  else if (type == "next_report")
142  ui->m_tree->setDisabled(true);
143  else if (type == "previous_report")
144  ui->m_tree->setDisabled(true);
145  else if (type == "terminal")
146  ui->m_tree->setEnabled(true);
147 }
148 
154 {
155  QStringList keys{"label", "plant", "comment", "description", "designation", "manufacturer", "manufacturer-reference", "supplier", "quantity", "unity", "machine-manufacturer-reference"};
156 
157  for(const QString& key : keys)
158  {
159  QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree);
160  qtwi->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
161  qtwi->setData(0, Qt::DisplayRole, QETApp::elementTranslatedInfoKey(key));
162  qtwi->setData(0, Qt::UserRole, key);
163  qtwi->setText(1, m_elmt_info.value(key).toString());
164  }
165 }
166 
172 {
173  m_basic_type = ui -> m_base_type_cb -> itemData(ui -> m_base_type_cb -> currentIndex()).toString();
174  if (m_basic_type == "slave") {
175  m_kind_info.addValue("state", ui -> m_state_cb -> itemData(ui -> m_state_cb -> currentIndex()));
176  m_kind_info.addValue("type", ui -> m_type_cb -> itemData(ui -> m_type_cb -> currentIndex()));
177  m_kind_info.addValue("number", QVariant(ui -> m_number_ctc -> value()));
178  }
179  else if(m_basic_type == "master") {
180  m_kind_info.addValue("type", ui -> m_master_type_cb -> itemData(ui -> m_master_type_cb -> currentIndex()));
181  }
182 
183  for (QTreeWidgetItem *qtwi : ui->m_tree->invisibleRootItem()->takeChildren())
184  {
185  QString txt = qtwi->text(1);
186  //remove line feed and carriage return
187  txt.remove("\r");
188  txt.remove("\n");
189 
190  m_elmt_info.addValue(qtwi->data(0, Qt::UserRole).toString(), txt);
191  }
192 
193  this->close();
194 }
195 
201 {
202  bool slave = false , master = false;
203 
204  if (ui->m_base_type_cb->itemData(index).toString() == "slave") slave = true;
205  else if (ui->m_base_type_cb->itemData(index).toString() == "master") master = true;
206 
207  ui->m_slave_gb->setVisible(slave);
208  ui->m_master_gb->setVisible(master);
209 
210  updateTree();
211 }
Ui::ElementPropertiesEditorWidget * ui
void populateTree()
ElementPropertiesEditorWidget::populateTree Create QTreeWidgetItem of the tree widget and populate it...
void on_m_base_type_cb_currentIndexChanged(int index)
ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged.
QVariant value(const QString &key) const
bool addValue(const QString &, const QVariant &, bool show=true)
The ElementPropertiesEditorWidget class This class provide a dialog for edit various property of elem...
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void on_m_buttonBox_accepted()
ElementPropertiesEditorWidget::on_m_buttonBox_accepted Action on button accepted : the new informatio...
ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &kind_info, DiagramContext &elmt_info, QWidget *parent=nullptr)
ElementPropertiesEditorWidget::ElementPropertiesEditorWidget Default constructor. ...
QIcon tr
Definition: qeticons.cpp:204
The EditorDelegate class This delegate is only use for disable the edition of the first column of the...
void upDateInterface()
ElementPropertiesEditorWidget::upDateInterface Update the interface with the curent value...
void setUpInterface()
ElementPropertiesEditorWidget::setUpInterface.
static QString elementTranslatedInfoKey(const QString &)
ElementsProperties::translatedInfo Return the translated information key given by If don&#39;t match...
Definition: qetapp.cpp:321
~ElementPropertiesEditorWidget() override
ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget Default destructor. ...