[qet] [4018] Properties dock : button edit element and find element work.

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


Revision: 4018
Author:   blacksun
Date:     2015-06-19 10:12:17 +0200 (Fri, 19 Jun 2015)
Log Message:
-----------
Properties dock : button edit element and find element work.

Modified Paths:
--------------
    trunk/sources/ui/diagrampropertieseditordockwidget.cpp
    trunk/sources/ui/diagrampropertieseditordockwidget.h

Modified: trunk/sources/ui/diagrampropertieseditordockwidget.cpp
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.cpp	2015-06-16 08:26:03 UTC (rev 4017)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.cpp	2015-06-19 08:12:17 UTC (rev 4018)
@@ -30,7 +30,7 @@
 DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget(QWidget *parent) :
 	PropertiesEditorDockWidget(parent),
 	m_diagram(nullptr),
-	m_edited_qgi_type(UnknowQGIType)
+	m_edited_qgi_type (-1)
 {}
 
 /**
@@ -73,42 +73,47 @@
 void DiagramPropertiesEditorDockWidget::selectionChanged()
 {
 	if (!m_diagram) return;
+		//This editor can edit only one item.
+	if (m_diagram->selectedItems().size() != 1)
+	{
+		clear();
+		m_edited_qgi_type = -1;
+		return;
+	}
 
-	if (m_diagram->selectedItems().size() == 1) //We can open an editor only when there is one selected item
+	QGraphicsItem *item = m_diagram->selectedItems().first();
+	const int type_ = item->type();
+
+	switch (type_)
 	{
-		QGraphicsItem *item = m_diagram->selectedItems().first();
-
-			//Edit an element
-		if (Element *elmt = dynamic_cast<Element*>(item))
-		{
-			if (m_edited_qgi_type == ElementQGIType && editors().size() == 1)
+		case Element::Type: {
+				//We already edit an element, just update the editor with a new element
+			if (m_edited_qgi_type == type_)
 			{
-				ElementPropertiesWidget *epw = dynamic_cast<ElementPropertiesWidget*>(editors().first());
-				if (epw) //In this case we only update each editor widget with the new element instead of create new widget.
-				{
-					epw->setElement(elmt);
-					return;
-				}
+				static_cast<ElementPropertiesWidget*>(editors().first())->setElement(static_cast<Element*>(item));
+				return;
 			}
+
 			clear();
-			m_edited_qgi_type = ElementQGIType;
-			addEditor(new ElementPropertiesWidget(elmt, this));
-		}
-			//Edit an image
-		else if (DiagramImageItem *image = dynamic_cast<DiagramImageItem *>(item))
-		{
+			m_edited_qgi_type = type_;
+			ElementPropertiesWidget *epw = new ElementPropertiesWidget(static_cast<Element*>(item), this);
+			connect (epw, &ElementPropertiesWidget::editElementRequired , m_diagram, &Diagram::editElementRequired);
+			connect (epw, &ElementPropertiesWidget::findElementRequired, m_diagram, &Diagram::findElementRequired);
+			addEditor(epw);
+			break; }
+
+		case DiagramImageItem::Type: {
 			clear();
-			m_edited_qgi_type = ImageQGIType;
-			addEditor(new ImagePropertiesWidget(image, this));
-		}
-			//Unknow type, we clear the dock
-		else
+			m_edited_qgi_type = type_;
+			addEditor(new ImagePropertiesWidget(static_cast<DiagramImageItem*>(item), this));
+			break; }
+
+		default:
+			m_edited_qgi_type = -1;
 			clear();
 	}
-	else
-		clear();
 
-	foreach(PropertiesEditorWidget *pew, editors())
+	foreach (PropertiesEditorWidget *pew, editors())
 		pew->setLiveEdit(true);
 }
 

Modified: trunk/sources/ui/diagrampropertieseditordockwidget.h
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.h	2015-06-16 08:26:03 UTC (rev 4017)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.h	2015-06-19 08:12:17 UTC (rev 4018)
@@ -21,7 +21,6 @@
 #include "PropertiesEditor/propertieseditordockwidget.h"
 
 class Diagram;
-class QGraphicsItem;
 
 class DiagramPropertiesEditorDockWidget : public PropertiesEditorDockWidget
 {
@@ -32,14 +31,17 @@
 
 		void setDiagram(Diagram *diagram);
 
+	private: //Make this method private because only this class manage the editor widget.
+		bool addEditor(PropertiesEditorWidget *editor, int index = 0) { return PropertiesEditorDockWidget::addEditor(editor, index); }
+		bool removeEditor(PropertiesEditorWidget *editor) { return PropertiesEditorDockWidget::removeEditor(editor); }
+
 	private slots:
 		void selectionChanged();
 		void diagramWasDeleted();
 
 	private:
-		enum EditedQGIType {UnknowQGIType, ElementQGIType, ImageQGIType};
 		Diagram *m_diagram;
-		EditedQGIType m_edited_qgi_type;
+		int m_edited_qgi_type;
 };
 
 #endif // DIAGRAMPROPERTIESEDITORDOCKWIDGET_H


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