[qet] qet/qet: [5265] Element editor : text field can now have a composite text as source of text

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5265
Author:   blacksun
Date:     2018-03-11 17:00:58 +0100 (Sun, 11 Mar 2018)
Log Message:
-----------
Element editor : text field can now have a composite text as source of text

Modified Paths:
--------------
    trunk/sources/editor/graphicspart/partdynamictextfield.cpp
    trunk/sources/editor/ui/dynamictextfieldeditor.cpp
    trunk/sources/editor/ui/dynamictextfieldeditor.h
    trunk/sources/ui/compositetexteditdialog.cpp
    trunk/sources/ui/compositetexteditdialog.h

Modified: trunk/sources/editor/graphicspart/partdynamictextfield.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partdynamictextfield.cpp	2018-03-11 15:11:08 UTC (rev 5264)
+++ trunk/sources/editor/graphicspart/partdynamictextfield.cpp	2018-03-11 16:00:58 UTC (rev 5265)
@@ -277,6 +277,8 @@
 void PartDynamicTextField::setCompositeText(const QString &text)
 {
 	m_composite_text = text;
+	if(elementScene())
+		setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementScene()->elementInformation()));
 	emit compositeTextChanged(m_composite_text);
 }
 
@@ -483,9 +485,11 @@
  */
 void PartDynamicTextField::elementInfoChanged()
 {
+	if(!elementScene())
+		return;
+	
 	if(m_text_from == DynamicElementTextItem::ElementInfo)
-	{
-		DiagramContext dc = elementScene()->elementInformation();
-		setPlainText(dc.value(m_info_name).toString());
-	}
+		setPlainText(elementScene()->elementInformation().value(m_info_name).toString());
+	else if (m_text_from == DynamicElementTextItem::CompositeText && elementScene())
+		setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, elementScene()->elementInformation()));
 }

Modified: trunk/sources/editor/ui/dynamictextfieldeditor.cpp
===================================================================
--- trunk/sources/editor/ui/dynamictextfieldeditor.cpp	2018-03-11 15:11:08 UTC (rev 5264)
+++ trunk/sources/editor/ui/dynamictextfieldeditor.cpp	2018-03-11 16:00:58 UTC (rev 5265)
@@ -22,6 +22,7 @@
 #include "QPropertyUndoCommand/qpropertyundocommand.h"
 #include "qetelementeditor.h"
 #include "qetapp.h"
+#include "compositetexteditdialog.h"
 
 #include <QPointer>
 #include <QGraphicsItem>
@@ -277,3 +278,17 @@
 		undoStack().push(undo);
 	}
 }
+
+void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
+{
+	CompositeTextEditDialog ctd(m_text_field.data()->compositeText(), this);
+	if(ctd.exec())
+	{
+		QString ct = ctd.plainText();
+		if(ct != m_text_field.data()->compositeText())
+		{
+			QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "compositeText", m_text_field.data()->compositeText(), ctd.plainText());
+			undoStack().push(undo);
+		}
+	}
+}

Modified: trunk/sources/editor/ui/dynamictextfieldeditor.h
===================================================================
--- trunk/sources/editor/ui/dynamictextfieldeditor.h	2018-03-11 15:11:08 UTC (rev 5264)
+++ trunk/sources/editor/ui/dynamictextfieldeditor.h	2018-03-11 16:00:58 UTC (rev 5265)
@@ -57,6 +57,8 @@
 		void on_m_elmt_info_cb_activated(const QString &arg1);
 		void on_m_text_from_cb_activated(int index);
 		
+		void on_m_composite_text_pb_clicked();
+		
 		private:
 		Ui::DynamicTextFieldEditor *ui;
 		QPointer<PartDynamicTextField> m_text_field;

Modified: trunk/sources/ui/compositetexteditdialog.cpp
===================================================================
--- trunk/sources/ui/compositetexteditdialog.cpp	2018-03-11 15:11:08 UTC (rev 5264)
+++ trunk/sources/ui/compositetexteditdialog.cpp	2018-03-11 16:00:58 UTC (rev 5265)
@@ -19,6 +19,19 @@
 	setUpComboBox();
 }
 
+CompositeTextEditDialog::CompositeTextEditDialog(QString text, QWidget *parent) :
+	QDialog(parent),
+	ui(new Ui::CompositeTextEditDialog)
+{
+	ui->setupUi(this);
+	m_default_text = text;
+	ui->m_plain_text_edit->setPlainText(m_default_text);
+#if QT_VERSION >= 0x050300
+	ui->m_plain_text_edit->setPlaceholderText(tr("Entrée votre texte composé ici, en vous aidant des variables disponible"));
+#endif
+	setUpComboBox();
+}
+
 CompositeTextEditDialog::~CompositeTextEditDialog() {
 	delete ui;
 }
@@ -38,34 +51,42 @@
 void CompositeTextEditDialog::setUpComboBox()
 {
 	QStringList qstrl;
-	if(m_text->parentElement()->linkType() & Element::AllReport) //Special treatment for text owned by a folio report
+	
+	if(m_text)
 	{
-		qstrl << "label";
-		
-		if(!m_text->m_watched_conductor.isNull())
+		if(m_text->parentElement()->linkType() & Element::AllReport) //Special treatment for text owned by a folio report
 		{
-			Conductor *cond = m_text->m_watched_conductor.data();
-			if (!cond->properties().m_function.isEmpty())
-				qstrl << "function";
-			if(!cond->properties().m_tension_protocol.isEmpty())
-				qstrl << "tension-protocol";
+			qstrl << "label";
+			
+			if(!m_text->m_watched_conductor.isNull())
+			{
+				Conductor *cond = m_text->m_watched_conductor.data();
+				if (!cond->properties().m_function.isEmpty())
+					qstrl << "function";
+				if(!cond->properties().m_tension_protocol.isEmpty())
+					qstrl << "tension-protocol";
+			}
 		}
+		else
+		{
+			Element *elmt = m_text->elementUseForInfo();
+			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;
+			}
+		}
 	}
 	else
 	{
-		Element *elmt = m_text->elementUseForInfo();
-		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;
-		}
+		qstrl = QETApp::elementInfoKeys();
 	}
 	
 		//We use a QMap because the keys of the map are sorted, then no matter the curent local,

Modified: trunk/sources/ui/compositetexteditdialog.h
===================================================================
--- trunk/sources/ui/compositetexteditdialog.h	2018-03-11 15:11:08 UTC (rev 5264)
+++ trunk/sources/ui/compositetexteditdialog.h	2018-03-11 16:00:58 UTC (rev 5265)
@@ -22,6 +22,7 @@
 	
 	public:
 		explicit CompositeTextEditDialog(DynamicElementTextItem *text, QWidget *parent = nullptr);
+		explicit CompositeTextEditDialog(QString text, QWidget *parent = nullptr);
 		~CompositeTextEditDialog() override;
 		
 		QString plainText() const;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/