Element editor : element informations (manufacturer, reference etc...) can be created directly from the element editor. For that go to the widget "Element Property"

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5057 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-10-01 15:25:34 +00:00
parent d5699f6b67
commit bb39413992
9 changed files with 350 additions and 208 deletions

View File

@@ -17,23 +17,51 @@
*/
#include "elementpropertieseditorwidget.h"
#include "ui_elementpropertieseditorwidget.h"
#include "qetapp.h"
#include <QItemDelegate>
/**
* @brief The EditorDelegate class
* This delegate is only use for disable the edition of the first
* column of the information tree widget
*/
class EditorDelegate : public QItemDelegate
{
public:
EditorDelegate(QObject *parent) :
QItemDelegate(parent)
{}
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if(index.column() == 1)
{
return QItemDelegate::createEditor(parent, option, index);
}
return nullptr;
}
};
/**
* @brief ElementPropertiesEditorWidget::ElementPropertiesEditorWidget
* Default constructor
* @param basic_type : QString of the drawed element
* @param dc : DiagramContext to store kindInfo of drawed element
* @param kind_info : DiagramContext to store kindInfo of drawed element
* @param elmt_info : the information of element (label, manufacturer etc...]
* @param parent : parent widget
*/
ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &dc, 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),
m_dc (dc)
m_kind_info (kind_info),
m_elmt_info (elmt_info)
{
ui->setupUi(this);
setUpInterface();
upDateInterface();
qDebug() << "const";
}
/**
@@ -49,17 +77,18 @@ ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget()
* @brief ElementPropertiesEditorWidget::upDateInterface
* Update the interface with the curent value
*/
void ElementPropertiesEditorWidget::upDateInterface() {
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_dc["state"].toString()));
ui -> m_type_cb -> setCurrentIndex (ui -> m_type_cb -> findData (m_dc["type"].toString()));
ui -> m_number_ctc -> setValue (m_dc["number"].toInt());
void ElementPropertiesEditorWidget::upDateInterface()
{
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_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_dc["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());
@@ -68,28 +97,71 @@ void ElementPropertiesEditorWidget::upDateInterface() {
/**
* @brief ElementPropertiesEditorWidget::setUpInterface
*/
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"));
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"));
// 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_type_cb -> addItem(tr("Temporisé travail"), QVariant("delayOn"));
ui -> m_type_cb -> addItem(tr("Temporisé repos"), QVariant("delayOff"));
// 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_type_cb->addItem(tr("Temporisé travail"), QVariant("delayOn"));
ui->m_type_cb->addItem(tr("Temporisé repos"), QVariant("delayOff"));
//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
ui->m_tree->setItemDelegate(new EditorDelegate(this));
ui->m_tree->header()->resizeSection(0, 150);
populateTree();
}
void ElementPropertiesEditorWidget::updateTree()
{
QString type = ui->m_base_type_cb->itemData(ui->m_base_type_cb->currentIndex()).toString();
if (type == "master")
ui->m_tree->setEnabled(true);
else if (type == "slave")
ui->m_tree->setDisabled(true);
else if (type == "simple")
ui->m_tree->setEnabled(true);
else if (type == "next_report")
ui->m_tree->setDisabled(true);
else if (type == "previous_report")
ui->m_tree->setDisabled(true);
else if (type == "terminal")
ui->m_tree->setEnabled(true);
}
/**
* @brief ElementPropertiesEditorWidget::populateTree
* Create QTreeWidgetItem of the tree widget and populate it
*/
void ElementPropertiesEditorWidget::populateTree()
{
QStringList keys{"label", "comment", "designation", "manufacturer", "manufacturer-reference", "machine-manufacturer-reference"};
for(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::UserRole, key);
qtwi->setText(1, m_elmt_info.value(key).toString());
}
}
/**
@@ -100,13 +172,18 @@ 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_dc.addValue("state", ui -> m_state_cb -> itemData(ui -> m_state_cb -> currentIndex()));
m_dc.addValue("type", ui -> m_type_cb -> itemData(ui -> m_type_cb -> currentIndex()));
m_dc.addValue("number", QVariant(ui -> m_number_ctc -> value()));
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_dc.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())
if(!qtwi->text(1).isEmpty())
m_elmt_info.addValue(qtwi->data(0, Qt::UserRole).toString(), qtwi->text(1));
this->close();
}
@@ -118,9 +195,11 @@ void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int in
{
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);
ui->m_slave_gb->setVisible(slave);
ui->m_master_gb->setVisible(master);
updateTree();
}

View File

@@ -37,24 +37,27 @@ class ElementPropertiesEditorWidget : public QDialog
//METHODS
public:
explicit ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &dc, QWidget *parent = nullptr);
~ElementPropertiesEditorWidget() override;
explicit ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &kind_info, DiagramContext &elmt_info, QWidget *parent = nullptr);
~ElementPropertiesEditorWidget() override;
void upDateInterface();
void upDateInterface();
private:
void setUpInterface();
void setUpInterface();
void updateTree();
void populateTree();
//SLOTS
//SLOTS
private slots:
void on_m_buttonBox_accepted();
void on_m_base_type_cb_currentIndexChanged(int index);
void on_m_buttonBox_accepted();
void on_m_base_type_cb_currentIndexChanged(int index);
//ATTRIBUTES
//ATTRIBUTES
private:
Ui::ElementPropertiesEditorWidget *ui;
QString &m_basic_type;
DiagramContext &m_dc;
Ui::ElementPropertiesEditorWidget *ui;
QString &m_basic_type;
DiagramContext &m_kind_info,
&m_elmt_info;
};
#endif // ELEMENTPROPERTIESEDITORWIDGET_H

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>450</width>
<height>321</height>
</rect>
</property>
<property name="windowTitle">
@@ -18,98 +18,136 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Type de base :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_base_type_cb"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="m_slave_gb">
<property name="title">
<string>Élément esclave</string>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QSpinBox" name="m_number_ctc">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<widget class="QWidget" name="Type">
<attribute name="title">
<string>Type</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Type de base :</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="m_base_type_cb"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="m_slave_gb">
<property name="title">
<string>Élément esclave</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QSpinBox" name="m_number_ctc">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Nombre de contact représenté</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type de contact</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>État du contact</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="m_state_cb"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_type_cb"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="m_master_gb">
<property name="title">
<string>Élément maître</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Type concret</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_master_type_cb"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="Informations">
<attribute name="title">
<string>Informations</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTreeWidget" name="m_tree">
<attribute name="headerDefaultSectionSize">
<number>150</number>
</attribute>
<column>
<property name="text">
<string>Nombre de contact représenté</string>
<string>Nom</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
</column>
<column>
<property name="text">
<string>Type de contact</string>
<string>Valeurs</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>État du contact</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="m_state_cb"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="m_type_cb"/>
</item>
</layout>
</item>
</layout>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="m_master_gb">
<property name="title">
<string>Élément maître</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Type concret</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_master_type_cb"/>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation">