/***************************************************************************
* Copyright (C) 2006 by Lawrence Lee *
* valheru@facticius.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "modelItem.h"
#include "articleModel.h"
#include <QtCore/QDebug>
#include <QtCore/QStringList>
{
QList<QString> rootData;
rootData << "From" << "Subject" << "Date" << "Message-ID" << "References" << "Lines";
rootItem = new ModelItem( rootData );
for ( int i = 0; i < data.count(); i += 6 ){
if( data[ i + 4 ] == "" || data[ i + 4 ].isEmpty() ){
///It has no reference, so we simply add it to the root of the model
ModelItem
*item
= new ModelItem
( QStringList() << data
[ i
] << data
[ i
+ 1 ] << data[ i + 2 ] << data[ i + 3 ]
<< data[ i + 4 ] << data[ i + 5 ], rootItem );
rootItem->appendChild( item );
///Remove it from the list
// for( int x = i; x < i + 6; ++x ){
// const_cast< QStringList& >( data ).removeAt( x );
// }
}
}
int maxReferences = 0;
for ( int i = 0; i < data.count(); i += 6 ){
if( !data[ i + 4 ].isEmpty() ){
if( references.count() > maxReferences ){
maxReferences = references.count();
}
}
}
int iteration = 1;
while( iteration <= maxReferences ){
for( int i = 0; i < data.count(); i += 6 ){
if( !data[ i + 4 ].isEmpty() ){
if( references.count() == iteration ){
for( int p = 0; p < rowCount(); ++p ){
if( references[ 0 ] == rootItem->child( p )->data( 3 ).toString() ){
ModelItem
*item
= new ModelItem
( QStringList() << data
[ i
] << data
[ i
+ 1 ] << data[ i + 2 ] << data[ i + 3 ]
<< data[ i + 4 ] << data[ i + 5 ], rootItem );
rootItem->child( p )->appendChild( item );
for( int t = 0; t < item->columnCount(); ++t ){
qDebug() << item->data( t ).toString();
}
qDebug() << data[ i + 1 ] << "is the child of" << rootItem->child( p )->data( 1 ).toString();
qDebug() << "because reference" << references[ 0 ] << "in child refers to parents Message-ID"
<< rootItem->child( p )->data( 3 ).toString() << "\r\n";
}
}
}
}
}
++iteration;
}
}
ArticleModel::~ArticleModel()
{
delete rootItem;
}
{
ModelItem * parentItem;
if ( !parent.isValid() )
parentItem = rootItem;
else
parentItem = static_cast<ModelItem*>( parent.internalPointer() );
ModelItem *childItem = parentItem->child( row );
if ( childItem )
return createIndex( row, column, childItem );
else
}
{
if ( !index.isValid() )
ModelItem *childItem = static_cast<ModelItem*>( index.internalPointer() );
ModelItem *parentItem = childItem->parent();
if ( parentItem == rootItem )
return createIndex( parentItem->row(), 0, parentItem );
}
int ArticleModel
::rowCount( const QModelIndex &parent
) const {
ModelItem * parentItem;
if ( !parent.isValid() )
parentItem = rootItem;
else
parentItem = static_cast<ModelItem*>( parent.internalPointer() );
return parentItem->childCount();
}
int ArticleModel
::columnCount( const QModelIndex &parent
) const {
if ( parent.isValid() )
return static_cast<ModelItem*>( parent.internalPointer() ) ->columnCount();
else
return rootItem->columnCount();
}
{
if ( !index.isValid() )
if ( role != Qt::DisplayRole )
ModelItem *item = static_cast<ModelItem*>( index.internalPointer() );
return item->data( index.column() );
}
Qt
::ItemFlags ArticleModel
::flags( const QModelIndex &index
) const{
if ( !index.isValid() )
return Qt::ItemIsEnabled;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant ArticleModel
::headerData( int section, Qt
::Orientation orientation,
int role
) const {
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
return rootItem->data( section );
}
Bookmarks