From 7632aac6c9ecf1dc11c6bc018836d6c678cdf8fb Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Fri, 26 Jun 2020 22:35:45 +0200
Subject: [PATCH] [DE] Update ElementTree bounds. More types.

Update for new signature of the getValueBounds().
Generalize to more types.
Deduplicate creation of the entries.
---
 .../DataView/ElementTreeModel.cpp             | 70 ++++++++++++++-----
 1 file changed, 52 insertions(+), 18 deletions(-)

diff --git a/Applications/DataExplorer/DataView/ElementTreeModel.cpp b/Applications/DataExplorer/DataView/ElementTreeModel.cpp
index 08d89021616..9b639ebc5de 100644
--- a/Applications/DataExplorer/DataView/ElementTreeModel.cpp
+++ b/Applications/DataExplorer/DataView/ElementTreeModel.cpp
@@ -25,6 +25,22 @@
 
 #include "TreeItem.h"
 
+namespace
+{
+template <typename PropertyType>
+QList<QVariant> propertyBounds(PropertyType const& property)
+{
+    auto const bounds = MeshLib::MeshInformation::getValueBounds(property);
+    if (bounds.has_value())
+    {
+        return {"[" + QString::number(bounds->first) + ",",
+                QString::number(bounds->second) + "]"};
+    }
+    // Makeup the same structure of output as in the valid case above.
+    return {"[empty,", "empty]"};
+}
+}  // namespace
+
 /**
  * Constructor.
  */
@@ -170,35 +186,53 @@ void ElementTreeModel::setMesh(MeshLib::Mesh const& mesh)
 
     for (auto [name, property] : mesh.getProperties())
     {
-        QList<QVariant> array_info;
-        array_info << QString::fromStdString(name) + ": ";
-        if (auto const vec_bounds =  // test if boost::optional is empty
-            MeshLib::MeshInformation::getValueBounds<int>(*property))
+        QList<QVariant> array_info{QString::fromStdString(name) + ": "};
+
+        if (auto p = dynamic_cast<MeshLib::PropertyVector<double>*>(property))
         {
-            array_info << "[" + QString::number(vec_bounds->first) + ","
-                       << QString::number(vec_bounds->second) + "]";
+            array_info.append(propertyBounds(*p));
         }
-        else if (auto const vec_bounds =  // test if boost::optional is empty
-                 MeshLib::MeshInformation::getValueBounds<double>(*property))
+        else if (auto p =
+                     dynamic_cast<MeshLib::PropertyVector<float>*>(property))
         {
-            array_info << "[" + QString::number(vec_bounds->first) + ","
-                       << QString::number(vec_bounds->second) + "]";
+            array_info.append(propertyBounds(*p));
         }
-        else
+        else if (auto p = dynamic_cast<MeshLib::PropertyVector<int>*>(property))
         {
-            // Makeup the same structure of output as in the valid cases above.
-            array_info << "[error,"
-                       << "error]";
+            array_info.append(propertyBounds(*p));
         }
-
-        if (array_info.size() == 1)
+        else if (auto p =
+                     dynamic_cast<MeshLib::PropertyVector<unsigned>*>(property))
         {
+            array_info.append(propertyBounds(*p));
+        }
+        else if (auto p =
+                     dynamic_cast<MeshLib::PropertyVector<long>*>(property))
+        {
+            array_info.append(propertyBounds(*p));
+        }
+        else if (auto p = dynamic_cast<MeshLib::PropertyVector<unsigned long>*>(
+                     property))
+        {
+            array_info.append(propertyBounds(*p));
+        }
+        else if (auto p = dynamic_cast<MeshLib::PropertyVector<std::size_t>*>(
+                     property))
+        {
+            array_info.append(propertyBounds(*p));
+        }
+        else if (auto p =
+                     dynamic_cast<MeshLib::PropertyVector<char>*>(property))
+        {
+            array_info.append(propertyBounds(*p));
+        }
+        else
+        {  // Unhandled property vector type.
             array_info << "[ ?"
                        << "? ]"
                        << "";
         }
-        auto* vec_item = new TreeItem(array_info, _rootItem);
-        _rootItem->appendChild(vec_item);
+        _rootItem->appendChild(new TreeItem(array_info, _rootItem));
     }
 
     endResetModel();
-- 
GitLab