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

@@ -23,8 +23,8 @@
*/ */
ElementEditionCommand::ElementEditionCommand(ElementScene *scene, ElementView *view, QUndoCommand *parent): ElementEditionCommand::ElementEditionCommand(ElementScene *scene, ElementView *view, QUndoCommand *parent):
QUndoCommand(parent), QUndoCommand(parent),
editor_scene_(scene), m_scene(scene),
editor_view_(view) m_view(view)
{ {
} }
@@ -35,8 +35,8 @@ ElementEditionCommand::ElementEditionCommand(ElementScene *scene, ElementView *v
*/ */
ElementEditionCommand::ElementEditionCommand(const QString &text, ElementScene *scene, ElementView *view, QUndoCommand *parent): ElementEditionCommand::ElementEditionCommand(const QString &text, ElementScene *scene, ElementView *view, QUndoCommand *parent):
QUndoCommand(text, parent), QUndoCommand(text, parent),
editor_scene_(scene), m_scene(scene),
editor_view_(view) m_view(view)
{ {
} }
@@ -50,28 +50,28 @@ ElementEditionCommand::~ElementEditionCommand() {
@return the element editor/scene the command should take place on @return the element editor/scene the command should take place on
*/ */
ElementScene *ElementEditionCommand::elementScene() const { ElementScene *ElementEditionCommand::elementScene() const {
return(editor_scene_); return(m_scene);
} }
/** /**
Define \a scene as the element editor/scene the command should take place Define \a scene as the element editor/scene the command should take place
*/ */
void ElementEditionCommand::setElementScene(ElementScene *scene) { void ElementEditionCommand::setElementScene(ElementScene *scene) {
editor_scene_ = scene; m_scene = scene;
} }
/** /**
@return the view the effect of the command should be rendered on @return the view the effect of the command should be rendered on
*/ */
ElementView *ElementEditionCommand::elementView() const { ElementView *ElementEditionCommand::elementView() const {
return(editor_view_); return(m_view);
} }
/** /**
Define \a view as the view the effect of the command should be rendered on Define \a view as the view the effect of the command should be rendered on
*/ */
void ElementEditionCommand::setElementView(ElementView *view) { void ElementEditionCommand::setElementView(ElementView *view) {
editor_view_ = view; m_view = view;
} }
/*** DeletePartsCommand ***/ /*** DeletePartsCommand ***/
@@ -90,33 +90,33 @@ DeletePartsCommand::DeletePartsCommand(
deleted_parts(parts) deleted_parts(parts)
{ {
foreach(QGraphicsItem *qgi, deleted_parts) { foreach(QGraphicsItem *qgi, deleted_parts) {
editor_scene_ -> qgiManager().manage(qgi); m_scene -> qgiManager().manage(qgi);
} }
} }
/// Destructeur : detruit egalement les parties supprimees /// Destructeur : detruit egalement les parties supprimees
DeletePartsCommand::~DeletePartsCommand() { DeletePartsCommand::~DeletePartsCommand() {
foreach(QGraphicsItem *qgi, deleted_parts) { foreach(QGraphicsItem *qgi, deleted_parts) {
editor_scene_ -> qgiManager().release(qgi); m_scene -> qgiManager().release(qgi);
} }
} }
/// Restaure les parties supprimees /// Restaure les parties supprimees
void DeletePartsCommand::undo() { void DeletePartsCommand::undo() {
editor_scene_ -> blockSignals(true); m_scene -> blockSignals(true);
foreach(QGraphicsItem *qgi, deleted_parts) { foreach(QGraphicsItem *qgi, deleted_parts) {
editor_scene_ -> addItem(qgi); m_scene -> addItem(qgi);
} }
editor_scene_ -> blockSignals(false); m_scene -> blockSignals(false);
} }
/// Supprime les parties /// Supprime les parties
void DeletePartsCommand::redo() { void DeletePartsCommand::redo() {
editor_scene_ -> blockSignals(true); m_scene -> blockSignals(true);
foreach(QGraphicsItem *qgi, deleted_parts) { foreach(QGraphicsItem *qgi, deleted_parts) {
editor_scene_ -> removeItem(qgi); m_scene -> removeItem(qgi);
} }
editor_scene_ -> blockSignals(false); m_scene -> blockSignals(false);
} }
/*** CutPartsCommand ***/ /*** CutPartsCommand ***/
@@ -137,27 +137,27 @@ PastePartsCommand::PastePartsCommand(
first_redo(true) first_redo(true)
{ {
setText(QObject::tr("coller")); setText(QObject::tr("coller"));
editor_scene_ -> qgiManager().manage(content_); m_scene -> qgiManager().manage(content_);
} }
/// Destructeur /// Destructeur
PastePartsCommand::~PastePartsCommand() { PastePartsCommand::~PastePartsCommand() {
editor_scene_ -> qgiManager().release(content_); m_scene -> qgiManager().release(content_);
} }
/// annule le coller /// annule le coller
void PastePartsCommand::undo() { void PastePartsCommand::undo() {
// enleve les parties // enleve les parties
editor_scene_ -> blockSignals(true); m_scene -> blockSignals(true);
foreach(QGraphicsItem *part, content_) { foreach(QGraphicsItem *part, content_) {
editor_scene_ -> removeItem(part); m_scene -> removeItem(part);
} }
editor_scene_ -> blockSignals(false); m_scene -> blockSignals(false);
if (uses_offset) { if (uses_offset) {
editor_view_ -> offset_paste_count_ = old_offset_paste_count_; m_view -> offset_paste_count_ = old_offset_paste_count_;
editor_view_ -> start_top_left_corner_ = old_start_top_left_corner_; m_view -> start_top_left_corner_ = old_start_top_left_corner_;
} }
editor_view_ -> adjustSceneRect(); m_view -> adjustSceneRect();
} }
/// refait le coller /// refait le coller
@@ -165,18 +165,18 @@ void PastePartsCommand::redo() {
if (first_redo) first_redo = false; if (first_redo) first_redo = false;
else { else {
// pose les parties // pose les parties
editor_scene_ -> blockSignals(true); m_scene -> blockSignals(true);
foreach(QGraphicsItem *part, content_) { foreach(QGraphicsItem *part, content_) {
editor_scene_ -> addItem(part); m_scene -> addItem(part);
} }
editor_scene_ -> blockSignals(false); m_scene -> blockSignals(false);
if (uses_offset) { if (uses_offset) {
editor_view_ -> offset_paste_count_ = new_offset_paste_count_; m_view -> offset_paste_count_ = new_offset_paste_count_;
editor_view_ -> start_top_left_corner_ = new_start_top_left_corner_; m_view -> start_top_left_corner_ = new_start_top_left_corner_;
} }
} }
editor_scene_ -> slot_select(content_); m_scene -> slot_select(content_);
editor_view_ -> adjustSceneRect(); m_view -> adjustSceneRect();
} }
/** /**
@@ -271,17 +271,17 @@ AddPartCommand::AddPartCommand(
part(p), part(p),
first_redo(true) first_redo(true)
{ {
editor_scene_ -> qgiManager().manage(part); m_scene -> qgiManager().manage(part);
} }
/// Destructeur /// Destructeur
AddPartCommand::~AddPartCommand() { AddPartCommand::~AddPartCommand() {
editor_scene_ -> qgiManager().release(part); m_scene -> qgiManager().release(part);
} }
/// Annule l'ajout /// Annule l'ajout
void AddPartCommand::undo() { void AddPartCommand::undo() {
editor_scene_ -> removeItem(part); m_scene -> removeItem(part);
} }
/// Refait l'ajout /// Refait l'ajout
@@ -291,15 +291,15 @@ void AddPartCommand::redo() {
if (!part -> zValue()) { if (!part -> zValue()) {
// the added part has no specific zValue already defined, we put it // the added part has no specific zValue already defined, we put it
// above existing items (but still under terminals) // above existing items (but still under terminals)
QList<QGraphicsItem *> existing_items = editor_scene_ -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot); QList<QGraphicsItem *> existing_items = m_scene -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
qreal z = existing_items.count() ? existing_items.last() -> zValue() + 1 : 1; qreal z = existing_items.count() ? existing_items.last() -> zValue() + 1 : 1;
part -> setZValue(z); part -> setZValue(z);
} }
editor_scene_ -> clearSelection(); m_scene -> clearSelection();
first_redo = false; first_redo = false;
return; return;
} }
editor_scene_ -> addItem(part); m_scene -> addItem(part);
} }
/** /**
@@ -327,12 +327,12 @@ ChangeNamesCommand::~ChangeNamesCommand() {
/// Annule le changement /// Annule le changement
void ChangeNamesCommand::undo() { void ChangeNamesCommand::undo() {
editor_scene_ -> setNames(names_before); m_scene -> setNames(names_before);
} }
/// Refait le changement /// Refait le changement
void ChangeNamesCommand::redo() { void ChangeNamesCommand::redo() {
editor_scene_ -> setNames(names_after); m_scene -> setNames(names_after);
} }
/** /**
@@ -350,7 +350,7 @@ ChangeZValueCommand::ChangeZValueCommand(
option(o) option(o)
{ {
// retrieve all primitives but terminals // retrieve all primitives but terminals
QList<QGraphicsItem *> items_list = editor_scene_ -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot); QList<QGraphicsItem *> items_list = m_scene -> zItems(ElementScene::SortByZValue | ElementScene::SelectedOrNot);
// prend un snapshot des zValues // prend un snapshot des zValues
foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue()); foreach(QGraphicsItem *qgi, items_list) undo_hash.insert(qgi, qgi -> zValue());
@@ -478,12 +478,12 @@ ChangeInformationsCommand::~ChangeInformationsCommand() {
/// Annule le changement d'autorisation pour les connexions internes /// Annule le changement d'autorisation pour les connexions internes
void ChangeInformationsCommand::undo() { void ChangeInformationsCommand::undo() {
editor_scene_ -> setInformations(old_informations_); m_scene -> setInformations(old_informations_);
} }
/// Refait le changement d'autorisation pour les connexions internes /// Refait le changement d'autorisation pour les connexions internes
void ChangeInformationsCommand::redo() { void ChangeInformationsCommand::redo() {
editor_scene_ -> setInformations(new_informations_); m_scene -> setInformations(new_informations_);
} }
/** /**
@@ -524,7 +524,7 @@ void ScalePartsCommand::redo() {
@return the element editor/scene the command should take place on @return the element editor/scene the command should take place on
*/ */
ElementScene *ScalePartsCommand::elementScene() const { ElementScene *ScalePartsCommand::elementScene() const {
return(editor_scene_); return(m_scene);
} }
/** /**
@@ -593,24 +593,27 @@ void ScalePartsCommand::adjustText() {
* @param context: new info about type. * @param context: new info about type.
* @param parent: parent undo * @param parent: parent undo
*/ */
ChangePropertiesCommand::ChangePropertiesCommand(ElementScene *scene, QString type, DiagramContext info, QUndoCommand *parent) : ChangePropertiesCommand::ChangePropertiesCommand(ElementScene *scene, QString type, DiagramContext info, DiagramContext elmt_info, QUndoCommand *parent) :
ElementEditionCommand(scene, nullptr, parent) ElementEditionCommand(scene, nullptr, parent)
{ {
m_type << scene->m_elmt_type << type; m_type << scene->m_elmt_type << type;
m_info << scene->m_elmt_kindInfo << info; m_kind_info << scene->m_elmt_kindInfo << info;
m_elmt_info << scene->m_elmt_information << elmt_info;
setText(QObject::tr("Modifier les propriétés")); setText(QObject::tr("Modifier les propriétés"));
} }
ChangePropertiesCommand::~ChangePropertiesCommand() {} ChangePropertiesCommand::~ChangePropertiesCommand() {}
void ChangePropertiesCommand::undo() { void ChangePropertiesCommand::undo() {
editor_scene_-> m_elmt_type = m_type.first(); m_scene->m_elmt_type = m_type.first();
editor_scene_-> m_elmt_kindInfo = m_info.first(); m_scene->m_elmt_kindInfo = m_kind_info.first();
m_scene->m_elmt_information = m_elmt_info.first();
} }
void ChangePropertiesCommand::redo() { void ChangePropertiesCommand::redo() {
editor_scene_-> m_elmt_type = m_type.last(); m_scene->m_elmt_type = m_type.last();
editor_scene_-> m_elmt_kindInfo = m_info.last(); m_scene->m_elmt_kindInfo = m_kind_info.last();
m_scene->m_elmt_information = m_elmt_info.last();
} }

View File

@@ -49,8 +49,8 @@ class ElementEditionCommand : public QUndoCommand
// attributes // attributes
protected: protected:
/// Element editor/view/scene the command should take place on /// Element editor/view/scene the command should take place on
ElementScene *editor_scene_; ElementScene *m_scene;
ElementView *editor_view_; ElementView *m_view;
}; };
/** /**
@@ -296,7 +296,7 @@ class ScalePartsCommand : public ElementEditionCommand {
class ChangePropertiesCommand : public ElementEditionCommand { class ChangePropertiesCommand : public ElementEditionCommand {
public: public:
ChangePropertiesCommand (ElementScene *scene, QString type, DiagramContext info, QUndoCommand *parent=nullptr); ChangePropertiesCommand (ElementScene *scene, QString type, DiagramContext info, DiagramContext elmt_info, QUndoCommand *parent=nullptr);
~ChangePropertiesCommand () override; ~ChangePropertiesCommand () override;
void undo() override; void undo() override;
@@ -304,7 +304,8 @@ class ChangePropertiesCommand : public ElementEditionCommand {
private: private:
QList <QString> m_type; QList <QString> m_type;
QList <DiagramContext> m_info; QList <DiagramContext> m_kind_info;
QList < DiagramContext> m_elmt_info;
}; };
#endif #endif

View File

@@ -341,6 +341,13 @@ const QDomDocument ElementScene::toXml(bool all_parts)
root.appendChild(kindInfo); root.appendChild(kindInfo);
} }
if(m_elmt_type == "simple" || m_elmt_type == "master" || m_elmt_type == "terminal")
{
QDomElement element_info = xml_document.createElement("elementInformations");
m_elmt_information.toXml(element_info, "elementInformation");
root.appendChild(element_info);
}
//complementary information about the element //complementary information about the element
QDomElement informations_element = xml_document.createElement("informations"); QDomElement informations_element = xml_document.createElement("informations");
root.appendChild(informations_element); root.appendChild(informations_element);
@@ -638,13 +645,19 @@ void ElementScene::slot_editAuthorInformations() {
* @brief ElementScene::slot_editProperties * @brief ElementScene::slot_editProperties
* Open dialog to edit the element properties * Open dialog to edit the element properties
*/ */
void ElementScene::slot_editProperties() { void ElementScene::slot_editProperties()
{
QString type = m_elmt_type; QString type = m_elmt_type;
DiagramContext info = m_elmt_kindInfo; DiagramContext kind_info = m_elmt_kindInfo;
ElementPropertiesEditorWidget epew(type, info); DiagramContext elmt_info = m_elmt_information;
ElementPropertiesEditorWidget epew(type, kind_info, elmt_info);
epew.exec(); epew.exec();
if (type != m_elmt_type || info != m_elmt_kindInfo)
undoStack().push(new ChangePropertiesCommand(this, type, info)); if (type != m_elmt_type ||
kind_info != m_elmt_kindInfo ||
elmt_info != m_elmt_information)
undoStack().push(new ChangePropertiesCommand(this, type, kind_info, elmt_info));
} }
/** /**
@@ -874,9 +887,11 @@ bool ElementScene::applyInformations(const QDomDocument &xml_document)
if (root.tagName() != "definition" || root.attribute("type") != "element") if (root.tagName() != "definition" || root.attribute("type") != "element")
return(false); return(false);
//Extract info about element type //Extract info about element type
m_elmt_type = root.attribute("link_type", "simple"); m_elmt_type = root.attribute("link_type", "simple");
m_elmt_kindInfo.fromXml(root.firstChildElement("kindInformations"), "kindInformation"); m_elmt_kindInfo.fromXml(root.firstChildElement("kindInformations"), "kindInformation");
//Extract info of element
m_elmt_information.fromXml(root.firstChildElement("elementInformations"), "elementInformation");
//Extract names of xml definition //Extract names of xml definition
m_names_list.fromXml(root); m_names_list.fromXml(root);

View File

@@ -61,19 +61,20 @@ class ElementScene : public QGraphicsScene
private: private:
ElementScene(const ElementScene &); ElementScene(const ElementScene &);
// attributes // attributes
private: private:
/// List of localized names /// List of localized names
NamesList m_names_list; NamesList m_names_list;
/// Extra informations /// Extra informations
QString m_informations; QString m_informations;
/// element type /// element type
QString m_elmt_type; QString m_elmt_type;
/// element kind info /// element kind info
DiagramContext m_elmt_kindInfo; DiagramContext m_elmt_kindInfo,
/// QGraphicsItem manager m_elmt_information;
/// QGraphicsItem manager
QGIManager m_qgi_manager; QGIManager m_qgi_manager;
/// Undo stack /// Undo stack
QUndoStack m_undo_stack; QUndoStack m_undo_stack;
/// Variables related to drawing /// Variables related to drawing

View File

@@ -17,23 +17,51 @@
*/ */
#include "elementpropertieseditorwidget.h" #include "elementpropertieseditorwidget.h"
#include "ui_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 * @brief ElementPropertiesEditorWidget::ElementPropertiesEditorWidget
* Default constructor * Default constructor
* @param basic_type : QString of the drawed element * @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 * @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), QDialog(parent),
ui(new Ui::ElementPropertiesEditorWidget), ui(new Ui::ElementPropertiesEditorWidget),
m_basic_type(basic_type), m_basic_type(basic_type),
m_dc (dc) m_kind_info (kind_info),
m_elmt_info (elmt_info)
{ {
ui->setupUi(this); ui->setupUi(this);
setUpInterface(); setUpInterface();
upDateInterface(); upDateInterface();
qDebug() << "const";
} }
/** /**
@@ -49,17 +77,18 @@ ElementPropertiesEditorWidget::~ElementPropertiesEditorWidget()
* @brief ElementPropertiesEditorWidget::upDateInterface * @brief ElementPropertiesEditorWidget::upDateInterface
* Update the interface with the curent value * Update the interface with the curent value
*/ */
void ElementPropertiesEditorWidget::upDateInterface() { 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") { 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_state_cb->setCurrentIndex(ui->m_state_cb->findData(m_kind_info["state"].toString()));
ui -> m_number_ctc -> setValue (m_dc["number"].toInt()); 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") { 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()); on_m_base_type_cb_currentIndexChanged(ui->m_base_type_cb->currentIndex());
@@ -68,28 +97,71 @@ void ElementPropertiesEditorWidget::upDateInterface() {
/** /**
* @brief ElementPropertiesEditorWidget::setUpInterface * @brief ElementPropertiesEditorWidget::setUpInterface
*/ */
void ElementPropertiesEditorWidget::setUpInterface() { void ElementPropertiesEditorWidget::setUpInterface()
// Type combo box {
ui -> m_base_type_cb -> addItem (tr("Simple"), QVariant("simple")); // Type combo box
ui -> m_base_type_cb -> addItem (tr("Maître"), QVariant("master")); ui->m_base_type_cb->addItem (tr("Simple"), QVariant("simple"));
ui -> m_base_type_cb -> addItem (tr("Esclave"), QVariant("slave")); ui->m_base_type_cb->addItem (tr("Maître"), QVariant("master"));
ui -> m_base_type_cb -> addItem (tr("Renvoi de folio suivant"), QVariant("next_report")); ui->m_base_type_cb->addItem (tr("Esclave"), QVariant("slave"));
ui -> m_base_type_cb -> addItem (tr("Renvoi de folio précédent"), QVariant("previous_report")); ui->m_base_type_cb->addItem (tr("Renvoi de folio suivant"), QVariant("next_report"));
ui -> m_base_type_cb -> addItem (tr("Bornier"), QVariant("terminal")); 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 ouvert"),QVariant("NO"));
ui -> m_state_cb -> addItem(tr("Normalement fermé"), QVariant("NC")); ui->m_state_cb->addItem(tr("Normalement fermé"), QVariant("NC"));
ui -> m_state_cb -> addItem(tr("Inverseur"), QVariant("SW")); ui->m_state_cb->addItem(tr("Inverseur"), QVariant("SW"));
ui -> m_type_cb -> addItem(tr("Simple"), QVariant("simple")); ui->m_type_cb->addItem(tr("Simple"), QVariant("simple"));
ui -> m_type_cb -> addItem(tr("Puissance"), QVariant("power")); 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é travail"), QVariant("delayOn"));
ui -> m_type_cb -> addItem(tr("Temporisé repos"), QVariant("delayOff")); ui->m_type_cb->addItem(tr("Temporisé repos"), QVariant("delayOff"));
//Master option //Master option
ui -> m_master_type_cb -> addItem(tr("Bobine"), QVariant("coil")); 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("Organe de protection"), QVariant("protection"));
ui -> m_master_type_cb -> addItem(tr("Commutateur / bouton"), QVariant("commutator")); 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(); m_basic_type = ui -> m_base_type_cb -> itemData(ui -> m_base_type_cb -> currentIndex()).toString();
if (m_basic_type == "slave") { if (m_basic_type == "slave") {
m_dc.addValue("state", ui -> m_state_cb -> itemData(ui -> m_state_cb -> currentIndex())); m_kind_info.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_kind_info.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("number", QVariant(ui -> m_number_ctc -> value()));
} }
else if(m_basic_type == "master") { 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(); this->close();
} }
@@ -118,9 +195,11 @@ void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int in
{ {
bool slave = false , master = false; bool slave = false , master = false;
if (ui -> m_base_type_cb -> itemData(index).toString() == "slave") slave = 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; else if (ui->m_base_type_cb->itemData(index).toString() == "master") master = true;
ui -> m_slave_gb -> setVisible(slave); ui->m_slave_gb->setVisible(slave);
ui -> m_master_gb -> setVisible(master); ui->m_master_gb->setVisible(master);
updateTree();
} }

View File

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

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>450</width>
<height>300</height> <height>321</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -18,98 +18,136 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <widget class="QTabWidget" name="tabWidget">
<item> <property name="currentIndex">
<widget class="QLabel" name="label"> <number>0</number>
<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> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QWidget" name="Type">
<item> <attribute name="title">
<layout class="QGridLayout" name="gridLayout"> <string>Type</string>
<item row="3" column="1"> </attribute>
<widget class="QSpinBox" name="m_number_ctc"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="minimum"> <item>
<number>1</number> <layout class="QHBoxLayout" name="horizontalLayout">
</property> <item>
</widget> <widget class="QLabel" name="label">
</item> <property name="text">
<item row="3" column="0"> <string>Type de base :</string>
<widget class="QLabel" name="label_4"> </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"> <property name="text">
<string>Nombre de contact représenté</string> <string>Nom</string>
</property> </property>
</widget> </column>
</item> <column>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Type de contact</string> <string>Valeurs</string>
</property> </property>
</widget> </column>
</item> </widget>
<item row="1" column="0"> </item>
<widget class="QLabel" name="label_2"> </layout>
<property name="text"> </widget>
<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> </widget>
</item> </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> <item>
<widget class="QDialogButtonBox" name="m_buttonBox"> <widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation"> <property name="orientation">

View File

@@ -150,7 +150,9 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
setToolTip(name()); setToolTip(name());
//load kind informations //load kind informations
kind_informations_.fromXml(xml_def_elmt.firstChildElement("kindInformations"), "kindInformation"); m_kind_informations.fromXml(xml_def_elmt.firstChildElement("kindInformations"), "kindInformation");
//load element information
m_element_informations.fromXml(xml_def_elmt.firstChildElement("elementInformations"), "elementInformation");
//scroll of the Children of the Definition: Parts of the Drawing //scroll of the Children of the Definition: Parts of the Drawing
int parsed_elements_count = 0; int parsed_elements_count = 0;

View File

@@ -136,7 +136,7 @@ class Element : public QetGraphicsItem
DiagramContext elementInformations ()const {return m_element_informations;} DiagramContext elementInformations ()const {return m_element_informations;}
DiagramContext& rElementInformations () {return m_element_informations;} DiagramContext& rElementInformations () {return m_element_informations;}
virtual void setElementInformations (DiagramContext dc); virtual void setElementInformations (DiagramContext dc);
DiagramContext kindInformations () const {return kind_informations_;} //@kind_information_ is used to store more information DiagramContext kindInformations () const {return m_kind_informations;} //@kind_information_ is used to store more information
//about the herited class like contactelement for know //about the herited class like contactelement for know
// kind of contact (simple tempo) or number of contact show by the element. // kind of contact (simple tempo) or number of contact show by the element.
@@ -154,7 +154,7 @@ class Element : public QetGraphicsItem
//ATTRIBUTES //ATTRIBUTES
protected: protected:
DiagramContext m_element_informations, kind_informations_; DiagramContext m_element_informations, m_kind_informations;
autonum::sequentialNumbers m_autoNum_seq; autonum::sequentialNumbers m_autoNum_seq;
bool m_freeze_label = false; bool m_freeze_label = false;
QString m_F_str; QString m_F_str;