Wrap code for better readability

This commit is contained in:
Simon De Backer
2020-08-25 20:32:21 +02:00
parent dfadcb5523
commit 9e4af439ef
4 changed files with 152 additions and 87 deletions

View File

@@ -33,11 +33,15 @@ class EditorDelegate : public QItemDelegate
QItemDelegate(parent)
{}
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
QWidget* createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if(index.column() == 1)
{
return QItemDelegate::createEditor(parent, option, index);
return QItemDelegate::createEditor(parent,
option,
index);
}
return nullptr;
}
@@ -51,7 +55,11 @@ class EditorDelegate : public QItemDelegate
@param elmt_info : the information of element (label, manufacturer etc...]
@param parent : parent widget
*/
ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &kind_info, DiagramContext &elmt_info, QWidget *parent) :
ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(
QString &basic_type,
DiagramContext &kind_info,
DiagramContext &elmt_info,
QWidget *parent) :
QDialog(parent),
ui(new Ui::ElementPropertiesEditorWidget),
m_basic_type(basic_type),
@@ -78,16 +86,24 @@ ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget()
*/
void ElementPropertiesEditorWidget::upDateInterface()
{
ui->m_base_type_cb->setCurrentIndex(ui->m_base_type_cb->findData(QVariant(m_basic_type)));
ui->m_base_type_cb->setCurrentIndex(
ui->m_base_type_cb->findData(
QVariant(m_basic_type)));
if (m_basic_type == "slave")
{
ui->m_state_cb->setCurrentIndex(ui->m_state_cb->findData(m_kind_info["state"].toString()));
ui->m_type_cb->setCurrentIndex (ui->m_type_cb->findData(m_kind_info["type"].toString()));
ui->m_state_cb->setCurrentIndex(
ui->m_state_cb->findData(
m_kind_info["state"].toString()));
ui->m_type_cb->setCurrentIndex (
ui->m_type_cb->findData(
m_kind_info["type"].toString()));
ui->m_number_ctc->setValue(m_kind_info["number"].toInt());
}
else if (m_basic_type == "master") {
ui->m_master_type_cb->setCurrentIndex(ui->m_master_type_cb->findData (m_kind_info["type"]));
ui->m_master_type_cb->setCurrentIndex(
ui->m_master_type_cb->findData (
m_kind_info["type"]));
}
on_m_base_type_cb_currentIndexChanged(ui->m_base_type_cb->currentIndex());
@@ -98,31 +114,36 @@ void ElementPropertiesEditorWidget::upDateInterface()
*/
void ElementPropertiesEditorWidget::setUpInterface()
{
// Type combo box
ui->m_base_type_cb->addItem (tr("Simple"), QVariant("simple"));
ui->m_base_type_cb->addItem (tr("Maître"), QVariant("master"));
ui->m_base_type_cb->addItem (tr("Esclave"), QVariant("slave"));
ui->m_base_type_cb->addItem (tr("Renvoi de folio suivant"), QVariant("next_report"));
ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"), QVariant("previous_report"));
ui->m_base_type_cb->addItem (tr("Bornier"), QVariant("terminal"));
// Type combo box
ui->m_base_type_cb->addItem (tr("Simple"), QVariant("simple"));
ui->m_base_type_cb->addItem (tr("Maître"), QVariant("master"));
ui->m_base_type_cb->addItem (tr("Esclave"), QVariant("slave"));
ui->m_base_type_cb->addItem (tr("Renvoi de folio suivant"),
QVariant("next_report"));
ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"),
QVariant("previous_report"));
ui->m_base_type_cb->addItem (tr("Bornier"), QVariant("terminal"));
// Slave option
// Slave option
ui->m_state_cb->addItem(tr("Normalement ouvert"),QVariant("NO"));
ui->m_state_cb->addItem(tr("Normalement fermé"), QVariant("NC"));
ui->m_state_cb->addItem(tr("Inverseur"), QVariant("SW"));
ui->m_type_cb->addItem(tr("Simple"), QVariant("simple"));
ui->m_type_cb->addItem(tr("Puissance"), QVariant("power"));
ui->m_state_cb->addItem(tr("Inverseur"), QVariant("SW"));
ui->m_type_cb->addItem(tr("Simple"), QVariant("simple"));
ui->m_type_cb->addItem(tr("Puissance"), QVariant("power"));
ui->m_type_cb->addItem(tr("Temporisé travail"), QVariant("delayOn"));
ui->m_type_cb->addItem(tr("Temporisé repos"), QVariant("delayOff"));
ui->m_type_cb->addItem(tr("Temporisé travail & repos"), QVariant("delayOnOff"));
ui->m_type_cb->addItem(tr("Temporisé repos"), QVariant("delayOff"));
ui->m_type_cb->addItem(tr("Temporisé travail & repos"),
QVariant("delayOnOff"));
//Master option
ui->m_master_type_cb->addItem(tr("Bobine"), QVariant("coil"));
ui->m_master_type_cb->addItem(tr("Organe de protection"), QVariant("protection"));
ui->m_master_type_cb->addItem(tr("Commutateur / bouton"), QVariant("commutator"));
//Master option
ui->m_master_type_cb->addItem(tr("Bobine"), QVariant("coil"));
ui->m_master_type_cb->addItem(tr("Organe de protection"),
QVariant("protection"));
ui->m_master_type_cb->addItem(tr("Commutateur / bouton"),
QVariant("commutator"));
//Disable the edition of the first column of the information tree
//by this little workaround
//Disable the edition of the first column of the information tree
//by this little workaround
ui->m_tree->setItemDelegate(new EditorDelegate(this));
ui->m_tree->header()->resizeSection(0, 150);
populateTree();
@@ -130,7 +151,8 @@ void ElementPropertiesEditorWidget::setUpInterface()
void ElementPropertiesEditorWidget::updateTree()
{
QString type = ui->m_base_type_cb->itemData(ui->m_base_type_cb->currentIndex()).toString();
QString type = ui->m_base_type_cb->itemData(
ui->m_base_type_cb->currentIndex()).toString();
if (type == "master")
ui->m_tree->setEnabled(true);
@@ -152,13 +174,17 @@ void ElementPropertiesEditorWidget::updateTree()
*/
void ElementPropertiesEditorWidget::populateTree()
{
QStringList keys{"label", "plant", "comment", "description", "designation", "manufacturer", "manufacturer_reference", "supplier", "quantity", "unity", "machine_manufacturer_reference"};
QStringList keys{"label", "plant", "comment", "description",
"designation", "manufacturer",
"manufacturer_reference", "supplier", "quantity",
"unity", "machine_manufacturer_reference"};
for(const QString& key : keys)
{
QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree);
qtwi->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
qtwi->setData(0, Qt::DisplayRole, QETApp::elementTranslatedInfoKey(key));
qtwi->setData(0, Qt::DisplayRole,
QETApp::elementTranslatedInfoKey(key));
qtwi->setData(0, Qt::UserRole, key);
qtwi->setText(1, m_elmt_info.value(key).toString());
}
@@ -170,24 +196,34 @@ void ElementPropertiesEditorWidget::populateTree()
*/
void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
{
m_basic_type = ui -> m_base_type_cb -> itemData(ui -> m_base_type_cb -> currentIndex()).toString();
if (m_basic_type == "slave") {
m_kind_info.addValue("state", ui -> m_state_cb -> itemData(ui -> m_state_cb -> currentIndex()));
m_kind_info.addValue("type", ui -> m_type_cb -> itemData(ui -> m_type_cb -> currentIndex()));
m_kind_info.addValue("number", QVariant(ui -> m_number_ctc -> value()));
m_basic_type = ui->m_base_type_cb->itemData(
ui->m_base_type_cb->currentIndex()).toString();
if (m_basic_type == "slave")
{
m_kind_info.addValue("state",
ui->m_state_cb->itemData(
ui->m_state_cb->currentIndex()));
m_kind_info.addValue("type",
ui->m_type_cb->itemData(
ui->m_type_cb->currentIndex()));
m_kind_info.addValue("number",
QVariant(ui->m_number_ctc->value()));
}
else if(m_basic_type == "master") {
m_kind_info.addValue("type", ui -> m_master_type_cb -> itemData(ui -> m_master_type_cb -> currentIndex()));
m_kind_info.addValue("type",
ui->m_master_type_cb->itemData(
ui->m_master_type_cb->currentIndex()));
}
for (QTreeWidgetItem *qtwi : ui->m_tree->invisibleRootItem()->takeChildren())
{
QString txt = qtwi->text(1);
//remove line feed and carriage return
//remove line feed and carriage return
txt.remove("\r");
txt.remove("\n");
m_elmt_info.addValue(qtwi->data(0, Qt::UserRole).toString(), txt);
m_elmt_info.addValue(qtwi->data(0, Qt::UserRole).toString(),
txt);
}
this->close();
@@ -197,12 +233,15 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
@brief ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged
@param index : Action when combo-box base type index change
*/
void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int index)
void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(
int index)
{
bool slave = false , master = false;
if (ui->m_base_type_cb->itemData(index).toString() == "slave") slave = true;
else if (ui->m_base_type_cb->itemData(index).toString() == "master") master = true;
if (ui->m_base_type_cb->itemData(index).toString() == "slave")
slave = true;
else if (ui->m_base_type_cb->itemData(index).toString() == "master")
master = true;
ui->m_slave_gb->setVisible(slave);
ui->m_master_gb->setVisible(master);