[qet] qet/qet: [5620] Search and replace : Add two search options, contain text/ entire word and case sensitive/insensitive

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


Revision: 5620
Author:   blacksun
Date:     2018-11-29 18:34:03 +0100 (Thu, 29 Nov 2018)
Log Message:
-----------
Search and replace : Add two search options, contain text/entire word and case sensitive/insensitive

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

Modified: trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp
===================================================================
--- trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp	2018-11-29 09:50:09 UTC (rev 5619)
+++ trunk/sources/SearchAndReplace/ui/searchandreplacewidget.cpp	2018-11-29 17:34:03 UTC (rev 5620)
@@ -202,15 +202,18 @@
  */
 void SearchAndReplaceWidget::setHideAdvanced(bool hide) const
 {
-	ui->m_advanced_pb   ->setChecked(!hide);
-	ui->m_replace       ->setHidden(hide);
-	ui->m_replace_le    ->setHidden(hide);
-	ui->m_folio_pb      ->setHidden(hide);
-	ui->m_element_pb    ->setHidden(hide);
-	ui->m_conductor_pb  ->setHidden(hide);
-	ui->m_tree_widget   ->setHidden(hide);
-	ui->m_replace_pb    ->setHidden(hide);
-	ui->m_replace_all_pb->setHidden(hide);
+	ui->m_advanced_pb      ->setChecked(!hide);
+	ui->m_replace          ->setHidden(hide);
+	ui->m_replace_le       ->setHidden(hide);
+	ui->m_folio_pb         ->setHidden(hide);
+	ui->m_element_pb       ->setHidden(hide);
+	ui->m_conductor_pb     ->setHidden(hide);
+	ui->m_tree_widget      ->setHidden(hide);
+	ui->m_replace_pb       ->setHidden(hide);
+	ui->m_replace_all_pb   ->setHidden(hide);
+	ui->m_mode             ->setHidden(hide);
+	ui->m_mode_cb          ->setHidden(hide);
+	ui->m_case_sensitive_cb->setHidden(hide);
 	QSize size = ui->m_v_spacer->sizeHint();
 	ui->m_v_spacer->changeSize(size.width(), size.height(), QSizePolicy::Minimum, hide ? QSizePolicy::Expanding : QSizePolicy::Ignored);
 }
@@ -274,6 +277,7 @@
 		QTreeWidgetItem *qtwi = new QTreeWidgetItem(m_indi_text_qtwi);
 		qtwi->setText(0, iti->toPlainText());
 		qtwi->setCheckState(0, Qt::Checked);
+		qtwi->setData(0, Qt::UserRole, iti->toPlainText());
 		m_text_hash.insert(qtwi, QPointer<IndependentTextItem>(iti));
 	}
 	m_indi_text_qtwi->sortChildren(0, Qt::AscendingOrder);
@@ -364,7 +368,18 @@
 		}
 		
 		bool match = false;
-		for (QTreeWidgetItem *qtwi : ui->m_tree_widget->findItems(str, Qt::MatchContains | Qt::MatchRecursive)) //Search in all items
+		Qt::MatchFlags flags;
+			
+			//Search on the text displayed at column 0 of each item
+		if (ui->m_mode_cb->currentIndex() == 0) {
+			flags = Qt::MatchContains | Qt::MatchRecursive; //Contain string
+		} else {
+			flags = Qt::MatchFixedString | Qt::MatchRecursive; //entire word
+		}
+		if (ui->m_case_sensitive_cb->isChecked()) {
+			flags = flags | Qt::MatchCaseSensitive;
+		}
+		for (QTreeWidgetItem *qtwi : ui->m_tree_widget->findItems(str, flags))
 		{
 			match = true;
 			qtwi->setHidden(false);
@@ -371,13 +386,32 @@
 			setVisibleAllParents(qtwi);
 		}
 		
-		QList<QTreeWidgetItem *> qtwi_list = m_diagram_hash.keys();
+			//Extended search,
+			//on each string stored in column 0 with role : UserRole
+		QList<QTreeWidgetItem *> qtwi_list;
+		qtwi_list.append(m_diagram_hash.keys());
 		qtwi_list.append(m_element_hash.keys());
+		qtwi_list.append(m_text_hash.keys());
 		for (QTreeWidgetItem *qtwi : qtwi_list)
 		{
 			QStringList list = qtwi->data(0, Qt::UserRole).toStringList();
-			if (!list.filter(str, Qt::CaseInsensitive).isEmpty())
+			
+			if(ui->m_mode_cb->currentIndex() == 0)
 			{
+					//Contain string
+				list = list.filter(str, ui->m_case_sensitive_cb->isChecked()? Qt::CaseSensitive : Qt::CaseInsensitive);
+			}
+			else
+			{
+					//entire word
+				QRegularExpression rx("\\b" + str + "\\b");
+				if (!ui->m_case_sensitive_cb->isChecked()) {
+					rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
+				}
+				list = list.filter(rx);
+			}
+			if (!list.isEmpty())
+			{
 				match = true;
 				qtwi->setHidden(false);
 				setVisibleAllParents(qtwi);
@@ -971,3 +1005,25 @@
 		m_worker.m_element_context = DiagramContext();
 	}
 }
+
+/**
+ * @brief SearchAndReplaceWidget::on_m_mode_cb_currentIndexChanged
+ * Update the search when user change mode.
+ * @param index
+ */
+void SearchAndReplaceWidget::on_m_mode_cb_currentIndexChanged(int index)
+{
+	Q_UNUSED(index);	
+	search();
+}
+
+/**
+ * @brief SearchAndReplaceWidget::on_m_case_sensitive_cb_stateChanged
+ * Update the search when change the case sensitive
+ * @param arg1
+ */
+void SearchAndReplaceWidget::on_m_case_sensitive_cb_stateChanged(int arg1)
+{
+    Q_UNUSED(arg1);
+	search();
+}

Modified: trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h
===================================================================
--- trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h	2018-11-29 09:50:09 UTC (rev 5619)
+++ trunk/sources/SearchAndReplace/ui/searchandreplacewidget.h	2018-11-29 17:34:03 UTC (rev 5620)
@@ -75,6 +75,8 @@
 		void on_m_replace_pb_clicked();
 		void on_m_replace_all_pb_clicked();
 		void on_m_element_pb_clicked();
+		void on_m_mode_cb_currentIndexChanged(int index);
+		void on_m_case_sensitive_cb_stateChanged(int arg1);
 		
 		private:
 		Ui::SearchAndReplaceWidget *ui;

Modified: trunk/sources/SearchAndReplace/ui/searchandreplacewidget.ui
===================================================================
--- trunk/sources/SearchAndReplace/ui/searchandreplacewidget.ui	2018-11-29 09:50:09 UTC (rev 5619)
+++ trunk/sources/SearchAndReplace/ui/searchandreplacewidget.ui	2018-11-29 17:34:03 UTC (rev 5620)
@@ -150,25 +150,35 @@
    </item>
    <item row="0" column="3" rowspan="3">
     <layout class="QGridLayout" name="gridLayout">
-     <item row="1" column="1" colspan="2">
-      <widget class="QLineEdit" name="m_replace_le">
-       <property name="placeholderText">
-        <string>Champ texte de folio</string>
+     <item row="1" column="0">
+      <widget class="QLabel" name="m_replace">
+       <property name="text">
+        <string>Remplacer :</string>
        </property>
+      </widget>
+     </item>
+     <item row="0" column="1" colspan="6">
+      <widget class="QLineEdit" name="m_search_le">
        <property name="clearButtonEnabled">
         <bool>true</bool>
        </property>
       </widget>
      </item>
-     <item row="1" column="3">
-      <widget class="QPushButton" name="m_folio_pb">
+     <item row="1" column="5">
+      <widget class="QPushButton" name="m_element_pb">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
        <property name="text">
-        <string>Folio</string>
+        <string>Élément</string>
        </property>
       </widget>
      </item>
-     <item row="0" column="1" colspan="5">
-      <widget class="QLineEdit" name="m_search_le">
+     <item row="1" column="1" colspan="3">
+      <widget class="QLineEdit" name="m_replace_le">
+       <property name="placeholderText">
+        <string>Champ texte de folio</string>
+       </property>
        <property name="clearButtonEnabled">
         <bool>true</bool>
        </property>
@@ -181,34 +191,48 @@
        </property>
       </widget>
      </item>
-     <item row="1" column="4">
-      <widget class="QPushButton" name="m_element_pb">
+     <item row="1" column="6">
+      <widget class="QPushButton" name="m_conductor_pb">
        <property name="enabled">
-        <bool>true</bool>
+        <bool>false</bool>
        </property>
        <property name="text">
-        <string>Élément</string>
+        <string>Conducteur</string>
        </property>
       </widget>
      </item>
-     <item row="1" column="5">
-      <widget class="QPushButton" name="m_conductor_pb">
-       <property name="enabled">
-        <bool>false</bool>
-       </property>
+     <item row="2" column="0">
+      <widget class="QLabel" name="m_mode">
        <property name="text">
-        <string>Conducteur</string>
+        <string>Mode :</string>
        </property>
       </widget>
      </item>
-     <item row="1" column="0">
-      <widget class="QLabel" name="m_replace">
+     <item row="1" column="4">
+      <widget class="QPushButton" name="m_folio_pb">
        <property name="text">
-        <string>Remplacer :</string>
+        <string>Folio</string>
        </property>
       </widget>
      </item>
      <item row="2" column="1">
+      <widget class="QComboBox" name="m_mode_cb">
+       <property name="frame">
+        <bool>true</bool>
+       </property>
+       <item>
+        <property name="text">
+         <string>Texte brut</string>
+        </property>
+       </item>
+       <item>
+        <property name="text">
+         <string>Mots entiers</string>
+        </property>
+       </item>
+      </widget>
+     </item>
+     <item row="2" column="3">
       <spacer name="horizontalSpacer">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
@@ -221,6 +245,13 @@
        </property>
       </spacer>
      </item>
+     <item row="2" column="2">
+      <widget class="QCheckBox" name="m_case_sensitive_cb">
+       <property name="text">
+        <string>Sensible à la casse</string>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item row="2" column="4" colspan="2">


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