Skip to content

Commit

Permalink
Add zooming to the named component when selecting a component
Browse files Browse the repository at this point in the history
from python. Re #3784.
  • Loading branch information
RussellTaylor committed Jan 13, 2012
1 parent eadd04b commit 2a7e2ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InstrumentTreeWidget:public QTreeView
void getSelectedBoundingBox(const QModelIndex& index,double &xmax, double &ymax, double &zmax, double &xmin, double &ymin, double &zmin);
//Mantid::Kernel::V3D getSamplePos()const;
QModelIndex findComponentByName(const QString & name) const;
protected slots:
public slots:
void sendComponentSelectedSignal(const QModelIndex);
signals:
void componentSelected(const Mantid::Geometry::ComponentID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include <numeric>
#include <fstream>
#include <stdexcept>

using namespace Mantid::API;
using namespace Mantid::Geometry;
Expand Down Expand Up @@ -590,16 +591,22 @@ void InstrumentWindow::setViewDirection(const QString& input)
repaint();
}

/**
* For the scripting API
/** For the scripting API. Selects a omponent 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 = mInstrumentTree->findComponentByName(name);
if( !component.isValid() ) return;
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);
}

/**
Expand Down

0 comments on commit 2a7e2ca

Please sign in to comment.