Changeset View
Changeset View
Standalone View
Standalone View
src/KChart/KChartModelDataCache_p.h
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Line(s) | 198 | const T value = data.isNull() ? ModelDataCachePrivate::nan< T >() | |||
---|---|---|---|---|---|
199 | : ( data.value< T >() ); | 199 | : ( data.value< T >() ); | ||
200 | 200 | | |||
201 | m_data[ row ][ column ] = value; | 201 | m_data[ row ][ column ] = value; | ||
202 | m_cacheValid[ row ][ column ] = true; | 202 | m_cacheValid[ row ][ column ] = true; | ||
203 | 203 | | |||
204 | return value; | 204 | return value; | ||
205 | } | 205 | } | ||
206 | 206 | | |||
207 | void columnsInserted( const QModelIndex& parent, int start, int end ) Q_DECL_OVERRIDE | 207 | void columnsInserted( const QModelIndex& parent, int start, int end ) override | ||
208 | { | 208 | { | ||
209 | Q_ASSERT( m_model != nullptr ); | 209 | Q_ASSERT( m_model != nullptr ); | ||
210 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | 210 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | ||
211 | 211 | | |||
212 | if ( parent != m_rootIndex ) | 212 | if ( parent != m_rootIndex ) | ||
213 | return; | 213 | return; | ||
214 | 214 | | |||
215 | Q_ASSERT( start <= end ); | 215 | Q_ASSERT( start <= end ); | ||
216 | Q_ASSERT( start <= m_model->columnCount(m_rootIndex) ); | 216 | Q_ASSERT( start <= m_model->columnCount(m_rootIndex) ); | ||
217 | 217 | | |||
218 | const int rowCount = m_data.count(); | 218 | const int rowCount = m_data.count(); | ||
219 | for ( int row = 0; row < rowCount; ++row ) | 219 | for ( int row = 0; row < rowCount; ++row ) | ||
220 | { | 220 | { | ||
221 | m_data[ row ].insert( start, end - start + 1, T() ); | 221 | m_data[ row ].insert( start, end - start + 1, T() ); | ||
222 | m_cacheValid[ row ].insert( start, end - start + 1, false ); | 222 | m_cacheValid[ row ].insert( start, end - start + 1, false ); | ||
223 | Q_ASSERT( m_data.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | 223 | Q_ASSERT( m_data.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | ||
224 | Q_ASSERT( m_cacheValid.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | 224 | Q_ASSERT( m_cacheValid.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | ||
225 | } | 225 | } | ||
226 | } | 226 | } | ||
227 | 227 | | |||
228 | void columnsRemoved( const QModelIndex& parent, int start, int end ) Q_DECL_OVERRIDE | 228 | void columnsRemoved( const QModelIndex& parent, int start, int end ) override | ||
229 | { | 229 | { | ||
230 | Q_ASSERT( m_model != nullptr ); | 230 | Q_ASSERT( m_model != nullptr ); | ||
231 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | 231 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | ||
232 | 232 | | |||
233 | if ( parent != m_rootIndex ) | 233 | if ( parent != m_rootIndex ) | ||
234 | return; | 234 | return; | ||
235 | 235 | | |||
236 | Q_ASSERT( start <= end ); | 236 | Q_ASSERT( start <= end ); | ||
237 | 237 | | |||
238 | const int rowCount = m_data.count(); | 238 | const int rowCount = m_data.count(); | ||
239 | for ( int row = 0; row < rowCount; ++row ) | 239 | for ( int row = 0; row < rowCount; ++row ) | ||
240 | { | 240 | { | ||
241 | m_data[ row ].remove( start, end - start + 1 ); | 241 | m_data[ row ].remove( start, end - start + 1 ); | ||
242 | m_cacheValid[ row ].remove( start, end - start + 1 ); | 242 | m_cacheValid[ row ].remove( start, end - start + 1 ); | ||
243 | Q_ASSERT( m_data.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | 243 | Q_ASSERT( m_data.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | ||
244 | Q_ASSERT( m_cacheValid.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | 244 | Q_ASSERT( m_cacheValid.at( row ).count() == m_model->columnCount( m_rootIndex ) ); | ||
245 | } | 245 | } | ||
246 | } | 246 | } | ||
247 | 247 | | |||
248 | void dataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight ) Q_DECL_OVERRIDE | 248 | void dataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight ) override | ||
249 | { | 249 | { | ||
250 | if ( !m_model ) | 250 | if ( !m_model ) | ||
251 | return; | 251 | return; | ||
252 | Q_ASSERT( m_model != nullptr ); | 252 | Q_ASSERT( m_model != nullptr ); | ||
253 | Q_ASSERT( topLeft.parent() == bottomRight.parent() ); | 253 | Q_ASSERT( topLeft.parent() == bottomRight.parent() ); | ||
254 | 254 | | |||
255 | if ( !topLeft.isValid() || !bottomRight.isValid() || topLeft.parent() != m_rootIndex ) | 255 | if ( !topLeft.isValid() || !bottomRight.isValid() || topLeft.parent() != m_rootIndex ) | ||
256 | return; | 256 | return; | ||
Show All 15 Lines | 271 | { | |||
272 | for ( int col = minCol; col <= maxCol; ++col ) | 272 | for ( int col = minCol; col <= maxCol; ++col ) | ||
273 | { | 273 | { | ||
274 | m_cacheValid[ row ][ col ] = false; | 274 | m_cacheValid[ row ][ col ] = false; | ||
275 | Q_ASSERT( !isCached( row, col ) ); | 275 | Q_ASSERT( !isCached( row, col ) ); | ||
276 | } | 276 | } | ||
277 | } | 277 | } | ||
278 | } | 278 | } | ||
279 | 279 | | |||
280 | void layoutChanged() Q_DECL_OVERRIDE | 280 | void layoutChanged() override | ||
281 | { | 281 | { | ||
282 | modelReset(); | 282 | modelReset(); | ||
283 | } | 283 | } | ||
284 | 284 | | |||
285 | void modelReset() Q_DECL_OVERRIDE | 285 | void modelReset() override | ||
286 | { | 286 | { | ||
287 | m_data.clear(); | 287 | m_data.clear(); | ||
288 | m_cacheValid.clear(); | 288 | m_cacheValid.clear(); | ||
289 | 289 | | |||
290 | if ( m_model == nullptr ) | 290 | if ( m_model == nullptr ) | ||
291 | return; | 291 | return; | ||
292 | 292 | | |||
293 | m_data.fill( QVector< T >( m_model->columnCount( m_rootIndex ) ), m_model->rowCount( m_rootIndex ) ); | 293 | m_data.fill( QVector< T >( m_model->columnCount( m_rootIndex ) ), m_model->rowCount( m_rootIndex ) ); | ||
294 | m_cacheValid.fill( QVector< bool >( m_model->columnCount( m_rootIndex ), false ), m_model->rowCount( m_rootIndex ) ); | 294 | m_cacheValid.fill( QVector< bool >( m_model->columnCount( m_rootIndex ), false ), m_model->rowCount( m_rootIndex ) ); | ||
295 | 295 | | |||
296 | Q_ASSERT( m_data.count() == m_model->rowCount( m_rootIndex ) ); | 296 | Q_ASSERT( m_data.count() == m_model->rowCount( m_rootIndex ) ); | ||
297 | Q_ASSERT( m_cacheValid.count() == m_model->rowCount( m_rootIndex ) ); | 297 | Q_ASSERT( m_cacheValid.count() == m_model->rowCount( m_rootIndex ) ); | ||
298 | } | 298 | } | ||
299 | 299 | | |||
300 | void rowsInserted( const QModelIndex& parent, int start, int end ) Q_DECL_OVERRIDE | 300 | void rowsInserted( const QModelIndex& parent, int start, int end ) override | ||
301 | { | 301 | { | ||
302 | Q_ASSERT( m_model != nullptr ); | 302 | Q_ASSERT( m_model != nullptr ); | ||
303 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | 303 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | ||
304 | 304 | | |||
305 | if ( parent != m_rootIndex || start >= m_model->rowCount(m_rootIndex) ) | 305 | if ( parent != m_rootIndex || start >= m_model->rowCount(m_rootIndex) ) | ||
306 | return; | 306 | return; | ||
307 | 307 | | |||
308 | Q_ASSERT( start <= end ); | 308 | Q_ASSERT( start <= end ); | ||
309 | Q_ASSERT( end - start + 1 <= m_model->rowCount(m_rootIndex) ); | 309 | Q_ASSERT( end - start + 1 <= m_model->rowCount(m_rootIndex) ); | ||
310 | 310 | | |||
311 | m_data.insert( start, end - start + 1, QVector< T >( m_model->columnCount( m_rootIndex ) ) ); | 311 | m_data.insert( start, end - start + 1, QVector< T >( m_model->columnCount( m_rootIndex ) ) ); | ||
312 | m_cacheValid.insert( start, end - start + 1, QVector< bool >( m_model->columnCount( m_rootIndex ), false ) ); | 312 | m_cacheValid.insert( start, end - start + 1, QVector< bool >( m_model->columnCount( m_rootIndex ), false ) ); | ||
313 | 313 | | |||
314 | Q_ASSERT( m_data.count() == m_model->rowCount( m_rootIndex ) ); | 314 | Q_ASSERT( m_data.count() == m_model->rowCount( m_rootIndex ) ); | ||
315 | Q_ASSERT( m_cacheValid.count() == m_model->rowCount( m_rootIndex ) ); | 315 | Q_ASSERT( m_cacheValid.count() == m_model->rowCount( m_rootIndex ) ); | ||
316 | } | 316 | } | ||
317 | 317 | | |||
318 | void rowsRemoved( const QModelIndex& parent, int start, int end ) Q_DECL_OVERRIDE | 318 | void rowsRemoved( const QModelIndex& parent, int start, int end ) override | ||
319 | { | 319 | { | ||
320 | Q_ASSERT( m_model != nullptr ); | 320 | Q_ASSERT( m_model != nullptr ); | ||
321 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | 321 | Q_ASSERT( parent.model() == m_model || !parent.isValid() ); | ||
322 | 322 | | |||
323 | if ( parent != m_rootIndex || start >= m_data.count() ) | 323 | if ( parent != m_rootIndex || start >= m_data.count() ) | ||
324 | return; | 324 | return; | ||
325 | 325 | | |||
326 | Q_ASSERT( start <= end ); | 326 | Q_ASSERT( start <= end ); | ||
327 | 327 | | |||
328 | m_data.remove( start, end - start + 1 ); | 328 | m_data.remove( start, end - start + 1 ); | ||
329 | m_cacheValid.remove( start, end - start + 1 ); | 329 | m_cacheValid.remove( start, end - start + 1 ); | ||
330 | 330 | | |||
331 | Q_ASSERT( m_data.count() == m_model->rowCount( m_rootIndex ) ); | 331 | Q_ASSERT( m_data.count() == m_model->rowCount( m_rootIndex ) ); | ||
332 | Q_ASSERT( m_cacheValid.count() == m_model->rowCount( m_rootIndex ) ); | 332 | Q_ASSERT( m_cacheValid.count() == m_model->rowCount( m_rootIndex ) ); | ||
333 | } | 333 | } | ||
334 | 334 | | |||
335 | void resetModel() Q_DECL_OVERRIDE | 335 | void resetModel() override | ||
336 | { | 336 | { | ||
337 | // no need to disconnect, this is a response to SIGNAL( destroyed() ) | 337 | // no need to disconnect, this is a response to SIGNAL( destroyed() ) | ||
338 | m_model = nullptr; | 338 | m_model = nullptr; | ||
339 | modelReset(); | 339 | modelReset(); | ||
340 | } | 340 | } | ||
341 | 341 | | |||
342 | private: | 342 | private: | ||
343 | QAbstractItemModel* m_model; | 343 | QAbstractItemModel* m_model; | ||
344 | QModelIndex m_rootIndex; | 344 | QModelIndex m_rootIndex; | ||
345 | ModelDataCachePrivate::ModelSignalMapperConnector m_connector; | 345 | ModelDataCachePrivate::ModelSignalMapperConnector m_connector; | ||
346 | mutable QVector< QVector< T > > m_data; | 346 | mutable QVector< QVector< T > > m_data; | ||
347 | mutable QVector< QVector< bool > > m_cacheValid; | 347 | mutable QVector< QVector< bool > > m_cacheValid; | ||
348 | }; | 348 | }; | ||
349 | } | 349 | } | ||
350 | 350 | | |||
351 | #endif | 351 | #endif |