mirror of https://github.com/vitalif/grive2
fixing the problems with multiple parent
parent
94d66f0d30
commit
93fe68ce4c
|
@ -70,7 +70,6 @@ int DriveModel::columnCount( 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 ;
|
||||
}
|
||||
|
||||
|
@ -93,14 +92,19 @@ QModelIndex DriveModel::parent( const QModelIndex& idx ) const
|
|||
if ( res == m_drv.Root() )
|
||||
return QModelIndex() ;
|
||||
|
||||
qDebug() << "getting parent of " << res->Title().c_str() ;
|
||||
|
||||
// if my parent is root, return model index of root (i.e. QModelIndex())
|
||||
const Resource *parent = m_drv.Parent(res) ;
|
||||
|
||||
if ( parent == 0 || parent == m_drv.Root() || idx.column() != 0 )
|
||||
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
|
||||
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
|
||||
|
|
|
@ -60,11 +60,15 @@ void Drive::Refresh( http::Agent *agent )
|
|||
{
|
||||
std::vector<std::string> 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 ;
|
||||
parent_child.push_back( std::make_pair( *p, r ) ) ;
|
||||
// std::cout << "parent = " << *p << std::endl ;
|
||||
// parent_child.push_back( std::make_pair( *p, r ) ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,12 +78,15 @@ void Drive::Refresh( http::Agent *agent )
|
|||
i != parent_child.end() ; ++i )
|
||||
{
|
||||
Resource *parent = Find( i->first ), *child = i->second ;
|
||||
std::cout << i->first << " " << child->ID() << std::endl ;
|
||||
assert( child != 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() ) ;
|
||||
child->SetParent( parent->ID() ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue