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
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
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
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
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()));
}
}
/**
@brief ChangePropertiesCommand::ChangePropertiesCommand
Change the properties of the drawed element
@param scene : scene to belong the property
@param type : new type of element.
@param info
@param elmt_info : new info about type.
@param parent : parent undo
* @brief changeElementDataCommand::changeElementDataCommand
* Change the properties of the drawed element
* @param scene : scene to belong the property
* @param old_data : old data
* @param new_data : new data
* @param parent : parent undo command
*/
ChangePropertiesCommand::ChangePropertiesCommand(
ElementScene *scene,
const QString& type,
const DiagramContext& info,
const DiagramContext& elmt_info,
changeElementDataCommand::changeElementDataCommand(ElementScene *scene,
ElementData old_data,
ElementData new_data,
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;
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ées de l'élément"));
}
ChangePropertiesCommand::~ChangePropertiesCommand()
{}
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 changeElementDataCommand::undo() {
m_scene->setElementData(m_old);
QUndoCommand::undo();
}
void ChangePropertiesCommand::redo()
{
m_scene->m_elmt_type = m_type.last();
m_scene->m_elmt_kindInfo = m_kind_info.last();
m_scene->setElementInfo(m_elmt_info.last());
void changeElementDataCommand::redo() {
m_scene->setElementData(m_new);
QUndoCommand::redo();
}

View File

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

View File

@@ -51,7 +51,6 @@
*/
ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
QGraphicsScene(parent),
m_elmt_type("simple"),
m_qgi_manager(this),
m_element_editor(editor)
{
@@ -74,6 +73,24 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
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
*/
@@ -437,7 +454,7 @@ const QDomDocument ElementScene::toXml(bool all_parts)
-(qRound(size.y() - (ymargin/2)))));
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
QDomElement uuid = xml_document.createElement("uuid");
@@ -445,29 +462,28 @@ const QDomDocument ElementScene::toXml(bool all_parts)
root.appendChild(uuid);
//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");
m_elmt_kindInfo.toXml(kindInfo, "kindInformation");
root.appendChild(kindInfo);
root.appendChild(m_element_data.kindInfoToXml(xml_document));
}
if(
m_elmt_type == "simple"
|| m_elmt_type == "master"
|| m_elmt_type == "terminal")
if(type_ == ElementData::Simple ||
type_ == ElementData::Master ||
type_ == ElementData::Terminale)
{
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);
}
//complementary information about the element
QDomElement informations_element = xml_document.createElement("informations");
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");
@@ -546,8 +562,15 @@ void ElementScene::fromXml(
bool state = true;
//Consider the informations of the element
if (consider_informations) {
state = applyInformations(xml_document);
if (consider_informations)
{
// 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)
@@ -699,19 +722,6 @@ QETElementEditor* ElementScene::editor() const
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
Select the item in content,
@@ -833,7 +843,7 @@ void ElementScene::slot_editAuthorInformations()
// ajoute un QTextEdit au dialogue
QTextEdit *text_field = new QTextEdit();
text_field -> setAcceptRichText(false);
text_field -> setPlainText(informations());
text_field -> setPlainText(m_element_data.m_drawing_information);
text_field -> setReadOnly(is_read_only);
dialog_layout -> addWidget(text_field);
@@ -851,10 +861,10 @@ void ElementScene::slot_editAuthorInformations()
if (dialog_author.exec() == QDialog::Accepted && !is_read_only)
{
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(
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()
{
QString type = m_elmt_type;
DiagramContext kind_info = m_elmt_kindInfo;
DiagramContext elmt_info = m_elmt_information;
ElementPropertiesEditorWidget epew(type, kind_info, elmt_info);
ElementPropertiesEditorWidget epew(m_element_data);
epew.exec();
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));
if (m_element_data != epew.editedData())
{
undoStack().push(new changeElementDataCommand(this,
m_element_data,
epew.editedData()));
}
}
/**
@@ -898,15 +903,15 @@ void ElementScene::slot_editNames()
dialog_.setInformationText(tr("Vous pouvez spécifier le nom de l'élément dans plusieurs langues."));
NameListWidget *nlw_ = dialog_.namelistWidget();
nlw_->setNames(m_names_list);
nlw_->setNames(m_element_data.m_names_list);
nlw_->setReadOnly(is_read_only);
if (dialog_.exec() == QDialog::Accepted && !is_read_only && !nlw_->isEmpty())
{
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,
m_names_list,
m_element_data.m_names_list,
new_names));
}
}
@@ -1087,62 +1092,6 @@ QRectF ElementScene::elementContentBoundingRect(
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
Create and load the content describe in the xml document.

View File

@@ -21,6 +21,7 @@
#include "../diagramcontext.h"
#include "../qgimanager.h"
#include "elementcontent.h"
#include "../properties/elementdata.h"
#include <QtWidgets>
#include <QtXml>
@@ -65,11 +66,7 @@ class ElementScene : public QGraphicsScene
// attributes
private:
NamesList m_names_list; /// List of localized names
QString m_informations; /// Extra informations
QString m_elmt_type; /// element type
DiagramContext m_elmt_kindInfo,
m_elmt_information; /// element kind info
ElementData m_element_data; ///ElementData. Actualy in transition with old data storage
QGIManager m_qgi_manager;
QUndoStack m_undo_stack;
@@ -90,21 +87,20 @@ class ElementScene : public QGraphicsScene
// methods
public:
ElementData elementData();
void setElementData(ElementData data);
void setEventInterface (ESEventInterface *event_interface);
void clearEventInterface();
void setBehavior (ElementScene::Behavior);
ElementScene::Behavior behavior() const;
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 yGrid() const;
virtual void setGrid(int, int);
virtual const QDomDocument toXml(bool = true);
virtual QRectF boundingRectFromXml(const QDomDocument &);
virtual void fromXml(const QDomDocument &,
@@ -128,7 +124,6 @@ class ElementScene : public QGraphicsScene
void cut();
void copy();
QETElementEditor* editor() const;
void setElementInfo(const DiagramContext& dc);
protected:
void mouseMoveEvent (QGraphicsSceneMouseEvent *) override;
@@ -137,12 +132,10 @@ class ElementScene : public QGraphicsScene
void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
void keyPressEvent (QKeyEvent *event) override;
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
void drawForeground(QPainter *, const QRectF &) override;
private:
QRectF elementContentBoundingRect(const ElementContent &) const;
bool applyInformations(const QDomDocument &);
ElementContent loadContent(const QDomDocument &);
ElementContent addContent(const ElementContent &);
ElementContent addContentAtPos(const ElementContent &, const QPointF &);
@@ -180,39 +173,4 @@ class ElementScene : public QGraphicsScene
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

View File

@@ -318,7 +318,7 @@ void PartDynamicTextField::setText(const QString &text) {
void PartDynamicTextField::setInfoName(const QString &info_name) {
m_info_name = info_name;
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);
}
@@ -338,7 +338,7 @@ QString PartDynamicTextField::infoName() const{
void PartDynamicTextField::setCompositeText(const QString &text) {
m_composite_text = text;
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);
}
@@ -551,10 +551,10 @@ void PartDynamicTextField::elementInfoChanged()
return;
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())
setPlainText(autonum::AssignVariables::replaceVariable(
m_composite_text, elementScene() -> elementInformation()));
m_composite_text, elementScene()->elementData().m_informations));
}
void PartDynamicTextField::prepareAlignment()

View File

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

View File

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

View File

@@ -133,7 +133,9 @@ void QETElementEditor::contextMenu(QPoint p, QList<QAction *> actions)
*/
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()
{
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_elmt_scene -> undoStack().isClean()) {
title += tr("[Modifié]", "window title tag");
@@ -724,7 +726,8 @@ bool QETElementEditor::checkElement()
// Warning #1: Element haven't got terminal
// (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(
tr("Absence de borne", "warning title"),
tr(
@@ -736,7 +739,7 @@ bool QETElementEditor::checkElement()
}
// Check folio report element
if (m_elmt_scene -> elementType().contains("report"))
if (m_elmt_scene->elementData().m_type & ElementData::AllReport)
{
int terminal =0;
@@ -876,7 +879,7 @@ bool QETElementEditor::canClose()
"Voulez-vous enregistrer l'élément %1 ?",
"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::Cancel
);
@@ -917,7 +920,9 @@ void QETElementEditor::readSettings()
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;
}
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)
{
switch (type) {
@@ -202,13 +283,11 @@ ElementData::SlaveState ElementData::slaveStateFromString(const QString &string)
void ElementData::kindInfoFromXml(const QDomElement &xml_element)
{
if (m_type != ElementData::Master ||
m_type != ElementData::Slave) {
return;
}
if (m_type == ElementData::Master ||
m_type == ElementData::Slave)
{
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")) {
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;
QDomElement toXml(QDomDocument &xml_element) const 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 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 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 elementInfoKeys();
QStringList elementEditorElementInfoKeys();
QString elementInfoToVar(const QString &info);
QString infoToVar(const QString &info);

View File

@@ -554,3 +554,30 @@ void QETXML::modelHeaderDataFromXml(
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(
const QDomElement &element,
QAbstractItemModel *model);
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
const QString &tag_name);
}
#endif // QETXML_H