104 int index = mItemList.indexOf( aItem ); |
111 int index = mItemList.indexOf( aItem ); |
105 if ( index >= 0 ) |
112 if ( index >= 0 ) |
106 { |
113 { |
107 beginRemoveRows( aIndex.parent(), index, index ); |
114 beginRemoveRows( aIndex.parent(), index, index ); |
108 // remove item from item list |
115 // remove item from item list |
109 int count = mItemList.count(); |
|
110 CntEditViewItem* item = mItemList.takeAt( index ); |
116 CntEditViewItem* item = mItemList.takeAt( index ); |
111 count = mItemList.count(); |
|
112 |
117 |
113 // get detailed information |
118 // get detailed information |
114 QContactDetail detail = item->data(ERoleContactDetail).value<QContactDetail>(); |
119 QContactDetail detail = item->data(ERoleContactDetail).value<QContactDetail>(); |
115 QStringList fields = item->data(ERoleContactDetailFields).toStringList(); |
120 QStringList fields = item->data(ERoleContactDetailFields).toStringList(); |
116 |
121 |
119 |
124 |
120 // Update lookup table. Note, in case of QContactAddress, |
125 // Update lookup table. Note, in case of QContactAddress, |
121 // we can't remove address template, so the mapping for address always points to address detail |
126 // we can't remove address template, so the mapping for address always points to address detail |
122 KLookupKey lookupKey = mLookupMap.value( detail.definitionName() ); |
127 KLookupKey lookupKey = mLookupMap.value( detail.definitionName() ); |
123 removeItem( lookupKey ); |
128 removeItem( lookupKey ); |
|
129 |
|
130 delete item; |
|
131 |
124 endRemoveRows(); |
132 endRemoveRows(); |
125 |
133 |
126 // Remove separator item if needed |
134 // Remove separator item if needed |
127 if (mItemList.last()->data( Hb::ItemTypeRole ) == QVariant(Hb::SeparatorItem)) |
135 if (mItemList.last()->data( Hb::ItemTypeRole ) == QVariant(Hb::SeparatorItem)) |
128 { |
136 { |
129 int separatorIndex = mItemList.indexOf( mSeparator ); |
137 int separatorIndex = mItemList.indexOf( mSeparator ); |
130 beginRemoveRows( aIndex.parent(), separatorIndex, separatorIndex ); |
138 beginRemoveRows( aIndex.parent(), separatorIndex, separatorIndex ); |
131 mItemList.removeAt( mItemList.indexOf(mSeparator) ); |
139 mItemList.removeAt( separatorIndex ); |
132 removeItem( ESeparator ); |
140 removeItem( ESeparator ); |
|
141 |
|
142 delete mSeparator; |
|
143 mSeparator = NULL; |
|
144 |
133 endRemoveRows(); |
145 endRemoveRows(); |
134 } |
146 } |
135 |
|
136 |
147 |
137 // Check if the removed item is -1 in lookuptable and if it needs a template |
148 // Check if the removed item is -1 in lookuptable and if it needs a template |
138 int lookupValue = mLookupTable.value( lookupKey ); |
149 int lookupValue = mLookupTable.value( lookupKey ); |
139 if ( lookupValue == -1 ) |
150 if ( lookupValue == -1 ) |
140 { |
151 { |
141 beginResetModel(); |
|
142 |
|
143 if ( detail.definitionName() == QContactPhoneNumber::DefinitionName ) |
152 if ( detail.definitionName() == QContactPhoneNumber::DefinitionName ) |
|
153 { |
|
154 beginInsertRows(aIndex.parent(), index, index); |
144 insertItem( EPhonenumber, mBuilder->phoneNumberItems(*mContact) ); |
155 insertItem( EPhonenumber, mBuilder->phoneNumberItems(*mContact) ); |
145 |
156 endInsertRows(); |
|
157 } |
146 else if ( detail.definitionName() == QContactEmailAddress::DefinitionName ) |
158 else if ( detail.definitionName() == QContactEmailAddress::DefinitionName ) |
|
159 { |
|
160 beginInsertRows(aIndex.parent(), index, index); |
147 insertItem( EEmailAddress, mBuilder->emailAddressItems(*mContact) ); |
161 insertItem( EEmailAddress, mBuilder->emailAddressItems(*mContact) ); |
148 |
162 endInsertRows(); |
|
163 } |
149 else if ( detail.definitionName() == QContactAddress::DefinitionName ) |
164 else if ( detail.definitionName() == QContactAddress::DefinitionName ) |
|
165 { |
|
166 // special case: unlike the others, address template isn't in the same index as the last deleted detail |
|
167 int emailIndex = mLookupTable.value( EEmailAddress ); |
|
168 beginInsertRows(aIndex.parent(), emailIndex + 1, emailIndex + 1); |
150 insertItem( EAddressTemplate, mBuilder->addressItems(*mContact) ); |
169 insertItem( EAddressTemplate, mBuilder->addressItems(*mContact) ); |
151 |
170 endInsertRows(); |
|
171 } |
152 else if ( detail.definitionName() == QContactUrl::DefinitionName ) |
172 else if ( detail.definitionName() == QContactUrl::DefinitionName ) |
|
173 { |
|
174 beginInsertRows(aIndex.parent(), index, index); |
153 insertItem( EUrl, mBuilder->urlItems(*mContact) ); |
175 insertItem( EUrl, mBuilder->urlItems(*mContact) ); |
154 |
176 endInsertRows(); |
155 endResetModel(); |
177 } |
156 } |
178 } |
157 delete item; |
|
158 } |
179 } |
159 } |
180 } |
160 |
181 |
161 void CntEditViewListModel::refreshExtensionItems() |
182 void CntEditViewListModel::refreshExtensionItems() |
162 { |
183 { |