[qet] qet/qet: [5088] Diagram editor : add in the tree widget use to edit the property of dynamic text item, two news items for edit the X and Y pos of the text.

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


Revision: 5088
Author:   blacksun
Date:     2017-10-29 11:43:34 +0100 (Sun, 29 Oct 2017)
Log Message:
-----------
Diagram editor : add in the tree widget use to edit the property of dynamic text item, two news items for edit the X and Y pos of the text.

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-10-27 18:44:37 UTC (rev 5087)
+++ trunk/sources/ui/dynamicelementtextitemeditor.cpp	2017-10-29 10:43:34 UTC (rev 5088)
@@ -120,6 +120,22 @@
 	m_tree_view->setCurrentIndex(index);
 }
 
+QUndoCommand *DynamicElementTextItemEditor::associatedUndo() const
+{
+	QUndoCommand *parent_undo = new QUndoCommand(tr("Modifier un texte d'élément"));
+	for (DynamicElementTextItem *deti : m_element->dynamicTextItems())
+		m_model->undoForEditedText(deti, parent_undo);
+	
+	if(parent_undo->childCount() >= 1)
+	{
+		if(parent_undo->childCount() >= 2)
+			parent_undo->setText(tr("Modifier %1 textes d'élément").arg(QString::number(parent_undo->childCount())));
+		return parent_undo;
+	}
+	else
+		return nullptr;
+}
+
 void DynamicElementTextItemEditor::dataEdited(DynamicElementTextItem *deti)
 {
 	Q_UNUSED(deti)

Modified: trunk/sources/ui/dynamicelementtextitemeditor.h
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.h	2017-10-27 18:44:37 UTC (rev 5087)
+++ trunk/sources/ui/dynamicelementtextitemeditor.h	2017-10-29 10:43:34 UTC (rev 5088)
@@ -42,6 +42,7 @@
 		bool setLiveEdit(bool live_edit) override;
 		void apply() override;
 		void setCurrentText(DynamicElementTextItem *text);
+		QUndoCommand *associatedUndo() const override;
 	
 	private:
 		void dataEdited(DynamicElementTextItem *deti);

Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp	2017-10-27 18:44:37 UTC (rev 5087)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp	2017-10-29 10:43:34 UTC (rev 5088)
@@ -160,7 +160,35 @@
     qsi_list.clear();
     qsi_list << color << colora;
 	qsi->appendRow(qsi_list);
+	
+		//X pos
+	QStandardItem *x_pos = new QStandardItem(tr("Position X"));
+	x_pos->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+	
+	QStandardItem *x_pos_a = new QStandardItem;
+	x_pos_a->setData(deti->pos().x(), Qt::EditRole);
+	x_pos_a->setData(DynamicElementTextModel::pos, Qt::UserRole+1);
+	x_pos_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
+	
+	qsi_list.clear();
+	qsi_list << x_pos << x_pos_a;
+	qsi->appendRow(qsi_list);
+	
+		//Y pos
+	QStandardItem *y_pos = new QStandardItem(tr("Position Y"));
+	y_pos->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+	
+	QStandardItem *y_pos_a = new QStandardItem;
+	y_pos_a->setData(deti->pos().y(), Qt::EditRole);
+	y_pos_a->setData(DynamicElementTextModel::pos, Qt::UserRole+1);
+	y_pos_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
+	
+	qsi_list.clear();
+	qsi_list << y_pos << y_pos_a;
+	qsi->appendRow(qsi_list);
     
+	
+	
 	qsi_list.clear();
 	QStandardItem *empty_qsi = new QStandardItem(0);
 	empty_qsi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
@@ -244,10 +272,15 @@
  * Each change made for @deti is append as a child of the returned QUndoCommand.
  * In other word, if the returned QUndoCommand have no child, that mean there is no change.
  */
-QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem *deti) const
+QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo) const
 {
-	QUndoCommand *undo = new QUndoCommand(tr("Éditer un texte d'élément"));
 	
+	QUndoCommand *undo = nullptr;
+	if(parent_undo)
+		undo = parent_undo;
+	else
+		undo = new QUndoCommand(tr("Éditer un texte d'élément"));
+	
 	if (!m_texts_list.contains(deti))
 		return undo;
 	
@@ -292,6 +325,12 @@
 	if(color != deti->color())
 		new QPropertyUndoCommand(deti, "color", QVariant(deti->color()), QVariant(color), undo);
 	
+	QPointF p(text_qsi->child(4,1)->data(Qt::EditRole).toDouble(),
+			  text_qsi->child(5,1)->data(Qt::EditRole).toDouble());
+	if(p != deti->pos())
+		new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo);
+	
+	
 	return undo;
 }
 
@@ -381,7 +420,7 @@
 	
 		//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)
+	if(qsi->column() == 1 && !m_block_dataForTextChanged)
 		emit dataForTextChanged(deti);
 }
 
@@ -406,6 +445,8 @@
 		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::infoNameChanged, [deti,this](){this->updateDataFromText(deti, infoText);});
+		connection_list << connect(deti, &DynamicElementTextItem::xChanged,        [deti,this](){this->updateDataFromText(deti, pos);});
+		connection_list << connect(deti, &DynamicElementTextItem::yChanged,        [deti,this](){this->updateDataFromText(deti, pos);});
 		connection_list << connect(deti, &DynamicElementTextItem::compositeTextChanged, [deti, this]() {this->updateDataFromText(deti, compositeText);});
 		
 		m_hash_text_connect.insert(deti, connection_list);
@@ -428,6 +469,8 @@
 	if (!qsi)
 		return;
 	
+	m_block_dataForTextChanged = true;
+	
 	switch (type)
 	{
 		case textFrom:
@@ -480,7 +523,15 @@
 			qsi->child(3,1)->setData(deti->color(), Qt::ForegroundRole);
 			break;
 		}
+		case pos:
+		{
+			qsi->child(4,1)->setData(deti->pos().x(), Qt::EditRole);
+			qsi->child(5,1)->setData(deti->pos().y(), Qt::EditRole);
+			break;
+		}
 	}
+	
+	m_block_dataForTextChanged = false;
 }
 
 
@@ -553,6 +604,18 @@
 			cd->setObjectName("color_dialog");
 			return cd;
 		}
+		case DynamicElementTextModel::pos:
+		{
+			QWidget *w = QStyledItemDelegate::createEditor(parent, option, index);
+			
+			if(QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>(w))
+			{
+				dsb->setDecimals(0);
+				dsb->setSuffix(" px");
+			}
+
+			return w;
+		}
 	}
 	return QStyledItemDelegate::createEditor(parent, option, index);
 }

Modified: trunk/sources/ui/dynamicelementtextmodel.h
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.h	2017-10-27 18:44:37 UTC (rev 5087)
+++ trunk/sources/ui/dynamicelementtextmodel.h	2017-10-29 10:43:34 UTC (rev 5088)
@@ -42,7 +42,8 @@
 			compositeText,
             size,
             tagg,
-            color
+            color,
+			pos
         };
         
 		DynamicElementTextModel(QObject *parent = nullptr);
@@ -53,7 +54,7 @@
         DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
         DynamicElementTextItem *textFromItem(QStandardItem *item) const;
 		QModelIndex indexFromText(DynamicElementTextItem *text) const;
-		QUndoCommand *undoForEditedText(DynamicElementTextItem *deti) const;
+		QUndoCommand *undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo = nullptr) const;
 		
 	signals:
 		void dataForTextChanged(DynamicElementTextItem *text);
@@ -67,6 +68,7 @@
 	private:
 		QHash <DynamicElementTextItem *, QStandardItem *> m_texts_list;
 		QHash <DynamicElementTextItem *, QList<QMetaObject::Connection>> m_hash_text_connect;
+		bool m_block_dataForTextChanged = false;
 };
 
 class DynamicTextItemDelegate : public QStyledItemDelegate


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