Salome HOME
[bos #40644][CEA](2024-T1) Feature search.
authordish <dmitrii.shvydkoi@opencascade.com>
Tue, 23 Apr 2024 09:45:34 +0000 (09:45 +0000)
committerdish <dmitrii.shvydkoi@opencascade.com>
Tue, 23 Apr 2024 09:45:34 +0000 (09:45 +0000)
Fix result ranking.

src/SUIT/SUIT_FindActionDialog.cxx

index 7700a183f14dac2eb76cb8b0bbbf521579e8de37..1d07958308e85df44b015ffdec176f5bd2e0593c 100644 (file)
@@ -121,7 +121,7 @@ SUIT_FoundActionTree::SUIT_FoundActionTree(SUIT_FindActionDialog* theParent)
 {
   setColumnCount(2);
   setSelectionMode(QAbstractItemView::SingleSelection);
-  setSortingEnabled(false); // Items
+  setSortingEnabled(false);
   header()->setSectionResizeMode(QHeaderView::Interactive);
   {
     QMap<int, QString> labelMap;
@@ -139,6 +139,9 @@ SUIT_FoundActionTree::SUIT_FoundActionTree(SUIT_FindActionDialog* theParent)
 
   setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
 
+  mySortKey = SUIT_FoundActionTree::SortKey::MatchMetrics;
+  mySortOrder = SUIT_FoundActionTree::SortOrder::Ascending;
+
   connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(onItemExecuted(QTreeWidgetItem*, int)));
 }
 
@@ -319,6 +322,12 @@ std::pair<SUIT_FoundActionTreeModule*, int> SUIT_FoundActionTree::findModuleItem
   return std::pair<SUIT_FoundActionTreeModule*, int>(nullptr, -1);
 }
 
+template <typename Float>
+bool approximatelyEqual(Float a, Float b, Float relativeTol = std::numeric_limits<Float>::epsilon())
+{
+    return std::abs(a - b) <= ( (std::abs(a) < std::abs(b) ? std::abs(b) : std::abs(a)) * relativeTol);
+}
+
 std::set<SUIT_FoundActionTreeAction*, std::function<bool(SUIT_FoundActionTreeAction*, SUIT_FoundActionTreeAction*)>> SUIT_FoundActionTree::createActionSetWithComparator() const
 {
   QList<std::pair<SUIT_FoundActionTree::SortKey, SUIT_FoundActionTree::SortOrder>> sortSchema = SUIT_FoundActionTree::DEFAULT_SORT_SCHEMA;
@@ -343,10 +352,11 @@ std::set<SUIT_FoundActionTreeAction*, std::function<bool(SUIT_FoundActionTreeAct
       bool* const fieldOfBIsDouble = new bool(false);
       const double matchMetricsA = fieldOfA.toDouble(fieldOfAIsDouble);
       const double matchMetricsB = fieldOfB.toDouble(fieldOfBIsDouble);
-      if (fieldOfAIsDouble && fieldOfBIsDouble) {
-        const double res = matchMetricsA - matchMetricsB;
-        if (std::abs(res) > std::numeric_limits<double>::epsilon())
+      if (*fieldOfAIsDouble && *fieldOfBIsDouble) {
+        if (!approximatelyEqual(matchMetricsA, matchMetricsB)) {
+          const double res = matchMetricsA - matchMetricsB;
           return keyAndOrder.second == SUIT_FoundActionTree::SortOrder::Ascending ? res < 0 : res > 0;
+        }
       }
       else {
         const int res = collator.compare(fieldOfA.toString(), fieldOfB.toString());