[qet] [3529] Report link widget : each content show the string of the conductor and search field filter with this string.

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


Revision: 3529
Author:   blacksun
Date:     2014-12-04 11:54:38 +0100 (Thu, 04 Dec 2014)
Log Message:
-----------
Report link widget : each content show the string of the conductor and search field filter with this string.

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

Modified: trunk/sources/ui/elementselectorwidget.cpp
===================================================================
--- trunk/sources/ui/elementselectorwidget.cpp	2014-12-03 10:45:16 UTC (rev 3528)
+++ trunk/sources/ui/elementselectorwidget.cpp	2014-12-04 10:54:38 UTC (rev 3529)
@@ -21,6 +21,9 @@
 #include "qeticons.h"
 #include "diagram.h"
 #include "element.h"
+#include "terminal.h"
+#include "conductor.h"
+#include "qet.h"
 
 /**
  * @brief ElementSelectorWidget::ElementSelectorWidget
@@ -71,7 +74,8 @@
  */
 void ElementSelectorWidget::clear() {
 	elements_list.clear();
-	string_filter.clear();
+	in_filter.clear();
+	out_filter.clear();
 	if(showed_element) showed_element->setHighlighted(false);
 	foreach(QWidget *w, content_list) {
 		ui->scroll_layout_->removeWidget(w);
@@ -116,8 +120,10 @@
 		//label for the button
 		QString button_text;
 
-		//if element is master and have label, add label to the string
-		//Also to comment
+			/*
+			 * 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();
 
@@ -129,23 +135,59 @@
 
 			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) {
+				//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\260 fil : ") + str_list.first() + "\n";
+						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
+			//Widget that contain the buttons
 		QWidget *widget = new QWidget(this);
 		content_list << widget;
 
-		//Radio button for select element
+			//Radio button for select element
 		QRadioButton *rb = new QRadioButton(button_text , widget);
 		m_button_group -> addButton(rb);
 
-		//Push button to highlight element
+			//Push button to highlight element
 		QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"", widget);
 		pb -> setToolTip(tr("Voir l'\351l\351ment"));
 
@@ -156,17 +198,10 @@
 		hl -> addWidget(pb);
 		ui -> scroll_layout_ -> insertWidget(map_id, widget);
 
-		//Add the string for filter this widget
-		QString filter;
-		foreach(QString str, elmt->elementInformations().keys()){
-			filter += elmt->elementInformations()[str].toString();
-		}
-		string_filter << filter;
-
-		//map the radio button signal
+			//map the radio button signal
 		connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
 		sm_ -> setMapping(rb, map_id);
-		//map the push button show diagram
+			//map the push button show diagram
 		connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map()));
 		sm_show_->setMapping(pb, map_id);
 
@@ -186,17 +221,26 @@
 
 /**
  * @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::filter(const QString &str) {
+void ElementSelectorWidget::filtered(const QString &str) {
 	if(str.isEmpty()) {
 		foreach (QWidget *w, content_list) w->setHidden(false);
 	}
 	else {
-		for (int i =0; i<string_filter.size(); i++) {
-			if (string_filter.at(i).contains(str, Qt::CaseInsensitive))
+		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);

Modified: trunk/sources/ui/elementselectorwidget.h
===================================================================
--- trunk/sources/ui/elementselectorwidget.h	2014-12-03 10:45:16 UTC (rev 3528)
+++ trunk/sources/ui/elementselectorwidget.h	2014-12-04 10:54:38 UTC (rev 3529)
@@ -46,14 +46,16 @@
 	void clear();
 	void setList(QList <Element *> elmt_list);
 
+	QStringList filter () const;
+
 	public slots:
-	void filter(const QString &str);
+	void filtered(const QString &str);
 
 	private:
 	void buildInterface();
 
 	private slots:
-	void setSelectedElement(const int i) {selected_element = elements_list.at(i);}
+	void setSelectedElement  (const int i) {selected_element = elements_list.at(i);}
 	void showElementFromList (const int i);
 
 
@@ -64,7 +66,9 @@
 	QSignalMapper             *sm_, *sm_show_;
 	Element                   *selected_element, *showed_element;
 	QList <QWidget *>          content_list;
-	QStringList                string_filter;
+	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;
 };
 

Modified: trunk/sources/ui/linksingleelementwidget.cpp
===================================================================
--- trunk/sources/ui/linksingleelementwidget.cpp	2014-12-03 10:45:16 UTC (rev 3528)
+++ trunk/sources/ui/linksingleelementwidget.cpp	2014-12-04 10:54:38 UTC (rev 3529)
@@ -94,8 +94,7 @@
 				ui->button_linked->setDisabled(true) :
 				buildUnlinkButton();
 
-	if(filter_ & Element::Master)
-		buildSearchField();
+	buildSearchField();
 }
 
 /**
@@ -132,12 +131,22 @@
  * like label or information
  */
 void LinkSingleElementWidget::buildSearchField() {
-	search_field = new QLineEdit(this);
+		//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);
 #if QT_VERSION >= 0x040700
 	search_field -> setPlaceholderText(tr("Rechercher"));
 #endif
 	setUpCompleter();
-	connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filter(QString)));
+	connect(search_field, SIGNAL(textChanged(QString)), esw_, SLOT(filtered(QString)));
 	ui->header_layout->addWidget(search_field);
 }
 
@@ -177,21 +186,16 @@
 
 /**
  * @brief LinkSingleElementWidget::setUpCompleter
- * Setup the completer for the find_field
+ * Setup the completer of search_field
  */
 void LinkSingleElementWidget::setUpCompleter() {
 	if (search_field) {
-		search_field->clear();
-		delete search_field->completer();
+		search_field -> clear();
+		delete search_field -> completer();
 
-		QStringList list;
-		foreach (Element *elmt, availableElements())
-			foreach(QString str, elmt->elementInformations().keys())
-				list << elmt->elementInformations()[str].toString();
-
-		QCompleter *comp = new QCompleter(list, search_field);
-		comp->setCaseSensitivity(Qt::CaseInsensitive);
-		search_field->setCompleter(comp);
+		QCompleter *comp = new QCompleter(esw_ -> filter(), search_field);
+		comp -> setCaseSensitivity(Qt::CaseInsensitive);
+		search_field -> setCompleter(comp);
 	}
 }
 
@@ -201,7 +205,7 @@
  */
 void LinkSingleElementWidget::setNewList() {
 	esw_->setList(availableElements());
-	setUpCompleter();
+	buildSearchField();
 }
 
 /**


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