// FIXME: this should actually be a member function of ContentIndex
 int contentIndexUp( KMime::ContentIndex &index )
 {
   Q_ASSERT( index.isValid() );
   QStringList ids = index.toString().split( QLatin1Char('.') );
   QString lastId = ids.takeLast();
   index = KMime::ContentIndex( ids.join( QLatin1String(".") ) );
   return lastId.toInt();
 }
QModelIndex MimeTreeModel::parent(const QModelIndex & index) const
{
  if ( !index.isValid() )
    return QModelIndex();
  KMime::Content *currentContent = static_cast<KMime::Content*>( index.internalPointer() );
  if ( !currentContent )
    return QModelIndex();

  KMime::ContentIndex currentIndex = d->root->indexForContent( currentContent );
  if ( !currentIndex.isValid() )
    return QModelIndex();
  d->contentIndexUp( currentIndex );
  KMime::Content *parentContent = d->root->content( currentIndex );
  int row = 0;
  if ( currentIndex.isValid() )
    row = d->contentIndexUp( currentIndex ) - 1; // 1 based -> 0 based

  return createIndex( row, 0, parentContent );
}
Esempio n. 3
0
void ContentIndexTest::testToString()
{
  KMime::ContentIndex ci;
  QCOMPARE( ci.toString(), QString() );
  ci.push( 1 );
  QCOMPARE( ci.toString(), QString( "1" ) );
  ci.push( 2 );
  QCOMPARE( ci.toString(), QString( "2.1" ) );
}