Skip to content

Commit

Permalink
GUI: offer links for numbers and strings of different types.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmayerguerr committed Oct 11, 2024
1 parent 6291a0f commit c35d0ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Bugfix: parameterNames: fixed wrong order.
- Bugfix: GraceAod2DoodsonHarmonics: fixed phase error.
- Bugfix: GnssOrbex2StarCamera: reads now free format.
- Other: GUI: offer links for numbers and strings of different types.
- Other: gnss: set margin for polynomial orbit interpolation to 1e-7 seconds.

# Release 2024-06-24
Expand Down
51 changes: 31 additions & 20 deletions gui/tree/treeElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,40 +435,51 @@ void TreeElement::updateLinks(QMap<QString, QString> &labelTypes)
if(loop) {auto labelTypesLocal = labelTypes; loop->updateLinks(labelTypesLocal);}
if(condition) {auto labelTypesLocal = labelTypes; condition->updateLinks(labelTypesLocal);}

// treat numbers and strings of different types as same
static const QStringList numberList({"int", "uint", "double", "angle", "boolean", "time", "expression"});
static const QStringList stringList({"string", "filename", "gnssType", "doodson"});
QString linkType = type();
if(numberList.contains(linkType)) linkType = "number_";
if(stringList.contains(linkType)) linkType = "string_";

if(!label().isEmpty() && !disabled())
labelTypes[label()] = type();
labelTypes[label()] = linkType;

// find all links
QStringList linkList;
for(auto iter = labelTypes.keyValueBegin(); iter != labelTypes.keyValueEnd(); iter++)
if((iter->first != label()) && (iter->second == linkType)) // should not linked to self
linkList.push_back(iter->first);
linkList.sort();

QString link;
QString selectedLink;
if(isLinked())
link = selectedValue();
selectedLink = selectedValue();

// remove all links
// remove all links and refill
while(_valueList.size() > _valueCount)
_valueList.removeAt(_valueCount);
while(comboBox && (comboBox->count() > _valueCount))
comboBox->removeItem(_valueCount);

// refill links
for(auto iter = labelTypes.keyValueBegin(); iter != labelTypes.keyValueEnd(); iter++)
if((iter->first != label()) && (iter->second == type())) // should not linked to self
{
_valueList.push_back(iter->first);
if(comboBox)
comboBox->insertItem(comboBox->count(), QIcon(":/icons/scalable/link.svg"), iter->first);
}
_valueList<<linkList;
if(comboBox)
{
while(comboBox->count() > _valueCount)
comboBox->removeItem(_valueCount);
for(const QString &link : linkList)
comboBox->insertItem(comboBox->count(), QIcon(":/icons/scalable/link.svg"), link);
}

// restore selected link
_brokenLinkIndex = -1;
if(!link.isEmpty())
if(!selectedLink.isEmpty())
{
int selectedIndex = findLinkIndex(link);
if(selectedIndex < 0)
int selectedIndex = findLinkIndex(selectedLink);
if(selectedIndex < 0) // broken link
{
selectedIndex = _valueList.size();
_brokenLinkIndex = selectedIndex;
_valueList.push_back(link);
_valueList.push_back(selectedLink);
if(comboBox)
comboBox->insertItem(comboBox->count(), QIcon(":/icons/scalable/link-broken.svg"), link);
comboBox->insertItem(comboBox->count(), QIcon(":/icons/scalable/link-broken.svg"), selectedLink);
}
setSelectedIndex(selectedIndex);
if(comboBox && (comboBox->currentIndex() != selectedIndex))
Expand Down

0 comments on commit c35d0ce

Please sign in to comment.