[qet] qet/qet: [5565] Search and replace : improve the search for diagram

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


Revision: 5565
Author:   blacksun
Date:     2018-10-24 16:04:04 +0200 (Wed, 24 Oct 2018)
Log Message:
-----------
Search and replace : improve the search for diagram

Modified Paths:
--------------
    trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp
    trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h

Modified: trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp
===================================================================
--- trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp	2018-10-21 09:54:59 UTC (rev 5564)
+++ trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp	2018-10-24 14:04:04 UTC (rev 5565)
@@ -246,6 +246,7 @@
 		
 		QTreeWidgetItem *qtwi = new QTreeWidgetItem(m_folio_qtwi);
 		qtwi->setText(0, str);
+		qtwi->setData(0, Qt::UserRole, searchTerms(diagram));
 		qtwi->setCheckState(0, Qt::Checked);
 		m_diagram_hash.insert(qtwi, QPointer<Diagram>(diagram));
 		dc += DiagramContent(diagram, false);
@@ -356,12 +357,22 @@
 		}
 		
 		bool match = false;
-		for(QTreeWidgetItem *qtwi : ui->m_tree_widget->findItems(str, Qt::MatchContains | Qt::MatchRecursive))
+		for (QTreeWidgetItem *qtwi : ui->m_tree_widget->findItems(str, Qt::MatchContains | Qt::MatchRecursive)) //Search in all items
 		{
 			match = true;
 			qtwi->setHidden(false);
 			setVisibleAllParents(qtwi);
 		}
+		for (QTreeWidgetItem *qtwi : m_diagram_hash.keys()) //Search for diagrams items
+		{
+			QStringList list = qtwi->data(0, Qt::UserRole).toStringList();
+			if (!list.filter(str, Qt::CaseInsensitive).isEmpty())
+			{
+				match = true;
+				qtwi->setHidden(false);
+				setVisibleAllParents(qtwi);
+			}
+		}
 		
 		QPalette background = ui->m_search_le->palette();
 		background.setColor(QPalette::Base, match ? QColor("#E0FFF0") : QColor("#FFE0EF"));
@@ -589,9 +600,33 @@
 	do {
 		on_m_next_pb_clicked();
 	} while ((ui->m_tree_widget->currentItem()->checkState(0) != Qt::Checked) &&
-			  ui->m_next_pb->isEnabled());
+			 ui->m_next_pb->isEnabled());
 }
 
+/**
+ * @brief SearchAndReplaceWidget::searchTerms
+ * @param diagram
+ * @return All QStrings use as terms for search.
+ */
+QStringList SearchAndReplaceWidget::searchTerms(Diagram *diagram) const
+{
+	QStringList list;
+	TitleBlockProperties prop = diagram->border_and_titleblock.exportTitleBlock();
+	list.append(prop.title);
+	list.append(prop.author);
+	list.append(prop.filename);
+	list.append(prop.machine);
+	list.append(prop.locmach);
+	list.append(prop.indexrev);
+	list.append(prop.folio);
+	list.append(prop.date.toString());
+	for (QString key : prop.context.keys()) {
+		list.append(prop.context.value(key).toString());
+	}
+	
+	return list;
+}
+
 void SearchAndReplaceWidget::on_m_quit_button_clicked() {
     this->setHidden(true);
 }
@@ -693,6 +728,10 @@
 	}
 	
 	updateNextPreviousButtons();
+	if (!current) {
+		return;
+	}
+	
 	if (current->checkState(0) == Qt::Checked && !m_category_qtwi.contains(current)) {
 		ui->m_replace_pb->setEnabled(true);
 	} else {

Modified: trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h
===================================================================
--- trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h	2018-10-21 09:54:59 UTC (rev 5564)
+++ trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h	2018-10-24 14:04:04 UTC (rev 5565)
@@ -60,6 +60,7 @@
 		void setChildCheckState(QTreeWidgetItem *item, Qt::CheckState check, bool deep = true);
 		void updateParentCheckState(QTreeWidgetItem *item, bool all_parents = true);
 		void activateNextChecked();
+		QStringList searchTerms(Diagram *diagram) const;
 		
 	private slots:
 		void on_m_quit_button_clicked();


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