[qet] qet/qet: [5021] Dynamic element text item, can have for source of text a composite text, a text composed both by user typed text and element info. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] qet/qet: [5021] Dynamic element text item, can have for source of text a composite text, a text composed both by user typed text and element info.
- From: subversion@xxxxxxxxxxxxx
- Date: Wed, 16 Aug 2017 15:52:16 +0200
Revision: 5021
Author: blacksun
Date: 2017-08-16 15:52:15 +0200 (Wed, 16 Aug 2017)
Log Message:
-----------
Dynamic element text item, can have for source of text a composite text, a text composed both by user typed text and element info.
Modified Paths:
--------------
trunk/sources/autoNum/assignvariables.cpp
trunk/sources/autoNum/assignvariables.h
trunk/sources/qetapp.cpp
trunk/sources/qetapp.h
trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
trunk/sources/qetgraphicsitem/dynamicelementtextitem.h
trunk/sources/ui/abstractelementpropertieseditorwidget.h
trunk/sources/ui/dynamicelementtextmodel.cpp
trunk/sources/ui/dynamicelementtextmodel.h
Added Paths:
-----------
trunk/sources/ui/compositetexteditdialog.cpp
trunk/sources/ui/compositetexteditdialog.h
trunk/sources/ui/compositetexteditdialog.ui
Modified: trunk/sources/autoNum/assignvariables.cpp
===================================================================
--- trunk/sources/autoNum/assignvariables.cpp 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/autoNum/assignvariables.cpp 2017-08-16 13:52:15 UTC (rev 5021)
@@ -154,7 +154,32 @@
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),
m_arg_formula(formula),
Modified: trunk/sources/autoNum/assignvariables.h
===================================================================
--- trunk/sources/autoNum/assignvariables.h 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/autoNum/assignvariables.h 2017-08-16 13:52:15 UTC (rev 5021)
@@ -23,6 +23,7 @@
#include <QStringList>
#include "numerotationcontext.h"
+#include "diagramcontext.h"
class Diagram;
class Element;
@@ -61,6 +62,7 @@
{
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);
Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/qetapp.cpp 2017-08-16 13:52:15 UTC (rev 5021)
@@ -319,6 +319,29 @@
}
/**
+ * @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
*/
Modified: trunk/sources/qetapp.h
===================================================================
--- trunk/sources/qetapp.h 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/qetapp.h 2017-08-16 13:52:15 UTC (rev 5021)
@@ -73,6 +73,7 @@
static ElementsCollectionCache *collectionCache();
static QStringList elementInfoKeys();
static QString elementTranslatedInfoKey(const QString &);
+ static QString elementInfoToVar(const QString &info);
static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection();
static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection();
Modified: trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/qetgraphicsitem/dynamicelementtextitem.cpp 2017-08-16 13:52:15 UTC (rev 5021)
@@ -84,6 +84,14 @@
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 @@
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 @@
*/
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,7 +267,7 @@
setPlainText(m_parent_element->elementInformations().value(info_name).toString());
}
- emit InfoNameChanged(info_name);
+ emit infoNameChanged(info_name);
}
QString DynamicElementTextItem::infoName() const {
@@ -253,6 +274,22 @@
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::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);
}
Modified: trunk/sources/qetgraphicsitem/dynamicelementtextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/dynamicelementtextitem.h 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/qetgraphicsitem/dynamicelementtextitem.h 2017-08-16 13:52:15 UTC (rev 5021)
@@ -20,6 +20,7 @@
#include "diagramtextitem.h"
#include <QUuid>
+#include <QPointer>
class Element;
@@ -35,14 +36,16 @@
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 @@
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 @@
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 @@
void elementInfoChanged();
private:
- Element *m_parent_element = nullptr;
+ QPointer <Element> 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;
};
Modified: trunk/sources/ui/abstractelementpropertieseditorwidget.h
===================================================================
--- trunk/sources/ui/abstractelementpropertieseditorwidget.h 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/ui/abstractelementpropertieseditorwidget.h 2017-08-16 13:52:15 UTC (rev 5021)
@@ -19,7 +19,7 @@
#define ABSTRACTELEMENTPROPERTIESEDITORWIDGET_H
#include "PropertiesEditor/propertieseditorwidget.h"
-#include "QPointer"
+#include <QPointer>
class Element;
Added: trunk/sources/ui/compositetexteditdialog.cpp
===================================================================
--- trunk/sources/ui/compositetexteditdialog.cpp (rev 0)
+++ trunk/sources/ui/compositetexteditdialog.cpp 2017-08-16 13:52:15 UTC (rev 5021)
@@ -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 <QString, QString> 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());
+}
Added: trunk/sources/ui/compositetexteditdialog.h
===================================================================
--- trunk/sources/ui/compositetexteditdialog.h (rev 0)
+++ trunk/sources/ui/compositetexteditdialog.h 2017-08-16 13:52:15 UTC (rev 5021)
@@ -0,0 +1,42 @@
+#ifndef COMPOSITETEXTEDITDIALOG_H
+#define COMPOSITETEXTEDITDIALOG_H
+
+#include <QDialog>
+
+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
Added: trunk/sources/ui/compositetexteditdialog.ui
===================================================================
--- trunk/sources/ui/compositetexteditdialog.ui (rev 0)
+++ trunk/sources/ui/compositetexteditdialog.ui 2017-08-16 13:52:15 UTC (rev 5021)
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CompositeTextEditDialog</class>
+ <widget class="QDialog" name="CompositeTextEditDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>664</width>
+ <height>538</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="1">
+ <widget class="QComboBox" name="m_info_cb"/>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Ajouter une variable :</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <widget class="QDialogButtonBox" name="m_button_box">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QPlainTextEdit" name="m_plain_text_edit">
+ <property name="placeholderText">
+ <string>Entrée votre votre texte composé ici, en vous aidant des variables disponible</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>m_button_box</sender>
+ <signal>accepted()</signal>
+ <receiver>CompositeTextEditDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>m_button_box</sender>
+ <signal>rejected()</signal>
+ <receiver>CompositeTextEditDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp 2017-08-16 13:52:15 UTC (rev 5021)
@@ -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 @@
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 @@
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 @@
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 @@
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,10 +290,14 @@
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);
qsi->child(0,1)->setEnabled(usr);
@@ -272,6 +304,9 @@
//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 @@
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 if (from == tr("Information de l'élément"))
+ enableSourceText(deti, DynamicElementTextItem::ElementInfo);
else
- enableSourceText(deti, DynamicElementTextItem::ElementInfo);
+ enableSourceText(deti, DynamicElementTextItem::CompositeText);
}
else if (qsi->data().toInt() == userText)
{
@@ -298,6 +337,13 @@
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 @@
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 @@
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 @@
}
case infoText:
break;
+ case compositeText:
+ break;
case size:
qsi->child(1,1)->setData(deti->fontSize(), Qt::EditRole);
break;
@@ -389,6 +443,7 @@
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 @@
}
return qcb;
}
+ case DynamicElementTextModel::compositeText:
+ {
+ const DynamicElementTextModel *detm = static_cast<const DynamicElementTextModel *>(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<QColor>());
@@ -459,6 +530,32 @@
}
}
+ else if (editor->objectName() == "composite_text")
+ {
+ if (QStandardItemModel *qsim = dynamic_cast<QStandardItemModel *>(model))
+ {
+ if(QStandardItem *qsi = qsim->itemFromIndex(index))
+ {
+
+ CompositeTextEditDialog *cted = static_cast<CompositeTextEditDialog *>(editor);
+
+ QString edited_text = cted->plainText();
+ QString assigned_text;
+
+ const DynamicElementTextModel *detm = static_cast<const DynamicElementTextModel *>(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);
Modified: trunk/sources/ui/dynamicelementtextmodel.h
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.h 2017-08-15 01:43:45 UTC (rev 5020)
+++ trunk/sources/ui/dynamicelementtextmodel.h 2017-08-16 13:52:15 UTC (rev 5021)
@@ -39,6 +39,7 @@
textFrom =1,
userText,
infoText,
+ compositeText,
size,
tagg,
color