[qet] qet/qet: [4867] Add variable %F in the widget used to link master element.

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


Revision: 4867
Author:   blacksun
Date:     2017-01-22 14:48:58 +0100 (Sun, 22 Jan 2017)
Log Message:
-----------
Add variable %F in the widget used to link master element.
Revamp the widget : replace QListWidget by QTreeWidget

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

Modified: trunk/sources/ui/masterpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/masterpropertieswidget.cpp	2017-01-21 21:39:43 UTC (rev 4866)
+++ trunk/sources/ui/masterpropertieswidget.cpp	2017-01-22 13:48:58 UTC (rev 4867)
@@ -37,8 +37,34 @@
 	m_project(nullptr)
 {
 	ui->setupUi(this);
-	connect(ui->free_list,		SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
-	connect(ui->linked_list,	SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
+	
+	ui->m_free_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu);
+	ui->m_link_tree_widget->setContextMenuPolicy(Qt::CustomContextMenu);
+	
+	m_context_menu  = new QMenu(this);
+	m_link_action   = new QAction(tr("Lier l'élément"), this);
+	m_unlink_action = new QAction(tr("Dé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 maître"), this);
+	
+	connect(ui->m_free_tree_widget, &QTreeWidget::itemDoubleClicked, this, &MasterPropertiesWidget::showElementFromTWI);
+	connect(ui->m_link_tree_widget, &QTreeWidget::itemDoubleClicked, this, &MasterPropertiesWidget::showElementFromTWI);
+	
+	connect(ui->m_free_tree_widget, &QTreeWidget::customContextMenuRequested, [this](QPoint point) {this->customContextMenu(point, 1);});
+	connect(ui->m_link_tree_widget, &QTreeWidget::customContextMenuRequested, [this](QPoint point) {this->customContextMenu(point, 2);});
+	
+	connect(m_link_action,   &QAction::triggered, this, &MasterPropertiesWidget::on_link_button_clicked);
+	connect(m_unlink_action, &QAction::triggered, this, &MasterPropertiesWidget::on_unlink_button_clicked);
+	connect(m_show_qtwi,     &QAction::triggered, [this]() {this->showElementFromTWI(this->m_qtwi_at_context_menu,0);});
+	
+	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);
 }
 
@@ -48,7 +74,11 @@
  */
 MasterPropertiesWidget::~MasterPropertiesWidget()
 {
-	if (m_showed_element) m_showed_element->setHighlighted(false);
+	if (m_showed_element)
+		m_showed_element->setHighlighted(false);
+	
+	m_element->setHighlighted(false);
+	
 	delete ui;
 }
 
@@ -59,9 +89,19 @@
  */
 void MasterPropertiesWidget::setElement(Element *element)
 {
-	if (m_element == element) return;
-	if (m_showed_element) {m_showed_element->setHighlighted(false); m_showed_element = nullptr;}
-	if (m_project) disconnect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
+	if (m_element == element)
+		return;
+	
+	if (m_showed_element)
+	{
+		m_showed_element->setHighlighted(false);
+		m_showed_element = nullptr;
+	}
+	if (m_element)
+		m_element->setHighlighted(false);
+	
+	if (m_project)
+		disconnect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
 
 	if(Q_LIKELY(element->diagram() && element->diagram()->project()))
 	{
@@ -68,10 +108,13 @@
 		m_project = element->diagram()->project();
 		connect(m_project, SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(diagramWasdeletedFromProject()));
 	}
-	else m_project = nullptr;
+	else
+		m_project = nullptr;
 
 		//Keep up to date this widget when the linked elements of m_element change
-	if (m_element) disconnect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
+	if (m_element)
+		disconnect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
+	
 	m_element = element;
 	connect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
 
@@ -94,11 +137,12 @@
  * @brief MasterPropertiesWidget::reset
  * Reset curent widget, clear eveything and rebuild widget.
  */
-void MasterPropertiesWidget::reset() {
-	foreach (QListWidgetItem *lwi, lwi_hash.keys()) {
-		delete lwi;
-	}
-	lwi_hash.clear();
+void MasterPropertiesWidget::reset()
+{
+	foreach (QTreeWidgetItem *qtwi, m_qtwi_hash.keys())
+		delete qtwi;
+	
+	m_qtwi_hash.clear();
 	updateUi();
 }
 
@@ -114,8 +158,8 @@
 	QList <Element *> to_link;
 	QList <Element *> linked_ = m_element->linkedElements();
 
-	for (int i=0; i<ui->linked_list->count(); i++)
-		to_link << lwi_hash[ui->linked_list->item(i)];
+	for (int i=0; i<ui->m_link_tree_widget->topLevelItemCount(); i++)
+		to_link << m_qtwi_hash[ui->m_link_tree_widget->topLevelItem(i)];
 
 		//The two list contain the same element, there is no change
 	if (to_link.size() == linked_.size())
@@ -158,43 +202,54 @@
  */
 void MasterPropertiesWidget::updateUi()
 {
-	ui->free_list->clear();
-	ui->linked_list->clear();
-	lwi_hash.clear();
+	ui->m_free_tree_widget->clear();
+	ui->m_link_tree_widget->clear();
+	m_qtwi_hash.clear();
 
-	if (Q_UNLIKELY(!m_project)) return;
+	if (Q_UNLIKELY(!m_project))
+		return;
 
 	ElementProvider elmt_prov(m_project);
 
 		//Build the list of free available element
+	QList <QTreeWidgetItem *> items_list;
 	foreach(Element *elmt, elmt_prov.freeElement(Element::Slave))
 	{
-		//label for list widget
-		QString widget_text;
-		QString title = elmt->diagram()->title();
-		if (title.isEmpty()) title = tr("Sans titre");
-		widget_text += QString(tr("Folio  %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
-																	  .arg(title)
-																	  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
-		QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
-		lwi_hash.insert(lwi_, elmt);
-		ui->free_list->addItem(lwi_);
+		QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_free_tree_widget);
+		qtwi->setIcon(0, elmt->pixmap());
+		qtwi->setText(1, QString::number(elmt->diagram()->folioIndex() + 1));
+		
+		autonum::sequentialNumbers seq;
+		QString F =autonum::AssignVariables::formulaToLabel(elmt->diagram()->border_and_titleblock.folio(), seq, elmt->diagram(), elmt);
+		qtwi->setText(2, F);
+		qtwi->setText(3, elmt->diagram()->title());
+		qtwi->setText(4, elmt->diagram()->convertPosition(elmt->scenePos()).toString());
+		items_list.append(qtwi);
+		m_qtwi_hash.insert(qtwi, elmt);
 	}
+	
+	ui->m_free_tree_widget->addTopLevelItems(items_list);
+	items_list.clear();
 
 		//Build the list of already linked element
 	foreach(Element *elmt, m_element->linkedElements())
 	{
-		//label for list widget
-		QString widget_text;
-		QString title = elmt->diagram()->title();
-		if (title.isEmpty()) title = tr("Sans titre");
-		widget_text += QString(tr("Folio  %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
-																	  .arg(title)
-																	  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
-		QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
-		lwi_hash.insert(lwi_, elmt);
-		ui->linked_list->addItem(lwi_);
+		QTreeWidgetItem *qtwi = new QTreeWidgetItem(ui->m_link_tree_widget);
+		qtwi->setIcon(0, elmt->pixmap());
+		qtwi->setText(1, QString::number(elmt->diagram()->folioIndex() + 1));
+		
+		autonum::sequentialNumbers seq;
+		QString F =autonum::AssignVariables::formulaToLabel(elmt->diagram()->border_and_titleblock.folio(), seq, elmt->diagram(), elmt);
+		qtwi->setText(2, F);
+		qtwi->setText(3, elmt->diagram()->title());
+		qtwi->setText(4, elmt->diagram()->convertPosition(elmt->scenePos()).toString());
+		items_list.append(qtwi);
+		m_qtwi_hash.insert(qtwi, elmt);
 	}
+	if(items_list.count())
+		ui->m_link_tree_widget->addTopLevelItems(items_list);
+	
+
 }
 
 /**
@@ -204,9 +259,9 @@
 void MasterPropertiesWidget::on_link_button_clicked()
 {
 		//take the curent item from free_list and push it to linked_list
-	ui->linked_list->addItem(
-				ui->free_list->takeItem(
-					ui->free_list->currentRow()));
+	QTreeWidgetItem *qtwi = ui->m_free_tree_widget->currentItem();
+	ui->m_free_tree_widget->takeTopLevelItem(ui->m_free_tree_widget->indexOfTopLevelItem(qtwi));
+	ui->m_link_tree_widget->insertTopLevelItem(0, qtwi);
 
 	if(m_live_edit) apply();
 }
@@ -218,27 +273,31 @@
 void MasterPropertiesWidget::on_unlink_button_clicked()
 {
 		//take the curent item from linked_list and push it to free_list
-	ui->free_list->addItem(
-				ui->linked_list->takeItem(
-					ui->linked_list->currentRow()));
+	QTreeWidgetItem *qtwi = ui->m_link_tree_widget->currentItem();
+	ui->m_link_tree_widget->takeTopLevelItem(ui->m_link_tree_widget->indexOfTopLevelItem(qtwi));
+	ui->m_free_tree_widget->insertTopLevelItem(0, qtwi);
 
 	if(m_live_edit) apply();
 }
 
 /**
- * @brief MasterPropertiesWidget::showElementFromLWI
- * Show the element corresponding to the given QListWidgetItem
- * @param lwi
+ * @brief MasterPropertiesWidget::showElementFromTWI
+ * Show the element corresponding to the given QTreeWidgetItem
+ * @param qtwi
+ * @param column
  */
-void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi)
+void MasterPropertiesWidget::showElementFromTWI(QTreeWidgetItem *qtwi, int column)
 {
+	Q_UNUSED(column);
 	if (m_showed_element)
 	{
 		disconnect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
 		m_showed_element -> setHighlighted(false);
 	}
+	if (m_element)
+		m_element->setHighlighted(false);
 
-	m_showed_element = lwi_hash[lwi];
+	m_showed_element = m_qtwi_hash[qtwi];
 	m_showed_element->diagram()->showMe();
 	m_showed_element->setHighlighted(true);
 	connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted()));
@@ -263,3 +322,47 @@
 		//we must to wait for this elements be unlinked, else the linked list provide deleted elements.
 	QTimer::singleShot(10, this, SLOT(updateUi()));
 }
+
+/**
+ * @brief MasterPropertiesWidget::customContextMenu
+ * Display a context menu
+ * @param pos
+ * @param i : the tree widget where the context menu was requested.
+ */
+void MasterPropertiesWidget::customContextMenu(const QPoint &pos, int i)
+{
+		//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_free_tree_widget->header()->height();
+	
+	m_context_menu->clear();
+	
+	if (i == 1)
+	{
+		point = ui->m_free_tree_widget->mapToGlobal(point);
+		
+			//Context at for free tree widget
+		if (ui->m_free_tree_widget->currentItem())
+		{
+			m_qtwi_at_context_menu = ui->m_free_tree_widget->currentItem();
+			m_context_menu->addAction(m_link_action);
+			m_context_menu->addAction(m_show_qtwi);
+		}
+	}
+	else
+	{
+		point = ui->m_link_tree_widget->mapToGlobal(point);
+		
+			//context at for link tre widget
+		if (ui->m_link_tree_widget->currentItem())
+		{
+			m_qtwi_at_context_menu = ui->m_link_tree_widget->currentItem();
+			m_context_menu->addAction(m_unlink_action);
+			m_context_menu->addAction(m_show_qtwi);
+		}
+	}
+	
+	m_context_menu->addAction(m_show_element);
+	m_context_menu->popup(point);
+}

Modified: trunk/sources/ui/masterpropertieswidget.h
===================================================================
--- trunk/sources/ui/masterpropertieswidget.h	2017-01-21 21:39:43 UTC (rev 4866)
+++ trunk/sources/ui/masterpropertieswidget.h	2017-01-22 13:48:58 UTC (rev 4867)
@@ -22,11 +22,13 @@
 #include <QHash>
 #include "abstractelementpropertieseditorwidget.h"
 
-class QListWidgetItem;
 class Element;
 class QUndoCommand;
 class QETProject;
 class Diagram;
+class QTreeWidgetItem;
+class QMenu;
+class QAction;
 
 namespace Ui {
 	class MasterPropertiesWidget;
@@ -50,7 +52,7 @@
 		void apply();
 		void reset();
 		QUndoCommand *associatedUndo () const;
-		QString title() const {return tr("Référence croisée (maitre)");}
+		QString title() const {return tr("Référence croisée (maître)");}
 		bool setLiveEdit(bool live_edit);
 
 	public slots:
@@ -59,15 +61,22 @@
 	private slots:
 		void on_link_button_clicked();
 		void on_unlink_button_clicked();
-		void showElementFromLWI(QListWidgetItem *lwi);
+		void showElementFromTWI(QTreeWidgetItem *qtwi, int column);
 		void showedElementWasDeleted ();
 		void diagramWasdeletedFromProject();
+		void customContextMenu(const QPoint &pos, int i=0);
 
 	private:
 	Ui::MasterPropertiesWidget *ui;
-	QHash <QListWidgetItem *, Element *> lwi_hash;
+	QHash <QTreeWidgetItem *, Element *> m_qtwi_hash;
+	QTreeWidgetItem *m_qtwi_at_context_menu = nullptr;
 	Element *m_showed_element;
 	QETProject *m_project;
+	QMenu *m_context_menu;
+	QAction *m_link_action,
+			*m_unlink_action,
+			*m_show_qtwi,
+			*m_show_element;
 };
 
 #endif // MASTERPROPERTIESWIDGET_H

Modified: trunk/sources/ui/masterpropertieswidget.ui
===================================================================
--- trunk/sources/ui/masterpropertieswidget.ui	2017-01-21 21:39:43 UTC (rev 4866)
+++ trunk/sources/ui/masterpropertieswidget.ui	2017-01-22 13:48:58 UTC (rev 4867)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>300</width>
-    <height>400</height>
+    <width>642</width>
+    <height>666</height>
    </rect>
   </property>
   <property name="minimumSize">
@@ -19,55 +19,139 @@
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout_2">
-   <item row="1" column="1" rowspan="5">
-    <widget class="QListWidget" name="free_list"/>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="2" column="2">
+    <widget class="QLabel" name="label_2">
+     <property name="frameShape">
+      <enum>QFrame::NoFrame</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Plain</enum>
+     </property>
+     <property name="text">
+      <string>Éléments liés</string>
+     </property>
+     <property name="scaledContents">
+      <bool>false</bool>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
    </item>
-   <item row="5" column="2">
-    <spacer name="verticalSpacer_2">
-     <property name="orientation">
-      <enum>Qt::Vertical</enum>
+   <item row="3" column="2" colspan="3">
+    <widget class="QTreeWidget" name="m_link_tree_widget">
+     <property name="frameShape">
+      <enum>QFrame::StyledPanel</enum>
      </property>
-     <property name="sizeHint" stdset="0">
+     <property name="showDropIndicator" stdset="0">
+      <bool>false</bool>
+     </property>
+     <property name="iconSize">
       <size>
-       <width>20</width>
-       <height>40</height>
+       <width>32</width>
+       <height>32</height>
       </size>
      </property>
-    </spacer>
-   </item>
-   <item row="4" column="2">
-    <widget class="QPushButton" name="unlink_button">
-     <property name="toolTip">
-      <string>Délier l'élément séléctionné</string>
+     <property name="uniformRowHeights">
+      <bool>true</bool>
      </property>
-     <property name="text">
-      <string/>
+     <property name="sortingEnabled">
+      <bool>true</bool>
      </property>
-     <property name="icon">
-      <iconset resource="../../qelectrotech.qrc">
-       <normaloff>:/ico/16x16/arrow-left.png</normaloff>:/ico/16x16/arrow-left.png</iconset>
-     </property>
+     <attribute name="headerDefaultSectionSize">
+      <number>80</number>
+     </attribute>
+     <attribute name="headerStretchLastSection">
+      <bool>true</bool>
+     </attribute>
+     <column>
+      <property name="text">
+       <string>Vignette</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 row="1" column="3" rowspan="5">
-    <widget class="QListWidget" name="linked_list"/>
-   </item>
-   <item row="3" column="2">
-    <widget class="QPushButton" name="link_button">
-     <property name="toolTip">
-      <string>Lier l'élément séléctionné</string>
+   <item row="1" column="2" colspan="3">
+    <widget class="QTreeWidget" name="m_free_tree_widget">
+     <property name="showDropIndicator" stdset="0">
+      <bool>false</bool>
      </property>
-     <property name="text">
-      <string/>
+     <property name="iconSize">
+      <size>
+       <width>32</width>
+       <height>32</height>
+      </size>
      </property>
-     <property name="icon">
-      <iconset resource="../../qelectrotech.qrc">
-       <normaloff>:/ico/16x16/arrow-right.png</normaloff>:/ico/16x16/arrow-right.png</iconset>
+     <property name="uniformRowHeights">
+      <bool>true</bool>
      </property>
+     <property name="sortingEnabled">
+      <bool>true</bool>
+     </property>
+     <property name="wordWrap">
+      <bool>false</bool>
+     </property>
+     <attribute name="headerVisible">
+      <bool>true</bool>
+     </attribute>
+     <attribute name="headerCascadingSectionResizes">
+      <bool>false</bool>
+     </attribute>
+     <attribute name="headerDefaultSectionSize">
+      <number>80</number>
+     </attribute>
+     <attribute name="headerStretchLastSection">
+      <bool>true</bool>
+     </attribute>
+     <column>
+      <property name="text">
+       <string>Vignette</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 row="0" column="1">
+   <item row="0" column="2">
     <widget class="QLabel" name="label">
      <property name="text">
       <string>Éléments disponibles</string>
@@ -77,28 +161,33 @@
      </property>
     </widget>
    </item>
-   <item row="0" column="3">
-    <widget class="QLabel" name="label_2">
+   <item row="2" column="3">
+    <widget class="QPushButton" name="unlink_button">
+     <property name="toolTip">
+      <string>Délier l'élément séléctionné</string>
+     </property>
      <property name="text">
-      <string>Éléments liés</string>
+      <string/>
      </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
+     <property name="icon">
+      <iconset resource="../../qelectrotech.qrc">
+       <normaloff>:/ico/16x16/go-up.png</normaloff>:/ico/16x16/go-up.png</iconset>
      </property>
     </widget>
    </item>
-   <item row="1" column="2">
-    <spacer name="verticalSpacer">
-     <property name="orientation">
-      <enum>Qt::Vertical</enum>
+   <item row="2" column="4">
+    <widget class="QPushButton" name="link_button">
+     <property name="toolTip">
+      <string>Lier l'élément séléctionné</string>
      </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>20</width>
-       <height>40</height>
-      </size>
+     <property name="text">
+      <string/>
      </property>
-    </spacer>
+     <property name="icon">
+      <iconset resource="../../qelectrotech.qrc">
+       <normaloff>:/ico/16x16/go-down.png</normaloff>:/ico/16x16/go-down.png</iconset>
+     </property>
+    </widget>
    </item>
   </layout>
  </widget>


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