fixing the problems with multiple parent

pull/40/head
Nestal Wan 2013-04-29 22:14:05 +08:00
parent 94d66f0d30
commit 93fe68ce4c
2 changed files with 21 additions and 10 deletions

View File

@ -70,7 +70,6 @@ int DriveModel::columnCount( const QModelIndex& parent ) const
bool DriveModel::hasChildren( const QModelIndex& parent ) const bool DriveModel::hasChildren( const QModelIndex& parent ) const
{ {
qDebug() << Res(parent)->Title().c_str() << " has " << Res(parent)->ChildCount() << " children" ;
return Res(parent)->ChildCount() > 0 ; return Res(parent)->ChildCount() > 0 ;
} }
@ -93,14 +92,19 @@ QModelIndex DriveModel::parent( const QModelIndex& idx ) const
if ( res == m_drv.Root() ) if ( res == m_drv.Root() )
return QModelIndex() ; return QModelIndex() ;
qDebug() << "getting parent of " << res->Title().c_str() ;
// if my parent is root, return model index of root (i.e. QModelIndex()) // if my parent is root, return model index of root (i.e. QModelIndex())
const Resource *parent = m_drv.Parent(res) ; const Resource *parent = m_drv.Parent(res) ;
if ( parent == 0 || parent == m_drv.Root() || idx.column() != 0 ) if ( parent == 0 || parent == m_drv.Root() || idx.column() != 0 )
return QModelIndex() ; return QModelIndex() ;
qDebug() << "parent of " << res->Title().c_str() << " should be " << parent->Title().c_str();
// check grand-parent to know the row() of my parent // check grand-parent to know the row() of my parent
const Resource *grand = m_drv.Parent(parent) ; const Resource *grand = m_drv.Parent(parent) ;
return createIndex( grand->Index(parent->ID()), 0, const_cast<Resource*>(grand) ) ; return createIndex( grand->Index(parent->ID()), 0, const_cast<Resource*>(parent) ) ;
} }
} // end of namespace } // end of namespace

View File

@ -60,11 +60,15 @@ void Drive::Refresh( http::Agent *agent )
{ {
std::vector<std::string> pids ; std::vector<std::string> pids ;
parents.Select<std::string>( "id", std::back_inserter(pids) ) ; parents.Select<std::string>( "id", std::back_inserter(pids) ) ;
for ( std::vector<std::string>::iterator p = pids.begin() ; p != pids.end() ; ++p ) // onlly the first parent counts
if ( !pids.empty() )
parent_child.push_back( std::make_pair( pids.front(), r ) ) ;
// for ( std::vector<std::string>::iterator p = pids.begin() ; p != pids.end() ; ++p )
{ {
std::cout << "parent = " << *p << std::endl ; // std::cout << "parent = " << *p << std::endl ;
parent_child.push_back( std::make_pair( *p, r ) ) ; // parent_child.push_back( std::make_pair( *p, r ) ) ;
} }
} }
} }
@ -74,12 +78,15 @@ void Drive::Refresh( http::Agent *agent )
i != parent_child.end() ; ++i ) i != parent_child.end() ; ++i )
{ {
Resource *parent = Find( i->first ), *child = i->second ; Resource *parent = Find( i->first ), *child = i->second ;
std::cout << i->first << " " << child->ID() << std::endl ; assert( child != 0 ) ;
if ( parent != 0 ) if ( parent != 0 )
{ {
// initialize parent IDs std::cout << "parent of " << child->Title() << " is " << parent->Title() << std::endl ;
// initialize parent IDs
parent->AddChild( child->ID() ) ; parent->AddChild( child->ID() ) ;
child->SetParent( parent->ID() ) ;
} }
} }
} }