gstengine: Add PipelineView class

Add ListView derivative class for displaying GstPipelineModel data. A
GetSelectedIds method provides the list of selected pipelie IDs.
This commit is contained in:
Jim Broadus 2021-01-26 22:41:56 -08:00 committed by John Maguire
parent 8d11e9ffab
commit 7d061afdc3
5 changed files with 91 additions and 0 deletions

View File

@ -138,6 +138,7 @@ set(SOURCES
engines/gstenginepipeline.cpp
engines/gstelementdeleter.cpp
engines/gstpipelinebase.cpp
engines/pipelineview.cpp
globalsearch/digitallyimportedsearchprovider.cpp
globalsearch/globalsearch.cpp
@ -461,6 +462,7 @@ set(HEADERS
engines/gstenginepipeline.h
engines/gstelementdeleter.h
engines/gstpipelinebase.h
engines/pipelineview.h
globalsearch/globalsearch.h
globalsearch/globalsearchmodel.h

View File

@ -76,3 +76,11 @@ int GstPipelineModel::FindRowById(int id) const {
return -1;
}
int GstPipelineModel::GetPipelineId(const QModelIndex& index) const {
const QStandardItem* item = itemFromIndex(index);
if (item != nullptr)
return item->data(Role::Role_Id).toInt();
else
return -1;
}

View File

@ -56,6 +56,10 @@ class GstPipelineModel : public QStandardItemModel {
void AddPipeline(int id, const QString& name);
void RemovePipeline(int id);
private:
friend class PipelineView;
int GetPipelineId(const QModelIndex& index) const;
private:
int FindRowById(int id) const;

View File

@ -0,0 +1,38 @@
/* This file is part of Clementine.
Copyright 2021, Jim Broadus <jbroadus@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pipelineview.h"
#include "gstpipelinebase.h"
void PipelineView::setPipelineModel(GstPipelineModel* model) {
QListView::setModel(model);
pipeline_model_ = model;
}
QList<int> PipelineView::GetSelectedIds() const {
QList<int> selected;
if (pipeline_model_ != nullptr) {
for (const QModelIndex& index : selectedIndexes()) {
int id = pipeline_model_->GetPipelineId(index);
if (id >= 0) {
selected << id;
}
}
}
return selected;
}

View File

@ -0,0 +1,39 @@
/* This file is part of Clementine.
Copyright 2021, Jim Broadus <jbroadus@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIPELINEVIEW_H
#define PIPELINEVIEW_H
#include <QList>
#include <QListView>
class GstPipelineModel;
class PipelineView : public QListView {
Q_OBJECT;
public:
explicit PipelineView(QWidget* parent) : QListView(parent) {}
void setPipelineModel(GstPipelineModel* model);
QList<int> GetSelectedIds() const;
private:
GstPipelineModel* pipeline_model_;
};
#endif // PIPELINEVIEW_H