Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Marmsoler
f6bef3a365 WIP2 2020-10-11 15:43:51 +02:00
Martin Marmsoler
b69dea1747 WIP 2020-10-11 13:19:20 +02:00
7 changed files with 81 additions and 31 deletions

View File

@@ -927,6 +927,8 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
const QDomElement& root = document; const QDomElement& root = document;
// The first element must be a diagram // The first element must be a diagram
if (root.tagName() != "diagram") return(false); if (root.tagName() != "diagram") return(false);
qDebug() << "Diagram: " << root.attribute("title");
// Read attributes of this diagram // Read attributes of this diagram
if (consider_informations) { if (consider_informations) {
@@ -1023,6 +1025,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
} }
int state = 0; int state = 0;
qDebug() << "Element from collection: " << element_location;
Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state); Element *nvel_elmt = ElementFactory::Instance() -> createElement(element_location, nullptr, &state);
if (state) if (state)
{ {

View File

@@ -118,7 +118,7 @@ int DiagramContext::count() {
/** /**
* @brief DiagramContext::keyMustShow * @brief DiagramContext::keyMustShow
* @return the value pairs with key, if key no found, return false * @return the value pairs with key, if key not found, return false
*/ */
bool DiagramContext::keyMustShow(const QString &key) const { bool DiagramContext::keyMustShow(const QString &key) const {
if (m_content_show.contains(key)) if (m_content_show.contains(key))

View File

@@ -418,6 +418,7 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
{ {
//Minor workaround to find if there is a "input" tagg as label. //Minor workaround to find if there is a "input" tagg as label.
//If not, we set the tagg "label" to the first "input. //If not, we set the tagg "label" to the first "input.
// TODO: Remove in later version begin
QList <QDomElement> input_field; QList <QDomElement> input_field;
bool have_label = false; bool have_label = false;
for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input")) for (QDomElement input_node = node.firstChildElement("input") ; !input_node.isNull() ; input_node = input_node.nextSiblingElement("input"))
@@ -429,8 +430,11 @@ bool Element::buildFromXml(const QDomElement &xml_def_elmt, int *state)
have_label = true; have_label = true;
} }
} }
if(!have_label && !input_field.isEmpty()) if(!have_label && !input_field.isEmpty()) {
qDebug() << input_field.first().attribute("text");
input_field.first().setAttribute("tagg", "label"); input_field.first().setAttribute("tagg", "label");
}
// TODO: Remove in later version end
//Parse the definition //Parse the definition
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling())
@@ -716,16 +720,21 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
} else { } else {
setRotation(90*read_ori); setRotation(90*read_ori);
} }
// TODO: elementInformations are not read from the diagram section or? Yes see below
//Befor load the dynamic text field, //#######################################################################################################################
//we remove the dynamic text field created from the description of this element, to avoid doublons. //#### START #######################################################################################################
//#######################################################################################################################
//Before load the dynamic text field,
//we remove the dynamic text field created from the description of this element, to avoid doublons.
for(DynamicElementTextItem *deti : m_dynamic_text_list) for(DynamicElementTextItem *deti : m_dynamic_text_list)
delete deti; delete deti;
m_dynamic_text_list.clear(); m_dynamic_text_list.clear();
//************************// //************************//
//***Dynamic texts item***// //***Dynamic texts item***//
//************************// //************************//
// Texts in diagram section
for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName())) for (const QDomElement& qde : QET::findInDomElement(e, "dynamic_texts", DynamicElementTextItem::xmlTagName()))
{ {
DynamicElementTextItem *deti = new DynamicElementTextItem(this); DynamicElementTextItem *deti = new DynamicElementTextItem(this);
@@ -733,20 +742,24 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
deti->fromXml(qde); deti->fromXml(qde);
} }
// TODO: remove in later version begin
//************************// //************************//
//***Element texts item***// //***Element texts item***//
//************************// //************************//
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input"); // Inputs in diagram section
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input"); // Inputs in diagram section
//First case, we check for the text item converted to dynamic text item //First case, we check for the text item converted to dynamic text item
const QList <DynamicElementTextItem *> conv_deti_list = m_converted_text_from_xml_description.keys(); const QList <DynamicElementTextItem *> conv_deti_list = m_converted_text_from_xml_description.keys(); // Texts in element definition (elements collection)
QList <DynamicElementTextItem *> successfully_converted; QList <DynamicElementTextItem *> successfully_converted;
const QList <QDomElement> dom_inputs = inputs; const QList <QDomElement> dom_inputs = inputs;
for (DynamicElementTextItem *deti : conv_deti_list)
for (DynamicElementTextItem *deti : conv_deti_list) // Texts from element definition (elements collection)
{ {
for(const QDomElement& dom_input : dom_inputs) for(const QDomElement& dom_input : dom_inputs) // Inputs in diagram section
{ {
//we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored. //we use the same method used in ElementTextItem::fromXml to compar and know if the input dom element is for one of the text stored.
//The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element //The comparaison is made from the text position : if the position of the text is the same as the position stored in 'input' dom element
@@ -817,7 +830,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
group->fromXml(qde); group->fromXml(qde);
} }
//load informations //load elementInformations from diagram section
DiagramContext dc; DiagramContext dc;
dc.fromXml(e.firstChildElement("elementInformations"), "elementInformation"); dc.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
/** /**
@@ -991,6 +1004,12 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
} }
} }
} }
// TODO: remove in later version end
//#######################################################################################################################
//#### END #######################################################################################################
//#######################################################################################################################
m_state = QET::GIOK; m_state = QET::GIOK;
return(true); return(true);
} }

View File

@@ -186,6 +186,10 @@ QUndoCommand *DynamicElementTextItemEditor::associatedUndo() const
return nullptr; return nullptr;
} }
/*!
* \brief DynamicElementTextItemEditor::dataEdited
* Apply changes to the text item. It is called when dataChanged() signal is called
*/
void DynamicElementTextItemEditor::dataEdited() void DynamicElementTextItemEditor::dataEdited()
{ {
if (m_live_edit) if (m_live_edit)

View File

@@ -29,6 +29,10 @@ namespace Ui {
class DynamicElementTextItemEditor; class DynamicElementTextItemEditor;
} }
/*!
* \brief The DynamicElementTextItemEditor class
* Widget used to modify the properties of DynamicElementTextItem.
*/
class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidget class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidget
{ {
Q_OBJECT Q_OBJECT

View File

@@ -57,6 +57,10 @@ static int adjust_grp_row = 4;
static int frame_grp_row = 5; static int frame_grp_row = 5;
static int hold_to_bottom_grp_row = 6; static int hold_to_bottom_grp_row = 6;
const char* user_text = "Texte utilisateur";
const char* element_information = "Information de l'élément";
const char* composite_text = "Texte composé";
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) : DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
QStandardItemModel(parent), QStandardItemModel(parent),
m_element(element) m_element(element)
@@ -136,9 +140,9 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(DynamicElementTextI
src->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); src->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QString title; QString title;
if (deti->textFrom() == DynamicElementTextItem::UserText) title = tr("Texte utilisateur"); if (deti->textFrom() == DynamicElementTextItem::UserText) title = tr(user_text);
else if (deti->textFrom() == DynamicElementTextItem::ElementInfo) title = tr("Information de l'élément"); else if (deti->textFrom() == DynamicElementTextItem::ElementInfo) title = tr(element_information);
else title = tr("Texte composé"); else title = tr(composite_text);
QStandardItem *srca = new QStandardItem(title); QStandardItem *srca = new QStandardItem(title);
srca->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); srca->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
srca->setData(textFrom, Qt::UserRole+1); srca->setData(textFrom, Qt::UserRole+1);
@@ -172,7 +176,7 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(DynamicElementTextI
qsi->appendRow(qsi_list); qsi->appendRow(qsi_list);
//Composite text //Composite text
QStandardItem *composite = new QStandardItem(tr("Texte composé")); QStandardItem *composite = new QStandardItem(tr(composite_text));
composite->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); composite->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
DiagramContext dc; DiagramContext dc;
@@ -397,7 +401,7 @@ DynamicElementTextItem *DynamicElementTextModel::textFromItem(QStandardItem *ite
QStandardItem *text_item = item; QStandardItem *text_item = item;
while (text_item->parent()) while (text_item->parent()) // recursive search for the highest parent
text_item = text_item->parent(); text_item = text_item->parent();
if (m_texts_list.values().contains(text_item)) //The item is a text if (m_texts_list.values().contains(text_item)) //The item is a text
@@ -458,26 +462,26 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
QStandardItem *text_qsi = m_texts_list.value(deti); QStandardItem *text_qsi = m_texts_list.value(deti);
QString from = text_qsi->child(src_txt_row,1)->data(Qt::DisplayRole).toString(); QString from = text_qsi->child(src_txt_row,1)->data(Qt::DisplayRole).toString();
if ((from == tr("Texte utilisateur")) && (deti->textFrom() != DynamicElementTextItem::UserText)) if ((from == tr(user_text)) && (deti->textFrom() != DynamicElementTextItem::UserText))
new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::UserText), undo); new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::UserText), undo);
else if ((from == tr("Information de l'élément")) && (deti->textFrom() != DynamicElementTextItem::ElementInfo)) else if ((from == tr(element_information)) && (deti->textFrom() != DynamicElementTextItem::ElementInfo))
new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::ElementInfo), undo); new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::ElementInfo), undo);
else if ((from == tr("Texte composé")) && (deti->textFrom() != DynamicElementTextItem::CompositeText)) else if ((from == tr(composite_text)) && (deti->textFrom() != DynamicElementTextItem::CompositeText))
new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::CompositeText), undo); new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::CompositeText), undo);
if(from == tr("Texte utilisateur")) if(from == tr(user_text))
{ {
QString text = text_qsi->child(usr_txt_row,1)->data(Qt::DisplayRole).toString(); QString text = text_qsi->child(usr_txt_row,1)->data(Qt::DisplayRole).toString();
if (text != deti->text()) if (text != deti->text())
new QPropertyUndoCommand(deti, "text", QVariant(deti->text()), QVariant(text), undo); new QPropertyUndoCommand(deti, "text", QVariant(deti->text()), QVariant(text), undo);
} }
else if (from == tr("Information de l'élément")) else if (from == tr(element_information))
{ {
QString info_name = text_qsi->child(info_txt_row,1)->data(Qt::UserRole+2).toString(); QString info_name = text_qsi->child(info_txt_row,1)->data(Qt::UserRole+2).toString();
if(info_name != deti->infoName()) if(info_name != deti->infoName())
new QPropertyUndoCommand(deti, "infoName", QVariant(deti->infoName()), QVariant(info_name), undo); new QPropertyUndoCommand(deti, "infoName", QVariant(deti->infoName()), QVariant(info_name), undo);
} }
else if (from == tr("Texte composé")) else if (from == tr(composite_text))
{ {
QString composite_text = text_qsi->child(compo_txt_row,1)->data(Qt::UserRole+2).toString(); QString composite_text = text_qsi->child(compo_txt_row,1)->data(Qt::UserRole+2).toString();
if(composite_text != deti->compositeText()) if(composite_text != deti->compositeText())
@@ -1112,6 +1116,7 @@ void DynamicElementTextModel::enableSourceText(DynamicElementTextItem *deti, Dyn
case DynamicElementTextItem::CompositeText: compo = true;break; case DynamicElementTextItem::CompositeText: compo = true;break;
} }
m_ignore_item_change = true;
//User text //User text
qsi->child(usr_txt_row,0)->setEnabled(usr); qsi->child(usr_txt_row,0)->setEnabled(usr);
qsi->child(usr_txt_row,1)->setEnabled(usr); qsi->child(usr_txt_row,1)->setEnabled(usr);
@@ -1120,6 +1125,7 @@ void DynamicElementTextModel::enableSourceText(DynamicElementTextItem *deti, Dyn
qsi->child(info_txt_row,1)->setEnabled(info); qsi->child(info_txt_row,1)->setEnabled(info);
//Composite text //Composite text
qsi->child(compo_txt_row,0)->setEnabled(compo); qsi->child(compo_txt_row,0)->setEnabled(compo);
m_ignore_item_change = false;
qsi->child(compo_txt_row,1)->setEnabled(compo); qsi->child(compo_txt_row,1)->setEnabled(compo);
} }
@@ -1157,6 +1163,10 @@ void DynamicElementTextModel::enableGroupRotationAndPos(ElementTextItemGroup *gr
void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi) void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi)
{ {
if (m_ignore_item_change)
return;
DynamicElementTextItem *deti = textFromItem(qsi); DynamicElementTextItem *deti = textFromItem(qsi);
ElementTextItemGroup *etig = groupFromItem(qsi); ElementTextItemGroup *etig = groupFromItem(qsi);
if (!deti && !etig) if (!deti && !etig)
@@ -1170,15 +1180,15 @@ void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi)
dc = deti->elementUseForInfo()->elementInformations(); dc = deti->elementUseForInfo()->elementInformations();
if (qsi->data().toInt() == textFrom) if (qsi->data().toInt() == textFrom)
{ { // change textFrom
QString from = qsi->data(Qt::DisplayRole).toString(); QString from = qsi->data(Qt::DisplayRole).toString();
if (from == tr("Texte utilisateur")) if (from == tr(user_text))
{ {
enableSourceText(deti, DynamicElementTextItem::UserText); enableSourceText(deti, DynamicElementTextItem::UserText);
text_qsi->setData(text_qsi->child(usr_txt_row,1)->data(Qt::DisplayRole).toString()); text_qsi->setData(text_qsi->child(usr_txt_row,1)->data(Qt::DisplayRole).toString());
} }
else if (from == tr("Information de l'élément")) else if (from == tr(element_information))
{ {
enableSourceText(deti, DynamicElementTextItem::ElementInfo); enableSourceText(deti, DynamicElementTextItem::ElementInfo);
QString info = text_qsi->child(info_txt_row,1)->data(Qt::UserRole+2).toString(); QString info = text_qsi->child(info_txt_row,1)->data(Qt::UserRole+2).toString();
@@ -1213,7 +1223,7 @@ void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi)
//We emit the signal only if @qsi is in the second column, because the data are stored on this column //We emit the signal only if @qsi is in the second column, because the data are stored on this column
//the first column is use only for display the title of the property, except for the name of texts group //the first column is use only for display the title of the property, except for the name of texts group
if((m_groups_list.values().contains(qsi) || qsi->column() == 1) && !m_block_dataChanged) if((m_groups_list.values().contains(qsi) || qsi->column() == 1) && !m_block_dataChanged)
emit dataChanged(); emit dataChanged(); // TODO: where it goes?
if(deti) deti->updateXref(); if(deti) deti->updateXref();
} }
@@ -1309,9 +1319,9 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V
{ {
switch (deti->textFrom()) switch (deti->textFrom())
{ {
case DynamicElementTextItem::UserText: qsi->child(0,1)->setData(tr("Texte utilisateur"), Qt::DisplayRole); break; case DynamicElementTextItem::UserText: qsi->child(0,1)->setData(tr(user_text), Qt::DisplayRole); break;
case DynamicElementTextItem::ElementInfo : qsi->child(0,1)->setData(tr("Information de l'élément"), Qt::DisplayRole); break; case DynamicElementTextItem::ElementInfo : qsi->child(0,1)->setData(tr(element_information), Qt::DisplayRole); break;
case DynamicElementTextItem::CompositeText : qsi->child(0,1)->setData(tr("Texte composé"), Qt::DisplayRole); break; case DynamicElementTextItem::CompositeText : qsi->child(0,1)->setData(tr(composite_text), Qt::DisplayRole); break;
} }
enableSourceText(deti, deti->textFrom()); enableSourceText(deti, deti->textFrom());
qsi->setData(deti->toPlainText(), Qt::DisplayRole); qsi->setData(deti->toPlainText(), Qt::DisplayRole);
@@ -1448,6 +1458,15 @@ DynamicTextItemDelegate::DynamicTextItemDelegate(QObject *parent) :
QStyledItemDelegate(parent) QStyledItemDelegate(parent)
{} {}
/*!
* \brief DynamicTextItemDelegate::createEditor
* Different widgets are used depending of the data which should be shown in the view.
* For example for choosing color, a color chooser is used.
* \param parent
* \param option
* \param index
* \return
*/
QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
switch (index.data(Qt::UserRole+1).toInt()) switch (index.data(Qt::UserRole+1).toInt())
@@ -1456,9 +1475,9 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti
{ {
QComboBox *qcb = new QComboBox(parent); QComboBox *qcb = new QComboBox(parent);
qcb->setObjectName("text_from"); qcb->setObjectName("text_from");
qcb->addItem(tr("Texte utilisateur")); qcb->addItem(tr(user_text));
qcb->addItem(tr("Information de l'élément")); qcb->addItem(tr(element_information));
qcb->addItem(tr("Texte composé")); qcb->addItem(tr(composite_text));
return qcb; return qcb;
} }
case DynamicElementTextModel::infoText: case DynamicElementTextModel::infoText:

View File

@@ -106,6 +106,7 @@ class DynamicElementTextModel : public QStandardItemModel
QHash <DynamicElementTextItem *, QList<QMetaObject::Connection>> m_hash_text_connect; QHash <DynamicElementTextItem *, QList<QMetaObject::Connection>> m_hash_text_connect;
QHash <ElementTextItemGroup *, QList<QMetaObject::Connection>> m_hash_group_connect; QHash <ElementTextItemGroup *, QList<QMetaObject::Connection>> m_hash_group_connect;
bool m_block_dataChanged = false; bool m_block_dataChanged = false;
bool m_ignore_item_change{false};
}; };
class DynamicTextItemDelegate : public QStyledItemDelegate class DynamicTextItemDelegate : public QStyledItemDelegate