[qet] qet/qet: [5191] Element texts group can be renamed

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


Revision: 5191
Author:   blacksun
Date:     2017-12-18 21:05:00 +0100 (Mon, 18 Dec 2017)
Log Message:
-----------
Element texts group can be renamed

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

Modified: trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/qetgraphicsitem/elementtextitemgroup.cpp	2017-12-18 20:05:00 UTC (rev 5191)
@@ -195,6 +195,7 @@
 void ElementTextItemGroup::setName(QString name)
 {
 	m_name = name;
+	emit nameChanged(m_name);
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/elementtextitemgroup.h
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitemgroup.h	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/qetgraphicsitem/elementtextitemgroup.h	2017-12-18 20:05:00 UTC (rev 5191)
@@ -39,6 +39,7 @@
 	Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
 	Q_PROPERTY(int verticalAdjustment READ verticalAdjustment WRITE setVerticalAdjustment NOTIFY verticalAdjustmentChanged)
 	Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
+	Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
 	
 	public:
 	signals:
@@ -45,6 +46,7 @@
 		void rotationChanged(qreal);
 		void verticalAdjustmentChanged(int);
 		void alignmentChanged(Qt::Alignment);
+		void nameChanged(QString);
 	
 	public:
 		ElementTextItemGroup(const QString &name, Element *parent);

Modified: trunk/sources/ui/dynamicelementtextitemeditor.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.cpp	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/ui/dynamicelementtextitemeditor.cpp	2017-12-18 20:05:00 UTC (rev 5191)
@@ -36,18 +36,13 @@
 {
     ui->setupUi(this);
 	
-    m_tree_view = new QTreeView(this);
-    m_tree_view->header()->setDefaultSectionSize(150);
-    m_tree_view->setItemDelegate(new DynamicTextItemDelegate(m_tree_view));
-	m_tree_view->setAlternatingRowColors(true);
-	m_tree_view->setEditTriggers(QAbstractItemView::CurrentChanged);
-	m_tree_view->installEventFilter(this);
-	m_tree_view->setDragDropMode(QAbstractItemView::InternalMove);
-    ui->verticalLayout->addWidget(m_tree_view);
-	
-	connect(m_tree_view, &QTreeView::clicked, this, &DynamicElementTextItemEditor::treeViewClicked);
+    ui->m_tree_view->setItemDelegate(new DynamicTextItemDelegate(ui->m_tree_view));
+	ui->m_tree_view->installEventFilter(this);
 	ui->m_remove_selection->setDisabled(true);
 	
+	ui->m_export_pb->hide();
+	ui->m_import_pb->hide();
+	
     setElement(element);
 }
 
@@ -64,9 +59,9 @@
      m_element = element;
     
     DynamicElementTextModel *old_model = m_model;
-    m_model = new DynamicElementTextModel(element, m_tree_view);
+    m_model = new DynamicElementTextModel(element, ui->m_tree_view);
 	connect(m_model, &DynamicElementTextModel::dataChanged, this, &DynamicElementTextItemEditor::dataEdited);
-    m_tree_view->setModel(m_model);
+    ui->m_tree_view->setModel(m_model);
     
     if(old_model)
 		delete old_model;
@@ -153,9 +148,9 @@
 	if(!index.isValid())
 		return;
 	
-	m_tree_view->expand(index);
-	m_tree_view->expand(index.child(0,0));
-	m_tree_view->setCurrentIndex(index);
+	ui->m_tree_view->expand(index);
+	ui->m_tree_view->expand(index.child(0,0));
+	ui->m_tree_view->setCurrentIndex(index);
 	ui->m_remove_selection->setEnabled(true);
 }
 
@@ -170,8 +165,8 @@
 	if(!index.isValid())
 		return;
 	
-	m_tree_view->expand(index);
-	m_tree_view->setCurrentIndex(index);
+	ui->m_tree_view->expand(index);
+	ui->m_tree_view->setCurrentIndex(index);
 	ui->m_remove_selection->setEnabled(true);
 }
 
@@ -197,14 +192,6 @@
 		apply();
 }
 
-void DynamicElementTextItemEditor::treeViewClicked(const QModelIndex &index)
-{
-	if(m_model->indexIsText(index) || m_model->indexIsGroup(index))
-		ui->m_remove_selection->setEnabled(true);
-	else
-		ui->m_remove_selection->setDisabled(true);
-}
-
 /**
  * @brief DynamicElementTextItemEditor::on_m_add_text_clicked
  * Add a new dynamic text
@@ -232,7 +219,7 @@
  */
 void DynamicElementTextItemEditor::on_m_remove_selection_clicked()
 {
-    DynamicElementTextItem *deti = m_model->textFromIndex(m_tree_view->currentIndex());
+    DynamicElementTextItem *deti = m_model->textFromIndex(ui->m_tree_view->currentIndex());
     if(deti)
     {
 		if(m_element->diagram())
@@ -243,7 +230,7 @@
 		}
 		return;
     }
-	ElementTextItemGroup *group = m_model->groupFromIndex(m_tree_view->currentIndex());
+	ElementTextItemGroup *group = m_model->groupFromIndex(ui->m_tree_view->currentIndex());
 	if(group && m_element.data()->diagram())
 		m_element.data()->diagram()->undoStack().push(new RemoveTextsGroupCommand(m_element.data(), group));
 }
@@ -261,3 +248,11 @@
 	else if (m_element.data()->diagram())
 		m_element.data()->diagram()->undoStack().push(new AddTextsGroupCommand(m_element, name));
 }
+
+void DynamicElementTextItemEditor::on_m_tree_view_clicked(const QModelIndex &index)
+{
+	if(m_model->indexIsText(index) || m_model->indexIsGroup(index))
+		ui->m_remove_selection->setEnabled(true);
+	else
+		ui->m_remove_selection->setDisabled(true);
+}

Modified: trunk/sources/ui/dynamicelementtextitemeditor.h
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.h	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/ui/dynamicelementtextitemeditor.h	2017-12-18 20:05:00 UTC (rev 5191)
@@ -22,7 +22,6 @@
 
 class DynamicElementTextItem;
 class DynamicElementTextModel;
-class QTreeView;
 class QStandardItem;
 class ElementTextItemGroup;
 
@@ -48,16 +47,15 @@
 	
 	private:
 		void dataEdited();
-		void treeViewClicked(const QModelIndex &index);
     
     private slots:
         void on_m_add_text_clicked();
         void on_m_remove_selection_clicked();
 		void on_m_add_group_clicked();
+		void on_m_tree_view_clicked(const QModelIndex &index);
 		
 		private:
 		Ui::DynamicElementTextItemEditor *ui;
-        QTreeView *m_tree_view = nullptr;
         DynamicElementTextModel *m_model = nullptr;
 };
 

Modified: trunk/sources/ui/dynamicelementtextitemeditor.ui
===================================================================
--- trunk/sources/ui/dynamicelementtextitemeditor.ui	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/ui/dynamicelementtextitemeditor.ui	2017-12-18 20:05:00 UTC (rev 5191)
@@ -73,6 +73,43 @@
      </item>
     </layout>
    </item>
+   <item>
+    <widget class="QTreeView" name="m_tree_view">
+     <property name="editTriggers">
+      <set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
+     </property>
+     <property name="dragDropMode">
+      <enum>QAbstractItemView::DragDrop</enum>
+     </property>
+     <property name="alternatingRowColors">
+      <bool>true</bool>
+     </property>
+     <property name="animated">
+      <bool>true</bool>
+     </property>
+     <attribute name="headerDefaultSectionSize">
+      <number>150</number>
+     </attribute>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="m_im_exp_layout">
+     <item>
+      <widget class="QPushButton" name="m_export_pb">
+       <property name="text">
+        <string>Exporter</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="m_import_pb">
+       <property name="text">
+        <string>Importer</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
   </layout>
  </widget>
  <resources>

Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp	2017-12-18 20:05:00 UTC (rev 5191)
@@ -520,6 +520,11 @@
 	if(group->verticalAdjustment() != v_adjustment)
 		new QPropertyUndoCommand(group, "verticalAdjustment", QVariant(group->verticalAdjustment()), QVariant(v_adjustment), undo);
 	
+	QString name = group_qsi->data(Qt::DisplayRole).toString();
+	if(group->name() != name)
+		new QPropertyUndoCommand(group, "name", QVariant(group->name()), QVariant(name), undo);
+		
+	
 	return undo;
 }
 
@@ -535,7 +540,7 @@
 	
 		//Group
 	QStandardItem *grp = new QStandardItem(group->name());
-	grp->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
+	grp->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
 	grp->setIcon(QET::Icons::textGroup);
 	
 	QStandardItem *empty_qsi = new QStandardItem(0);
@@ -836,7 +841,7 @@
 					if(group && deti) //Text successfully added in a group	
 					{
 						m_element.data()->diagram()->undoStack().push(new AddTextToGroupCommand(deti, group));
-						return false;
+						return true;
 					}
 				}
 			}
@@ -860,7 +865,7 @@
 							stack.push(new AddTextToGroupCommand(deti, group));
 							stack.endMacro();
 							
-							return false;
+							return true;
 						}
 					}
 				}
@@ -889,7 +894,7 @@
 			if(deti && group) //Text successfully removed from group
 			{
 				m_element.data()->diagram()->undoStack().push((new RemoveTextFromGroupCommand(deti, group)));
-				return false;
+				return true;
 			}
 			
 			return false;
@@ -1020,8 +1025,8 @@
 	}
 	
 		//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 && !m_block_dataChanged)
+		//the first column is use only for display the title of the property, except for the name of texts group
+	if((m_groups_list.values().contains(qsi) || qsi->column() == 1) && !m_block_dataChanged)
 		emit dataChanged();
 }
 
@@ -1083,6 +1088,7 @@
 		connection_list << connect(group, &ElementTextItemGroup::alignmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_alignment);});
 		connection_list << connect(group, &ElementTextItemGroup::rotationChanged, [group, this]() {this->updateDataFromGroup(group, grp_rotation);});
 		connection_list << connect(group, &ElementTextItemGroup::verticalAdjustmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_v_adjust);});
+		connection_list << connect(group, &ElementTextItemGroup::verticalAdjustmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_name);});
 		
 		m_hash_group_connect.insert(group, connection_list);
 	}
@@ -1203,6 +1209,9 @@
 		case grp_v_adjust:
 			qsi->child(adjust_grp_row,1)->setData(group->verticalAdjustment(), Qt::EditRole);
 			break;
+		case grp_name:
+			qsi->setData(group->name(), Qt::DisplayRole);
+			break;
 	}
 	
 	m_block_dataChanged = false;

Modified: trunk/sources/ui/dynamicelementtextmodel.h
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.h	2017-12-17 18:53:55 UTC (rev 5190)
+++ trunk/sources/ui/dynamicelementtextmodel.h	2017-12-18 20:05:00 UTC (rev 5191)
@@ -49,7 +49,8 @@
 			rotation, 
 			grp_alignment,
 			grp_rotation,
-			grp_v_adjust
+			grp_v_adjust,
+			grp_name
         };
         
 		DynamicElementTextModel(Element *element, QObject *parent = nullptr);


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