[qet] qet/qet: [5030] Keep up to date the model when a dynamic text item change, for exemple after an undo command

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


Revision: 5030
Author:   blacksun
Date:     2017-08-24 19:35:40 +0200 (Thu, 24 Aug 2017)
Log Message:
-----------
Keep up to date the model when a dynamic text item change, for exemple after an undo command

Modified Paths:
--------------
    trunk/sources/ui/dynamicelementtextitemeditor.cpp
    trunk/sources/ui/dynamicelementtextitemeditor.h
    trunk/sources/ui/dynamicelementtextmodel.cpp
    trunk/sources/ui/dynamicelementtextmodel.h

Modified: trunk/sources/ui/dynamicelementtextitemeditor.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.cpp	2017-08-24 14:55:13 UTC (rev 5029)
+++ trunk/sources/ui/dynamicelementtextitemeditor.cpp	2017-08-24 17:35:40 UTC (rev 5030)
@@ -55,7 +55,7 @@
     
     DynamicElementTextModel *old_model = m_model;
     m_model = new DynamicElementTextModel(m_tree_view);
-	connect(m_model, &DynamicElementTextModel::itemChanged, this, &DynamicElementTextItemEditor::dataEdited);
+	connect(m_model, &DynamicElementTextModel::dataForTextChanged, this, &DynamicElementTextItemEditor::dataEdited);
     
     for (DynamicElementTextItem *deti : m_element->dynamicTextItems())
         m_model->addText(deti);
@@ -120,9 +120,9 @@
 	m_tree_view->setCurrentIndex(index);
 }
 
-void DynamicElementTextItemEditor::dataEdited(QStandardItem *qsi)
+void DynamicElementTextItemEditor::dataEdited(DynamicElementTextItem *deti)
 {
-	Q_UNUSED(qsi)
+	Q_UNUSED(deti)
 	if (m_live_edit)
 		apply();
 }

Modified: trunk/sources/ui/dynamicelementtextitemeditor.h
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.h	2017-08-24 14:55:13 UTC (rev 5029)
+++ trunk/sources/ui/dynamicelementtextitemeditor.h	2017-08-24 17:35:40 UTC (rev 5030)
@@ -44,7 +44,7 @@
 		void setCurrentText(DynamicElementTextItem *text);
 	
 	private:
-		void dataEdited(QStandardItem *qsi);
+		void dataEdited(DynamicElementTextItem *deti);
     
     private slots:
         void on_m_add_text_clicked();

Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp	2017-08-24 14:55:13 UTC (rev 5029)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp	2017-08-24 17:35:40 UTC (rev 5030)
@@ -35,7 +35,7 @@
     setHeaderData(0, Qt::Horizontal, tr("Propriété"), Qt::DisplayRole);
     setHeaderData(1, Qt::Horizontal, tr("Valeur"), Qt::DisplayRole);
     
-    connect(this, &DynamicElementTextModel::itemChanged, this, &DynamicElementTextModel::dataEdited);
+	connect(this, &DynamicElementTextModel::itemChanged, this, &DynamicElementTextModel::itemDataChanged);
 }
 
 DynamicElementTextModel::~DynamicElementTextModel()
@@ -56,7 +56,7 @@
         return;
     
     QList <QStandardItem *> qsi_list;
-    
+
 	QStandardItem *qsi = new QStandardItem(deti->toPlainText());
     qsi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
 	
@@ -300,7 +300,7 @@
 {
 	if (!m_texts_list.contains(deti))
 		return;
-	
+
 	QStandardItem *qsi = m_texts_list.value(deti)->child(0,0);
 	
 	bool usr = false, info = false, compo = false;
@@ -308,9 +308,9 @@
 	switch (tf) {
 		case DynamicElementTextItem::UserText: usr = true; break;
 		case DynamicElementTextItem::ElementInfo: info = true; break;
-		case DynamicElementTextItem::CompositeText: compo = true; break;
+		case DynamicElementTextItem::CompositeText: compo = true;break;
 	}
-	
+
 		//User text
 	qsi->child(0,0)->setEnabled(usr);
 	qsi->child(0,1)->setEnabled(usr);
@@ -322,41 +322,59 @@
 	qsi->child(2,1)->setEnabled(compo);
 }
 
-void DynamicElementTextModel::dataEdited(QStandardItem *qsi)
+void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi)
 {
 	DynamicElementTextItem *deti = textFromItem(qsi);
 	if (!deti)
 		return;
 	
-	blockSignals(true);
+	QStandardItem *text_qsi = m_texts_list.value(deti);
 	
 	if (qsi->data().toInt() == textFrom)
 	{
+		QStandardItem *text_from_qsi = text_qsi->child(0,0);
 		QString from = qsi->data(Qt::DisplayRole).toString();
+		
 		if (from == tr("Texte utilisateur"))
+		{
 			enableSourceText(deti, DynamicElementTextItem::UserText);
+			text_qsi->setData(text_from_qsi->child(0,1)->data(Qt::DisplayRole).toString());
+		}
 		else if (from == tr("Information de l'élément"))
+		{
 			enableSourceText(deti, DynamicElementTextItem::ElementInfo);
+			QString info = text_from_qsi->child(1,1)->data(Qt::UserRole+2).toString();
+			text_qsi->setData(deti->parentElement()->elementInformations().value(info), Qt::DisplayRole);
+		}
 		else
+		{
 			enableSourceText(deti, DynamicElementTextItem::CompositeText);
+			QString compo = text_from_qsi->child(2,1)->data(Qt::UserRole+2).toString();
+			text_qsi->setData(autonum::AssignVariables::replaceVariable(compo, deti->parentElement()->elementInformations()), Qt::DisplayRole);
+		}
+		
+		
 	}
 	else if (qsi->data().toInt() == userText)
 	{
 		QString text = qsi->data(Qt::DisplayRole).toString();
-		m_texts_list.value(deti)->setData(text, Qt::DisplayRole);
+		text_qsi->setData(text, Qt::DisplayRole);
 	}
 	else if (qsi->data().toInt() == infoText && deti->parentElement())
 	{
 		QString info = qsi->data(Qt::UserRole+2).toString();
-		m_texts_list.value(deti)->setData(deti->parentElement()->elementInformations().value(info), Qt::DisplayRole);
+		text_qsi->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);
+		text_qsi->setData(autonum::AssignVariables::replaceVariable(compo, deti->parentElement()->elementInformations()), Qt::DisplayRole);
 	}
 	
-	blockSignals(false);
+		//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
+	if(qsi->column() == 1)
+		emit dataForTextChanged(deti);
 }
 
 /**
@@ -377,8 +395,10 @@
 		connection_list << connect(deti, &DynamicElementTextItem::colorChanged,    [deti,this](){this->updateDataFromText(deti, color);});
 		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::textFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);});
 		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::infoNameChanged, [deti,this](){this->updateDataFromText(deti, infoText);});
+		connection_list << connect(deti, &DynamicElementTextItem::compositeTextChanged, [deti, this]() {this->updateDataFromText(deti, compositeText);});
 		
 		m_hash_text_connect.insert(deti, connection_list);
 	}
@@ -404,15 +424,19 @@
 	{
 		case textFrom:
 		{
-			switch (deti->textFrom()) {
+			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;
 			}
+			enableSourceText(deti, deti->textFrom());
+			qsi->setData(deti->toPlainText(), Qt::DisplayRole);
 			break;
 		}
 		case userText:
 		{
+			qsi->setData(deti->toPlainText(), Qt::DisplayRole);
 			QStandardItem *qsia = qsi->child(0,0);
 			qsia->child(0,1)->setData(deti->toPlainText(), Qt::DisplayRole);
 			qsi->setData(deti->toPlainText(), Qt::DisplayRole);
@@ -419,9 +443,23 @@
 			break;
 		}
 		case infoText:
+		{
+			qsi->setData(deti->toPlainText(), Qt::DisplayRole);
+			QStandardItem *qsia = qsi->child(0,0);
+			QString info_name = deti->infoName();
+			qsia->child(1,1)->setData(info_name, Qt::UserRole+2);
+			qsia->child(1,1)->setData(QETApp::elementTranslatedInfoKey(info_name), Qt::DisplayRole);
 			break;
+		}
 		case compositeText:
+		{
+			qsi->setData(deti->toPlainText(), Qt::DisplayRole);
+			QStandardItem *qsia = qsi->child(0,0);
+			qsia->child(2,1)->setData(deti->compositeText(), Qt::UserRole+2);
+			qsia->child(2,1)->setData(deti->toPlainText(), Qt::DisplayRole);
+			qsi->setData(deti->toPlainText(), Qt::DisplayRole);
 			break;
+		}
 		case size:
 			qsi->child(1,1)->setData(deti->fontSize(), Qt::EditRole);
 			break;

Modified: trunk/sources/ui/dynamicelementtextmodel.h
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.h	2017-08-24 14:55:13 UTC (rev 5029)
+++ trunk/sources/ui/dynamicelementtextmodel.h	2017-08-24 17:35:40 UTC (rev 5030)
@@ -54,10 +54,13 @@
         DynamicElementTextItem *textFromItem(QStandardItem *item) const;
 		QModelIndex indexFromText(DynamicElementTextItem *text) const;
 		QUndoCommand *undoForEditedText(DynamicElementTextItem *deti) const;
+		
+	signals:
+		void dataForTextChanged(DynamicElementTextItem *text);
         
     private:
 		void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf );
-        void dataEdited(QStandardItem *qsi);
+        void itemDataChanged(QStandardItem *qsi);
 		void setConnection(DynamicElementTextItem *deti, bool set);
 		void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type);
 		


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