logsui/logscntfinder/tsrc/lcfprotoui/src/lcfmodel.cpp
changeset 0 4a5361db8937
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "lcfmodel.h"
       
    19 #include "logslogger.h"
       
    20 #include "logscntfinder.h"
       
    21 #include <QStringList>
       
    22 
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 LcfModel::LcfModel(LogsCntFinder& finder ) 
       
    29     : QAbstractListModel(),
       
    30       mFinder( finder ),
       
    31       mEnabled( true )
       
    32 {
       
    33     LOGS_QDEBUG( "logs [LCFPROTO] -> LcfModel::LcfModel()" )
       
    34     LOGS_QDEBUG( "logs [LCFPROTO] <- LcfModel::LcfModel()" )
       
    35 }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 LcfModel::~LcfModel()
       
    42 {
       
    43     LOGS_QDEBUG( "logs [LCFPROTO] -> LcfModel::~LcfModel()" )
       
    44     LOGS_QDEBUG( "logs [LCFPROTO] <- LcfModel::~LcfModel()" )
       
    45 }
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // From QAbstractListModel
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 int LcfModel::rowCount(const QModelIndex & /* parent */) const
       
    53 {
       
    54     if (!mEnabled) {
       
    55         return 0;
       
    56     }
       
    57     int count = mFinder.resultsCount();
       
    58     LOGS_QDEBUG_2( "logs [LCFPROTO] <-> rowCount()=", count )
       
    59     return count;
       
    60 }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // From QAbstractItemModel
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 QVariant LcfModel::data(const QModelIndex &index, int role ) const
       
    68 {
       
    69     LOGS_QDEBUG_2( "logs [LCFPROTO] <-> row()=", index.row() )
       
    70     const QChar separ( ' ');
       
    71     
       
    72     if (!mEnabled) {
       
    73         return QVariant();
       
    74     }
       
    75     
       
    76     int resultCount = mFinder.resultsCount();
       
    77     if (!index.isValid() || 
       
    78          index.row() >= resultCount || 
       
    79          index.row() < 0 ) {
       
    80         return QVariant();
       
    81     }
       
    82     if (role == Qt::DisplayRole ){
       
    83         const LogsCntEntry& result = mFinder.resultAt( index.row() );
       
    84         QStringList name;
       
    85         for( int i=0;i<result.firstName().count();i++) {
       
    86             name << result.firstName()[i].richText();
       
    87         }        
       
    88         for( int i=0;i<result.lastName().count();i++) {
       
    89             name << result.lastName()[i].richText();
       
    90         }
       
    91         
       
    92         if ( result.phoneNumber().text().isEmpty() ) {
       
    93             return QVariant(name.join( separ ) );
       
    94         } else {
       
    95             QStringList all( name.join( separ ) );
       
    96             all.append( result.phoneNumber().richText() );
       
    97             return QVariant( all );
       
    98         }
       
    99         
       
   100     } else {
       
   101         return QVariant();
       
   102     }
       
   103     
       
   104 }
       
   105