Skip to content

Commit

Permalink
check nullability after cast to numeric feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Friedel committed Dec 5, 2023
1 parent 1913c34 commit dfad1c1
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions tools/fm-editor/tree/FeatureTreeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
QVariant numericValue(vara::feature::Feature *Item) {
if (Item->getKind() == vara::feature::Feature::FeatureKind::FK_NUMERIC) {
auto *NumItem = llvm::dyn_cast<vara::feature::NumericFeature>(Item);
string Result = "[";
if (std::holds_alternative<vara::feature::NumericFeature::ValueRangeType>(
NumItem->getValues())) {
auto Range = std::get<vara::feature::NumericFeature::ValueRangeType>(
NumItem->getValues());
Result += std::to_string(Range.first) + ", " +
std::to_string(Range.second) + "]";
} else {
auto Range = std::get<vara::feature::NumericFeature::ValueListType>(
NumItem->getValues());
for (auto It = Range.begin(); It != Range.end(); It++) {
if (It != Range.begin()) {
Result += ",";
if (NumItem != nullptr) {
string Result = "[";
if (std::holds_alternative<vara::feature::NumericFeature::ValueRangeType>(
NumItem->getValues())) {
auto Range = std::get<vara::feature::NumericFeature::ValueRangeType>(
NumItem->getValues());
Result += std::to_string(Range.first) + ", " +
std::to_string(Range.second) + "]";
} else {
auto Range = std::get<vara::feature::NumericFeature::ValueListType>(
NumItem->getValues());
for (auto It = Range.begin(); It != Range.end(); It++) {
if (It != Range.begin()) {
Result += ",";
}
Result += std::to_string(*It.base());
}
Result += std::to_string(*It.base());
Result += "]";
}
Result += "]";
}

return QString::fromStdString(Result);
return QString::fromStdString(Result);
}
}

return {};
Expand Down Expand Up @@ -79,23 +81,20 @@ std::vector<FeatureTreeItem *> FeatureTreeItem::getChildrenRecursive() {
}

QVariant FeatureTreeItemFeature::data(int Column) const {
if (Item != nullptr) {
switch (Column) {
case 0:
return QString::fromStdString(Item->getName().str());
case 1:
return Item->isOptional() ? QVariant("") : QVariant("x");
case 2:
return numericValue(Item);
case 3:
return locationString(Item);
case 4:
return QString::fromStdString(Item->getOutputString().str());
default:
return {};
}
switch (Column) {
case 0:
return QString::fromStdString(Item->getName().str());
case 1:
return Item->isOptional() ? QVariant("") : QVariant("x");
case 2:
return numericValue(Item);
case 3:
return locationString(Item);
case 4:
return QString::fromStdString(Item->getOutputString().str());
default:
return {};
}
return {};
}

void FeatureTreeItemFeature::inspect() { emit(inspectSource(Item)); }
Expand Down

0 comments on commit dfad1c1

Please sign in to comment.