Revision 1781 trunk/client/gui_qt/DownloadQueueModel.cpp

DownloadQueueModel.cpp (revision 1781)
511 511
    Q_UNUSED(subject);
512 512
    Q_UNUSED(new_collection_name);
513 513

                
514
    bool was_selected;
515 514
    DownloadQueueItem *collection_node = lookupCollectionItem(orig_collection_name);
516 515
    DownloadQueueItem *subject_node = lookupSubjectItem(collection_node, subject);
517 516

                
... ...
522 521
        return;
523 522
    }
524 523

                
525
#if 0
526
    was_selected = collection_node->child(old_position)->isSelected();
527
#endif
528

                
529
    Q_ASSERT(collection_node->removeChild(subject_node));
530

                
531
    QModelIndex idx_start = createIndex(subject_node->row(), 0, subject_node);
532
    QModelIndex idx_end = createIndex(subject_node->row(), DownloadQueueItem::NUM_FIELDS - 1, subject_node);
533
    emit dataChanged(idx_start, idx_end);
534

                
524
    /* Do we need to move the item to the bottom */
535 525
    if (new_position == -1) {
536
        collection_node->appendChild(subject_node);
537
    } else {
538
        collection_node->insertChild(new_position, subject_node);
526
        new_position = collection_node->childCount();
539 527
    }
540 528

                
541
    idx_start = createIndex(subject_node->row(), 0, subject_node);
542
    idx_end = createIndex(subject_node->row(), DownloadQueueItem::NUM_FIELDS - 1, subject_node);
543
    emit dataChanged(idx_start, idx_end);
544

                
545
#if 0
546
    if (was_selected) {
547
        subject_node->setSelected(true);
529
    QModelIndex parent_idx = createIndex(subject_node->row(), 0, collection_node);
530
    int new_pos_in_model = qMin(collection_node->childCount(), ((old_position < new_position) ? new_position + 1 : new_position));
531
    if (!beginMoveRows(parent_idx, old_position, old_position, parent_idx, new_pos_in_model)) {
532
        qWarning("beginMoveRows failed\n");
533
        return;
548 534
    }
549
#endif
535

                
536
    collection_node->removeChild(subject_node);
537
    collection_node->insertChild(new_position, subject_node);
538

                
539
    endMoveRows();
550 540
}
551 541

                
552 542
void DownloadQueueModel::onCollectionAdded(QString collection_name, QString poster)
... ...
596 586

                
597 587
void DownloadQueueModel::onCollectionMoved(QString collection_name, int old_position, int new_position)
598 588
{
599
    qDebug("collection moved: old_position: %i, new position: %i", old_position, new_position);
600
    bool was_selected;
589
#if 0
601 590
    bool was_expanded;
591
#endif
602 592
    DownloadQueueItem *collection_node;
603 593

                
604 594
#if 0
605
    was_selected = ui->treeWidget->topLevelItem(old_position)->isSelected();
606 595
    was_expanded = ui->treeWidget->topLevelItem(old_position)->isExpanded();
607 596
#endif
608 597
    collection_node = lookupCollectionItem(collection_name);
609 598

                
610
    rootItem->removeChild(collection_node);
611
    QModelIndex idx_start = createIndex(collection_node->row(), 0, collection_node);
612
    QModelIndex idx_end = createIndex(collection_node->row(), DownloadQueueItem::NUM_FIELDS - 1, collection_node);
613
    emit dataChanged(idx_start, idx_end);
599
    /* Do we need to move the item to the bottom */
600
    if (new_position == -1) {
601
        new_position = rootItem->childCount();
602
    }
614 603

                
615
    if (new_position == -1) { // To bottom
616
        rootItem->appendChild(collection_node);
617
    } else {
618
        rootItem->insertChild(new_position, collection_node);
604
    QModelIndex parent_idx = createIndex(rootItem->row(), 0, rootItem);
605
    int new_pos_in_model = qMin(rootItem->childCount(), ((old_position < new_position) ? new_position + 1 : new_position));
606
    if (!beginMoveRows(parent_idx, old_position, old_position, parent_idx, new_pos_in_model)) {
607
        qWarning("beginMoveRows failed\n");
608
        return;
619 609
    }
620 610

                
621
    idx_start = createIndex(collection_node->row(), 0, collection_node);
622
    idx_end = createIndex(collection_node->row(), DownloadQueueItem::NUM_FIELDS - 1, collection_node);
623
    emit dataChanged(idx_start, idx_end);
611
    rootItem->removeChild(collection_node);
612
    rootItem->insertChild(new_position, collection_node);
624 613

                
625
#if 0
626
    if (was_selected) {
627
        collection_node->setSelected(true);
628
    }
614
    endMoveRows();
629 615

                
616
#if 0
630 617
    if (was_expanded) {
631 618
        collection_node->setExpanded(true);
632 619
    }

Also available in: Unified diff