Placefile "Remove" functionality

This commit is contained in:
Dan Paulat 2023-08-22 23:52:55 -05:00
parent 9955c4ccbe
commit ad5c2b583d
6 changed files with 115 additions and 2 deletions

View file

@ -45,6 +45,11 @@ PlacefileModel::PlacefileModel(QObject* parent) :
this,
&PlacefileModel::HandlePlacefileUpdate);
connect(p->placefileManager_.get(),
&manager::PlacefileManager::PlacefileRemoved,
this,
&PlacefileModel::HandlePlacefileRemoved);
connect(p->placefileManager_.get(),
&manager::PlacefileManager::PlacefileRenamed,
this,
@ -292,6 +297,24 @@ bool PlacefileModel::setData(const QModelIndex& index,
return true;
}
void PlacefileModel::HandlePlacefileRemoved(const std::string& name)
{
auto it =
std::find(p->placefileNames_.begin(), p->placefileNames_.end(), name);
if (it != p->placefileNames_.end())
{
// Placefile exists, delete row
const int row = std::distance(p->placefileNames_.begin(), it);
QModelIndex topLeft = createIndex(row, kFirstColumn);
QModelIndex bottomRight = createIndex(row, kLastColumn);
beginRemoveRows(QModelIndex(), row, row);
p->placefileNames_.erase(it);
endRemoveRows();
}
}
void PlacefileModel::HandlePlacefileRenamed(const std::string& oldName,
const std::string& newName)
{

View file

@ -45,6 +45,7 @@ public:
int role = Qt::EditRole) override;
public slots:
void HandlePlacefileRemoved(const std::string& name);
void HandlePlacefileRenamed(const std::string& oldName,
const std::string& newName);
void HandlePlacefileUpdate(const std::string& name);