From 29748874fd60f4f592afa14d94416cfbb772f9eb Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 16 Aug 2017 13:52:15 +0000 Subject: [PATCH] Dynamic element text item, can have for source of text a composite text, a text composed both by user typed text and element info. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5021 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/autoNum/assignvariables.cpp | 25 ++++ sources/autoNum/assignvariables.h | 2 + sources/qetapp.cpp | 23 ++++ sources/qetapp.h | 1 + .../dynamicelementtextitem.cpp | 65 ++++++++-- .../qetgraphicsitem/dynamicelementtextitem.h | 21 ++-- .../abstractelementpropertieseditorwidget.h | 2 +- sources/ui/compositetexteditdialog.cpp | 66 +++++++++++ sources/ui/compositetexteditdialog.h | 42 +++++++ sources/ui/compositetexteditdialog.ui | 81 +++++++++++++ sources/ui/dynamicelementtextmodel.cpp | 111 ++++++++++++++++-- sources/ui/dynamicelementtextmodel.h | 1 + 12 files changed, 416 insertions(+), 24 deletions(-) create mode 100644 sources/ui/compositetexteditdialog.cpp create mode 100644 sources/ui/compositetexteditdialog.h create mode 100644 sources/ui/compositetexteditdialog.ui diff --git a/sources/autoNum/assignvariables.cpp b/sources/autoNum/assignvariables.cpp index 3b53411e6..b89d02aca 100644 --- a/sources/autoNum/assignvariables.cpp +++ b/sources/autoNum/assignvariables.cpp @@ -154,6 +154,31 @@ namespace autonum seqStruct = av.m_seq_struct; return av.m_assigned_label; } + + /** + * @brief AssignVariables::replaceVariable + * Replace the variables in @formula in form %{my-var} to the corresponding value stored in @dc + * @param formula + * @param dc + * @return + */ + QString AssignVariables::replaceVariable(const QString &formula, const DiagramContext &dc) + { + QString str = formula; + str.replace("%{label}", dc.value("label").toString()); + str.replace("%{comment}", dc.value("comment").toString()); + str.replace("%{designation}", dc.value("designation").toString()); + str.replace("%{manufacturer}", dc.value("manufacturer").toString()); + str.replace("%{manufacturer-reference}", dc.value("manufacturer-reference").toString()); + str.replace("%{auxiliary1}", dc.value("auxiliary1").toString()); + str.replace("%{auxiliary2}", dc.value("auxiliary2").toString()); + str.replace("%{machine-manufacturer-reference}", dc.value("machine-manufacturer-reference").toString()); + str.replace("%{location}", dc.value("location").toString()); + str.replace("%{function}", dc.value("function").toString()); + str.replace("%{void}", QString()); + + return str; + } AssignVariables::AssignVariables(QString formula, sequentialNumbers seqStruct , Diagram *diagram, const Element *elmt): m_diagram(diagram), diff --git a/sources/autoNum/assignvariables.h b/sources/autoNum/assignvariables.h index 8a7e72f7e..dbdee8b31 100644 --- a/sources/autoNum/assignvariables.h +++ b/sources/autoNum/assignvariables.h @@ -23,6 +23,7 @@ #include #include "numerotationcontext.h" +#include "diagramcontext.h" class Diagram; class Element; @@ -61,6 +62,7 @@ namespace autonum { public: static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt = nullptr); + static QString replaceVariable (const QString &formula, const DiagramContext &dc); private: AssignVariables(QString formula, sequentialNumbers seqStruct , Diagram *diagram, const Element *elmt = nullptr); diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 953568bfe..82e058989 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -318,6 +318,29 @@ QString QETApp::elementTranslatedInfoKey(const QString &info) return (info); } +/** + * @brief QETApp::elementInfoToVar + * @param info + * @return var in form %{my-var} corresponding to the info, if there is not available var for the given info + * the returned var is %{void} + */ +QString QETApp::elementInfoToVar(const QString &info) +{ + if (info == "formula") return QString("%{formula}"); + else if (info == "label") return QString("%{label}"); + else if (info == "comment") return QString("%{comment}"); + else if (info == "designation") return QString("%{designation}"); + else if (info == "manufacturer") return QString("%{manufacturer}"); + else if (info == "manufacturer-reference") return QString("%{manufacturer-reference}"); + else if (info == "auxiliary1") return QString("%{auxiliary1}"); + else if (info == "auxiliary2") return QString("%{auxiliary2}"); + else if (info == "machine-manufacturer-reference") return QString("%{machine-manufacturer-reference}"); + else if (info == "location") return QString("%{location}"); + else if (info == "function") return QString("%{function}"); + + return (QString ("%{void}")); +} + /** @return the common title block templates collection, i.e. the one provided by QElecrotTech diff --git a/sources/qetapp.h b/sources/qetapp.h index b59fbda40..2ad729bbb 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -73,6 +73,7 @@ class QETApp : public QETSingleApplication { static ElementsCollectionCache *collectionCache(); static QStringList elementInfoKeys(); static QString elementTranslatedInfoKey(const QString &); + static QString elementInfoToVar(const QString &info); static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index b66ce0ff0..c6d96706e 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -84,6 +84,14 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const dom_info_name.appendChild(dom_doc.createTextNode(m_info_name)); root_element.appendChild(dom_info_name); } + + //Composite text + if(!m_composite_text.isEmpty()) + { + QDomElement dom_comp_text = dom_doc.createElement("composite_text"); + dom_comp_text.appendChild(dom_doc.createTextNode(m_composite_text)); + root_element.appendChild(dom_comp_text); + } //tagg if (!m_tagg.isEmpty()) @@ -142,6 +150,11 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt) QDomElement dom_info_name = dom_elmt.firstChildElement("info_name"); if(!dom_info_name.isNull()) m_info_name = dom_info_name.text(); + + //Composite text + QDomElement dom_comp_text = dom_elmt.firstChildElement("composite_text"); + if(!dom_comp_text.isNull()) + m_composite_text = dom_comp_text.text(); //tagg QDomElement dom_tagg = dom_elmt.firstChildElement("tagg"); @@ -177,21 +190,29 @@ DynamicElementTextItem::TextFrom DynamicElementTextItem::textFrom() const { */ void DynamicElementTextItem::setTextFrom(DynamicElementTextItem::TextFrom text_from) { - m_text_from = text_from; - setNoEditable(m_text_from == ElementInfo? true : false); + setNoEditable(text_from == ElementInfo? true : false); - if(m_text_from == UserText) + if(text_from == UserText) { setPlainText(m_text); - disconnect(m_parent_element, &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged); + disconnect(m_parent_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged); } - else if (m_text_from == ElementInfo && m_parent_element) + else if (text_from == ElementInfo && m_parent_element) { setPlainText(m_parent_element->elementInformations().value(m_info_name).toString()); - connect(m_parent_element, &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged); + + if(m_text_from == UserText) + connect(m_parent_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged); + } + else if (text_from == CompositeText && m_parent_element) + { + setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, m_parent_element->elementInformations())); + if(m_text_from == UserText) + connect(m_parent_element.data(), &Element::elementInfoChange, this, &DynamicElementTextItem::elementInfoChanged); } - emit TextFromChanged(m_text_from); + m_text_from = text_from; + emit textFromChanged(m_text_from); } /** @@ -246,13 +267,29 @@ void DynamicElementTextItem::setInfoName(const QString &info_name) setPlainText(m_parent_element->elementInformations().value(info_name).toString()); } - emit InfoNameChanged(info_name); + emit infoNameChanged(info_name); } QString DynamicElementTextItem::infoName() const { return m_info_name; } +void DynamicElementTextItem::setCompositeText(const QString &text) +{ + m_composite_text = text; + + + if(m_parent_element) { + setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, m_parent_element->elementInformations())); + } + emit compositeTextChanged(m_composite_text); +} + +QString DynamicElementTextItem::compositeText() const +{ + return m_composite_text; +} + /** * @brief DynamicElementTextItem::mouseMoveEvent * @param event @@ -307,6 +344,16 @@ void DynamicElementTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void DynamicElementTextItem::elementInfoChanged() { - setPlainText(m_parent_element->elementInformations().value(m_info_name).toString()); + if(!m_parent_element) + return; + + QString final_text; + + if (m_text_from == ElementInfo) + final_text = m_parent_element->elementInformations().value(m_info_name).toString(); + else if (m_text_from == CompositeText) + final_text = autonum::AssignVariables::replaceVariable(m_composite_text, m_parent_element->elementInformations()); + + setPlainText(final_text); } diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h index 00ca69066..3bff68534 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.h +++ b/sources/qetgraphicsitem/dynamicelementtextitem.h @@ -20,6 +20,7 @@ #include "diagramtextitem.h" #include +#include class Element; @@ -35,14 +36,16 @@ class DynamicElementTextItem : public DiagramTextItem Q_PROPERTY(QString tagg READ tagg WRITE setTagg NOTIFY taggChanged) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) - Q_PROPERTY(TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY TextFromChanged) - Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY InfoNameChanged) + Q_PROPERTY(TextFrom textFrom READ textFrom WRITE setTextFrom NOTIFY textFromChanged) + Q_PROPERTY(QString infoName READ infoName WRITE setInfoName NOTIFY infoNameChanged) + Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged) public: Q_ENUMS(TextFrom) enum TextFrom { UserText, - ElementInfo + ElementInfo, + CompositeText }; enum {Type = UserType + 1010}; int type() const override {return Type;} @@ -50,8 +53,9 @@ class DynamicElementTextItem : public DiagramTextItem signals: void taggChanged(QString tagg); void textChanged(QString text); - void TextFromChanged(DynamicElementTextItem::TextFrom text_from); - void InfoNameChanged(QString info); + void textFromChanged(DynamicElementTextItem::TextFrom text_from); + void infoNameChanged(QString info); + void compositeTextChanged(QString text); public: DynamicElementTextItem(Element *parent_element); @@ -74,6 +78,8 @@ class DynamicElementTextItem : public DiagramTextItem static QString xmlTaggName() {return QString("dynamic_elmt_text");} void setInfoName(const QString &info_name); QString infoName() const; + void setCompositeText(const QString &text); + QString compositeText() const; protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; @@ -83,10 +89,11 @@ class DynamicElementTextItem : public DiagramTextItem void elementInfoChanged(); private: - Element *m_parent_element = nullptr; + QPointer m_parent_element; QString m_tagg, m_text, - m_info_name; + m_info_name, + m_composite_text; DynamicElementTextItem::TextFrom m_text_from = UserText; QUuid m_uuid; }; diff --git a/sources/ui/abstractelementpropertieseditorwidget.h b/sources/ui/abstractelementpropertieseditorwidget.h index 584bd70a9..100681d57 100644 --- a/sources/ui/abstractelementpropertieseditorwidget.h +++ b/sources/ui/abstractelementpropertieseditorwidget.h @@ -19,7 +19,7 @@ #define ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H #include "PropertiesEditor/propertieseditorwidget.h" -#include "QPointer" +#include class Element; diff --git a/sources/ui/compositetexteditdialog.cpp b/sources/ui/compositetexteditdialog.cpp new file mode 100644 index 000000000..0da6588ff --- /dev/null +++ b/sources/ui/compositetexteditdialog.cpp @@ -0,0 +1,66 @@ +#include "compositetexteditdialog.h" +#include "ui_compositetexteditdialog.h" +#include "dynamicelementtextitem.h" +#include "element.h" +#include "qetapp.h" + +CompositeTextEditDialog::CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent) : + QDialog(parent), + ui(new Ui::CompositeTextEditDialog), + m_text(text) +{ + ui->setupUi(this); + m_default_text = m_text->compositeText(); + ui->m_plain_text_edit->setPlainText(m_default_text); + setUpComboBox(); +} + +CompositeTextEditDialog::~CompositeTextEditDialog() { + delete ui; +} + +/** + * @brief CompositeTextEditDialog::plainText + * @return The edited text + */ +QString CompositeTextEditDialog::plainText() const { + return ui->m_plain_text_edit->toPlainText(); +} + +/** + * @brief CompositeTextEditDialog::setUpComboBox + * Add the available element information in the combo box + */ +void CompositeTextEditDialog::setUpComboBox() +{ + QStringList qstrl; + Element *elmt = m_text->ParentElement(); + if(!elmt) + return; + + QStringList info_list = QETApp::elementInfoKeys(); + info_list.removeAll("formula"); //No need to have formula + DiagramContext dc = elmt->elementInformations(); + + for(QString info : info_list) + { + if(dc.contains(info)) + qstrl << info; + } + + //We use a QMap because the keys of the map are sorted, then no matter the curent local, + //the value of the combo box are always alphabetically sorted + QMap info_map; + for(QString str : qstrl) { + info_map.insert(QETApp::elementTranslatedInfoKey(str), QETApp::elementInfoToVar(str)); + } + for(QString key : info_map.keys()) { + ui->m_info_cb->addItem(key, info_map.value(key)); + } +} + +void CompositeTextEditDialog::on_m_info_cb_activated(const QString &arg1) +{ + Q_UNUSED(arg1) + ui->m_plain_text_edit->insertPlainText(ui->m_info_cb->currentData().toString()); +} diff --git a/sources/ui/compositetexteditdialog.h b/sources/ui/compositetexteditdialog.h new file mode 100644 index 000000000..502397a77 --- /dev/null +++ b/sources/ui/compositetexteditdialog.h @@ -0,0 +1,42 @@ +#ifndef COMPOSITETEXTEDITDIALOG_H +#define COMPOSITETEXTEDITDIALOG_H + +#include + +namespace Ui { + class CompositeTextEditDialog; +} + +class DynamicElementTextItem; + +/** + * @brief The CompositeTextEditDialog class + * CompositeTextEditDialog display a dialog use to write the complex text + * of a dynamic element text item. + * This dialog provide a QComboBox to quickly add an information of the element + * in the composite text. + */ +class CompositeTextEditDialog : public QDialog +{ + Q_OBJECT + + public: + explicit CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent = nullptr); + ~CompositeTextEditDialog() override; + + QString plainText() const; + + private slots: + void on_m_info_cb_activated(const QString &arg1); + + private : + void setUpComboBox(); + QString infoToVar(const QString& info) const; + + private: + Ui::CompositeTextEditDialog *ui; + QString m_default_text; + DynamicElementTextItem *m_text = nullptr; +}; + +#endif // COMPOSITETEXTEDITDIALOG_H diff --git a/sources/ui/compositetexteditdialog.ui b/sources/ui/compositetexteditdialog.ui new file mode 100644 index 000000000..6e1d6edd4 --- /dev/null +++ b/sources/ui/compositetexteditdialog.ui @@ -0,0 +1,81 @@ + + + CompositeTextEditDialog + + + + 0 + 0 + 664 + 538 + + + + Dialog + + + + + + + + + Ajouter une variable : + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Entrée votre votre texte composé ici, en vous aidant des variables disponible + + + + + + + + + m_button_box + accepted() + CompositeTextEditDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + m_button_box + rejected() + CompositeTextEditDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sources/ui/dynamicelementtextmodel.cpp b/sources/ui/dynamicelementtextmodel.cpp index b5527dabb..38de27cdf 100644 --- a/sources/ui/dynamicelementtextmodel.cpp +++ b/sources/ui/dynamicelementtextmodel.cpp @@ -26,6 +26,7 @@ #include "QPropertyUndoCommand/qpropertyundocommand.h" #include "qetapp.h" #include "element.h" +#include "compositetexteditdialog.h" DynamicElementTextModel::DynamicElementTextModel(QObject *parent) : QStandardItemModel(parent) @@ -64,7 +65,11 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti) QStandardItem *src = new QStandardItem(tr("Source du texte")); src->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); - QStandardItem *srca = new QStandardItem(deti->textFrom() == DynamicElementTextItem::UserText ? tr("Texte utilisateur") : tr("Information de l'élément")); + QString title; + if (deti->textFrom() == DynamicElementTextItem::UserText) title = tr("Texte utilisateur"); + else if (deti->textFrom() == DynamicElementTextItem::ElementInfo) title = tr("Information de l'élément"); + else title = tr("Texte composé"); + QStandardItem *srca = new QStandardItem(title); srca->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); srca->setData(textFrom, Qt::UserRole+1); @@ -95,6 +100,21 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti) qsi_list.clear(); qsi_list << info << infoa; src->appendRow(qsi_list); + + //Composite text + QStandardItem *composite = new QStandardItem(tr("Texte composé")); + composite->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + QStandardItem *compositea = new QStandardItem(deti->compositeText().isEmpty() ? + tr("Mon texte composé") : + autonum::AssignVariables::replaceVariable(deti->compositeText(), deti->ParentElement()->elementInformations())); + compositea->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); + compositea->setData(DynamicElementTextModel::compositeText, Qt::UserRole+1); //Use to know the edited thing + compositea->setData(deti->compositeText(), Qt::UserRole+2); //Use to know to element composite formula + + qsi_list.clear(); + qsi_list << composite << compositea; + src->appendRow(qsi_list); //Size @@ -220,6 +240,8 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::UserText), undo); else if ((from == tr("Information de l'élément")) && (deti->textFrom() != DynamicElementTextItem::ElementInfo)) new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::ElementInfo), undo); + else if ((from == tr("Texte composé")) && (deti->textFrom() != DynamicElementTextItem::CompositeText)) + new QPropertyUndoCommand(deti, "textFrom", QVariant(deti->textFrom()), QVariant(DynamicElementTextItem::CompositeText), undo); if(from == tr("Texte utilisateur")) { @@ -233,6 +255,12 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem if(info_name != deti->infoName()) new QPropertyUndoCommand(deti, "infoName", QVariant(deti->infoName()), QVariant(info_name), undo); } + else if (from == tr("Texte composé")) + { + QString composite_text = text_qsi->child(0,0)->child(2,1)->data(Qt::UserRole+2).toString(); + if(composite_text != deti->compositeText()) + new QPropertyUndoCommand(deti, "compositeText", QVariant(deti->compositeText()), QVariant(composite_text), undo); + } int fs = text_qsi->child(1,1)->data(Qt::EditRole).toInt(); if (fs != deti->fontSize()) @@ -262,9 +290,13 @@ void DynamicElementTextModel::enableSourceText(DynamicElementTextItem *deti, Dyn QStandardItem *qsi = m_texts_list.value(deti)->child(0,0); - bool usr = true, info = false; - if(tf == DynamicElementTextItem::ElementInfo) { - usr = false; info = true;} + bool usr = false, info = false, compo = false; + + switch (tf) { + case DynamicElementTextItem::UserText: usr = true; break; + case DynamicElementTextItem::ElementInfo: info = true; break; + case DynamicElementTextItem::CompositeText: compo = true; break; + } //User text qsi->child(0,0)->setEnabled(usr); @@ -272,6 +304,9 @@ void DynamicElementTextModel::enableSourceText(DynamicElementTextItem *deti, Dyn //Info text qsi->child(1,0)->setEnabled(info); qsi->child(1,1)->setEnabled(info); + //Composite text + qsi->child(2,0)->setEnabled(compo); + qsi->child(2,1)->setEnabled(compo); } void DynamicElementTextModel::dataEdited(QStandardItem *qsi) @@ -280,13 +315,17 @@ void DynamicElementTextModel::dataEdited(QStandardItem *qsi) if (!deti) return; + blockSignals(true); + if (qsi->data().toInt() == textFrom) { QString from = qsi->data(Qt::DisplayRole).toString(); if (from == tr("Texte utilisateur")) enableSourceText(deti, DynamicElementTextItem::UserText); - else + else if (from == tr("Information de l'élément")) enableSourceText(deti, DynamicElementTextItem::ElementInfo); + else + enableSourceText(deti, DynamicElementTextItem::CompositeText); } else if (qsi->data().toInt() == userText) { @@ -298,6 +337,13 @@ void DynamicElementTextModel::dataEdited(QStandardItem *qsi) QString info = qsi->data(Qt::UserRole+2).toString(); m_texts_list.value(deti)->setData(deti->ParentElement()->elementInformations().value(info), Qt::DisplayRole); } + else if (qsi->data().toInt() == compositeText && deti->ParentElement()) + { + QString compo = qsi->data(Qt::UserRole+2).toString(); + m_texts_list.value(deti)->setData(autonum::AssignVariables::replaceVariable(compo, deti->ParentElement()->elementInformations()), Qt::DisplayRole); + } + + blockSignals(false); } /** @@ -319,7 +365,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s connection_list << connect(deti, &DynamicElementTextItem::fontSizeChanged, [deti,this](){this->updateDataFromText(deti, size);}); connection_list << connect(deti, &DynamicElementTextItem::taggChanged, [deti,this](){this->updateDataFromText(deti, tagg);}); connection_list << connect(deti, &DynamicElementTextItem::textChanged, [deti,this](){this->updateDataFromText(deti, userText);}); - connection_list << connect(deti, &DynamicElementTextItem::TextFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);}); + connection_list << connect(deti, &DynamicElementTextItem::textFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);}); m_hash_text_connect.insert(deti, connection_list); } @@ -344,8 +390,14 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V switch (type) { case textFrom: - qsi->child(0,1)->setData(deti->textFrom() == DynamicElementTextItem::UserText ? tr("Texte utilisateur") : tr("Information de l'élément"), Qt::DisplayRole); + { + switch (deti->textFrom()) { + case DynamicElementTextItem::UserText: qsi->child(0,1)->setData(tr("Texte utilisateur"), Qt::DisplayRole); break; + case DynamicElementTextItem::ElementInfo : qsi->child(0,1)->setData(tr("Information de l'élément"), Qt::DisplayRole); break; + case DynamicElementTextItem::CompositeText : qsi->child(0,1)->setData(tr("Texte composé"), Qt::DisplayRole); break; + } break; + } case userText: { QStandardItem *qsia = qsi->child(0,0); @@ -355,6 +407,8 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V } case infoText: break; + case compositeText: + break; case size: qsi->child(1,1)->setData(deti->fontSize(), Qt::EditRole); break; @@ -389,6 +443,7 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti QComboBox *qcb = new QComboBox(parent); qcb->addItem(tr("Texte utilisateur")); qcb->addItem(tr("Information de l'élément")); + qcb->addItem(tr("Texte composé")); return qcb; } case DynamicElementTextModel::infoText: @@ -417,6 +472,22 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti } return qcb; } + case DynamicElementTextModel::compositeText: + { + const DynamicElementTextModel *detm = static_cast(index.model()); + QStandardItem *qsi = detm->itemFromIndex(index); + + if(!qsi) + break; + + DynamicElementTextItem *deti = detm->textFromIndex(index); + if(!deti) + break; + + CompositeTextEditDialog *cted = new CompositeTextEditDialog(deti); + cted->setObjectName("composite_text"); + return cted; + } case DynamicElementTextModel::color: { QColorDialog *cd = new QColorDialog(index.data(Qt::EditRole).value()); @@ -459,6 +530,32 @@ void DynamicTextItemDelegate::setModelData(QWidget *editor, QAbstractItemModel * } } + else if (editor->objectName() == "composite_text") + { + if (QStandardItemModel *qsim = dynamic_cast(model)) + { + if(QStandardItem *qsi = qsim->itemFromIndex(index)) + { + + CompositeTextEditDialog *cted = static_cast(editor); + + QString edited_text = cted->plainText(); + QString assigned_text; + + const DynamicElementTextModel *detm = static_cast(index.model()); + DynamicElementTextItem *deti = detm->textFromIndex(index); + if(deti) + { + DiagramContext dc = deti->ParentElement()->elementInformations(); + assigned_text = autonum::AssignVariables::replaceVariable(edited_text, dc); + } + + qsi->setData(assigned_text, Qt::DisplayRole); + qsi->setData(edited_text, Qt::UserRole+2); + return; + } + } + } } QStyledItemDelegate::setModelData(editor, model, index); diff --git a/sources/ui/dynamicelementtextmodel.h b/sources/ui/dynamicelementtextmodel.h index c9fe5d783..d048d3663 100644 --- a/sources/ui/dynamicelementtextmodel.h +++ b/sources/ui/dynamicelementtextmodel.h @@ -39,6 +39,7 @@ class DynamicElementTextModel : public QStandardItemModel textFrom =1, userText, infoText, + compositeText, size, tagg, color