C++: How to select an object in the pipeline browser


this is likely very simple but I’ve decided to ask here after not being able to solve it. What I want to do is to mark an object in the pipeline browser as selected, given its pqPipelineSource pointer. I’m working inside the pqOpenVRControls class, where the reverse example of getting a pqPipelineSource* based on selection already exists.

My approach looks somewhat like this:

QItemSelectionModel* smodel = this->Internals->pipelineBrowser->getSelectionModel();
QModelIndex index = smodel->model()->index(0,0); //Tried a lot of stuff here
const pqPipelineModel* model = this->Internals->pipelineBrowser->getPipelineModel(index);
QModelIndex selindex = model->getIndexFor(source); // source being the provided pqPipelineSource*
smodel->select(selindex, QItemSelectionModel::SelectionFlag::Select);

A common error I get is that I’m using a QModelIndex from a different model, but I’m not sure how to solve this.

Thank you in advance.


You could just set you source as the active source (pqActiveObjects::instance().setActiveSource(pqsource));) and the pipeline widget will automatically set it as the active/selected pipeline source.