/***************************************************************************
* 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"<< "Lines";
rootItem = new ModelItem( rootData );
for ( int i = 0; i < data.count(); i += 5 ) {
ModelItem
*item
= new ModelItem
( QStringList() << data
[ i
] << data
[ i
+ 1 ] << data
[ i
+ 2 ] << data
[ i
+ 3 ] << data
[ i
+ 4 ], rootItem
);
rootItem->appendChild( item );
}
}
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 );
}
/***************************************************************************
* 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>
ArticleModel::ArticleModel( const QStringList &data, QObject *parent ) : QAbstractItemModel( parent )
{
QList<QString> rootData;
rootData << "From" << "Subject" << "Date" << "Message-ID"<< "Lines";
rootItem = new ModelItem( rootData );
for ( int i = 0; i < data.count(); i += 5 ) {
ModelItem *item = new ModelItem( QStringList() << data[ i ] << data[ i + 1 ] << data[ i + 2 ] << data[ i + 3 ] << data[ i + 4 ], rootItem );
rootItem->appendChild( item );
}
}
ArticleModel::~ArticleModel()
{
delete rootItem;
}
QModelIndex ArticleModel::index( int row, int column, const QModelIndex &parent ) const
{
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
return QModelIndex();
}
QModelIndex ArticleModel::parent( const QModelIndex &index ) const
{
if ( !index.isValid() )
return QModelIndex();
ModelItem *childItem = static_cast<ModelItem*>( index.internalPointer() );
ModelItem *parentItem = childItem->parent();
if ( parentItem == rootItem )
return QModelIndex();
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();
}
QVariant ArticleModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() )
return QVariant();
if ( role != Qt::DisplayRole )
return QVariant();
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 );
return QVariant();
}
To copy to clipboard, switch view to plain text mode
Bookmarks