mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-03 13:30:26 +01:00
gstengine: Add a model for pipelines
Provide GstPipelineModel for displaying lists of GstPipelineBase instances.
This commit is contained in:
parent
a7a32b08b6
commit
befaacebf9
@ -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;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user