Skip to content

Commit

Permalink
QuickView restore isNumber check and customfields
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlong13 committed Dec 9, 2022
1 parent 70188c5 commit 4452d2f
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Controls/QuickViewOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using MissionPlanner.Utilities;

namespace MissionPlanner.Controls
{
Expand All @@ -23,32 +24,40 @@ public QuickViewOptions(QuickView qv)
private void QuickViewOptions_Shown(object sender, EventArgs e)
{
// Populate combobox with variables
List<string> options = new List<string>();
object defaultsrc = MainV2.comPort.MAV.cs;
Type test = defaultsrc.GetType();
object thisBoxed = MainV2.comPort.MAV.cs;
Type test = thisBoxed.GetType();

List<Tuple<string, string>> fields = new List<Tuple<string, string>>();

foreach (var field in test.GetProperties())
{
// field.Name has the field's name.
object fieldValue;
TypeCode typeCode;
try
{
fieldValue = field.GetValue(defaultsrc, null); // Get value

if (fieldValue == null)
continue;
object fieldValue = field.GetValue(thisBoxed, null); // Get value
if (fieldValue == null)
continue;

// Get the TypeCode enumeration. Multiple types get mapped to a common typecode.
typeCode = Type.GetTypeCode(fieldValue.GetType());
}
catch
if (!fieldValue.IsNumber() && !(fieldValue is bool))
{
continue;
}

options.Add(field.Name);
if (field.Name.Contains("customfield"))
{
if (CurrentState.custom_field_names.ContainsKey(field.Name))
{
string name = CurrentState.custom_field_names[field.Name];
fields.Add(new Tuple<string, string>(field.Name, name));
}
}
else
{
fields.Add(new Tuple<string, string>(field.Name, field.Name));
}
}
CMB_Source.DataSource = options;

CMB_Source.ValueMember = "Item1";
CMB_Source.DisplayMember = "Item2";
CMB_Source.DataSource = fields;

// Initialize combobox selection
CMB_Source.Text = (string)_qv.Tag;
Expand Down Expand Up @@ -79,7 +88,7 @@ private void QuickViewOptions_Shown(object sender, EventArgs e)

private void CMB_Source_SelectedIndexChanged(object sender, EventArgs e)
{
Utilities.Settings.Instance[_qv.Name] = CMB_Source.Text;
Utilities.Settings.Instance[_qv.Name] = (string) CMB_Source.SelectedValue;
}

private void NUM_precision_ValueChanged(object sender, EventArgs e)
Expand Down

0 comments on commit 4452d2f

Please sign in to comment.