Skip to content

Commit 11478b2

Browse files
authored
Add remove function for Data1D. (#73)
1 parent 95422ea commit 11478b2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/widget.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,24 @@ Data1DEntity *MildredWidget::addData1D(const QString &tag)
204204
return entity;
205205
}
206206

207+
// Remove data entity with the supplied data
208+
bool MildredWidget::removeData1D(const QString &tag)
209+
{
210+
// Check for existing tag
211+
auto it = std::find_if(dataEntities_.begin(), dataEntities_.end(), [tag](const auto &d) { return tag == d.first; });
212+
if (it == dataEntities_.end())
213+
{
214+
qDebug() << QString("Data with tag '%1' does not exist, so it can't be removed from the plot.\n").arg(it->first);
215+
return false;
216+
}
217+
auto &[entityTag, entity] = *it;
218+
219+
entity->setParent(static_cast<Qt3DCore::QNode *>(nullptr));
220+
dataEntities_.erase(it);
221+
222+
return true;
223+
}
224+
207225
/*
208226
* Grouping
209227
*/

src/widget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class MildredWidget : public QWidget
206206
public:
207207
// Add new data entity for supplied data
208208
Data1DEntity *addData1D(const QString &tag);
209+
// Remove data entity with the supplied data
210+
bool removeData1D(const QString &tag);
209211

210212
/*
211213
* Grouping

0 commit comments

Comments
 (0)