[qet] [3992] Link single element widget, set live edit enable.

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


Revision: 3992
Author:   blacksun
Date:     2015-05-27 09:22:50 +0200 (Wed, 27 May 2015)
Log Message:
-----------
Link single element widget, set live edit enable.
In properties dock widget, no need to click on apply button, change are apply immediately.

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/masterelement.cpp
    trunk/sources/qetgraphicsitem/reportelement.cpp
    trunk/sources/qetgraphicsitem/slaveelement.cpp
    trunk/sources/ui/diagrampropertieseditordockwidget.cpp
    trunk/sources/ui/elementpropertieswidget.cpp
    trunk/sources/ui/elementpropertieswidget.h
    trunk/sources/ui/elementselectorwidget.cpp
    trunk/sources/ui/elementselectorwidget.h
    trunk/sources/ui/linksingleelementwidget.cpp
    trunk/sources/ui/linksingleelementwidget.h
    trunk/sources/ui/linksingleelementwidget.ui

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/qetgraphicsitem/element.h	2015-05-27 07:22:50 UTC (rev 3992)
@@ -120,6 +120,7 @@
 		kind              link_type_;
 
 	signals:
+		void linkedElementChanged(); //This signal is emtied when the linked elements with this element change
 		void elementInfoChange(DiagramContext old_info, DiagramContext new_info);
 
 		//METHODS related to information

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -49,9 +49,11 @@
  * For this class element must be a slave
  * @param elmt
  */
-void MasterElement::linkToElement(Element *elmt) {	
-	// check if element is slave and if isn't already linked
-	if (elmt->linkType() == Slave && !connected_elements.contains(elmt)) {
+void MasterElement::linkToElement(Element *elmt)
+{
+		// check if element is slave and if isn't already linked
+	if (elmt->linkType() == Slave && !connected_elements.contains(elmt))
+	{
 		connected_elements << elmt;
 		elmt->linkToElement(this);
 
@@ -60,6 +62,7 @@
 		connect(elmt, SIGNAL(xChanged()), cri_, SLOT(updateLabel()));
 		connect(elmt, SIGNAL(yChanged()), cri_, SLOT(updateLabel()));
 		cri_ -> updateLabel();
+		emit linkedElementChanged();
 	}
 }
 
@@ -67,12 +70,14 @@
  * @brief MasterElement::unlinkAllElements
  * Unlink all of the element in the QList connected_elements
  */
-void MasterElement::unlinkAllElements() {
-	// if this element is free no need to do something
-	if (!isFree()) {
-		foreach(Element *elmt, connected_elements) {
+void MasterElement::unlinkAllElements()
+{
+		// if this element is free no need to do something
+	if (!isFree())
+	{
+		foreach(Element *elmt, connected_elements)
 			unlinkElement(elmt);
-		}
+		emit linkedElementChanged();
 	}
 }
 
@@ -96,6 +101,7 @@
 
 		cri_ -> updateLabel();
 		aboutDeleteXref();
+		emit linkedElementChanged();
 	}
 }
 

Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -81,6 +81,7 @@
 		updateLabel();
 
 		elmt -> linkToElement(this);
+		emit linkedElementChanged();
 	}
 }
 
@@ -90,7 +91,8 @@
  */
 void ReportElement::unlinkAllElements()
 {
-	if (!isFree()){
+	if (!isFree())
+	{
 		QList <Element *> tmp_elmt = connected_elements;
 
 		foreach(Element *elmt, connected_elements)
@@ -107,6 +109,7 @@
 			elmt -> setHighlighted(false);
 			elmt -> unlinkAllElements();
 		}
+		emit linkedElementChanged();
 	}
 }
 /**

Modified: trunk/sources/qetgraphicsitem/slaveelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/qetgraphicsitem/slaveelement.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -50,9 +50,11 @@
  * For this class element must be a master
  * @param elmt
  */
-void SlaveElement::linkToElement(Element *elmt) {
-	// check if element is master and if isn't already linked
-	if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
+void SlaveElement::linkToElement(Element *elmt)
+{
+		// check if element is master and if isn't already linked
+	if (elmt->linkType() == Master && !connected_elements.contains(elmt))
+	{
 		if(!isFree()) unlinkAllElements();
 		connected_elements << elmt;
 
@@ -64,6 +66,7 @@
 
 		updateLabel();
 		elmt -> linkToElement(this);
+		emit linkedElementChanged();
 	}
 }
 
@@ -71,12 +74,14 @@
  * @brief SlaveElement::unlinkAllElements
  * Unlink all of the element in the QList connected_elements
  */
-void SlaveElement::unlinkAllElements() {
-	// if this element is free no need to do something
-	if (!isFree()) {
-		foreach(Element *elmt, connected_elements) {
+void SlaveElement::unlinkAllElements()
+{
+		// if this element is free no need to do something
+	if (!isFree())
+	{
+		foreach(Element *elmt, connected_elements)
 			unlinkElement(elmt);
-		}
+		emit linkedElementChanged();
 	}
 }
 
@@ -103,6 +108,7 @@
 		updateLabel();
 		elmt -> unlinkElement  (this) ;
 		elmt -> setHighlighted (false);
+		emit linkedElementChanged();
 	}
 }
 

Modified: trunk/sources/ui/diagrampropertieseditordockwidget.cpp
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -78,6 +78,7 @@
 	{
 		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)
@@ -93,17 +94,22 @@
 			m_edited_qgi_type = ElementQGIType;
 			addEditor(new ElementPropertiesWidget(elmt, this));
 		}
+			//Edit an image
 		else if (DiagramImageItem *image = dynamic_cast<DiagramImageItem *>(item))
 		{
 			clear();
 			m_edited_qgi_type = ImageQGIType;
 			addEditor(new ImagePropertiesWidget(image, this));
 		}
+			//Unknow type, we clear the dock
 		else
 			clear();
 	}
 	else
 		clear();
+
+	foreach(PropertiesEditorWidget *pew, editors())
+		pew->setLiveEdit(true);
 }
 
 /**

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -107,6 +107,17 @@
 	foreach (PropertiesEditorWidget *pew, m_list_editor) pew->reset();
 }
 
+bool ElementPropertiesWidget::setLiveEdit(bool live_edit)
+{
+	if (m_live_edit == live_edit) return true;
+	m_live_edit = live_edit;
+
+	foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
+		aepew->setLiveEdit(m_live_edit);
+
+	return true;
+}
+
 /**
  * @brief ElementPropertiesWidget::findInPanel
  * If m_element is a custom element, emit findElementRequired
@@ -158,7 +169,7 @@
 	qDeleteAll(m_list_editor); m_list_editor.clear();
 	if(m_general_widget) delete m_general_widget; m_general_widget = nullptr;
 
-		//Add tab according to the element
+		//Create editor according to the type of element
 	switch (m_element -> linkType())
 	{
 		case Element::Simple:
@@ -183,9 +194,15 @@
 			break;
 	}
 
-	foreach (PropertiesEditorWidget *pew, m_list_editor) m_tab->addTab(pew, pew->title());
+		//Add each editors in tab widget
+	foreach (AbstractElementPropertiesEditorWidget *aepew, m_list_editor)
+	{
+		aepew->setLiveEdit(m_live_edit);
+		m_tab->addTab(aepew, aepew->title());
+	}
 	addGeneralWidget();
 
+		//Go to the tab, edited at the beginning of this method
 	if (!tab_text.isEmpty())
 	{
 		for(int i=0 ; i<m_tab->count() ; ++i)

Modified: trunk/sources/ui/elementpropertieswidget.h
===================================================================
--- trunk/sources/ui/elementpropertieswidget.h	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/elementpropertieswidget.h	2015-05-27 07:22:50 UTC (rev 3992)
@@ -35,6 +35,7 @@
 		void setElement(Element *element);
 		void apply();
 		void reset();
+		bool setLiveEdit(bool live_edit);
 
 	public slots:
 		void findInPanel ();

Modified: trunk/sources/ui/elementselectorwidget.cpp
===================================================================
--- trunk/sources/ui/elementselectorwidget.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/elementselectorwidget.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -220,6 +220,12 @@
 	}
 }
 
+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

Modified: trunk/sources/ui/elementselectorwidget.h
===================================================================
--- trunk/sources/ui/elementselectorwidget.h	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/elementselectorwidget.h	2015-05-27 07:22:50 UTC (rev 3992)
@@ -48,14 +48,17 @@
 
 	QStringList filter () const;
 
+	signals:
+		void elementSelected (Element *element);
+
 	public slots:
-	void filtered(const QString &str);
+		void filtered(const QString &str);
 
 	private:
-	void buildInterface();
+		void buildInterface();
 
 	private slots:
-		void setSelectedElement  (const int i) {selected_element = elements_list.at(i);}
+		void setSelectedElement  (const int i);
 		void showElementFromList (const int i);
 		void showedElementWasDeleted ();
 

Modified: trunk/sources/ui/linksingleelementwidget.cpp
===================================================================
--- trunk/sources/ui/linksingleelementwidget.cpp	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/linksingleelementwidget.cpp	2015-05-27 07:22:50 UTC (rev 3992)
@@ -34,12 +34,12 @@
 	AbstractElementPropertiesEditorWidget(parent),
 	ui(new Ui::LinkSingleElementWidget),
 	esw_(0),
-	unlink_widget(0),
 	unlink_(false),
-	search_field(0)
+	search_field(nullptr)
 {
 	ui->setupUi(this);
 	connect(ui->folio_combo_box, SIGNAL(currentIndexChanged(int)), this, SLOT(setNewList()));
+	connect(ui->m_unlink_pb, SIGNAL(clicked()), this, SLOT(unlinkClicked()));
 	setElement(elmt);
 }
 
@@ -59,12 +59,16 @@
 void LinkSingleElementWidget::setElement(Element *element)
 {
 	if (m_element == element) return;
+
+		//Remove connection of previous edited element
 	if (m_element)
 	{
 		disconnect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
+		disconnect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi);
 		diagram_list.clear();
 	}
 
+		//Setup the new element, connection and ui
 	m_element = element;
 	diagram_list << m_element->diagram()->project()->diagrams();
 
@@ -76,13 +80,15 @@
 		filter_ = Element::Simple;
 
 	connect(m_element->diagram()->project(), &QETProject::diagramRemoved, this, &LinkSingleElementWidget::diagramWasRemovedFromProject);
+	connect(m_element, &Element::linkedElementChanged, this, &LinkSingleElementWidget::updateUi, Qt::QueuedConnection);
 
-	buildInterface();
+	updateUi();
 }
 
 /**
  * @brief LinkSingleElementWidget::apply
- * Apply the new property of the edited element
+ * Apply the new property of the edited element by pushing
+ * the associated undo command to parent project undo stack
  */
 void LinkSingleElementWidget::apply()
 {
@@ -106,6 +112,10 @@
 	return nullptr;
 }
 
+/**
+ * @brief LinkSingleElementWidget::title
+ * @return the title used for this editor
+ */
 QString LinkSingleElementWidget::title() const
 {
 	if (m_element->linkType() == Element::AllReport)
@@ -118,11 +128,76 @@
  * @brief LinkSingleElementWidget::updateUi
  * Update the content of this widget
  */
-void LinkSingleElementWidget::updateUi() {
-	buildInterface();
+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"));
+
+	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())
+	{
+		ui->button_linked->setDisabled(true);
+		ui->m_unlink_widget->hide();
+	}
+	else
+		ui->m_unlink_widget->show();
+
+	buildSearchField();
 }
 
 /**
+ * @brief LinkSingleElementWidget::setLiveEdit
+ * @param live_edit
+ * @return
+ */
+bool LinkSingleElementWidget::setLiveEdit(bool live_edit)
+{
+	if (m_live_edit == live_edit) return true;
+	m_live_edit = live_edit;
+
+	if (m_live_edit)
+		enableLiveEdit();
+	else
+		disableLiveEdit();
+
+	return true;
+}
+
+/**
+ * @brief LinkSingleElementWidget::enableLiveEdit
+ */
+void LinkSingleElementWidget::enableLiveEdit()
+{
+	if (!esw_) return;
+	connect(esw_, &ElementSelectorWidget::elementSelected, this, &LinkSingleElementWidget::apply);
+	connect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply);
+}
+
+/**
+ * @brief LinkSingleElementWidget::disableLiveEdit
+ */
+void LinkSingleElementWidget::disableLiveEdit()
+{
+	if (!esw_) return;
+	disconnect(esw_, &ElementSelectorWidget::elementSelected, this, &LinkSingleElementWidget::apply);
+	disconnect(ui->m_unlink_pb, &QPushButton::clicked, this, &LinkSingleElementWidget::apply);
+}
+
+/**
  * @brief LinkSingleElementWidget::buildList
  * Build the element list of this widget,
  * the list is fill with the element find in the
@@ -143,38 +218,6 @@
 }
 
 /**
- * @brief LinkSingleElementWidget::buildLinkUnlinkButton
- * Build the button link or unlink according to the current edited
- * element, if is already linked with a master element or not
- */
-void LinkSingleElementWidget::buildLinkUnlinkButton()
-{
-	if (m_element->isFree())
-	{
-		ui->button_linked->setDisabled(true);
-		if (unlink_widget)
-		{
-			ui->main_layout->removeWidget(unlink_widget);
-			delete unlink_widget; unlink_widget = nullptr;
-		}
-	}
-	else if (!unlink_widget)
-	{
-		ui->button_linked->setEnabled(true);
-		unlink_widget = new QWidget(this);
-		QHBoxLayout *unlink_layout = new QHBoxLayout(unlink_widget);
-		QLabel *lb = new QLabel(tr("Cet élément est déjà lié."), unlink_widget);
-		QPushButton *pb = new QPushButton(tr("Délier"), unlink_widget);
-		connect(pb, SIGNAL(clicked()), this, SLOT(unlinkClicked()));
-		unlink_layout->addWidget(lb);
-		unlink_layout->addStretch();
-		unlink_layout->addWidget(pb);
-		ui->main_layout->insertWidget(0, unlink_widget);
-	}
-
-}
-
-/**
  * @brief LinkSingleElementWidget::buildSearchField
  * Build a line edit for search element by they information,
  * like label or information
@@ -182,8 +225,10 @@
 void LinkSingleElementWidget::buildSearchField()
 {
 		//If there isn't string to filter, we remove the search field
-	if (esw_->filter().isEmpty()) {
-		if (search_field) {
+	if (esw_->filter().isEmpty())
+	{
+		if (search_field)
+		{
 			ui -> header_layout -> removeWidget(search_field);
 			delete search_field;
 			search_field = nullptr;
@@ -258,32 +303,6 @@
 }
 
 /**
- * @brief LinkSingleElementWidget::buildInterface
- * Build the interface of this widget
- */
-void LinkSingleElementWidget::buildInterface()
-{
-	ui->folio_combo_box->blockSignals(true);
-	ui->folio_combo_box->clear();
-	ui->folio_combo_box->addItem(tr("Tous"));
-
-		//Fill the combo box for filter the result by folio
-	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();
-	buildLinkUnlinkButton();
-	buildSearchField();
-}
-
-/**
  * @brief LinkSingleElementWidget::setNewList
  * Set the list according to the selected diagram in the combo_box
  */
@@ -299,8 +318,7 @@
  */
 void LinkSingleElementWidget::unlinkClicked()
 {
-	ui->main_layout->removeWidget(unlink_widget);
-	delete unlink_widget; unlink_widget = nullptr;
+	ui->m_unlink_widget->hide();
 	unlink_ = true;
 	setNewList();
 }
@@ -334,5 +352,5 @@
 	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(buildInterface()));
+	QTimer::singleShot(10, this, SLOT(updateUi()));
 }

Modified: trunk/sources/ui/linksingleelementwidget.h
===================================================================
--- trunk/sources/ui/linksingleelementwidget.h	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/linksingleelementwidget.h	2015-05-27 07:22:50 UTC (rev 3992)
@@ -53,17 +53,22 @@
 		void apply();
 		QUndoCommand *associatedUndo() const;
 		QString title() const;
+
+	public slots:
 		void updateUi();
 
-	private:
+	public:
+		bool setLiveEdit(bool live_edit);
+
+	private :
+		void enableLiveEdit();
+		void disableLiveEdit();
 		void buildList();
-		void buildLinkUnlinkButton();
 		void buildSearchField();
 		QList <Element *> availableElements();
 		void setUpCompleter();
 
 	private slots:
-		void buildInterface();
 		void setNewList();
 		void unlinkClicked();
 		void on_button_this_clicked();
@@ -75,7 +80,6 @@
 	Ui::LinkSingleElementWidget *ui;
 	ElementSelectorWidget *esw_;
 	QList <Diagram *> diagram_list;
-	QWidget *unlink_widget;
 	bool unlink_;
 	Element::kind filter_;
 	QLineEdit *search_field;

Modified: trunk/sources/ui/linksingleelementwidget.ui
===================================================================
--- trunk/sources/ui/linksingleelementwidget.ui	2015-05-25 15:15:02 UTC (rev 3991)
+++ trunk/sources/ui/linksingleelementwidget.ui	2015-05-27 07:22:50 UTC (rev 3992)
@@ -17,6 +17,39 @@
    <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>


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