phonebookui/pbkcommonui/src/cntnoteeditormodel.cpp
changeset 31 2a11b5b00470
parent 27 de1630741fbe
child 40 b46a585f6909
equal deleted inserted replaced
27:de1630741fbe 31:2a11b5b00470
    19 #include <qcontactnote.h>
    19 #include <qcontactnote.h>
    20 
    20 
    21 CntNoteEditorModel::CntNoteEditorModel( QContact* aContact ) :
    21 CntNoteEditorModel::CntNoteEditorModel( QContact* aContact ) :
    22 CntDetailEditorModel( aContact )
    22 CntDetailEditorModel( aContact )
    23     {
    23     {
    24     QList<QContactNote> noteList = mContact->details<QContactNote>();
       
    25     if ( noteList.isEmpty() )
       
    26         {
       
    27         QContactNote emptyNote;
       
    28         noteList.append( emptyNote );
       
    29         }
       
    30     
       
    31     HbDataFormModelItem* root = invisibleRootItem();
    24     HbDataFormModelItem* root = invisibleRootItem();
    32     foreach ( QContactNote note, noteList )
    25     foreach ( QContactNote note, mContact->details<QContactNote>() )
    33         {
    26         {
    34         CntDetailModelItem* item = new CntDetailModelItem(note);
    27         CntDetailModelItem* item = new CntDetailModelItem(note);
    35         appendDataFormItem( item, root );
    28         appendDataFormItem( item, root );
    36         }
    29         }
    37     }
    30     }
    51     HbDataFormModelItem* root = invisibleRootItem();
    44     HbDataFormModelItem* root = invisibleRootItem();
    52       
    45       
    53     int count( root->childCount() );
    46     int count( root->childCount() );
    54     for ( int i(0); i < count; i++ ) {
    47     for ( int i(0); i < count; i++ ) {
    55         CntDetailModelItem* detail = static_cast<CntDetailModelItem*>( root->childAt(i) );
    48         CntDetailModelItem* detail = static_cast<CntDetailModelItem*>( root->childAt(i) );
    56         QContactNote note = detail->detail();
    49         QContactDetail note = detail->detail();
    57         if ( note.note().length() > 0 ) {
    50         mContact->saveDetail( &note );
    58             mContact->saveDetail( &note );
    51         
       
    52         if ( note.value(QContactNote::FieldNote).isEmpty() )
       
    53         {
       
    54             mContact->removeDetail( &note );
    59         }
    55         }
    60     }
    56     }
    61 }
    57 }
    62 // End of File
    58 // End of File