diff --git a/src/engines/gstpipelinebase.cpp b/src/engines/gstpipelinebase.cpp index e6268c7e6..b8a3efc7b 100644 --- a/src/engines/gstpipelinebase.cpp +++ b/src/engines/gstpipelinebase.cpp @@ -48,3 +48,31 @@ void GstPipelineBase::DumpGraph() { } #endif } + +GstPipelineModel::GstPipelineModel(QObject* parent) + : QStandardItemModel(parent) {} + +void GstPipelineModel::AddPipeline(int id, const QString& name) { + QStandardItem* item = new QStandardItem(); + item->setData(name, Qt::DisplayRole); + item->setData(id, Role::Role_Id); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + appendRow(item); +} + +void GstPipelineModel::RemovePipeline(int id) { + int row = FindRowById(id); + if (row < 0) { + qLog(Warning) << "Did not find pipeline" << id; + return; + } + removeRow(row); +} + +int GstPipelineModel::FindRowById(int id) { + for (int i = 0; i < rowCount(); i++) { + if (item(i)->data(Role::Role_Id).toInt() == id) return i; + } + + return -1; +} diff --git a/src/engines/gstpipelinebase.h b/src/engines/gstpipelinebase.h index b6ef97cc5..f65d6b1f0 100644 --- a/src/engines/gstpipelinebase.h +++ b/src/engines/gstpipelinebase.h @@ -21,6 +21,7 @@ #include #include +#include class GstPipelineBase : public QObject { public: @@ -47,4 +48,18 @@ class GstPipelineBase : public QObject { const int id_; }; +class GstPipelineModel : public QStandardItemModel { + Q_OBJECT + + public: + explicit GstPipelineModel(QObject* parent = nullptr); + void AddPipeline(int id, const QString& name); + void RemovePipeline(int id); + + private: + int FindRowById(int id) const; + + enum Role { Role_Id = Qt::UserRole + 1 }; +}; + #endif // GSTPIPELINEBASE_H