199 |
199 |
200 if(mBufferPosition < 0 ){ |
200 if(mBufferPosition < 0 ){ |
201 mBufferPosition = 0; |
201 mBufferPosition = 0; |
202 } |
202 } |
203 |
203 |
204 //request new Buffer |
204 if (mBufferPosition>1){ |
205 mRequestStart = mBufferPosition; |
205 mObserver->release(0, mBufferPosition-1); |
206 mRequestCount = mBufferSize; |
206 } |
207 mResetOrdered = true; |
207 |
208 calculate(); |
208 mObserver->request( mBufferPosition, |
209 } |
209 mBufferPosition + mBufferSize -1 ); |
210 |
210 |
211 void HgBufferManager::itemCountChanged( int aIndex, |
211 if (mBufferPosition + mBufferSize < mTotalCount){ |
212 bool aRemoved, |
212 mObserver->release(mBufferPosition + mBufferSize, mTotalCount); |
213 int aNewTotalCount ) |
213 } |
214 { |
214 |
215 Q_UNUSED(aIndex); |
215 mDiff = 0; |
216 Q_UNUSED(aRemoved); |
216 mResetOrdered = false; |
217 //release all, to make sure that no old items are skipped |
217 mRequestStart = 0; |
218 mObserver->release(0, aNewTotalCount); |
218 mRequestCount = 0; |
219 resetBuffer(mBufferPosition + (mBufferSize / 2), aNewTotalCount); |
219 mReleaseStart = 0; |
220 } |
220 mReleaseCount = 0; |
|
221 |
|
222 } |
|
223 |
|
224 void HgBufferManager::aboutToRemoveItem(int pos) |
|
225 { |
|
226 if(pos < 0 || pos >= mTotalCount ){ |
|
227 return; |
|
228 } |
|
229 |
|
230 if ( pos >= mBufferPosition && pos < mBufferPosition + mBufferSize ){ |
|
231 mObserver->release(pos, pos); |
|
232 } |
|
233 } |
|
234 |
|
235 void HgBufferManager::removedItem(int pos) |
|
236 { |
|
237 if(pos < 0 || pos >= mTotalCount ){ |
|
238 return; |
|
239 } |
|
240 |
|
241 mTotalCount--; |
|
242 if( mTotalCount >= mBufferSize ){ |
|
243 if (pos < mBufferPosition){ //before buffer pos is >=0 |
|
244 mBufferPosition--; |
|
245 } else if (pos >= mBufferPosition && pos < mBufferPosition + mBufferSize){ |
|
246 if( mBufferPosition + mBufferSize <= mTotalCount ){ |
|
247 // Requested from the end |
|
248 mObserver->request( mBufferPosition + mBufferSize - 1, |
|
249 mBufferPosition + mBufferSize - 1 ); |
|
250 }else if( mBufferPosition > 0 ){ |
|
251 // Move buffer and request from the beginning |
|
252 mBufferPosition--; |
|
253 mObserver->request( mBufferPosition, |
|
254 mBufferPosition ); |
|
255 } |
|
256 } |
|
257 } |
|
258 } |
|
259 |
|
260 void HgBufferManager::aboutToInsertItem(int pos) |
|
261 { |
|
262 if(pos < 0 || pos > mTotalCount ){ |
|
263 return; |
|
264 } |
|
265 |
|
266 if ( pos >= mBufferPosition && pos < mBufferPosition + mBufferSize ){ |
|
267 if( mBufferPosition + mBufferSize < mTotalCount ){ |
|
268 // Release from the end of the buffer |
|
269 mObserver->release(mBufferPosition + mBufferSize - 1, mBufferPosition + mBufferSize - 1); |
|
270 } |
|
271 } |
|
272 } |
|
273 |
|
274 void HgBufferManager::insertedItem(int pos) |
|
275 { |
|
276 if(pos < 0 || pos > mTotalCount ){ |
|
277 return; |
|
278 } |
|
279 |
|
280 mTotalCount++; |
|
281 if ( pos >= mBufferPosition && pos < mBufferPosition + mBufferSize ){ |
|
282 mObserver->request(pos, pos); |
|
283 }else if (pos<mBufferPosition){ //if we have inserted item before buffer, we should move buffer. |
|
284 mBufferPosition++; |
|
285 } |
|
286 } |
|
287 |
221 //eof |
288 //eof |