diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04a88e36a..bb83a4ee5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/engines/gstpipelinebase.cpp b/src/engines/gstpipelinebase.cpp index 92dd9bf41..03ad19dac 100644 --- a/src/engines/gstpipelinebase.cpp +++ b/src/engines/gstpipelinebase.cpp @@ -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; +} diff --git a/src/engines/gstpipelinebase.h b/src/engines/gstpipelinebase.h index f65d6b1f0..00a27b204 100644 --- a/src/engines/gstpipelinebase.h +++ b/src/engines/gstpipelinebase.h @@ -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; diff --git a/src/engines/pipelineview.cpp b/src/engines/pipelineview.cpp new file mode 100644 index 000000000..d2220e9f0 --- /dev/null +++ b/src/engines/pipelineview.cpp @@ -0,0 +1,38 @@ +/* This file is part of Clementine. + Copyright 2021, Jim Broadus + + 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 . +*/ + +#include "pipelineview.h" + +#include "gstpipelinebase.h" + +void PipelineView::setPipelineModel(GstPipelineModel* model) { + QListView::setModel(model); + pipeline_model_ = model; +} + +QList PipelineView::GetSelectedIds() const { + QList selected; + if (pipeline_model_ != nullptr) { + for (const QModelIndex& index : selectedIndexes()) { + int id = pipeline_model_->GetPipelineId(index); + if (id >= 0) { + selected << id; + } + } + } + return selected; +} diff --git a/src/engines/pipelineview.h b/src/engines/pipelineview.h new file mode 100644 index 000000000..6238cfa08 --- /dev/null +++ b/src/engines/pipelineview.h @@ -0,0 +1,39 @@ +/* This file is part of Clementine. + Copyright 2021, Jim Broadus + + 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 . +*/ + +#ifndef PIPELINEVIEW_H +#define PIPELINEVIEW_H + +#include +#include + +class GstPipelineModel; + +class PipelineView : public QListView { + Q_OBJECT; + + public: + explicit PipelineView(QWidget* parent) : QListView(parent) {} + + void setPipelineModel(GstPipelineModel* model); + QList GetSelectedIds() const; + + private: + GstPipelineModel* pipeline_model_; +}; + +#endif // PIPELINEVIEW_H