From 89af75f9a2938d67c507fc231f802cc5a1a40ec8 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Thu, 17 Sep 2020 11:34:38 -0400 Subject: [PATCH] Ensure track types are sorted in the delegate Modify TrackTypeDelegate to explicitly sort the collection of types we get from KWIVER (using locale-aware sort, also). This will ensure that the types are presented to the user in the best possible order, regardless of whether what KWIVER gives us is in order or not (which may or may not be changing upstream). --- sealtk/noaa/gui/TrackTypeDelegate.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sealtk/noaa/gui/TrackTypeDelegate.cpp b/sealtk/noaa/gui/TrackTypeDelegate.cpp index 05f1ace..91c35d7 100644 --- a/sealtk/noaa/gui/TrackTypeDelegate.cpp +++ b/sealtk/noaa/gui/TrackTypeDelegate.cpp @@ -42,16 +42,26 @@ QWidget* TrackTypeDelegate::createEditor( QWidget* parent, QStyleOptionViewItem const& option, QModelIndex const& index) const { - QComboBox* box = new QComboBox{parent}; + auto* const box = new QComboBox{parent}; box->setEditable(true); box->setFocusPolicy(Qt::StrongFocus); box->setFrame(false); + // Get collection of type names + auto types = QStringList{}; for (auto const& type : kv::detected_object_type::all_class_names()) { - box->addItem(qtString(type)); + types.append(qtString(type)); } + // Sort names according to locale + auto compare = + qOverload(&QString::localeAwareCompare); + std::sort(types.begin(), types.end(), compare); + + // Populate combo box + box->addItems(types); + return box; }