[qet] [4468] Improve the way how an element is updated in the new element panel.

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


Revision: 4468
Author:   blacksun
Date:     2016-05-05 15:31:04 +0200 (Thu, 05 May 2016)
Log Message:
-----------
Improve the way how an element is updated in the new element panel.
Now Qet only use the new embbeded collection (XmlElementCollection).
No need to reload the old element panel for add a new element created by the new element panel
Elements are always imported to the embbeded collection of a project

Modified Paths:
--------------
    trunk/sources/ElementsCollection/elementcollectionitem.cpp
    trunk/sources/ElementsCollection/elementcollectionitem.h
    trunk/sources/ElementsCollection/elementscollectionmodel.cpp
    trunk/sources/ElementsCollection/elementscollectionmodel.h
    trunk/sources/ElementsCollection/elementscollectionwidget.cpp
    trunk/sources/ElementsCollection/elementslocation.cpp
    trunk/sources/ElementsCollection/elementslocation.h
    trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
    trunk/sources/ElementsCollection/fileelementcollectionitem.h
    trunk/sources/ElementsCollection/xmlelementcollection.cpp
    trunk/sources/ElementsCollection/xmlelementcollection.h
    trunk/sources/diagramevent/diagrameventaddelement.cpp
    trunk/sources/diagramview.cpp
    trunk/sources/qetproject.cpp
    trunk/sources/qetproject.h

Added Paths:
-----------
    trunk/sources/ui/importelementdialog.cpp
    trunk/sources/ui/importelementdialog.h
    trunk/sources/ui/importelementdialog.ui

Modified: trunk/sources/ElementsCollection/elementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementcollectionitem.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -143,6 +143,30 @@
 }
 
 /**
+ * @brief ElementCollectionItem::itemAtPath
+ * @param path
+ * @return the item at path or nullptr if doesn't exist
+ */
+ElementCollectionItem *ElementCollectionItem::itemAtPath(const QString &path)
+{
+	QStringList str_list = path.split("/");
+	if (str_list.isEmpty()) return nullptr;
+
+	ElementCollectionItem *match_eci = this;
+	foreach (QString str, str_list) {
+		ElementCollectionItem *eci = match_eci->childWithCollectionName(str);
+		if (!eci) {
+			return nullptr;
+		}
+		else {
+			match_eci = eci;
+		}
+	}
+
+	return match_eci;
+}
+
+/**
  * @brief ElementCollectionItem::rowForInsertItem
  * Return the row for insert a new child item to this item with name @collection_name.
  * If row can't be found (collection_name is null, or already exist) return -1;
@@ -396,22 +420,3 @@
 	m_bg_color = color;
 	m_show_bg_color = show;
 }
-
-/**
- * @brief ElementCollectionItem::canRemoveContent
- * @return true if this item can remove the content that he represent
- * By default return false.
- */
-bool ElementCollectionItem::canRemoveContent() {
-	return false;
-}
-
-/**
- * @brief ElementCollectionItem::removeContent
- * Remove the content that he represent this item (a directory or an element).
- * This method do nothing and return false. Inherit it, to handle removing
- * @return true if the content was successfully removed
- */
-bool ElementCollectionItem::removeContent() {
-	return false;
-}

Modified: trunk/sources/ElementsCollection/elementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/elementcollectionitem.h	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementcollectionitem.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -47,6 +47,7 @@
 		ElementCollectionItem *child(int row) const;
 		ElementCollectionItem *childWithCollectionName(QString name) const;
 		ElementCollectionItem *lastItemForPath(const QString &path, QString &newt_item);
+		ElementCollectionItem *itemAtPath(const QString &path);
 		int rowForInsertItem(const QString &collection_name);
 		virtual void insertNewItem(const QString &collection_name);
         int childCount() const;
@@ -72,10 +73,6 @@
 		int indexOfChild(ElementCollectionItem *child) const;
 		void setBackgroundColor(Qt::GlobalColor color, bool show);
 
-
-		virtual bool canRemoveContent();
-		virtual bool removeContent();
-
 	signals:
 		void beginInsertRows(ElementCollectionItem *parent, int first, int last);
 		void endInsertRows();

Modified: trunk/sources/ElementsCollection/elementscollectionmodel.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionmodel.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementscollectionmodel.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -21,6 +21,7 @@
 #include "fileelementcollectionitem.h"
 #include "xmlprojectelementcollectionitem.h"
 #include "qetproject.h"
+#include "xmlelementcollection.h"
 
 /**
  * @brief ElementsCollectionModel::ElementsCollectionModel
@@ -273,7 +274,7 @@
 
 /**
  * @brief ElementsCollectionModel::addProject
- * Add @project to the disalyed collection
+ * Add @project to the displayed collection
  * @param project
  * @return true if project was successfully added. If project is already
  * handled, return false.
@@ -288,21 +289,27 @@
 	XmlProjectElementCollectionItem *xpeci = new XmlProjectElementCollectionItem(project, m_root_item);
 	bool r = m_root_item->insertChild(row, xpeci);
 	endInsertRows();
-	connect(project, &QETProject::elementIntegratedToCollection, this, &ElementsCollectionModel::elementIntegratedToCollection);
+	connect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
+	connect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
 
-
 	return r;
 }
 
+/**
+ * @brief ElementsCollectionModel::removeProject
+ * Remove @project from this model
+ * @param project
+ * @return true if the project was successfully removed, false if not (or project doesn't managed)
+ */
 bool ElementsCollectionModel::removeProject(QETProject *project)
 {
 	if (!m_project_list.contains(project)) return false;
 
 	int row = m_project_list.indexOf(project);
-	if (removeRows(row, 1, QModelIndex()))
-	{
+	if (removeRows(row, 1, QModelIndex())) {
 		m_project_list.removeOne(project);
-		disconnect(project, &QETProject::elementIntegratedToCollection, this, &ElementsCollectionModel::elementIntegratedToCollection);
+		disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
+		connect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
 		return true;
 	}
 	else
@@ -339,26 +346,75 @@
  * @brief ElementsCollectionModel::elementAddedToEmbeddedCollection
  * When an element is added to embedded collection of a project,
  * this method create and display the new element
- * @param project -The project where new element was added.
- * @param path -The path of the new element in the embedded collection of project
+ * @param path -The path of the new element in the embedded collection of a project
  */
-void ElementsCollectionModel::elementIntegratedToCollection(QETProject *project, QString path)
+void ElementsCollectionModel::elementIntegratedToCollection (QString path)
 {
-	XmlProjectElementCollectionItem *xpeci = itemForProject(project);
-	if (!xpeci) return;
+	QObject *object = sender();
+	XmlElementCollection *collection = static_cast<XmlElementCollection *> (object);
+	if (!collection) return;
 
-	QString collection_name;
-	ElementCollectionItem *eci = xpeci->lastItemForPath(path, collection_name);
-	if (!eci) return;
+	QETProject *project = nullptr;
 
-	int new_row = eci->rowForInsertItem(collection_name);
-	if (new_row <= -1) return;
-	QModelIndex parent_index = createIndex(eci->row(), 0, eci);
-	beginInsertRows(parent_index, new_row, new_row);
-	eci->insertNewItem(collection_name);
-	endInsertRows();
+		//Get the owner project of the collection
+	foreach (QETProject *prj, m_project_list) {
+		if (prj->embeddedElementCollection() == collection) {
+			project = prj;
+		}
+	}
+
+	if (project) {
+		XmlProjectElementCollectionItem *xpeci = itemForProject(project);
+		if (!xpeci) return;
+
+		QString collection_name;
+		ElementCollectionItem *eci = xpeci->lastItemForPath(path, collection_name);
+		if (!eci) return;
+
+		int new_row = eci->rowForInsertItem(collection_name);
+		if (new_row <= -1) return;
+		QModelIndex parent_index = createIndex(eci->row(), 0, eci);
+		beginInsertRows(parent_index, new_row, new_row);
+		eci->insertNewItem(collection_name);
+		endInsertRows();
+	}
 }
 
+/**
+ * @brief ElementsCollectionModel::updateItem
+ * Update the item at path
+ * @param path
+ */
+void ElementsCollectionModel::updateItem(QString path)
+{
+	QObject *object = sender();
+	XmlElementCollection *collection = static_cast<XmlElementCollection *> (object);
+	if (!collection) return;
+
+	QETProject *project = nullptr;
+
+		//Get the owner project of the collection
+	foreach (QETProject *prj, m_project_list) {
+		if (prj->embeddedElementCollection() == collection) {
+			project = prj;
+		}
+	}
+
+	if (project) {
+		XmlProjectElementCollectionItem *xpeci = itemForProject(project);
+		if (!xpeci) {
+			return;
+		}
+
+		ElementCollectionItem *eci = xpeci->itemAtPath(path);
+		if (!eci) {
+			return;
+		}
+
+		eci->clearData();
+	}
+}
+
 void ElementsCollectionModel::bir(ElementCollectionItem *eci, int first, int last)
 {
 	Q_UNUSED(eci);

Modified: trunk/sources/ElementsCollection/elementscollectionmodel.h
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionmodel.h	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementscollectionmodel.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -61,7 +61,8 @@
 
 	private:
 		XmlProjectElementCollectionItem *itemForProject(QETProject *project);
-		void elementIntegratedToCollection (QETProject *project, QString path);
+		void elementIntegratedToCollection (QString path);
+		void updateItem (QString path);
 			//Use as slot in method drop mime data
 		void bir(ElementCollectionItem *eci, int first, int last);
 		void brr(ElementCollectionItem *eci, int first, int last);

Modified: trunk/sources/ElementsCollection/elementscollectionwidget.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementscollectionwidget.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementscollectionwidget.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -263,21 +263,26 @@
 	ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
 
 	if (!eci) return;
-	if (!(eci->isElement() && eci->canRemoveContent())) return;
 
+	ElementsLocation loc(eci->collectionPath());
+	if (! (loc.isElement() && loc.exist() && loc.isFileSystem() && loc.collectionPath().startsWith("custom://")) ) return;
+
 	if (QET::QetMessageBox::question(this,
 									 tr("Supprimer l'élément ?", "message box title"),
 									 tr("Êtes-vous sûr  de vouloir supprimer cet élément ?\n", "message box content"),
 									 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
 	{
-		if (!eci->removeContent())
+		QFile file(loc.fileSystemPath());
+		if (file.remove())
 		{
+			m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
+		}
+		else
+		{
 			QET::QetMessageBox::warning(this,
 										tr("Suppression de l'élément", "message box title"),
 										tr("La suppression de l'élément a échoué.", "message box content"));
-		}
-		else
-			m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
+		}	
 	}
 }
 
@@ -290,8 +295,10 @@
 	ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
 
 	if (!eci) return;
-	if (!(eci->isDir() && eci->canRemoveContent())) return;
 
+	ElementsLocation loc (eci->collectionPath());
+	if (! (loc.isDirectory() && loc.exist() && loc.isFileSystem() && loc.collectionPath().startsWith("custom://")) ) return;
+
 	if (QET::QetMessageBox::question(this,
 									 tr("Supprimer le dossier?", "message box title"),
 									 tr("Êtes-vous sûr  de vouloir supprimer le dossier ?\n"
@@ -299,14 +306,17 @@
 										"message box content"),
 									 QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
 	{
-		if (!eci->removeContent())
+		QDir dir (loc.fileSystemPath());
+		if (dir.removeRecursively())
 		{
+			m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
+		}
+		else
+		{
 			QET::QetMessageBox::warning(this,
 										tr("Suppression du dossier", "message box title"),
 										tr("La suppression du dossier a échoué.", "message box content"));
 		}
-		else
-			m_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent());
 	}
 }
 
@@ -344,8 +354,9 @@
 
 	ElementsLocation location(feci->collectionPath());
 	ElementsCategoryEditor new_dir_editor(location, false, this);
-	if (new_dir_editor.exec() == QDialog::Accepted)
-		reload();;
+	if (new_dir_editor.exec() == QDialog::Accepted) {
+		reload();
+	}
 }
 
 /**

Modified: trunk/sources/ElementsCollection/elementslocation.cpp
===================================================================
--- trunk/sources/ElementsCollection/elementslocation.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementslocation.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -677,3 +677,19 @@
 uint qHash(const ElementsLocation &location) {
 	return(qHash(location.toString()));
 }
+
+QDebug operator<< (QDebug debug, const ElementsLocation &location)
+{
+	QDebugStateSaver saver(debug);
+	debug.noquote();
+
+	QString msg;
+	msg += "ElementsLocation(";
+	msg += (location.isProject()? location.projectCollectionPath() : location.collectionPath(true));
+	msg += location.exist()? ", true" : ", false";
+	msg +=")";
+
+	debug << msg;
+
+	return debug;
+}

Modified: trunk/sources/ElementsCollection/elementslocation.h
===================================================================
--- trunk/sources/ElementsCollection/elementslocation.h	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/elementslocation.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -83,6 +83,9 @@
 	public:
 		static int MetaTypeId; ///< Id of the corresponding Qt meta type
 };
+
+QDebug operator<<(QDebug debug, const ElementsLocation &location);
+
 Q_DECLARE_METATYPE(ElementsLocation)
 uint qHash(const ElementsLocation &);
 #endif

Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.cpp
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -391,40 +391,6 @@
 	return m_name;
 }
 
-/**
- * @brief FileElementCollectionItem::canRemoveContent
- * Reimplemented from ElementCollectionItem
- * @return
- */
-bool FileElementCollectionItem::canRemoveContent()
-{
-	if (isCommonCollection()) return false;
-	else if (isDir() && isCollectionRoot()) return false;
-	else return true;
-}
-
-/**
- * @brief FileElementCollectionItem::removeContent
- * Reimplemented from ElementCollectionItem
- * @return
- */
-bool FileElementCollectionItem::removeContent()
-{
-	if (!canRemoveContent()) return false;
-
-	if (isElement())
-	{
-		QFile file(fileSystemPath());
-		return file.remove();
-	}
-	else if (isDir() && !isCollectionRoot())
-	{
-		QDir dir (fileSystemPath());
-		return dir.removeRecursively();
-	}
-	return false;
-}
-
 void FileElementCollectionItem::insertNewItem(const QString &collection_name)
 {
 	if (collection_name.isEmpty()) return;

Modified: trunk/sources/ElementsCollection/fileelementcollectionitem.h
===================================================================
--- trunk/sources/ElementsCollection/fileelementcollectionitem.h	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/fileelementcollectionitem.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -60,8 +60,6 @@
 		virtual bool isValid() const;
 		virtual QString name();
 
-		virtual bool canRemoveContent();
-		virtual bool removeContent();
 		virtual void insertNewItem(const QString &collection_name);
 
     private:

Modified: trunk/sources/ElementsCollection/xmlelementcollection.cpp
===================================================================
--- trunk/sources/ElementsCollection/xmlelementcollection.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/xmlelementcollection.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -433,6 +433,7 @@
  * @brief XmlElementCollection::copy
  * Copy the content represented by source (an element or a directory) to destination.
  * Destination must be a directory of this collection.
+ * If the destination already have an item at the same path of source, he will be replaced by source.
  * @param source : content to copy
  * @param destination : destination of the copy, must be a directory of this collection
  * @param rename : rename the copy with @rename else use the name of source
@@ -545,10 +546,12 @@
 
 /**
  * @brief XmlElementCollection::copyElement
+ * Copy the element represented by source to destination (must be a directory)
+ * If element already exist in destination he will be replaced by the new.
  * @param source : element to copy
  * @param destination : destination of the copy
  * @param rename : rename the copy with @rename else use the name of source
- * @return
+ * @return The ElementsLocation of the copy
  */
 ElementsLocation XmlElementCollection::copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename)
 {
@@ -575,13 +578,25 @@
 
 		//Remove the previous element with the same path
 	QDomElement element = child(destination.collectionPath(false) + "/" + new_elmt_name);
-	if (!element.isNull())
+	bool removed = false;
+	if (!element.isNull()) {
 		element.parentNode().removeChild(element);
+		removed = true;
+	}
 
 		//Get the xml directory where the new element must be added
 	QDomElement dir_dom = directory(destination.collectionPath(false));
 	if (dir_dom.isNull()) return ElementsLocation();
 	dir_dom.appendChild(elmt_dom);
 
-	return ElementsLocation(destination.projectCollectionPath() + "/" + new_elmt_name);
+	ElementsLocation copy_loc(destination.projectCollectionPath() + "/" + new_elmt_name);
+
+	if (removed) {
+		emit elementChanged(copy_loc.collectionPath(false));
+	}
+	else {
+		emit elementAdded(copy_loc.collectionPath(false));
+	}
+
+	return copy_loc;
 }

Modified: trunk/sources/ElementsCollection/xmlelementcollection.h
===================================================================
--- trunk/sources/ElementsCollection/xmlelementcollection.h	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/ElementsCollection/xmlelementcollection.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -62,6 +62,12 @@
 			 * @param collection_path, the path of element in this collection
 			 */
 		void elementAdded(QString collection_path);
+			/**
+			 * @brief elementChanged
+			 * This signal is emited when the defintion of the element at path was changed
+			 * @param collection_path, the path of this element in this collection
+			 */
+		void elementChanged (QString collection_path);
 
 	public slots:
 

Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -172,22 +172,22 @@
 {
 	if (QETProject::integrateElementToProject(m_location, m_diagram -> project()))
 	{
-		QString error_msg;
-		IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler();
-		m_integrate_path = m_diagram -> project() -> integrateElement(m_location.toString(), integ_handler, error_msg);
-		delete integ_handler;
-		if (m_integrate_path.isEmpty())
-		{
-			qDebug() << "DiagramView::addDroppedElement : Impossible d'ajouter l'element. Motif : " << qPrintable(error_msg);
+		ElementsLocation loc = m_diagram->project()->importElement(m_location);
+		if (loc.exist()) {
+			m_integrate_path = loc.projectCollectionPath();
+		}
+		else {
+			qDebug() << "DiagramView::addDroppedElement : Impossible d'ajouter l'element.";
 			return false;
 		}
+
 	}
 
 	int state;
-	m_element = ElementFactory::Instance() -> createElement(m_location, 0, &state);
+	ElementsLocation loc(m_integrate_path);
+	m_element = ElementFactory::Instance() -> createElement(loc, 0, &state);
 		//The creation of element failed, we delete it
-	if (state)
-	{
+	if (state) {
 		delete m_element;
 		return(false);
 	}

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/diagramview.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -279,18 +279,18 @@
 	Handle the drop of an element.
 	@param e the QDropEvent describing the current drag'n drop
 */
-void DiagramView::handleElementDrop(QDropEvent *e)
+void DiagramView::handleElementDrop(QDropEvent *event)
 {
-		//fetch the element location from the drop event
-	QString elmt_path = e -> mimeData() -> text();
-	
-	ElementsLocation location(elmt_path);
-	
-		// verifie qu'il existe un element correspondant a cet emplacement
-	ElementsCollectionItem *dropped_item = QETApp::collectionItem(location);
-	if (!dropped_item) return;
+		//Build an element from the text of the mime data
+	ElementsLocation location(event->mimeData()->text());
 
-	diagram()->setEventInterface(new DiagramEventAddElement(location, diagram(), mapToScene(e->pos())));
+	if ( !(location.isElement() && location.exist()) )
+	{
+		qDebug() << "DiagramView::handleElementDrop, location can't be use : " << location;
+		return;
+	}
+
+	diagram()->setEventInterface(new DiagramEventAddElement(location, diagram(), mapToScene(event->pos())));
 		//Set focus to the view to get event
 	this->setFocus();
 }

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/qetproject.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -33,6 +33,7 @@
 #include "reportproperties.h"
 #include "integrationmovetemplateshandler.h"
 #include "xmlelementcollection.h"
+#include "importelementdialog.h"
 
 #include <QStandardPaths>
 
@@ -68,9 +69,7 @@
 	connect(collection_, SIGNAL(written()), this, SLOT(componentWritten()));
 
 	m_elements_collection = new XmlElementCollection(this);
-	
-	// une categorie dediee aux elements integres automatiquement
-	ensureIntegrationCategoryExists();
+
 	setupTitleBlockTemplatesCollection();
 
 	undo_stack_ = new QUndoStack();
@@ -146,17 +145,10 @@
  */
 bool QETProject::integrateElementToProject(const ElementsLocation &location, const QETProject *project)
 {
-		//Integration element must be enable
-	QSettings settings;
-	bool auto_integration_enabled = settings.value("diagrameditor/integrate-elements", true).toBool();
+	if (location.isFileSystem()) {return true;}
+	if (location.isProject() && (location.project() != project)) {return true;}
 
-		//the element belongs there a project and if so, is this another project of the project given by parameter?
-	bool elmt_from_project = location.project();
-	bool elmt_from_another_project = elmt_from_project && location.project() != project;
-
-	bool must_integrate_element = (elmt_from_another_project || (auto_integration_enabled && !elmt_from_project));
-
-	return(must_integrate_element);
+	return false;
 }
 
 /**
@@ -639,24 +631,6 @@
 }
 
 /**
-	Cree une categorie dediee aux elements integres automatiquement dans le
-	projet si celle-ci n'existe pas deja.
-	@return true si tout s'est bien passe, false sinon
-*/
-bool QETProject::ensureIntegrationCategoryExists() {
-	ElementsCategory *root_cat = rootCategory();
-	if (!root_cat) return(false);
-	
-	if (root_cat -> category(integration_category_name)) return(true);
-	
-	ElementsCategory *integration_category = root_cat -> createCategory(integration_category_name);
-	if (!integration_category) return(false);
-	
-	integration_category -> setNames(namesListForIntegrationCategory());
-	return(true);
-}
-
-/**
 	@return la categorie dediee aux elements integres automatiquement dans le
 	projet ou 0 si celle-ci n'a pu etre creee.
 	@see ensureIntegrationCategoryExists()
@@ -669,134 +643,94 @@
 }
 
 /**
-	Integre un element dans le projet.
-	Cette methode delegue son travail a la methode
-	integrateElement(const QString &, MoveElementsHandler *, QString &)
-	en lui passant un MoveElementsHandler approprie.
-	@param elmt_location Emplacement de l'element a integrer
-	@param error_msg Reference vers une chaine de caractere qui contiendra
-	eventuellement un message d'erreur
-	@return L'emplacement de l'element apres integration, ou une chaine vide si
-	l'integration a echoue.
-*/
-QString QETProject::integrateElement(const QString &elmt_location, QString &error_msg) {
-	// handler dedie a l'integration d'element
-	IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler(0);
-	QString integ_path = integrateElement(elmt_location, integ_handler, error_msg);
-	delete integ_handler;
-	
-	return(integ_path);
-}
+ * @brief QETProject::importElement
+ * Import the element represented by @location to the embbeded collection of this project
+ * @param location
+ * @return the location of the imported element, location can be null.
+ */
+ElementsLocation QETProject::importElement(ElementsLocation &location)
+{
+		//Location isn't an element or doesn't exist
+	if (! (location.isElement() && location.exist()) ) {
+		return ElementsLocation();
+	}
 
-/**
-	Integre un element dans le projet.
-	Cette methode prend en parametre l'emplacement d'un element a integrer.
-	Chaque categorie mentionnee dans le chemin de cet element sera copiee de
-	maniere non recursive sous la categorie dediee a l'integration si elle
-	n'existe pas deja.
-	L'element sera ensuite copiee dans cette copie de la hierarchie d'origine.
-	En cas de probleme, error_message sera modifiee de facon a contenir un
-	message decrivant l'erreur rencontree.
-	@param elmt_path Emplacement de l'element a integrer
-	@param handler Gestionnaire a utiliser pour gerer les copies d'elements et categories
-	@param error_message Reference vers une chaine de caractere qui contiendra
-	eventuellement un message d'erreur
-	@return L'emplacement de l'element apres integration, ou une chaine vide si
-	l'integration a echoue.
-*/
-QString QETProject::integrateElement(const QString &elmt_path, MoveElementsHandler *handler, QString &error_message) {
-	// on s'assure que le projet a une categorie dediee aux elements importes automatiquement
-	if (!ensureIntegrationCategoryExists())
-	{
-		error_message = tr("Impossible de créer la catégorie pour l'intégration des éléments");
-		return(QString());
+		//Get the path where the element must be imported
+	QString import_path;
+	if (location.isFileSystem()) {
+		import_path = "import/" + location.collectionPath(false);
 	}
-	
-	// accede a la categorie d'integration
-	ElementsCategory *integ_cat = integrationCategory();
-	
-	// accede a l'element a integrer
-	ElementsCollectionItem *integ_item = QETApp::collectionItem(ElementsLocation(elmt_path));
-	ElementDefinition *integ_elmt = integ_item ? integ_item -> toElement() : 0;
-	if (!integ_item || !integ_elmt)
-	{
-		error_message = tr("Impossible d'accéder à l'élément à intégrer");
-		return(QString());
+
+	if (location.isProject()) {
+		if (location.project() == this) {
+			return location;
+		}
+
+		import_path = location.collectionPath(false);
 	}
-	
-	// recopie l'arborescence de l'element de facon non recursive
-	QList<ElementsCategory *> integ_par_cat = integ_elmt -> parentCategories();
-	ElementsCategory *target_cat = integ_cat;
-	foreach(ElementsCategory *par_cat, integ_par_cat)
-	{
-		if (par_cat -> isRootCategory()) continue;
-		
-		if (ElementsCategory *existing_cat = target_cat -> category(par_cat -> pathName()))
-		{
-			// la categorie cible existe deja : on continue la progression
-			target_cat = existing_cat;
+
+		//Element already exist in the embedded collection, we ask what to do to user
+	if (m_elements_collection->exist(import_path)) {
+		ElementsLocation existing_location(import_path, this);
+
+			//@existing_location and @location have the same uuid, so it is the same element
+		if (existing_location.uuid() == location.uuid()) {
+			return existing_location;
 		}
-		else
-		{
-			// la categorie cible n'existe pas : on la cree par recopie
-			ElementsCollectionItem *result_cat = par_cat -> copy(target_cat, handler, false);
-			if (!result_cat || !result_cat -> isCategory())
-			{
-				error_message = QString(tr("Un problème s'est produit pendant la copie de la catégorie %1")).arg(par_cat -> location().toString());
-				return(QString());
+
+		ImportElementDialog ied;
+		if (ied.exec() == QDialog::Accepted) {
+			QET::Action action = ied.action();
+
+				//Use the exisitng element
+			if (action == QET::Ignore) {
+				return existing_location;
 			}
-			target_cat = result_cat -> toCategory();
+				//Erase the existing element, and use the newer instead
+			else if (action == QET::Erase) {
+				ElementsLocation parent_loc = existing_location.parent();
+				return m_elements_collection->copy(location, parent_loc);
+			}
+				//Add the new element with an other name.
+			else if (action == QET::Rename) {
+				int a = 0;
+				QString parent_path = existing_location.parent().projectCollectionPath();
+				QString name_ = existing_location.fileName();
+				name_.remove(".elmt");
+
+				ElementsLocation loc;
+				do
+				{
+					a++;
+					QString new_path = parent_path + "/" + name_ + QString::number(a) + ".elmt";
+					loc = ElementsLocation (new_path);
+				} while (loc.exist());
+
+				ElementsLocation parent_loc = existing_location.parent();
+				return m_elements_collection->copy(location, parent_loc, loc.fileName());
+			}
+			else {
+				return ElementsLocation();
+			}
 		}
+		else {
+			return ElementsLocation();
+		}
 	}
-	
-	// recopie l'element
-	ElementsLocation result;
-	if (ElementDefinition *existing_elmt = target_cat -> element(integ_item -> pathName()))
-	{
-		
-		// l'element existe deja - on demande au handler ce que l'on doit faire
-		QET::Action action = handler -> elementAlreadyExists(integ_elmt, existing_elmt);
-		
-		if (action == QET::Ignore)
-		{
-			// il faut conserver et utiliser l'element deja integre
-			result = existing_elmt -> location();
+		//Element doesn't exist in the collection, we just import it
+	else {
+		ElementsLocation loc(m_elements_collection->addElement(location), this);
+
+		if (!loc.exist()) {
+			qDebug() << "QETProject::importElement : failed to import location. " << location;
+			return ElementsLocation();
 		}
-		else if (action == QET::Erase)
-		{
-			// il faut ecraser l'element deja integre
-			BasicMoveElementsHandler *erase_handler = new BasicMoveElementsHandler();
-			result = copyElementWithHandler(integ_elmt, target_cat, erase_handler, error_message);
-			delete erase_handler;
+		else {
+			return loc;
 		}
-		else if (action == QET::Rename)
-		{
-			// il faut faire cohabiter les deux elements en renommant le nouveau 
-			QString integ_element_name = handler -> nameForRenamingOperation();
-			BasicMoveElementsHandler *rename_handler = new BasicMoveElementsHandler();
-			rename_handler -> setActionIfItemAlreadyExists(QET::Rename);
-			rename_handler -> setNameForRenamingOperation(integ_element_name);
-			result = copyElementWithHandler(integ_elmt, target_cat, rename_handler, error_message);
-			delete rename_handler;
-		}
-		else
-		{
-			// il faut annuler la pose de l'element
-			result = ElementsLocation();
-		}
 	}
-	else
-	{
-		// integre l'element normalement
-		result = copyElementWithHandler(integ_elmt, target_cat, handler, error_message);
 
-		ElementsLocation location(elmt_path);
-		QString xml_path = m_elements_collection->addElement(location);
-		if (!xml_path.isNull()) emit elementIntegratedToCollection(this, xml_path);
-	}
-	
-	if (!result.isNull()) emit(elementIntegrated(this, result));
-	return(result.toString());
+	return ElementsLocation();
 }
 
 /**

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2016-05-04 13:45:25 UTC (rev 4467)
+++ trunk/sources/qetproject.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -127,10 +127,8 @@
 		bool isReadOnly() const;
 		void setReadOnly(bool);
 		bool isEmpty() const;
-		bool ensureIntegrationCategoryExists();
 		ElementsCategory *integrationCategory() const;
-		QString integrateElement(const QString &, QString &);
-		QString integrateElement(const QString &, MoveElementsHandler *, QString &);
+		ElementsLocation importElement(ElementsLocation &location);
 		QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler);
 		bool usesElement(const ElementsLocation &);
 		bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &);
@@ -164,7 +162,6 @@
 	void readOnlyChanged(QETProject *, bool);
 	void reportPropertiesChanged(QString);
 	void XRefPropertiesChanged ();
-		void elementIntegratedToCollection(QETProject *project, QString path);
 	
 	private slots:
 	void updateDiagramsFolioData();

Added: trunk/sources/ui/importelementdialog.cpp
===================================================================
--- trunk/sources/ui/importelementdialog.cpp	                        (rev 0)
+++ trunk/sources/ui/importelementdialog.cpp	2016-05-05 13:31:04 UTC (rev 4468)
@@ -0,0 +1,53 @@
+/*
+	Copyright 2006-2016 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "importelementdialog.h"
+#include "ui_importelementdialog.h"
+
+ImportElementDialog::ImportElementDialog(QWidget *parent) :
+	QDialog(parent),
+	ui(new Ui::ImportElementDialog)
+{
+	ui->setupUi(this);
+	setUpWidget();
+}
+
+ImportElementDialog::~ImportElementDialog()
+{
+	delete ui;
+}
+
+QET::Action ImportElementDialog::action() const
+{
+	if (ui->m_use_actual_rd->isChecked()) { return QET::Ignore; }
+	else if (ui->m_erase_actual_rb->isChecked()) { return QET::Erase; }
+	else if (ui->m_use_both_rb->isChecked()) { return QET::Rename; }
+	else return QET::Abort;
+}
+
+void ImportElementDialog::setUpWidget()
+{
+	QButtonGroup *button_group = new QButtonGroup(this);
+	button_group->addButton(ui->m_use_actual_rd);
+	button_group->addButton(ui->m_use_drop_rb);
+	QButtonGroup *button_group_drop = new QButtonGroup(this);
+	button_group_drop->addButton(ui->m_erase_actual_rb);
+	button_group_drop->addButton(ui->m_use_both_rb);
+
+	ui->m_use_drop_rb->setChecked(true);
+	ui->m_use_both_rb->setChecked(true);
+}

Added: trunk/sources/ui/importelementdialog.h
===================================================================
--- trunk/sources/ui/importelementdialog.h	                        (rev 0)
+++ trunk/sources/ui/importelementdialog.h	2016-05-05 13:31:04 UTC (rev 4468)
@@ -0,0 +1,46 @@
+/*
+	Copyright 2006-2016 The QElectroTech Team
+	This file is part of QElectroTech.
+
+	QElectroTech is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 2 of the License, or
+	(at your option) any later version.
+
+	QElectroTech is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef IMPORTELEMENTDIALOG_H
+#define IMPORTELEMENTDIALOG_H
+
+#include <QDialog>
+#include "qet.h"
+
+namespace Ui {
+	class ImportElementDialog;
+}
+
+class ImportElementDialog : public QDialog
+{
+		Q_OBJECT
+
+	public:
+		explicit ImportElementDialog(QWidget *parent = 0);
+		~ImportElementDialog();
+
+		QET::Action action() const;
+
+	private:
+		void setUpWidget();
+		void setUpConnection();
+
+	private:
+		Ui::ImportElementDialog *ui;
+};
+
+#endif // IMPORTELEMENTDIALOG_H

Added: trunk/sources/ui/importelementdialog.ui
===================================================================
--- trunk/sources/ui/importelementdialog.ui	                        (rev 0)
+++ trunk/sources/ui/importelementdialog.ui	2016-05-05 13:31:04 UTC (rev 4468)
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ImportElementDialog</class>
+ <widget class="QDialog" name="ImportElementDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>754</width>
+    <height>176</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Intégration d'un élément</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>L'élément a déjà été intégré dans le projet. Toutefois, la version que vous tentez de poser semble différente. Que souhaitez-vous faire ?</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QRadioButton" name="m_use_actual_rd">
+     <property name="text">
+      <string>Utiliser l'élément déjà integré</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QRadioButton" name="m_use_drop_rb">
+     <property name="text">
+      <string>Intégrer l'élément déposé</string>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
+     </property>
+     <property name="checked">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout_2">
+     <property name="leftMargin">
+      <number>15</number>
+     </property>
+     <item>
+      <widget class="QRadioButton" name="m_erase_actual_rb">
+       <property name="text">
+        <string>Écraser l'élément déjà intégé</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QRadioButton" name="m_use_both_rb">
+       <property name="text">
+        <string>Faire cohabiter les deux éléments</string>
+       </property>
+       <property name="checked">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>ImportElementDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>ImportElementDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>m_use_drop_rb</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>m_erase_actual_rb</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>375</x>
+     <y>162</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>375</x>
+     <y>188</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>m_use_drop_rb</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>m_use_both_rb</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>375</x>
+     <y>162</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>375</x>
+     <y>214</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>


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