Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/plugins/folder/positioner.cpp
Show First 20 Lines • Show All 419 Lines • ▼ Show 20 Line(s) | 419 | if (to < oldCount) { | |||
---|---|---|---|---|---|
420 | const QModelIndex &toIdx = index(to, 0); | 420 | const QModelIndex &toIdx = index(to, 0); | ||
421 | emit dataChanged(toIdx, toIdx); | 421 | emit dataChanged(toIdx, toIdx); | ||
422 | } | 422 | } | ||
423 | } | 423 | } | ||
424 | 424 | | |||
425 | const int newCount = rowCount(); | 425 | const int newCount = rowCount(); | ||
426 | 426 | | |||
427 | if (newCount > oldCount) { | 427 | if (newCount > oldCount) { | ||
428 | if (m_beginInsertRowsCalled) { | ||||
429 | endInsertRows(); | ||||
430 | m_beginInsertRowsCalled = false; | ||||
431 | } | ||||
428 | beginInsertRows(QModelIndex(), oldCount, newCount - 1); | 432 | beginInsertRows(QModelIndex(), oldCount, newCount - 1); | ||
429 | endInsertRows(); | 433 | endInsertRows(); | ||
430 | } | 434 | } | ||
431 | 435 | | |||
432 | if (newCount < oldCount) { | 436 | if (newCount < oldCount) { | ||
433 | beginRemoveRows(QModelIndex(), newCount, oldCount - 1); | 437 | beginRemoveRows(QModelIndex(), newCount, oldCount - 1); | ||
434 | endRemoveRows(); | 438 | endRemoveRows(); | ||
435 | } | 439 | } | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 504 | { | |||
505 | emit endResetModel(); | 509 | emit endResetModel(); | ||
506 | } | 510 | } | ||
507 | 511 | | |||
508 | void Positioner::sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) | 512 | void Positioner::sourceRowsAboutToBeInserted(const QModelIndex &parent, int start, int end) | ||
509 | { | 513 | { | ||
510 | if (m_enabled) { | 514 | if (m_enabled) { | ||
511 | if (m_proxyToSource.isEmpty()) { | 515 | if (m_proxyToSource.isEmpty()) { | ||
512 | if (!m_pendingPositions) { | 516 | if (!m_pendingPositions) { | ||
513 | emit beginInsertRows(parent, start, end); | 517 | beginInsertRows(parent, start, end); | ||
518 | m_beginInsertRowsCalled = true; | ||||
514 | 519 | | |||
515 | initMaps(end + 1); | 520 | initMaps(end + 1); | ||
516 | } | 521 | } | ||
517 | 522 | | |||
518 | return; | 523 | return; | ||
519 | } | 524 | } | ||
520 | 525 | | |||
526 | // When new rows are inserted, they might go in the beginning or in the middle. | ||||
527 | // In this case we must update first the existing proxy->source and source->proxy | ||||
528 | // mapping, otherwise the proxy items will point to the wrong source item. | ||||
529 | int count = end - start + 1; | ||||
530 | m_sourceToProxy.clear(); | ||||
531 | for (auto it = m_proxyToSource.begin(); it != m_proxyToSource.end(); ++it) { | ||||
532 | int sourceIdx = *it; | ||||
533 | if (sourceIdx >= start) { | ||||
534 | *it += count; | ||||
535 | } | ||||
536 | m_sourceToProxy[*it] = it.key(); | ||||
537 | } | ||||
538 | | ||||
521 | int free = -1; | 539 | int free = -1; | ||
522 | int rest = -1; | 540 | int rest = -1; | ||
523 | 541 | | |||
524 | for (int i = start; i <= end; ++i) { | 542 | for (int i = start; i <= end; ++i) { | ||
525 | free = firstFreeRow(); | 543 | free = firstFreeRow(); | ||
526 | 544 | | |||
527 | if (free != -1) { | 545 | if (free != -1) { | ||
528 | updateMaps(free, i); | 546 | updateMaps(free, i); | ||
529 | m_pendingChanges << createIndex(free, 0); | 547 | m_pendingChanges << createIndex(free, 0); | ||
530 | } else { | 548 | } else { | ||
531 | rest = i; | 549 | rest = i; | ||
532 | break; | 550 | break; | ||
533 | } | 551 | } | ||
534 | } | 552 | } | ||
535 | 553 | | |||
536 | if (rest != -1) { | 554 | if (rest != -1) { | ||
537 | int firstNew = lastRow() + 1; | 555 | int firstNew = lastRow() + 1; | ||
538 | int remainder = (end - rest); | 556 | int remainder = (end - rest); | ||
539 | 557 | | |||
540 | beginInsertRows(parent, firstNew, firstNew + remainder); | 558 | beginInsertRows(parent, firstNew, firstNew + remainder); | ||
559 | m_beginInsertRowsCalled = true; | ||||
541 | 560 | | |||
542 | for (int i = 0; i <= remainder; ++i) { | 561 | for (int i = 0; i <= remainder; ++i) { | ||
543 | updateMaps(firstNew + i, rest + i); | 562 | updateMaps(firstNew + i, rest + i); | ||
544 | } | 563 | } | ||
545 | } else { | 564 | } else { | ||
546 | m_ignoreNextTransaction = true; | 565 | m_ignoreNextTransaction = true; | ||
547 | } | 566 | } | ||
548 | } else { | 567 | } else { | ||
549 | emit beginInsertRows(parent, start, end); | 568 | emit beginInsertRows(parent, start, end); | ||
569 | beginInsertRows(parent, start, end); | ||||
570 | m_beginInsertRowsCalled = true; | ||||
550 | } | 571 | } | ||
551 | } | 572 | } | ||
552 | 573 | | |||
553 | void Positioner::sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, | 574 | void Positioner::sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, | ||
554 | int sourceEnd, const QModelIndex& destinationParent, int destinationRow) | 575 | int sourceEnd, const QModelIndex& destinationParent, int destinationRow) | ||
555 | { | 576 | { | ||
556 | emit beginMoveRows(sourceParent, sourceStart, sourceEnd, destinationParent, destinationRow); | 577 | emit beginMoveRows(sourceParent, sourceStart, sourceEnd, destinationParent, destinationRow); | ||
557 | } | 578 | } | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | |||||
612 | void Positioner::sourceRowsInserted(const QModelIndex &parent, int first, int last) | 633 | void Positioner::sourceRowsInserted(const QModelIndex &parent, int first, int last) | ||
613 | { | 634 | { | ||
614 | Q_UNUSED(parent) | 635 | Q_UNUSED(parent) | ||
615 | Q_UNUSED(first) | 636 | Q_UNUSED(first) | ||
616 | Q_UNUSED(last) | 637 | Q_UNUSED(last) | ||
617 | 638 | | |||
618 | if (!m_ignoreNextTransaction) { | 639 | if (!m_ignoreNextTransaction) { | ||
619 | if (!m_pendingPositions) { | 640 | if (!m_pendingPositions) { | ||
620 | emit endInsertRows(); | 641 | if (m_beginInsertRowsCalled) { | ||
642 | endInsertRows(); | ||||
643 | m_beginInsertRowsCalled = false; | ||||
644 | } | ||||
621 | } else { | 645 | } else { | ||
622 | applyPositions(); | 646 | applyPositions(); | ||
623 | } | 647 | } | ||
624 | } else { | 648 | } else { | ||
625 | m_ignoreNextTransaction = false; | 649 | m_ignoreNextTransaction = false; | ||
626 | } | 650 | } | ||
627 | 651 | | |||
628 | flushPendingChanges(); | 652 | flushPendingChanges(); | ||
▲ Show 20 Lines • Show All 288 Lines • Show Last 20 Lines |