From 93fe68ce4c225179111daa8b88218636f64595bf Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Mon, 29 Apr 2013 22:14:05 +0800 Subject: [PATCH] fixing the problems with multiple parent --- bgrive/src/DriveModel.cc | 10 +++++++--- libgrive/src/drive2/Drive.cc | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bgrive/src/DriveModel.cc b/bgrive/src/DriveModel.cc index c58f757..65b8090 100644 --- a/bgrive/src/DriveModel.cc +++ b/bgrive/src/DriveModel.cc @@ -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(grand) ) ; + return createIndex( grand->Index(parent->ID()), 0, const_cast(parent) ) ; } } // end of namespace diff --git a/libgrive/src/drive2/Drive.cc b/libgrive/src/drive2/Drive.cc index 97e9ad5..945c78a 100644 --- a/libgrive/src/drive2/Drive.cc +++ b/libgrive/src/drive2/Drive.cc @@ -60,11 +60,15 @@ void Drive::Refresh( http::Agent *agent ) { std::vector pids ; parents.Select( "id", std::back_inserter(pids) ) ; - - for ( std::vector::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::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() ) ; } } }