From 9f9011d49b2c9d3c682aadcf1e7b5fde1872e8f7 Mon Sep 17 00:00:00 2001
From: Jake <j@kedrahos.com>
Date: Sun, 9 Apr 2017 17:53:11 -0500
Subject: [PATCH] Added smarts to setpoint choosers

Now they do a good job of defaulting to the right setpoints
---
 groundStation/gui/MicroCART/mainwindow.cpp | 36 +++++++++++++++-------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp
index 3b2ac7dba..06198eaa5 100644
--- a/groundStation/gui/MicroCART/mainwindow.cpp
+++ b/groundStation/gui/MicroCART/mainwindow.cpp
@@ -143,17 +143,31 @@ void MainWindow::newNodes(QStringList blocks)
 
 void MainWindow::newConstantBlocks(QStringList blocks)
 {
-    QComboBox * select = findChild<QComboBox *>("xSetpointSelect");
-    select->clear(); /* Hopefully this clears the list */
-    select->addItems(blocks);
-
-    select = findChild<QComboBox *>("ySetpointSelect");
-    select->clear(); /* Hopefully this clears the list */
-    select->addItems(blocks);
-
-    select = findChild<QComboBox *>("zSetpointSelect");
-    select->clear(); /* Hopefully this clears the list */
-    select->addItems(blocks);
+    QComboBox * xSelect = findChild<QComboBox *>("xSetpointSelect");
+    xSelect->clear(); /* Hopefully this clears the list */
+    xSelect->addItems(blocks);
+
+    QComboBox * ySelect = findChild<QComboBox *>("ySetpointSelect");
+    ySelect->clear(); /* Hopefully this clears the list */
+    ySelect->addItems(blocks);
+
+    QComboBox * zSelect = findChild<QComboBox *>("zSetpointSelect");
+    zSelect->clear(); /* Hopefully this clears the list */
+    zSelect->addItems(blocks);
+
+    for (ssize_t i = 0; i < blocks.size(); i++) {
+        if (blocks[i].contains("setpoint", Qt::CaseInsensitive) || blocks[i].contains("sp", Qt::CaseInsensitive)) {
+            if (blocks[i].contains("x ", Qt::CaseInsensitive)) {
+                xSelect->setCurrentIndex(i);
+            }
+            if (blocks[i].contains("y ", Qt::CaseInsensitive)) {
+                ySelect->setCurrentIndex(i);
+            }
+            if (blocks[i].contains("z ", Qt::CaseInsensitive) || blocks[i].contains("alt", Qt::CaseInsensitive)) {
+                zSelect->setCurrentIndex(i);
+            }
+        }
+    }
 }
 
 void MainWindow::newParams(QStringList params)
-- 
GitLab