[qet] qet/qet: [4874] Link single element widget : revamp the widget ( use a QTreeWidget instead of a list of widgets) and add the variable %F to the value displayed

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


Revision: 4874
Author:   blacksun
Date:     2017-01-26 11:09:07 +0100 (Thu, 26 Jan 2017)
Log Message:
-----------
Link single element widget : revamp the widget (use a QTreeWidget instead of a list of widgets) and add the variable %F to the value displayed 

Modified Paths:
--------------
    trunk/sources/ui/linksingleelementwidget.cpp
    trunk/sources/ui/linksingleelementwidget.h
    trunk/sources/ui/linksingleelementwidget.ui
    trunk/sources/ui/masterpropertieswidget.ui

Removed Paths:
-------------
    trunk/sources/ui/elementselectorwidget.cpp
    trunk/sources/ui/elementselectorwidget.h
    trunk/sources/ui/elementselectorwidget.ui

Deleted: trunk/sources/ui/elementselectorwidget.cpp
===================================================================
--- trunk/sources/ui/elementselectorwidget.cpp	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/elementselectorwidget.cpp	2017-01-26 10:09:07 UTC (rev 4874)
@@ -1,279 +0,0 @@
-/*
-	Copyright 2006-2017 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 "elementselectorwidget.h"
-#include "ui_elementselectorwidget.h"
-#include "diagramposition.h"
-#include "qeticons.h"
-#include "diagram.h"
-#include "element.h"
-#include "terminal.h"
-#include "conductor.h"
-#include "qet.h"
-#include "assignvariables.h"
-
-/**
- * @brief ElementSelectorWidget::ElementSelectorWidget
- * Default constructor
- * @param elmt_list
- * List of element to be displayed by the selector
- * @param parent
- * Parent widget
- */
-ElementSelectorWidget::ElementSelectorWidget(QList <Element *> elmt_list, QWidget *parent) :
-	QWidget(parent),
-	ui(new Ui::ElementSelectorWidget),
-	elements_list(elmt_list),
-	selected_element (nullptr),
-	showed_element   (nullptr),
-	m_button_group   (nullptr)
-{
-	qSort(elements_list.begin(), elements_list.end(), comparPos);
-	ui->setupUi(this);
-	buildInterface();
-}
-
-/**
- * @brief ElementSelectorWidget::~ElementSelectorWidget
- * Default destructor
- */
-ElementSelectorWidget::~ElementSelectorWidget()
-{
-	if (showed_element) showed_element->setHighlighted(false);
-	delete ui;
-}
-
-/**
- * @brief ElementSelectorWidget::showElement
- * Show the element given by parametre
- * @param elmt
- */
-void ElementSelectorWidget::showElement(Element *elmt) {
-	if (showed_element)
-	{
-		disconnect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
-		showed_element->setHighlighted(false);
-	}
-	elmt->diagram()->showMe();
-	elmt->setHighlighted(true);
-	showed_element = elmt;
-	connect(showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
-}
-
-/**
- * @brief ElementSelectorWidget::clear
- * Clear the curent list and the widget
- */
-void ElementSelectorWidget::clear() {
-	elements_list.clear();
-	in_filter.clear();
-	out_filter.clear();
-	selected_element = nullptr;
-	if(showed_element) showed_element->setHighlighted(false);
-	foreach(QWidget *w, content_list) {
-		ui->scroll_layout_->removeWidget(w);
-		delete w;
-	}
-	content_list.clear();
-	delete sm_;
-	delete sm_show_;
-	delete m_button_group;
-}
-
-/**
- * @brief ElementSelectorWidget::setList
- * Set new list of elements
- * @param elmt_list the new elements list
- */
-void ElementSelectorWidget::setList(QList<Element *> elmt_list) {
-	clear();
-	elements_list << elmt_list;
-	qSort(elements_list.begin(), elements_list.end(), comparPos);
-	buildInterface();
-}
-
-/**
- * @brief ElementSelectorWidget::buildInterface
- * Build interface of this widget (fill all available element)
- */
-void ElementSelectorWidget::buildInterface() {
-	//Setup the signal mapper
-	int map_id = 0; //this int is used to map the signal
-
-	sm_ = new QSignalMapper(this);
-	connect(sm_, SIGNAL(mapped(int)), this, SLOT(setSelectedElement(int)));
-
-	sm_show_ = new QSignalMapper(this);
-	connect(sm_show_, SIGNAL(mapped(int)), this, SLOT(showElementFromList(int)));
-
-	m_button_group = new QButtonGroup(this);
-
-	//Build the list
-	foreach (Element *elmt, elements_list) {
-		//label for the button
-		QString button_text;
-
-			/*
-			 * If element is master and have label,
-			 * we add label and comment to the button text
-			 */
-		if (elmt->linkType() & Element::Master) {
-			DiagramContext dc = elmt -> elementInformations();
-
-			if (!dc["label"].toString().isEmpty())
-				button_text = autonum::AssignVariables::formulaToLabel(dc["label"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt) + " ";
-
-			if (!dc["comment"].toString().isEmpty())
-				button_text = autonum::AssignVariables::formulaToLabel(dc["comment"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
-
-			if (!dc["location"].toString().isEmpty())
-				button_text = autonum::AssignVariables::formulaToLabel(dc["location"].toString(), elmt->rSequenceStruct(), elmt->diagram(), elmt);
-
-			if (!button_text.isEmpty())
-				button_text += "\n";
-
-				//Add the string for filter this widget
-			QString filter;
-			foreach(QString str, elmt->elementInformations().keys()){
-				QString filter_str = elmt->elementInformations()[str].toString();
-				filter += filter_str;
-				out_filter << filter_str;
-			}
-			in_filter << filter;
-		}
-
-			/*
-			 * If element is a folio report, have conductors docked to his terminal,
-			 * and each conductor have the same text,
-			 * we add this text to the button label and provide it through the filter
-			 */
-		if (elmt -> linkType() & Element::AllReport) {
-				//Add empty string to keep the same index with content_list
-				//see how work filtered for more detail why we need this
-			in_filter << "";
-				//Report have one terminal, but we check it to prevent assert.
-			if (!elmt -> terminals().isEmpty()) {
-					//We must to have at least one conductor
-				if (!elmt -> terminals().first() -> conductors().isEmpty()) {
-					Conductor *cond = elmt->terminals().first()->conductors().first();
-					QSet <Conductor *> cdr_set = cond -> relatedPotentialConductors();
-					cdr_set << cond;
-
-					QStringList str_list;
-					foreach (Conductor* c, cdr_set)
-						str_list << c->properties().text;
-
-					if (QET::eachStrIsEqual(str_list)) {
-						button_text = tr("N° fil : ") + str_list.first() + "\n";
-							//Replace the last empty string by the conductor text
-						in_filter.pop_back();
-						in_filter  << str_list.first();
-						out_filter << str_list.first();
-					}
-				}
-			}
-		}
-
-		QString title = elmt->diagram()->title();
-		if (title.isEmpty()) title = tr("Sans titre");
-		button_text += QString("Folio %1 (%2), position %3.").arg(elmt->diagram()->folioIndex() + 1)
-																		  .arg(title)
-																		  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
-
-			//Widget that contain the buttons
-		QWidget *widget = new QWidget(this);
-		content_list << widget;
-
-			//Radio button for select element
-		QRadioButton *rb = new QRadioButton(button_text , widget);
-		m_button_group -> addButton(rb);
-
-			//Push button to highlight element
-		QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", widget);
-		pb -> setToolTip(tr("Voir l'élément"));
-
-		QHBoxLayout *hl = new QHBoxLayout(widget);
-		hl -> setContentsMargins(0,0,0,0);
-		hl -> addWidget(rb);
-		hl -> addStretch();
-		hl -> addWidget(pb);
-		ui -> scroll_layout_ -> insertWidget(map_id, widget);
-
-			//map the radio button signal
-		connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
-		sm_ -> setMapping(rb, map_id);
-			//map the push button show diagram
-		connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map()));
-		sm_show_->setMapping(pb, map_id);
-
-		map_id++; //increase the map_id for next button.
-	}
-}
-
-void ElementSelectorWidget::setSelectedElement(const int i)
-{
-	selected_element = elements_list.at(i);
-	emit elementSelected(selected_element);
-}
-
-/**
- * @brief ElementSelectorWidget::showElementFromList
- * Show the element at the position i in @elements_list
- * @param i
- */
-void ElementSelectorWidget::showElementFromList(const int i) {
-	if (elements_list.size() >= i)
-		showElement(elements_list.at(i));
-}
-
-/**
- * @brief ElementSelectorWidget::showedElementWasDeleted
- * Set to nullptr the current showed element when he was deleted
- */
-void ElementSelectorWidget::showedElementWasDeleted() {
-	showed_element = nullptr;
-}
-
-/**
- * @brief ElementSelectorWidget::filter
- * @return A stringlist with all available value
- * to filter the content of this widget;
- */
-QStringList ElementSelectorWidget::filter() const {
-	return out_filter;
-}
-
-/**
- * @brief ElementSelectorWidget::filter
- * Filter the content of the list.
- * Give an empty string remove all filter.
- * @param str string to filter
- */
-void ElementSelectorWidget::filtered(const QString &str) {
-	if(str.isEmpty()) {
-		foreach (QWidget *w, content_list) w->setHidden(false);
-	}
-	else {
-		for (int i = 0; i<in_filter.size(); i++) {
-			if (in_filter.at(i).contains(str, Qt::CaseInsensitive)) {
-				content_list.at(i)->setHidden(false);
-			}
-			else
-				content_list.at(i)->setHidden(true);
-		}
-	}
-}

Deleted: trunk/sources/ui/elementselectorwidget.h
===================================================================
--- trunk/sources/ui/elementselectorwidget.h	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/elementselectorwidget.h	2017-01-26 10:09:07 UTC (rev 4874)
@@ -1,79 +0,0 @@
-/*
-	Copyright 2006-2017 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 ELEMENTSELECTORWIDGET_H
-#define ELEMENTSELECTORWIDGET_H
-
-#include <QWidget>
-class Element;
-class QSignalMapper;
-class QButtonGroup;
-
-namespace Ui {
-	class ElementSelectorWidget;
-}
-
-/**
- * @brief The ElementSelectorWidget class
- * This class provide a widget with a list of element.
- * User can select an element in the list and higligth it.
- * For know what element is selected, call selectedElement.
- */
-class ElementSelectorWidget : public QWidget
-{
-	Q_OBJECT
-
-	///Methods
-	public:
-	explicit ElementSelectorWidget(QList <Element *> elmt_list, QWidget *parent = 0);
-	~ElementSelectorWidget();
-	Element * selectedElement () const{return selected_element;}
-	void showElement(Element *elmt);
-	void clear();
-	void setList(QList <Element *> elmt_list);
-
-	QStringList filter () const;
-
-	signals:
-		void elementSelected (Element *element);
-
-	public slots:
-		void filtered(const QString &str);
-
-	private:
-		void buildInterface();
-
-	private slots:
-		void setSelectedElement  (const int i);
-		void showElementFromList (const int i);
-		void showedElementWasDeleted ();
-
-
-	///Attributes
-	private:
-	Ui::ElementSelectorWidget *ui;
-	QList <Element *>          elements_list;
-	QSignalMapper             *sm_, *sm_show_;
-	Element                   *selected_element, *showed_element;
-	QList <QWidget *>          content_list;
-	QStringList                in_filter,  //In filter is used inside this class to filter the content of this widget
-							   out_filter; //Out filter is used to return (with the method filter) a list of
-										   //available string to filter the content of this widget
-	QButtonGroup               *m_button_group;
-};
-
-#endif // ELEMENTSELECTORWIDGET_H

Deleted: trunk/sources/ui/elementselectorwidget.ui
===================================================================
--- trunk/sources/ui/elementselectorwidget.ui	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/elementselectorwidget.ui	2017-01-26 10:09:07 UTC (rev 4874)
@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>ElementSelectorWidget</class>
- <widget class="QWidget" name="ElementSelectorWidget">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>300</width>
-    <height>400</height>
-   </rect>
-  </property>
-  <property name="minimumSize">
-   <size>
-    <width>300</width>
-    <height>400</height>
-   </size>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <widget class="QScrollArea" name="scrollArea">
-     <property name="widgetResizable">
-      <bool>true</bool>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
-     </property>
-     <widget class="QWidget" name="scrollAreaWidgetContents">
-      <property name="geometry">
-       <rect>
-        <x>0</x>
-        <y>0</y>
-        <width>280</width>
-        <height>380</height>
-       </rect>
-      </property>
-      <layout class="QVBoxLayout" name="scroll_layout_">
-       <item>
-        <spacer name="verticalSpacer">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
-      </layout>
-     </widget>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>

Modified: trunk/sources/ui/linksingleelementwidget.cpp
===================================================================
--- trunk/sources/ui/linksingleelementwidget.cpp	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/linksingleelementwidget.cpp	2017-01-26 10:09:07 UTC (rev 4874)
@@ -19,9 +19,11 @@
 #include "ui_linksingleelementwidget.h"
 #include "diagram.h"
 #include "elementprovider.h"
-#include "elementselectorwidget.h"
 #include "linkelementcommand.h"
+#include "diagramposition.h"
 
+#include <QTreeWidgetItem>
+
 /**
  * @brief LinkSingleElementWidget::LinkSingleElementWidget
  * Default constructor
@@ -32,14 +34,27 @@
  */
 LinkSingleElementWidget::LinkSingleElementWidget(Element *elmt, QWidget *parent) :
 	AbstractElementPropertiesEditorWidget(parent),
-	ui(new Ui::LinkSingleElementWidget),
-	esw_(nullptr),
-	unlink_(false),
-	search_field(nullptr)
+	ui(new Ui::LinkSingleElementWidget)
 {
 	ui->setupUi(this);
-	connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(setNewList()));
-	connect(ui->m_unlink_pb, SIGNAL(clicked()), this, SLOT(unlinkClicked()));
+	
+	ui->m_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu);
+	m_context_menu  = new QMenu(this);
+	m_link_action   = new QAction(tr("Lier l'élément"), this);
+	m_show_qtwi     = new QAction(tr("Montrer l'élément"), this);
+	m_show_element  = new QAction(tr("Montrer l'élément esclave"), this);
+	
+	connect(m_show_qtwi, &QAction::triggered, [this]() {this->on_m_tree_widget_itemDoubleClicked(this->m_qtwi_at_context_menu, 0);});
+	connect(m_link_action, &QAction::triggered, this, &LinkSingleElementWidget::linkTriggered);
+	
+	connect(m_show_element,  &QAction::triggered, [this]()
+	{
+		this->m_element->diagram()->showMe();
+		this->m_element->setHighlighted(true);
+		if(this->m_showed_element)
+			m_showed_element->setHighlighted(false);
+	});
+			
 	setElement(elmt);
 }
 
@@ -47,7 +62,15 @@
  * @brief LinkSingleElementWidget::~LinkSingleElementWidget
  * Default destructor
  */
-LinkSingleElementWidget::~LinkSingleElementWidget() {
+LinkSingleElementWidget::~LinkSingleElementWidget()
+{
+	if(m_showed_element)
+		m_showed_element->setHighlighted(false);
+	
+	m_element->setHighlighted(false);
+	
+	if (!m_element->isFree())
+		m_element->linkedElements().first()->setHighlighted(false);
 	delete ui;
 }
 
@@ -58,7 +81,8 @@
  */
 void LinkSingleElementWidget::setElement(Element *element)
 {
-	if (m_element == element) return;
+	if (m_element == element)
+		return;
 
 		//Remove connection of previous edited element
 	if (m_element)
@@ -65,19 +89,26 @@
 	{
 		disconnect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
 		disconnect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi);
-		diagram_list.clear();
+		m_element->setHighlighted(false);
 	}
+	
+	if(m_showed_element)
+		m_showed_element->setHighlighted(false);
+	
+	m_unlink = false;
+	m_showed_element = nullptr;
+	m_element_to_link = nullptr;
+	m_pending_qtwi = nullptr;
 
 		//Setup the new element, connection and ui
 	m_element = element;
-	diagram_list << m_element->diagram()->project()->diagrams();
 
 	if (m_element->linkType() & Element::Slave)
-		filter_ = Element::Master;
+		m_filter = Element::Master;
 	else if (m_element->linkType() & Element::AllReport)
-		filter_ = m_element->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport;
+		m_filter = m_element->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport;
 	else
-		filter_ = Element::Simple;
+		m_filter = Element::Simple;
 
 	connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
 	connect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection);
@@ -95,6 +126,10 @@
 	QUndoCommand *undo = associatedUndo();
 	if (undo)
 		m_element->diagram()->undoStack().push(undo);
+	
+	m_unlink = false;
+	m_element_to_link = nullptr;
+	m_pending_qtwi = nullptr;
 }
 
 /**
@@ -104,13 +139,13 @@
  */
 QUndoCommand *LinkSingleElementWidget::associatedUndo() const
 {
-	if (esw_->selectedElement() || unlink_)
+	LinkElementCommand *undo = new LinkElementCommand(m_element);
+
+	if (m_element_to_link || m_unlink)
 	{
-		LinkElementCommand *undo = new LinkElementCommand(m_element);
-
-		if (esw_->selectedElement())
-			undo->setLink(esw_->selectedElement());
-		else if (unlink_)
+		if (m_element_to_link)
+			undo->setLink(m_element_to_link);
+		else if (m_unlink)
 			undo->unlinkAll();
 
 		return undo;
@@ -137,33 +172,47 @@
  */
 void LinkSingleElementWidget::updateUi()
 {
-		//Fill the combo box for filter the result by folio
-	ui->folio_combo_box->blockSignals(true);
-	ui->folio_combo_box->clear();
-	ui->folio_combo_box->addItem(tr("Tous"));
+	m_unlink = false;
 
-	foreach (Diagram *d, diagram_list)
-	{
-		QString title = d->title();
-		if (title.isEmpty()) title = tr("Sans titre");
-		title.prepend(QString::number(d->folioIndex() + 1) + " ");
-		ui->folio_combo_box->addItem(title);
-	}
-	ui->folio_combo_box->blockSignals(false);
-
-	unlink_ = false;
-	buildList();
-
 		//Update the behavior of link/unlink button
 	if (m_element->isFree())
+		hideButtons();
+	else
+		showButtons();
+	
+	buildTree();
+}
+
+/**
+ * @brief LinkSingleElementWidget::buildTree
+ * Build the content of the QTreeWidget
+ */
+void LinkSingleElementWidget::buildTree()
+{
+	clearTreeWidget();
+	foreach(Element *elmt, availableElements())
 	{
-		ui->button_linked->setDisabled(true);
-		ui->m_unlink_widget->hide();
+		QStringList str_list;
+		str_list << elmt->elementInformations()["label"].toString();
+		str_list << elmt->elementInformations()["comment"].toString();
+		if (Diagram *diag = elmt->diagram())
+		{
+			str_list << QString::number(diag->folioIndex() + 1);
+			autonum::sequentialNumbers seq;
+			QString F =autonum::AssignVariables::formulaToLabel(diag->border_and_titleblock.folio(), seq, diag, elmt);
+			str_list << F;
+			str_list << diag->title();
+			str_list << diag->convertPosition(elmt->scenePos()).toString();
+		}
+		else
+		{
+			qDebug() << "In method void LinkSingleElementWidget::updateUi(), provied element must have be in a diagram";
+		}
+		QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_tree_widget, str_list);
+		m_qtwi_elmt_hash.insert(qtwi, elmt);
 	}
-	else
-		ui->m_unlink_widget->show();
-
-	buildSearchField();
+	
+	//setUpCompleter();
 }
 
 /**
@@ -173,195 +222,231 @@
  */
 bool LinkSingleElementWidget::setLiveEdit(bool live_edit)
 {
-	if (m_live_edit == live_edit) return true;
+	if (m_live_edit == live_edit)
+		return true;
+	
 	m_live_edit = live_edit;
+	
+	return true;
+}
 
-	if (m_live_edit)
-		enableLiveEdit();
+/**
+ * @brief LinkSingleElementWidget::availableElements
+ * @return A QList with all available element
+ * to be linked with the edited element.
+ * This methode take care of the combo box "find in diagram"
+ */
+QList <Element *> LinkSingleElementWidget::availableElements()
+{
+	QList <Element *> elmt_list;
+		//if element isn't free and unlink isn't pressed, return an empty list
+	if (!m_element->isFree() && !m_unlink)
+		return elmt_list;
+
+	if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_list;
+	
+	ElementProvider ep(m_element->diagram()->project());
+	if (m_filter & Element::AllReport)
+		elmt_list = ep.freeElement(m_filter);
 	else
-		disableLiveEdit();
+		elmt_list = ep.find(m_filter);
+	
+		//If element is linked, remove is parent from the list
+	if(!m_element->isFree()) elmt_list.removeAll(m_element->linkedElements().first());
 
-	return true;
+	return elmt_list;
 }
 
+///**
+// * @brief LinkSingleElementWidget::setUpCompleter
+// * Setup the completer of search_field
+// */
+//void LinkSingleElementWidget::setUpCompleter()
+//{
+//	ui->m_search_field->clear();
+//	if(ui->m_search_field->completer())
+//		delete ui->m_search_field->completer();
+	
+//	QStringList filter;
+//	foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys())
+//	{
+//		filter << qtwi->data(0, Qt::DisplayRole).toString();
+//		filter << qtwi->data(1, Qt::DisplayRole).toString();
+//	}
+//	QCompleter *c = new QCompleter(filter, ui->m_search_field);
+//	c->setCaseSensitivity(Qt::CaseInsensitive);
+//	ui->m_search_field->setCompleter(c);
+//}
+
 /**
- * @brief LinkSingleElementWidget::enableLiveEdit
+ * @brief LinkSingleElementWidget::clearTreeWidget
+ * Clear the tree widget.
+ * Delete all QTreeWidget (in the tree widget and in the hash).
+ * Clear the hash.
  */
-void LinkSingleElementWidget::enableLiveEdit()
+void LinkSingleElementWidget::clearTreeWidget()
 {
-	if (!esw_) return;
-	connect(esw_, &ElementSelectorWidget::elementSelected, this, &LinkSingleElementWidget::apply, Qt::QueuedConnection);
-	connect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply, Qt::QueuedConnection);
+	while(ui->m_tree_widget->topLevelItemCount())
+	{
+		QTreeWidgetItem *qtwi = ui->m_tree_widget->takeTopLevelItem(0);
+		if (!m_qtwi_elmt_hash.contains(qtwi))
+			delete qtwi;
+	}
+	
+	foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys())
+		delete qtwi;
+	
+	m_qtwi_elmt_hash.clear();
 }
 
 /**
- * @brief LinkSingleElementWidget::disableLiveEdit
+ * @brief LinkSingleElementWidget::diagramWasRemovedFromProject
+ *  * This slot is called when a diagram is removed from the parent project of edited element
+ * to update the content of this widget
  */
-void LinkSingleElementWidget::disableLiveEdit()
+void LinkSingleElementWidget::diagramWasRemovedFromProject()
 {
-	if (!esw_) return;
-	disconnect(esw_, &ElementSelectorWidget::elementSelected, this, &LinkSingleElementWidget::apply);
-	disconnect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply);
+		//We use a timer because if the removed diagram contain the master element linked to the edited element
+		//we must to wait for this elements be unlinked, else the list of available master isn't up to date
+	QTimer::singleShot(10, this, SLOT(updateUi()));
 }
 
+void LinkSingleElementWidget::showedElementWasDeleted()
+{
+	m_showed_element = nullptr;
+}
+
 /**
- * @brief LinkSingleElementWidget::buildList
- * Build the element list of this widget,
- * the list is fill with the element find in the
- * required folio (folio selected with the combo box)
+ * @brief LinkSingleElementWidget::linkTriggered
+ * Action linkis triggered
  */
-void LinkSingleElementWidget::buildList()
+void LinkSingleElementWidget::linkTriggered()
 {
-	if (!esw_)
+	if(!m_qtwi_at_context_menu)
+		return;
+	
+	m_element_to_link = m_qtwi_elmt_hash.value(m_qtwi_at_context_menu);
+	
+	if(m_live_edit)
 	{
-		esw_ = new ElementSelectorWidget(availableElements(), this);
-		ui->content_layout->addWidget(esw_);
+		apply();
+		updateUi();
 	}
 	else
 	{
-		esw_->setList(availableElements());
+			//In no live edit mode, we set the background of the qtwi green, to inform the user
+			//which element will be linked when he press the apply button
+		if (m_pending_qtwi)
+		{
+			QBrush brush(Qt::white, Qt::NoBrush);
+			for(int i=0 ; i<6 ; i++)
+			{
+				m_pending_qtwi->setBackground(i,brush);
+			}
+		}
+		
+		for (int i=0 ; i<6 ; i++)
+		{
+			m_qtwi_at_context_menu->setBackgroundColor(i, Qt::green);
+		}
+		m_pending_qtwi = m_qtwi_at_context_menu;
 	}
-	buildSearchField();
+	
 }
 
 /**
- * @brief LinkSingleElementWidget::buildSearchField
- * Build a line edit for search element by they information,
- * like label or information
+ * @brief LinkSingleElementWidget::hideButtons
+ * Hide the button displayed when element is already linked
  */
-void LinkSingleElementWidget::buildSearchField()
+void LinkSingleElementWidget::hideButtons()
 {
-		//If there isn't string to filter, we remove the search field
-	if (esw_->filter().isEmpty())
-	{
-		if (search_field)
-		{
-			ui -> header_layout -> removeWidget(search_field);
-			delete search_field;
-			search_field = nullptr;
-		}
-		return;
-	}
-
-	if(!search_field)
-	{
-		search_field = new QLineEdit(this);
-		search_field -> setPlaceholderText(tr("Rechercher"));
-		connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filtered(QString)));
-		ui->header_layout->addWidget(search_field);
-	}
-	setUpCompleter();
+	ui->m_label->hide();
+	ui->m_unlink_pb->hide();
+	ui->m_show_linked_pb->hide();
+	ui->m_show_this_pb->hide();
 }
 
 /**
- * @brief LinkSingleElementWidget::availableElements
- * @return A QList with all available element
- * to be linked with the edited element.
- * This methode take care of the combo box "find in diagram"
+ * @brief LinkSingleElementWidget::showButtons
+ * Show the button displayed when element is already linked
  */
-QList <Element *> LinkSingleElementWidget::availableElements()
+void LinkSingleElementWidget::showButtons()
 {
-	QList <Element *> elmt_list;
-		//if element isn't free and unlink isn't pressed, return an empty list
-	if (!m_element->isFree() && !unlink_) return elmt_list;
+	ui->m_label->show();
+	ui->m_unlink_pb->show();
+	ui->m_show_linked_pb->show();
+	ui->m_show_this_pb->show();
+}
 
-	int i = ui->folio_combo_box->currentIndex();
-		//find in all diagram of this project
-	if (i == 0)
+void LinkSingleElementWidget::on_m_unlink_pb_clicked()
+{
+	m_unlink = true;
+	
+	if(m_live_edit)
 	{
-		if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_list;
-
-		ElementProvider ep(m_element->diagram()->project());
-		if (filter_ & Element::AllReport)
-			elmt_list = ep.freeElement(filter_);
-		else
-			elmt_list = ep.find(filter_);
+		apply();
+		updateUi();
 	}
-		//find in single diagram
 	else
-	{
-		ElementProvider ep (diagram_list.at(i-1));
-		if (filter_ & Element::AllReport)
-			elmt_list = ep.freeElement(filter_);
-		else
-			elmt_list = ep.find(filter_);
-	}
-
-
-		//If element is linked, remove is parent from the list
-	if(!m_element->isFree()) elmt_list.removeAll(m_element->linkedElements().first());
-
-	return elmt_list;
+		buildTree();
 }
 
 /**
- * @brief LinkSingleElementWidget::setUpCompleter
- * Setup the completer of search_field
+ * @brief LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked
+ * Highlight the element represented by @item
+ * @param item
+ * @param column
  */
-void LinkSingleElementWidget::setUpCompleter()
+void LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column)
 {
-	if (search_field)
+	Q_UNUSED(column);
+	
+	if (m_showed_element)
 	{
-		search_field -> clear();
-		delete search_field -> completer();
-
-		QStringList filter = esw_->filter();
-		filter.sort();
-		QCompleter *comp = new QCompleter(filter, search_field);
-		comp -> setCaseSensitivity(Qt::CaseInsensitive);
-		search_field -> setCompleter(comp);
+		disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
+		m_showed_element->setHighlighted(false);
 	}
-}
+	
+	Element *elmt = m_qtwi_elmt_hash.value(item);
+	elmt->diagram()->showMe();
+	elmt->setHighlighted(true);
+	m_showed_element = elmt;
+	connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
 
-/**
- * @brief LinkSingleElementWidget::setNewList
- * Set the list according to the selected diagram in the combo_box
- */
-void LinkSingleElementWidget::setNewList()
-{
-	esw_->setList(availableElements());
-	buildSearchField();
 }
 
-/**
- * @brief LinkSingleElementWidget::unlinkClicked
- * Action when 'unlink' button is clicked
- */
-void LinkSingleElementWidget::unlinkClicked()
+void LinkSingleElementWidget::on_m_tree_widget_customContextMenuRequested(const QPoint &pos)
 {
-	ui->m_unlink_widget->hide();
-	unlink_ = true;
-	setNewList();
+		//add the size of the header to display the topleft of the QMenu at the position of the mouse.
+		//See doc about QWidget::customContextMenuRequested section related to QAbstractScrollArea 
+	QPoint point = pos;
+	point.ry()+=ui->m_tree_widget->header()->height();
+	point = ui->m_tree_widget->mapToGlobal(point);
+	
+	m_context_menu->clear();
+	
+	if (ui->m_tree_widget->currentItem())
+	{
+		m_qtwi_at_context_menu = ui->m_tree_widget->currentItem();
+		m_context_menu->addAction(m_link_action);
+		m_context_menu->addAction(m_show_qtwi);
+	}
+	
+	m_context_menu->addAction(m_show_element);
+	m_context_menu->popup(point);
 }
 
-/**
- * @brief FolioReportProperties::on_button_this_clicked
- * Action when push button "this report" is clicked
- */
-void LinkSingleElementWidget::on_button_this_clicked() {
-	esw_->showElement(m_element);
-}
-
-/**
- * @brief FolioReportProperties::on_button_linked_clicked
- * Action when push button "linked report" is clicked
- */
-void LinkSingleElementWidget::on_button_linked_clicked()
+void LinkSingleElementWidget::on_m_show_linked_pb_clicked()
 {
-	if (m_element->isFree()) return;
-	esw_->showElement(m_element->linkedElements().first());
+	if (!m_element->isFree())
+	{
+		Element *elmt = m_element->linkedElements().first();
+		elmt->diagram()->showMe();
+		elmt->setHighlighted(true);
+	}
 }
 
-/**
- * @brief LinkSingleElementWidget::diagramWasRemovedFromProject
- *  * This slot is called when a diagram is removed from the parent project of edited element
- * to update the content of this widget
- */
-void LinkSingleElementWidget::diagramWasRemovedFromProject()
+void LinkSingleElementWidget::on_m_show_this_pb_clicked()
 {
-	diagram_list.clear();
-	diagram_list << m_element->diagram()->project()->diagrams();
-		//We use a timer because if the removed diagram contain the master element linked to the edited element
-		//we must to wait for this elements be unlinked, else the list of available master isn't up to date
-	QTimer::singleShot(10, this, SLOT(updateUi()));
+	m_show_element->trigger();
 }

Modified: trunk/sources/ui/linksingleelementwidget.h
===================================================================
--- trunk/sources/ui/linksingleelementwidget.h	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/linksingleelementwidget.h	2017-01-26 10:09:07 UTC (rev 4874)
@@ -21,11 +21,8 @@
 #include "element.h"
 #include "abstractelementpropertieseditorwidget.h"
 
+class QTreeWidgetItem;
 
-class Diagram;
-class QLineEdit;
-class ElementSelectorWidget;
-
 namespace Ui {
 	class LinkSingleElementWidget;
 }
@@ -44,7 +41,7 @@
 {
 	Q_OBJECT
 
-	///Methods
+		///Methods
 	public:
 		explicit LinkSingleElementWidget(Element *elmt, QWidget *parent = 0);
 		~LinkSingleElementWidget();
@@ -56,33 +53,47 @@
 
 	public slots:
 		void updateUi();
+		void buildTree();
 
 	public:
 		bool setLiveEdit(bool live_edit);
 
 	private :
-		void enableLiveEdit();
-		void disableLiveEdit();
-		void buildList();
-		void buildSearchField();
 		QList <Element *> availableElements();
-		void setUpCompleter();
+//		void setUpCompleter();
+		void clearTreeWidget();
 
 	private slots:
-		void setNewList();
-		void unlinkClicked();
-		void on_button_this_clicked();
-		void on_button_linked_clicked();
 		void diagramWasRemovedFromProject();
-
-	///Attributes
+		void showedElementWasDeleted();
+		void linkTriggered();
+		void hideButtons();
+		void showButtons();
+		
+		void on_m_unlink_pb_clicked();
+		void on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem *item, int column);
+		void on_m_tree_widget_customContextMenuRequested(const QPoint &pos);
+		void on_m_show_linked_pb_clicked();
+		void on_m_show_this_pb_clicked();
+		
 	private:
 	Ui::LinkSingleElementWidget *ui;
-	ElementSelectorWidget *esw_;
-	QList <Diagram *> diagram_list;
-	bool unlink_;
-	Element::kind filter_;
-	QLineEdit *search_field;
+
+	bool m_unlink = false;
+	Element::kind m_filter;
+	
+	QHash <QTreeWidgetItem*, Element*> m_qtwi_elmt_hash;
+	
+	QTreeWidgetItem *m_qtwi_at_context_menu = nullptr,
+					*m_pending_qtwi = nullptr;
+	
+	Element *m_showed_element = nullptr,
+			*m_element_to_link = nullptr;
+	
+	QMenu *m_context_menu;
+	QAction *m_link_action,
+			*m_show_qtwi,
+			*m_show_element;
 };
 
 #endif // LINKSINGLEELEMENTWIDGET_H

Modified: trunk/sources/ui/linksingleelementwidget.ui
===================================================================
--- trunk/sources/ui/linksingleelementwidget.ui	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/linksingleelementwidget.ui	2017-01-26 10:09:07 UTC (rev 4874)
@@ -6,95 +6,82 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>265</width>
-    <height>182</height>
+    <width>389</width>
+    <height>442</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" name="main_layout">
-   <item>
-    <layout class="QVBoxLayout" name="header_layout">
-     <item>
-      <widget class="QWidget" name="m_unlink_widget" native="true">
-       <layout class="QHBoxLayout" name="horizontalLayout_3">
-        <item>
-         <widget class="QLabel" name="label_2">
-          <property name="text">
-           <string>Cet élément est déjà lié</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <spacer name="horizontalSpacer_2">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>40</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-        <item>
-         <widget class="QPushButton" name="m_unlink_pb">
-          <property name="text">
-           <string>Délier</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </widget>
-     </item>
-     <item>
-      <widget class="QLabel" name="label">
-       <property name="text">
-        <string>Rechercher dans le folio :</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer name="horizontalSpacer">
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>40</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QComboBox" name="folio_combo_box"/>
-     </item>
-    </layout>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="m_label">
+     <property name="text">
+      <string>Cet élément est déjà lié</string>
+     </property>
+    </widget>
    </item>
-   <item>
-    <layout class="QVBoxLayout" name="content_layout"/>
+   <item row="2" column="0" colspan="3">
+    <widget class="QTreeWidget" name="m_tree_widget">
+     <property name="indentation">
+      <number>5</number>
+     </property>
+     <property name="sortingEnabled">
+      <bool>true</bool>
+     </property>
+     <column>
+      <property name="text">
+       <string>Label</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>Commentaire</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>N° de folio</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>Label de folio</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>Titre de folio</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>Position</string>
+      </property>
+     </column>
+    </widget>
    </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_2">
-     <item>
-      <widget class="QPushButton" name="button_this">
-       <property name="text">
-        <string>Voir cet élément</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="button_linked">
-       <property name="text">
-        <string>Voir l'élément lié</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
+   <item row="1" column="2">
+    <widget class="QPushButton" name="m_show_this_pb">
+     <property name="text">
+      <string>Voir cette élément</string>
+     </property>
+    </widget>
    </item>
+   <item row="0" column="2">
+    <widget class="QPushButton" name="m_show_linked_pb">
+     <property name="text">
+      <string>Voir l'élément lié</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QPushButton" name="m_unlink_pb">
+     <property name="text">
+      <string>Délier</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

Modified: trunk/sources/ui/masterpropertieswidget.ui
===================================================================
--- trunk/sources/ui/masterpropertieswidget.ui	2017-01-25 18:46:11 UTC (rev 4873)
+++ trunk/sources/ui/masterpropertieswidget.ui	2017-01-26 10:09:07 UTC (rev 4874)
@@ -53,6 +53,9 @@
        <height>32</height>
       </size>
      </property>
+     <property name="indentation">
+      <number>5</number>
+     </property>
      <property name="uniformRowHeights">
       <bool>true</bool>
      </property>
@@ -103,6 +106,9 @@
        <height>32</height>
       </size>
      </property>
+     <property name="indentation">
+      <number>5</number>
+     </property>
      <property name="uniformRowHeights">
       <bool>true</bool>
      </property>


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