QetElementEditor : Use elementData class

This commit is contained in:
joshua
2021-02-13 21:38:36 +01:00
parent ffe3d98279
commit 8f85cacb06
15 changed files with 354 additions and 335 deletions

View File

@@ -282,13 +282,17 @@ ChangeNamesCommand::~ChangeNamesCommand()
/// Annule le changement /// Annule le changement
void ChangeNamesCommand::undo() void ChangeNamesCommand::undo()
{ {
m_scene -> setNames(names_before); auto data = m_scene->elementData();
data.m_names_list = names_before;
m_scene->setElementData(data);
} }
/// Refait le changement /// Refait le changement
void ChangeNamesCommand::redo() void ChangeNamesCommand::redo()
{ {
m_scene -> setNames(names_after); auto data = m_scene->elementData();
data.m_names_list = names_after;
m_scene->setElementData(data);
} }
/** /**
@@ -453,13 +457,17 @@ 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()
{ {
m_scene -> setInformations(old_informations_); auto data = m_scene->elementData();
data.m_drawing_information = old_informations_;
m_scene->setElementData(data);
} }
/// Refait le changement d'autorisation pour les connexions internes /// Refait le changement d'autorisation pour les connexions internes
void ChangeInformationsCommand::redo() void ChangeInformationsCommand::redo()
{ {
m_scene -> setInformations(new_informations_); auto data = m_scene->elementData();
data.m_drawing_information = new_informations_;
m_scene->setElementData(data);
} }
/** /**
@@ -572,45 +580,32 @@ void ScalePartsCommand::adjustText()
setText(QObject::tr("redimensionnement de %1 primitives", "undo caption -- %1 always > 1").arg(scaled_primitives_.count())); setText(QObject::tr("redimensionnement de %1 primitives", "undo caption -- %1 always > 1").arg(scaled_primitives_.count()));
} }
} }
/** /**
@brief ChangePropertiesCommand::ChangePropertiesCommand * @brief changeElementDataCommand::changeElementDataCommand
Change the properties of the drawed element * Change the properties of the drawed element
@param scene : scene to belong the property * @param scene : scene to belong the property
@param type : new type of element. * @param old_data : old data
@param info * @param new_data : new data
@param elmt_info : new info about type. * @param parent : parent undo command
@param parent : parent undo
*/ */
ChangePropertiesCommand::ChangePropertiesCommand( changeElementDataCommand::changeElementDataCommand(ElementScene *scene,
ElementScene *scene, ElementData old_data,
const QString& type, ElementData new_data,
const DiagramContext& info,
const DiagramContext& elmt_info,
QUndoCommand *parent) : QUndoCommand *parent) :
ElementEditionCommand(scene, nullptr, parent) ElementEditionCommand(scene, nullptr, parent),
m_old(old_data),
m_new(new_data)
{ {
m_type << scene->m_elmt_type << type; setText(QObject::tr("Modifier les propriétées de l'élément"));
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"));
} }
ChangePropertiesCommand::~ChangePropertiesCommand() void changeElementDataCommand::undo() {
{} m_scene->setElementData(m_old);
QUndoCommand::undo();
void ChangePropertiesCommand::undo()
{
m_scene->m_elmt_type = m_type.first();
m_scene->m_elmt_kindInfo = m_kind_info.first();
m_scene->setElementInfo(m_elmt_info.first());
} }
void ChangePropertiesCommand::redo() void changeElementDataCommand::redo() {
{ m_scene->setElementData(m_new);
m_scene->m_elmt_type = m_type.last(); QUndoCommand::redo();
m_scene->m_elmt_kindInfo = m_kind_info.last();
m_scene->setElementInfo(m_elmt_info.last());
} }

View File

@@ -262,23 +262,21 @@ class ScalePartsCommand : public ElementEditionCommand {
bool first_redo; bool first_redo;
}; };
class ChangePropertiesCommand : public ElementEditionCommand { class changeElementDataCommand : public ElementEditionCommand
{
public: public:
ChangePropertiesCommand ( changeElementDataCommand(ElementScene *scene,
ElementScene *scene, ElementData old_data,
const QString& type, ElementData new_data,
const DiagramContext& info,
const DiagramContext& elmt_info,
QUndoCommand *parent = nullptr); QUndoCommand *parent = nullptr);
~ChangePropertiesCommand () override; ~changeElementDataCommand() override {}
void undo() override; void undo() override;
void redo() override; void redo() override;
private: private:
QList <QString> m_type; ElementData m_old,
QList <DiagramContext> m_kind_info; m_new;
QList < DiagramContext> m_elmt_info;
}; };
#endif #endif

View File

@@ -51,7 +51,6 @@
*/ */
ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
QGraphicsScene(parent), QGraphicsScene(parent),
m_elmt_type("simple"),
m_qgi_manager(this), m_qgi_manager(this),
m_element_editor(editor) m_element_editor(editor)
{ {
@@ -74,6 +73,24 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
this, SLOT(managePrimitivesGroups())); this, SLOT(managePrimitivesGroups()));
} }
/**
* @brief ElementScene::elementData
* @return the elementdata using by the scene
*/
ElementData ElementScene::elementData() {
return m_element_data;
}
void ElementScene::setElementData(ElementData data)
{
bool emit_ = m_element_data.m_informations != data.m_informations;
m_element_data = data;
if (emit_)
emit elementInfoChanged();
}
/** /**
@brief ElementScene::~ElementScene @brief ElementScene::~ElementScene
*/ */
@@ -437,7 +454,7 @@ const QDomDocument ElementScene::toXml(bool all_parts)
-(qRound(size.y() - (ymargin/2))))); -(qRound(size.y() - (ymargin/2)))));
root.setAttribute("version", QET::version); root.setAttribute("version", QET::version);
root.setAttribute("link_type", m_elmt_type); root.setAttribute("link_type", m_element_data.typeToString(m_element_data.m_type));
//Uuid used to compare two elements //Uuid used to compare two elements
QDomElement uuid = xml_document.createElement("uuid"); QDomElement uuid = xml_document.createElement("uuid");
@@ -445,29 +462,28 @@ const QDomDocument ElementScene::toXml(bool all_parts)
root.appendChild(uuid); root.appendChild(uuid);
//names of element //names of element
root.appendChild(m_names_list.toXml(xml_document)); root.appendChild(m_element_data.m_names_list.toXml(xml_document));
if (m_elmt_type == "slave" || m_elmt_type == "master") auto type_ = m_element_data.m_type;
if (type_ == ElementData::Slave ||
type_ == ElementData::Master)
{ {
QDomElement kindInfo = xml_document.createElement("kindInformations"); root.appendChild(m_element_data.kindInfoToXml(xml_document));
m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
root.appendChild(kindInfo);
} }
if( if(type_ == ElementData::Simple ||
m_elmt_type == "simple" type_ == ElementData::Master ||
|| m_elmt_type == "master" type_ == ElementData::Terminale)
|| m_elmt_type == "terminal")
{ {
QDomElement element_info = xml_document.createElement("elementInformations"); QDomElement element_info = xml_document.createElement("elementInformations");
m_elmt_information.toXml(element_info, "elementInformation"); m_element_data.m_informations.toXml(element_info, "elementInformation");
root.appendChild(element_info); 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);
informations_element.appendChild(xml_document.createTextNode(informations())); informations_element.appendChild(xml_document.createTextNode(m_element_data.m_drawing_information));
QDomElement description = xml_document.createElement("description"); QDomElement description = xml_document.createElement("description");
@@ -546,8 +562,15 @@ void ElementScene::fromXml(
bool state = true; bool state = true;
//Consider the informations of the element //Consider the informations of the element
if (consider_informations) { if (consider_informations)
state = applyInformations(xml_document); {
// Root must be an element definition
QDomElement root = xml_document.documentElement();
if (root.tagName() == "definition" &&
root.attribute("type") == "element") {
m_element_data.fromXml(root);
}
} }
if (state) if (state)
@@ -699,19 +722,6 @@ QETElementEditor* ElementScene::editor() const
return m_element_editor; return m_element_editor;
} }
/**
@brief ElementScene::setElementInfo
@param dc
*/
void ElementScene::setElementInfo(const DiagramContext& dc)
{
if(m_elmt_information != dc)
{
m_elmt_information = dc;
emit elementInfoChanged();
}
}
/** /**
@brief ElementScene::slot_select @brief ElementScene::slot_select
Select the item in content, Select the item in content,
@@ -833,7 +843,7 @@ void ElementScene::slot_editAuthorInformations()
// ajoute un QTextEdit au dialogue // ajoute un QTextEdit au dialogue
QTextEdit *text_field = new QTextEdit(); QTextEdit *text_field = new QTextEdit();
text_field -> setAcceptRichText(false); text_field -> setAcceptRichText(false);
text_field -> setPlainText(informations()); text_field -> setPlainText(m_element_data.m_drawing_information);
text_field -> setReadOnly(is_read_only); text_field -> setReadOnly(is_read_only);
dialog_layout -> addWidget(text_field); dialog_layout -> addWidget(text_field);
@@ -851,10 +861,10 @@ void ElementScene::slot_editAuthorInformations()
if (dialog_author.exec() == QDialog::Accepted && !is_read_only) if (dialog_author.exec() == QDialog::Accepted && !is_read_only)
{ {
QString new_infos = text_field -> toPlainText().remove(QChar(13)); // CR-less text QString new_infos = text_field -> toPlainText().remove(QChar(13)); // CR-less text
if (new_infos != informations()) if (new_infos != m_element_data.m_drawing_information)
{ {
undoStack().push(new ChangeInformationsCommand( undoStack().push(new ChangeInformationsCommand(
this, informations(), new_infos)); this, m_element_data.m_drawing_information, new_infos));
} }
} }
} }
@@ -865,20 +875,15 @@ void ElementScene::slot_editAuthorInformations()
*/ */
void ElementScene::slot_editProperties() void ElementScene::slot_editProperties()
{ {
QString type = m_elmt_type; ElementPropertiesEditorWidget epew(m_element_data);
DiagramContext kind_info = m_elmt_kindInfo;
DiagramContext elmt_info = m_elmt_information;
ElementPropertiesEditorWidget epew(type, kind_info, elmt_info);
epew.exec(); epew.exec();
if (type != m_elmt_type || if (m_element_data != epew.editedData())
kind_info != m_elmt_kindInfo || {
elmt_info != m_elmt_information) undoStack().push(new changeElementDataCommand(this,
undoStack().push(new ChangePropertiesCommand(this, m_element_data,
type, epew.editedData()));
kind_info, }
elmt_info));
} }
/** /**
@@ -898,15 +903,15 @@ void ElementScene::slot_editNames()
dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues.")); dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues."));
NameListWidget *nlw_ = dialog_.namelistWidget(); NameListWidget *nlw_ = dialog_.namelistWidget();
nlw_->setNames(m_names_list); nlw_->setNames(m_element_data.m_names_list);
nlw_->setReadOnly(is_read_only); nlw_->setReadOnly(is_read_only);
if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty()) if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty())
{ {
NamesList new_names = nlw_->names(); NamesList new_names = nlw_->names();
if (new_names != m_names_list) { if (new_names != m_element_data. m_names_list) {
undoStack().push(new ChangeNamesCommand(this, undoStack().push(new ChangeNamesCommand(this,
m_names_list, m_element_data.m_names_list,
new_names)); new_names));
} }
} }
@@ -1087,62 +1092,6 @@ QRectF ElementScene::elementContentBoundingRect(
return(bounding_rect); return(bounding_rect);
} }
/**
@brief ElementScene::applyInformations
Applies the information (dimensions, hostpot, orientations,
internal connections, names and additional information)
contained in an XML document.
\~French Applique les informations (dimensions, hostpot, orientations,
connexions internes, noms et informations complementaires)
contenu dans un document XML.
\~ @param xml_document : Document XML a analyser
\~ @return
true if reading and applying the information went well, false otherwise.
\~French true si la lecture et l'application
des informations s'est bien passee, false sinon.
*/
bool ElementScene::applyInformations(const QDomDocument &xml_document)
{
// Root must be an element definition
QDomElement root = xml_document.documentElement();
if (
root.tagName() != "definition"
||
root.attribute("type") != "element")
return(false);
//Extract info about element type
m_elmt_type = root.attribute("link_type", "simple");
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
m_names_list.fromXml(root);
//extract additional informations
setInformations(QString());
for (QDomNode node = root.firstChild() ;
!node.isNull() ;
node = node.nextSibling())
{
QDomElement elmt = node.toElement();
if (elmt.isNull()) continue;
if (elmt.tagName() == "informations")
{
setInformations(elmt.text());
break;
}
}
return(true);
}
/** /**
@brief ElementScene::loadContent @brief ElementScene::loadContent
Create and load the content describe in the xml document. Create and load the content describe in the xml document.

View File

@@ -21,6 +21,7 @@
#include "../diagramcontext.h" #include "../diagramcontext.h"
#include "../qgimanager.h" #include "../qgimanager.h"
#include "elementcontent.h" #include "elementcontent.h"
#include "../properties/elementdata.h"
#include <QtWidgets> #include <QtWidgets>
#include <QtXml> #include <QtXml>
@@ -65,11 +66,7 @@ class ElementScene : public QGraphicsScene
// attributes // attributes
private: private:
NamesList m_names_list; /// List of localized names ElementData m_element_data; ///ElementData. Actualy in transition with old data storage
QString m_informations; /// Extra informations
QString m_elmt_type; /// element type
DiagramContext m_elmt_kindInfo,
m_elmt_information; /// element kind info
QGIManager m_qgi_manager; QGIManager m_qgi_manager;
QUndoStack m_undo_stack; QUndoStack m_undo_stack;
@@ -90,21 +87,20 @@ class ElementScene : public QGraphicsScene
// methods // methods
public: public:
ElementData elementData();
void setElementData(ElementData data);
void setEventInterface (ESEventInterface *event_interface); void setEventInterface (ESEventInterface *event_interface);
void clearEventInterface(); void clearEventInterface();
void setBehavior (ElementScene::Behavior); void setBehavior (ElementScene::Behavior);
ElementScene::Behavior behavior() const; ElementScene::Behavior behavior() const;
QPointF snapToGrid(QPointF point); QPointF snapToGrid(QPointF point);
void setNames(const NamesList &);
NamesList names() const;
QString informations() const;
void setInformations(const QString &);
QString elementType () const {return m_elmt_type;}
DiagramContext elementKindInfo () const {return m_elmt_kindInfo;}
DiagramContext elementInformation() const {return m_elmt_information;}
virtual int xGrid() const; virtual int xGrid() const;
virtual int yGrid() const; virtual int yGrid() const;
virtual void setGrid(int, int); virtual void setGrid(int, int);
virtual const QDomDocument toXml(bool = true); virtual const QDomDocument toXml(bool = true);
virtual QRectF boundingRectFromXml(const QDomDocument &); virtual QRectF boundingRectFromXml(const QDomDocument &);
virtual void fromXml(const QDomDocument &, virtual void fromXml(const QDomDocument &,
@@ -128,7 +124,6 @@ class ElementScene : public QGraphicsScene
void cut(); void cut();
void copy(); void copy();
QETElementEditor* editor() const; QETElementEditor* editor() const;
void setElementInfo(const DiagramContext& dc);
protected: protected:
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override; void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
@@ -137,12 +132,10 @@ class ElementScene : public QGraphicsScene
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override; void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
void keyPressEvent (QKeyEvent *event) override; void keyPressEvent (QKeyEvent *event) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override; void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
void drawForeground(QPainter *, const QRectF &) override; void drawForeground(QPainter *, const QRectF &) override;
private: private:
QRectF elementContentBoundingRect(const ElementContent &) const; QRectF elementContentBoundingRect(const ElementContent &) const;
bool applyInformations(const QDomDocument &);
ElementContent loadContent(const QDomDocument &); ElementContent loadContent(const QDomDocument &);
ElementContent addContent(const ElementContent &); ElementContent addContent(const ElementContent &);
ElementContent addContentAtPos(const ElementContent &, const QPointF &); ElementContent addContentAtPos(const ElementContent &, const QPointF &);
@@ -180,39 +173,4 @@ class ElementScene : public QGraphicsScene
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions) Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
/**
@brief ElementScene::setNames
@param nameslist New set of naes for the currently edited element
*/
inline void ElementScene::setNames(const NamesList &nameslist) {
m_names_list = nameslist;
}
/**
@brief ElementScene::names
@return the list of names of the currently edited element
*/
inline NamesList ElementScene::names() const
{
return(m_names_list);
}
/**
@brief ElementScene::informations
@return extra informations of the currently edited element
*/
inline QString ElementScene::informations() const
{
return(m_informations);
}
/**
@brief ElementScene::setInformations
@param infos new extra information for the currently edited element
*/
inline void ElementScene::setInformations(const QString &infos) {
m_informations = infos;
}
#endif #endif

View File

@@ -318,7 +318,7 @@ void PartDynamicTextField::setText(const QString &text) {
void PartDynamicTextField::setInfoName(const QString &info_name) { void PartDynamicTextField::setInfoName(const QString &info_name) {
m_info_name = info_name; m_info_name = info_name;
if(m_text_from == DynamicElementTextItem::ElementInfo && elementScene()) if(m_text_from == DynamicElementTextItem::ElementInfo && elementScene())
setPlainText(elementScene() -> elementInformation().value(m_info_name).toString()); setPlainText(elementScene()->elementData().m_informations.value(m_info_name).toString());
emit infoNameChanged(m_info_name); emit infoNameChanged(m_info_name);
} }
@@ -338,7 +338,7 @@ QString PartDynamicTextField::infoName() const{
void PartDynamicTextField::setCompositeText(const QString &text) { void PartDynamicTextField::setCompositeText(const QString &text) {
m_composite_text = text; m_composite_text = text;
if(m_text_from == DynamicElementTextItem::CompositeText && elementScene()) if(m_text_from == DynamicElementTextItem::CompositeText && elementScene())
setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementScene() -> elementInformation())); setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementScene()->elementData().m_informations));
emit compositeTextChanged(m_composite_text); emit compositeTextChanged(m_composite_text);
} }
@@ -551,10 +551,10 @@ void PartDynamicTextField::elementInfoChanged()
return; return;
if(m_text_from == DynamicElementTextItem::ElementInfo) if(m_text_from == DynamicElementTextItem::ElementInfo)
setPlainText(elementScene() -> elementInformation().value(m_info_name).toString()); setPlainText(elementScene()->elementData().m_informations.value(m_info_name).toString());
else if (m_text_from == DynamicElementTextItem::CompositeText && elementScene()) else if (m_text_from == DynamicElementTextItem::CompositeText && elementScene())
setPlainText(autonum::AssignVariables::replaceVariable( setPlainText(autonum::AssignVariables::replaceVariable(
m_composite_text, elementScene() -> elementInformation())); m_composite_text, elementScene()->elementData().m_informations));
} }
void PartDynamicTextField::prepareAlignment() void PartDynamicTextField::prepareAlignment()

View File

@@ -225,9 +225,9 @@ void DynamicTextFieldEditor::fillInfoComboBox()
ui -> m_elmt_info_cb -> clear(); ui -> m_elmt_info_cb -> clear();
QStringList strl; QStringList strl;
QString type = elementEditor() -> elementScene() -> elementType(); auto type = elementEditor()->elementScene()->elementData().m_type;
if(type.contains("report")) { if(type & ElementData::AllReport) {
strl = QETInformation::folioReportInfoKeys(); strl = QETInformation::folioReportInfoKeys();
} }
else { else {
@@ -334,7 +334,7 @@ void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1) {
undo->setText(tr("Modifier l'information d'un texte")); undo->setText(tr("Modifier l'information d'un texte"));
undoStack().push(undo); undoStack().push(undo);
m_parts[i]->setPlainText( m_parts[i]->setPlainText(
elementEditor() -> elementScene() -> elementInformation().value(m_parts[i] -> infoName()).toString()); elementEditor()->elementScene()->elementData().m_informations.value(m_parts[i] -> infoName()).toString());
} }
} }
} }

View File

@@ -20,6 +20,7 @@
#include "../../qetapp.h" #include "../../qetapp.h"
#include "../../qetinformation.h" #include "../../qetinformation.h"
#include "ui_elementpropertieseditorwidget.h" #include "ui_elementpropertieseditorwidget.h"
#include "../../qetinformation.h"
#include <QItemDelegate> #include <QItemDelegate>
@@ -37,7 +38,7 @@ class EditorDelegate : public QItemDelegate
QWidget* createEditor(QWidget *parent, QWidget* createEditor(QWidget *parent,
const QStyleOptionViewItem &option, const QStyleOptionViewItem &option,
const QModelIndex &index) const const QModelIndex &index) const override
{ {
if(index.column() == 1) if(index.column() == 1)
{ {
@@ -50,23 +51,14 @@ class EditorDelegate : public QItemDelegate
}; };
/** /**
@brief ElementPropertiesEditorWidget::ElementPropertiesEditorWidget * @brief ElementPropertiesEditorWidget::ElementPropertiesEditorWidget
Default constructor * @param data
@param basic_type : QString of the drawed element * @param parent
@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( ElementPropertiesEditorWidget::ElementPropertiesEditorWidget(ElementData data, QWidget *parent) :
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_data(data)
m_kind_info (kind_info),
m_elmt_info (elmt_info)
{ {
ui->setupUi(this); ui->setupUi(this);
setUpInterface(); setUpInterface();
@@ -90,22 +82,22 @@ void ElementPropertiesEditorWidget::upDateInterface()
{ {
ui->m_base_type_cb->setCurrentIndex( ui->m_base_type_cb->setCurrentIndex(
ui->m_base_type_cb->findData( ui->m_base_type_cb->findData(
QVariant(m_basic_type))); m_data.m_type));
if (m_basic_type == "slave") if (m_data.m_type == ElementData::Slave)
{ {
ui->m_state_cb->setCurrentIndex( ui->m_state_cb->setCurrentIndex(
ui->m_state_cb->findData( ui->m_state_cb->findData(
m_kind_info["state"].toString())); m_data.m_slave_state));
ui->m_type_cb->setCurrentIndex ( ui->m_type_cb->setCurrentIndex (
ui->m_type_cb->findData( ui->m_type_cb->findData(
m_kind_info["type"].toString())); m_data.m_slave_type));
ui->m_number_ctc->setValue(m_kind_info["number"].toInt()); ui->m_number_ctc->setValue(m_data.m_contact_count);
} }
else if (m_basic_type == "master") { else if (m_data.m_type == ElementData::Master) {
ui->m_master_type_cb->setCurrentIndex( ui->m_master_type_cb->setCurrentIndex(
ui->m_master_type_cb->findData ( ui->m_master_type_cb->findData (
m_kind_info["type"])); m_data.m_master_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());
@@ -117,32 +109,27 @@ void ElementPropertiesEditorWidget::upDateInterface()
void ElementPropertiesEditorWidget::setUpInterface() void ElementPropertiesEditorWidget::setUpInterface()
{ {
// Type combo box // Type combo box
ui->m_base_type_cb->addItem (tr("Simple"), QVariant("simple")); ui->m_base_type_cb->addItem (tr("Simple"), ElementData::Simple);
ui->m_base_type_cb->addItem (tr("Maître"), QVariant("master")); ui->m_base_type_cb->addItem (tr("Maître"), ElementData::Master);
ui->m_base_type_cb->addItem (tr("Esclave"), QVariant("slave")); ui->m_base_type_cb->addItem (tr("Esclave"), ElementData::Slave);
ui->m_base_type_cb->addItem (tr("Renvoi de folio suivant"), ui->m_base_type_cb->addItem (tr("Renvoi de folio suivant"), ElementData::NextReport);
QVariant("next_report")); ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"), ElementData::PreviousReport);
ui->m_base_type_cb->addItem (tr("Renvoi de folio précédent"), ui->m_base_type_cb->addItem (tr("Bornier"), ElementData::Terminale);
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"), ElementData::NO);
ui->m_state_cb->addItem(tr("Normalement fermé"), QVariant("NC")); ui->m_state_cb->addItem(tr("Normalement fermé"), ElementData::NC);
ui->m_state_cb->addItem(tr("Inverseur"), QVariant("SW")); ui->m_state_cb->addItem(tr("Inverseur"), ElementData::SW);
ui->m_type_cb->addItem(tr("Simple"), QVariant("simple")); ui->m_type_cb->addItem(tr("Simple"), ElementData::SSimple);
ui->m_type_cb->addItem(tr("Puissance"), QVariant("power")); ui->m_type_cb->addItem(tr("Puissance"), ElementData::Power);
ui->m_type_cb->addItem(tr("Temporisé travail"), QVariant("delayOn")); ui->m_type_cb->addItem(tr("Temporisé travail"), ElementData::DelayOn);
ui->m_type_cb->addItem(tr("Temporisé repos"), QVariant("delayOff")); ui->m_type_cb->addItem(tr("Temporisé repos"), ElementData::DelayOff);
ui->m_type_cb->addItem(tr("Temporisé travail & repos"), ui->m_type_cb->addItem(tr("Temporisé travail & repos"), ElementData::delayOnOff);
QVariant("delayOnOff"));
//Master option //Master option
ui->m_master_type_cb->addItem(tr("Bobine"), QVariant("coil")); ui->m_master_type_cb->addItem(tr("Bobine"), ElementData::Coil);
ui->m_master_type_cb->addItem(tr("Organe de protection"), ui->m_master_type_cb->addItem(tr("Organe de protection"), ElementData::Protection);
QVariant("protection")); ui->m_master_type_cb->addItem(tr("Commutateur / bouton"), ElementData::Commutator);
ui->m_master_type_cb->addItem(tr("Commutateur / bouton"),
QVariant("commutator"));
//Disable the edition of the first column of the information tree //Disable the edition of the first column of the information tree
//by this little workaround //by this little workaround
@@ -153,21 +140,28 @@ void ElementPropertiesEditorWidget::setUpInterface()
void ElementPropertiesEditorWidget::updateTree() void ElementPropertiesEditorWidget::updateTree()
{ {
QString type = ui->m_base_type_cb->itemData( auto type_ = ui->m_base_type_cb->currentData().value<ElementData::Type>();
ui->m_base_type_cb->currentIndex()).toString();
if (type == "master") switch (type_) {
case ElementData::Simple:
ui->m_tree->setEnabled(true); ui->m_tree->setEnabled(true);
else if (type == "slave") break;
case ElementData::NextReport:
ui->m_tree->setDisabled(true); ui->m_tree->setDisabled(true);
else if (type == "simple") break;
case ElementData::PreviousReport:
ui->m_tree->setDisabled(true);
break;
case ElementData::Master:
ui->m_tree->setEnabled(true); ui->m_tree->setEnabled(true);
else if (type == "next_report") break;
case ElementData::Slave:
ui->m_tree->setDisabled(true); ui->m_tree->setDisabled(true);
else if (type == "previous_report") break;
ui->m_tree->setDisabled(true); case ElementData::Terminale:
else if (type == "terminal")
ui->m_tree->setEnabled(true); ui->m_tree->setEnabled(true);
break;
}
} }
/** /**
@@ -176,11 +170,7 @@ void ElementPropertiesEditorWidget::updateTree()
*/ */
void ElementPropertiesEditorWidget::populateTree() void ElementPropertiesEditorWidget::populateTree()
{ {
QStringList keys{"label", "plant", "comment", "description", auto keys = QETInformation::elementEditorElementInfoKeys();
"designation", "manufacturer",
"manufacturer_reference", "supplier", "quantity",
"unity", "machine_manufacturer_reference"};
for(const QString& key : keys) for(const QString& key : keys)
{ {
QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree); QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree);
@@ -188,7 +178,7 @@ void ElementPropertiesEditorWidget::populateTree()
qtwi->setData(0, Qt::DisplayRole, qtwi->setData(0, Qt::DisplayRole,
QETInformation::translatedInfoKey(key)); QETInformation::translatedInfoKey(key));
qtwi->setData(0, Qt::UserRole, key); qtwi->setData(0, Qt::UserRole, key);
qtwi->setText(1, m_elmt_info.value(key).toString()); qtwi->setText(1, m_data.m_informations.value(key).toString());
} }
} }
@@ -198,23 +188,16 @@ void ElementPropertiesEditorWidget::populateTree()
*/ */
void ElementPropertiesEditorWidget::on_m_buttonBox_accepted() void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
{ {
m_basic_type = ui->m_base_type_cb->itemData( m_data.m_type = ui->m_base_type_cb->currentData().value<ElementData::Type>();
ui->m_base_type_cb->currentIndex()).toString();
if (m_basic_type == "slave") if (m_data.m_type == ElementData::Slave)
{ {
m_kind_info.addValue("state", m_data.m_slave_state = ui->m_state_cb->currentData().value<ElementData::SlaveState>();
ui->m_state_cb->itemData( m_data.m_slave_type = ui->m_type_cb->currentData().value<ElementData::SlaveType>();
ui->m_state_cb->currentIndex())); m_data.m_contact_count = ui->m_number_ctc->value();
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") { else if (m_data.m_type == ElementData::Master) {
m_kind_info.addValue("type", m_data.m_master_type = ui->m_master_type_cb->currentData().value<ElementData::MasterType>();
ui->m_master_type_cb->itemData(
ui->m_master_type_cb->currentIndex()));
} }
for (QTreeWidgetItem *qtwi : ui->m_tree->invisibleRootItem()->takeChildren()) for (QTreeWidgetItem *qtwi : ui->m_tree->invisibleRootItem()->takeChildren())
@@ -224,7 +207,7 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
txt.remove("\r"); txt.remove("\r");
txt.remove("\n"); txt.remove("\n");
m_elmt_info.addValue(qtwi->data(0, Qt::UserRole).toString(), m_data.m_informations.addValue(qtwi->data(0, Qt::UserRole).toString(),
txt); txt);
} }
@@ -235,14 +218,14 @@ void ElementPropertiesEditorWidget::on_m_buttonBox_accepted()
@brief ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged @brief ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged
@param index : Action when combo-box base type index change @param index : Action when combo-box base type index change
*/ */
void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged( void ElementPropertiesEditorWidget::on_m_base_type_cb_currentIndexChanged(int index)
int index)
{ {
bool slave = false , master = false; bool slave = false , master = false;
if (ui->m_base_type_cb->itemData(index).toString() == "slave") auto type_ = ui->m_base_type_cb->itemData(index).value<ElementData::Type>();
if (type_ == ElementData::Slave)
slave = true; slave = true;
else if (ui->m_base_type_cb->itemData(index).toString() == "master") else if (type_ == ElementData::Master)
master = true; master = true;
ui->m_slave_gb->setVisible(slave); ui->m_slave_gb->setVisible(slave);

View File

@@ -19,6 +19,7 @@
#define ELEMENTPROPERTIESEDITORWIDGET_H #define ELEMENTPROPERTIESEDITORWIDGET_H
#include "../../diagramcontext.h" #include "../../diagramcontext.h"
#include "../../properties/elementdata.h"
#include <QAbstractButton> #include <QAbstractButton>
#include <QDialog> #include <QDialog>
@@ -38,12 +39,13 @@ class ElementPropertiesEditorWidget : public QDialog
//METHODS //METHODS
public: public:
explicit ElementPropertiesEditorWidget(QString &basic_type, DiagramContext &kind_info, DiagramContext &elmt_info, QWidget *parent = nullptr); explicit ElementPropertiesEditorWidget(ElementData data, QWidget *parent = nullptr);
~ElementPropertiesEditorWidget() override; ~ElementPropertiesEditorWidget() override;
void upDateInterface(); ElementData editedData() {return m_data;}
private: private:
void upDateInterface();
void setUpInterface(); void setUpInterface();
void updateTree(); void updateTree();
void populateTree(); void populateTree();
@@ -56,9 +58,7 @@ class ElementPropertiesEditorWidget : public QDialog
//ATTRIBUTES //ATTRIBUTES
private: private:
Ui::ElementPropertiesEditorWidget *ui; Ui::ElementPropertiesEditorWidget *ui;
QString &m_basic_type; ElementData m_data;
DiagramContext &m_kind_info,
&m_elmt_info;
}; };
#endif // ELEMENTPROPERTIESEDITORWIDGET_H #endif // ELEMENTPROPERTIESEDITORWIDGET_H

View File

@@ -133,7 +133,9 @@ void QETElementEditor::contextMenu(QPoint p, QList<QAction *> actions)
*/ */
void QETElementEditor::setNames(const NamesList &name_list) void QETElementEditor::setNames(const NamesList &name_list)
{ {
m_elmt_scene->setNames(name_list); auto data = m_elmt_scene->elementData();
data.m_names_list = name_list;
m_elmt_scene->setElementData(data);
} }
/** /**
@@ -438,7 +440,7 @@ QString QETElementEditor::getOpenElementFileName(QWidget *parent, const QString
void QETElementEditor::updateTitle() void QETElementEditor::updateTitle()
{ {
QString title = m_min_title; QString title = m_min_title;
title += " - " + m_elmt_scene -> names().name() + " "; title += " - " + m_elmt_scene->elementData().m_names_list.name() + " ";
if (!m_file_name.isEmpty() || !m_location.isNull()) { if (!m_file_name.isEmpty() || !m_location.isNull()) {
if (!m_elmt_scene -> undoStack().isClean()) { if (!m_elmt_scene -> undoStack().isClean()) {
title += tr("[Modifié]", "window title tag"); title += tr("[Modifié]", "window title tag");
@@ -724,7 +726,8 @@ bool QETElementEditor::checkElement()
// Warning #1: Element haven't got terminal // Warning #1: Element haven't got terminal
// (except for report, because report must have one terminal and this checking is do below) // (except for report, because report must have one terminal and this checking is do below)
if (!m_elmt_scene -> containsTerminals() && !m_elmt_scene -> elementType().contains("report")) { if (!m_elmt_scene -> containsTerminals() &&
!(m_elmt_scene->elementData().m_type & ElementData::AllReport)) {
warnings << qMakePair( warnings << qMakePair(
tr("Absence de borne", "warning title"), tr("Absence de borne", "warning title"),
tr( tr(
@@ -736,7 +739,7 @@ bool QETElementEditor::checkElement()
} }
// Check folio report element // Check folio report element
if (m_elmt_scene -> elementType().contains("report")) if (m_elmt_scene->elementData().m_type & ElementData::AllReport)
{ {
int terminal =0; int terminal =0;
@@ -876,7 +879,7 @@ bool QETElementEditor::canClose()
"Voulez-vous enregistrer l'élément %1 ?", "Voulez-vous enregistrer l'élément %1 ?",
"dialog content - %1 is an element name" "dialog content - %1 is an element name"
) )
).arg(m_elmt_scene -> names().name()), ).arg(m_elmt_scene->elementData().m_names_list.name()),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Cancel QMessageBox::Cancel
); );
@@ -917,7 +920,9 @@ void QETElementEditor::readSettings()
restoreState(state.toByteArray()); restoreState(state.toByteArray());
} }
m_elmt_scene->setInformations(settings.value("elementeditor/default-informations", "").toString()); auto data = m_elmt_scene->elementData();
data.m_drawing_information = settings.value("elementeditor/default-informations", "").toString();
m_elmt_scene->setElementData(data);
} }
/** /**

View File

@@ -63,6 +63,87 @@ bool ElementData::fromXml(const QDomElement &xml_element)
return true; return true;
} }
QDomElement ElementData::kindInfoToXml(QDomDocument &document)
{
//kindInformations
auto returned_elmt = document.createElement("kindInformations");
if (m_type == ElementData::Master)
{
auto xml_type = document.createElement("kindInformation");
xml_type.setAttribute("name", "type");
auto type_txt = document.createTextNode(masterTypeToString(m_master_type));
xml_type.appendChild(type_txt);
returned_elmt.appendChild(xml_type);
}
else if (m_type == ElementData::Slave)
{
//type
auto xml_type = document.createElement("kindInformation");
xml_type.setAttribute("name", "type");
auto type_txt = document.createTextNode(slaveTypeToString(m_slave_type));
xml_type.appendChild(type_txt);
returned_elmt.appendChild(xml_type);
//state
auto xml_state = document.createElement("kindInformation");
xml_state.setAttribute("name", "state");
auto state_txt = document.createTextNode(slaveStateToString(m_slave_state));
xml_state.appendChild(state_txt);
returned_elmt.appendChild(xml_state);
//contact count
auto xml_count = document.createElement("kindInformation");
xml_count.setAttribute("name", "number");
auto count_txt = document.createTextNode(QString::number(m_contact_count));
xml_count.appendChild(count_txt);
returned_elmt.appendChild(xml_count);
}
return returned_elmt;
}
bool ElementData::operator==(const ElementData &data) const
{
if (data.m_type != m_type) {
return false;
}
if (data.m_type == ElementData::Master) {
if(data.m_master_type != m_master_type) {
return false;
}
}
else if (data.m_type == ElementData::Slave) {
if (data.m_slave_state != m_slave_state ||
data.m_slave_type != m_slave_type ||
data.m_contact_count != m_contact_count) {
return false;
}
}
if(data.m_informations != m_informations) {
return false;
}
if (data.m_names_list != m_names_list) {
return false;
}
if (m_drawing_information != m_drawing_information) {
return false;
}
return true;
}
bool ElementData::operator !=(const ElementData &data) const {
return !(*this == data);
}
QString ElementData::typeToString(ElementData::Type type) QString ElementData::typeToString(ElementData::Type type)
{ {
switch (type) { switch (type) {
@@ -202,13 +283,11 @@ ElementData::SlaveState ElementData::slaveStateFromString(const QString &string)
void ElementData::kindInfoFromXml(const QDomElement &xml_element) void ElementData::kindInfoFromXml(const QDomElement &xml_element)
{ {
if (m_type != ElementData::Master || if (m_type == ElementData::Master ||
m_type != ElementData::Slave) { m_type == ElementData::Slave)
return; {
}
auto xml_kind = xml_element.firstChildElement("kindInformations"); auto xml_kind = xml_element.firstChildElement("kindInformations");
for (auto dom_elmt : QETXML::findInDomElement(xml_kind, "kindInformation")) for (const auto &dom_elmt : QETXML::findInDomElement(xml_kind, "kindInformation"))
{ {
if (!dom_elmt.hasAttribute("name")) { if (!dom_elmt.hasAttribute("name")) {
continue; continue;
@@ -230,3 +309,4 @@ void ElementData::kindInfoFromXml(const QDomElement &xml_element)
} }
} }
} }
}

View File

@@ -73,6 +73,10 @@ class ElementData : public PropertiesInterface
void fromSettings(const QSettings &settings, const QString prefix = QString()) override; void fromSettings(const QSettings &settings, const QString prefix = QString()) override;
QDomElement toXml(QDomDocument &xml_element) const override; QDomElement toXml(QDomDocument &xml_element) const override;
bool fromXml(const QDomElement &xml_element) override; bool fromXml(const QDomElement &xml_element) override;
QDomElement kindInfoToXml(QDomDocument &document);
bool operator==(const ElementData &data) const;
bool operator!=(const ElementData &data) const;
static QString typeToString(ElementData::Type type); static QString typeToString(ElementData::Type type);
static ElementData::Type typeFromString(const QString &string); static ElementData::Type typeFromString(const QString &string);

View File

@@ -239,3 +239,19 @@ QString QETInformation::translatedInfoKey(const QString &info)
else if (info == COND_FORMULA) return QObject::tr("Formule du texte"); else if (info == COND_FORMULA) return QObject::tr("Formule du texte");
else return QString(); else return QString();
} }
QStringList QETInformation::elementEditorElementInfoKeys()
{
QStringList list = { ELMT_LABEL,
ELMT_PLANT,
ELMT_COMMENT,
ELMT_DESCRIPTION,
ELMT_DESIGNATION,
ELMT_MANUFACTURER,
ELMT_MANUFACTURER_REF,
ELMT_SUPPLIER,
ELMT_QUANTITY,
ELMT_UNITY,
ELMT_MACHINE_MANUFACTURER_REF};
return list;
}

View File

@@ -105,6 +105,7 @@ namespace QETInformation
QStringList diagramInfoKeys(); QStringList diagramInfoKeys();
QStringList elementInfoKeys(); QStringList elementInfoKeys();
QStringList elementEditorElementInfoKeys();
QString elementInfoToVar(const QString &info); QString elementInfoToVar(const QString &info);
QString infoToVar(const QString &info); QString infoToVar(const QString &info);

View File

@@ -554,3 +554,30 @@ void QETXML::modelHeaderDataFromXml(
model->setHeaderData(section_, orientation_, data_, role_); model->setHeaderData(section_, orientation_, data_, role_);
} }
} }
/**
* @brief QETXML::findInDomElement
* @param dom_elmt
* @param tag_name
* @return all direct child of dom_elmt with tag name tag_name
*/
QVector<QDomElement> QETXML::findInDomElement(const QDomElement &dom_elmt, const QString &tag_name)
{
QVector<QDomElement> return_list;
for (auto node = dom_elmt.firstChild() ;
!node.isNull() ;
node = node.nextSibling())
{
if (!node.isElement()) {
continue;
}
auto element = node.toElement();
if (element.isNull() || element.tagName() != tag_name) {
continue;
}
return_list << element;
}
return(return_list);
}

View File

@@ -86,6 +86,9 @@ namespace QETXML
void modelHeaderDataFromXml( void modelHeaderDataFromXml(
const QDomElement &element, const QDomElement &element,
QAbstractItemModel *model); QAbstractItemModel *model);
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
const QString &tag_name);
} }
#endif // QETXML_H #endif // QETXML_H