Commit 65edc1e3 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD #61] drag and drop now also re-sorts ROIs internally to ensure correct...

[ADD #61] drag and drop now also re-sorts ROIs internally to ensure correct saving order in project files.
parent 9f85fa8b
...@@ -90,7 +90,7 @@ void WRMBranch::addRoi( osg::ref_ptr< WROI > roi ) ...@@ -90,7 +90,7 @@ void WRMBranch::addRoi( osg::ref_ptr< WROI > roi )
bool WRMBranch::contains( osg::ref_ptr< WROI > roi ) bool WRMBranch::contains( osg::ref_ptr< WROI > roi )
{ {
for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{ {
if( ( *iter ) == roi ) if( ( *iter ) == roi )
{ {
...@@ -103,7 +103,7 @@ bool WRMBranch::contains( osg::ref_ptr< WROI > roi ) ...@@ -103,7 +103,7 @@ bool WRMBranch::contains( osg::ref_ptr< WROI > roi )
void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi ) void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi )
{ {
roi->removeROIChangeNotifier( m_changeRoiSignal ); roi->removeROIChangeNotifier( m_changeRoiSignal );
for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{ {
if( ( *iter ) == roi ) if( ( *iter ) == roi )
{ {
...@@ -116,7 +116,7 @@ void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi ) ...@@ -116,7 +116,7 @@ void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi )
void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT
{ {
for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{ {
roiVec.push_back( ( *iter ) ); roiVec.push_back( ( *iter ) );
} }
...@@ -125,7 +125,7 @@ void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT ...@@ -125,7 +125,7 @@ void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT
WROIManager::ROIs WRMBranch::getRois() const WROIManager::ROIs WRMBranch::getRois() const
{ {
WROIManager::ROIs ret; WROIManager::ROIs ret;
for( std::list< osg::ref_ptr< WROI > >::const_iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) for( std::vector< osg::ref_ptr< WROI > >::const_iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{ {
ret.push_back( ( *iter ) ); ret.push_back( ( *iter ) );
} }
...@@ -134,7 +134,7 @@ WROIManager::ROIs WRMBranch::getRois() const ...@@ -134,7 +134,7 @@ WROIManager::ROIs WRMBranch::getRois() const
void WRMBranch::removeAllRois() void WRMBranch::removeAllRois()
{ {
for( std::list< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter ) for( std::vector< osg::ref_ptr< WROI > >::iterator iter = m_rois.begin(); iter != m_rois.end(); ++iter )
{ {
WGraphicsEngine::getGraphicsEngine()->getScene()->remove( ( *iter ) ); WGraphicsEngine::getGraphicsEngine()->getScene()->remove( ( *iter ) );
} }
......
...@@ -193,6 +193,16 @@ public: ...@@ -193,6 +193,16 @@ public:
*/ */
void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier ); void removeChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
/**
* Resorts the ROIs using the specified comparator from its begin to its end.
*
* \tparam Comparator the comparator type. Usually a boost::function or class providing the operator<().
*
* \param comp the comparator
*/
template < typename Comparator >
void sort( Comparator comp );
protected: protected:
/** /**
* initializes properties * initializes properties
...@@ -207,8 +217,8 @@ protected: ...@@ -207,8 +217,8 @@ protected:
private: private:
boost::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager boost::shared_ptr< WROIManager > m_roiManager; //!< stores a pointer to the roi manager
std::list< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch, std::vector< osg::ref_ptr< WROI > > m_rois; //!< list of rois in this this branch,
// first in the list is the master roi // first in the list is the master roi
/** /**
* the property object for the module * the property object for the module
*/ */
...@@ -263,4 +273,12 @@ inline bool WRMBranch::isNot() ...@@ -263,4 +273,12 @@ inline bool WRMBranch::isNot()
{ {
return m_isNot->get(); return m_isNot->get();
} }
template < typename Comparator >
void WRMBranch::sort( Comparator comp )
{
// NOTE: technically, we need not setDirty here as the order of the ROIs has no influence
return std::sort( m_rois.begin(), m_rois.end(), comp );
}
#endif // WRMBRANCH_H #endif // WRMBRANCH_H
...@@ -143,7 +143,44 @@ QWidget* WQtBranchTreeItem::getWidget() const ...@@ -143,7 +143,44 @@ QWidget* WQtBranchTreeItem::getWidget() const
return m_itemWidget; return m_itemWidget;
} }
class RoiSort
{
public:
RoiSort( std::map< WROI::RefPtr, int > indexMap ):
m_indexMap( indexMap )
{
}
/**
* Operator to compare the order of two ROIs
*
* \param a first ROI
* \param b second ROI
*
* \return true if first is in front of second
*/
bool operator()( WROI::RefPtr a, WROI::RefPtr b )
{
return ( m_indexMap[ a ] < m_indexMap[ b ] );
}
private:
/**
* Map needed to know the index in the GUI representation
*/
std::map< WROI::RefPtr, int > m_indexMap;
};
void WQtBranchTreeItem::updateRoiManagerSorting() void WQtBranchTreeItem::updateRoiManagerSorting()
{ {
wlog::error( "WQtBranchTreeItem" )<< "resort not yet implemented"; std::map< WROI::RefPtr, int > indexMap;
// build an index map for each roi to its item
for( int i = 0; i < childCount(); ++i )
{
WQtRoiTreeItem* rti = dynamic_cast< WQtRoiTreeItem* >( child( i ) );
WAssert( rti, "All children of a branch item need to be ROI items." );
indexMap[ rti->getRoi() ] = i;
}
// this map now allows to start a comparator
m_branch->sort( RoiSort( indexMap ) );
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment