Don't allow placefiles with an empty name

This commit is contained in:
Dan Paulat 2023-09-11 22:19:04 -05:00
parent e14db6cd21
commit df4500478c
2 changed files with 23 additions and 10 deletions

View file

@ -356,10 +356,13 @@ void PlacefileManager::Impl::ReadPlacefileSettings()
PlacefileRecord record = PlacefileRecord record =
boost::json::value_to<PlacefileRecord>(placefileEntry); boost::json::value_to<PlacefileRecord>(placefileEntry);
self_->AddUrl(record.name_, if (!record.name_.empty())
record.title_, {
record.enabled_, self_->AddUrl(record.name_,
record.thresholded_); record.title_,
record.enabled_,
record.thresholded_);
}
} }
catch (const std::exception& ex) catch (const std::exception& ex)
{ {

View file

@ -257,6 +257,7 @@ bool PlacefileModel::setData(const QModelIndex& index,
} }
const auto& placefileName = p->placefileNames_.at(index.row()); const auto& placefileName = p->placefileNames_.at(index.row());
bool result = false;
switch (index.column()) switch (index.column())
{ {
@ -265,7 +266,7 @@ bool PlacefileModel::setData(const QModelIndex& index,
{ {
p->placefileManager_->set_placefile_enabled(placefileName, p->placefileManager_->set_placefile_enabled(placefileName,
value.toBool()); value.toBool());
return true; result = true;
} }
break; break;
@ -274,16 +275,20 @@ bool PlacefileModel::setData(const QModelIndex& index,
{ {
p->placefileManager_->set_placefile_thresholded(placefileName, p->placefileManager_->set_placefile_thresholded(placefileName,
value.toBool()); value.toBool());
return true; result = true;
} }
break; break;
case static_cast<int>(Column::Placefile): case static_cast<int>(Column::Placefile):
if (role == Qt::ItemDataRole::EditRole) if (role == Qt::ItemDataRole::EditRole)
{ {
p->placefileManager_->set_placefile_url( QString str = value.toString();
placefileName, value.toString().toStdString()); if (!str.isEmpty())
return true; {
p->placefileManager_->set_placefile_url(placefileName,
str.toStdString());
result = true;
}
} }
break; break;
@ -291,7 +296,12 @@ bool PlacefileModel::setData(const QModelIndex& index,
break; break;
} }
return true; if (result)
{
Q_EMIT dataChanged(index, index);
}
return result;
} }
void PlacefileModel::HandlePlacefileRemoved(const std::string& name) void PlacefileModel::HandlePlacefileRemoved(const std::string& name)