Skip to content

Commit

Permalink
Re #6162. Restored component selection in script
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Dec 10, 2012
1 parent defb7fe commit c9eff45
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,22 +628,13 @@ void InstrumentWindow::setViewDirection(const QString& input)
repaint();
}

/** For the scripting API. Selects a omponent in the tree and zooms to it.
/** For the scripting API. Selects a component in the tree and zooms to it.
* @param name The name of the component
* @throw std::invalid_argument If the component name given does not exist in the tree
*/
void InstrumentWindow::selectComponent(const QString & name)
{
// QModelIndex component = m_treeTab->findComponentByName(name);
// if( !component.isValid() )
// {
// throw std::invalid_argument("No component named \'"+name.toStdString()+"\' found");
// }

// mInstrumentTree->clearSelection();
// mInstrumentTree->scrollTo(component, QAbstractItemView::EnsureVisible );
// mInstrumentTree->selectionModel()->select(component, QItemSelectionModel::Select);
// mInstrumentTree->sendComponentSelectedSignal(component);
emit requestSelectComponent(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs
void scaleTypeChanged(int);
void integrationRangeChanged(double,double);
void glOptionChanged(bool);
void requestSelectComponent(const QString&);

protected:
/// Called just before a show event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ InstrumentWindowTab(instrWindow)
layout->addWidget(m_instrumentTree);
connect(m_instrumentTree,SIGNAL(componentSelected(Mantid::Geometry::ComponentID)),
m_instrWindow,SLOT(componentSelected(Mantid::Geometry::ComponentID)));
connect(m_instrWindow,SIGNAL(requestSelectComponent(QString)),this,SLOT(selectComponentByName(QString)));
}

void InstrumentWindowTreeTab::initSurface()
Expand All @@ -23,9 +24,18 @@ void InstrumentWindowTreeTab::initSurface()
* Find an instrument component by its name.
* @param name :: Name of an instrument component.
*/
QModelIndex InstrumentWindowTreeTab::findComponentByName(const QString &name)
void InstrumentWindowTreeTab::selectComponentByName(const QString &name)
{
return QModelIndex();
QModelIndex component = m_instrumentTree->findComponentByName(name);
if( !component.isValid() )
{
throw std::invalid_argument("No component named \'"+name.toStdString()+"\' found");
}

m_instrumentTree->clearSelection();
m_instrumentTree->scrollTo(component, QAbstractItemView::EnsureVisible );
m_instrumentTree->selectionModel()->select(component, QItemSelectionModel::Select);
m_instrumentTree->sendComponentSelectedSignal(component);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class InstrumentWindowTreeTab: public InstrumentWindowTab
public:
InstrumentWindowTreeTab(InstrumentWindow* instrWindow);
void initSurface();
QModelIndex findComponentByName(const QString& name);
public slots:
void selectComponentByName(const QString& name);
private:
void hideEvent(QHideEvent *);
/// Widget to display instrument tree
Expand Down

0 comments on commit c9eff45

Please sign in to comment.