Revision 1781
| trunk/client/gui_qt/WidgetDownloadQueue.cpp (revision 1781) | ||
|---|---|---|
| 5 | 5 |
|
| 6 | 6 |
#include "WidgetDownloadQueue.h" |
| 7 | 7 |
#include "ui_WidgetDownloadQueue.h" |
| 8 |
#include "DownloadQueueSelectionModel.h" |
|
| 8 | 9 |
|
| 9 | 10 |
#include "nntpgrab_utils.h" |
| 10 | 11 |
|
| ... | ... | |
| 31 | 32 |
connect(ui->btnQueueMoveDown, SIGNAL(clicked(void)), SLOT(btnQueueMoveDown_clicked(void))); |
| 32 | 33 |
connect(ui->btnQueueMoveToBottom, SIGNAL(clicked(void)), SLOT(btnQueueMoveToBottom_clicked(void))); |
| 33 | 34 |
|
| 34 |
QItemSelectionModel *selectionModel = ui->treeView->selectionModel(); |
|
| 35 |
DownloadQueueSelectionModel *selectionModel = new DownloadQueueSelectionModel(this->model); |
|
| 36 |
ui->treeView->setSelectionModel(selectionModel); |
|
| 35 | 37 |
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &))); |
| 36 | 38 |
|
| 37 | 39 |
connect(ui->actionMarkItemOptional, SIGNAL(triggered()), SLOT(actionMarkItemOptional_activated())); |
| ... | ... | |
| 143 | 145 |
|
| 144 | 146 |
for (int j = 0; j < collection_item->childCount(); j++) {
|
| 145 | 147 |
subject_item = collection_item->child(j); |
| 146 |
QModelIndex idx_subject = model->index(i, 0, idx_collection); |
|
| 148 |
QModelIndex idx_subject = model->index(subject_item->row(), 0, idx_collection); |
|
| 147 | 149 |
|
| 148 | 150 |
if (selectionModel->isSelected(idx_subject)) {
|
| 149 | 151 |
if (j == collection_item->childCount() - 1 && direction == MOVE_DIRECTION_DOWN) {
|
| trunk/client/gui_qt/gui_qt.pro (revision 1781) | ||
|---|---|---|
| 39 | 39 |
QNZBCreator.cpp \ |
| 40 | 40 |
AutoImport.cpp \ |
| 41 | 41 |
DownloadQueueModel.cpp \ |
| 42 |
DownloadQueueItem.cpp |
|
| 42 |
DownloadQueueItem.cpp \ |
|
| 43 |
DownloadQueueSelectionModel.cpp |
|
| 43 | 44 |
HEADERS += mainwindow.h \ |
| 44 | 45 |
QNNTPGrabGlue.h \ |
| 45 | 46 |
WidgetConfig.h \ |
| ... | ... | |
| 71 | 72 |
QNZBCreator.h \ |
| 72 | 73 |
AutoImport.h \ |
| 73 | 74 |
DownloadQueueModel.h \ |
| 74 |
DownloadQueueItem.h |
|
| 75 |
DownloadQueueItem.h \ |
|
| 76 |
DownloadQueueSelectionModel.h |
|
| 75 | 77 |
FORMS += mainwindow.ui \ |
| 76 | 78 |
WidgetConfig.ui \ |
| 77 | 79 |
WidgetDownloadQueue.ui \ |
| trunk/client/gui_qt/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 |
} |
| trunk/client/gui_qt/DownloadQueueSelectionModel.h (revision 1781) | ||
|---|---|---|
| 1 |
#ifndef DOWNLOADQUEUESELECTIONMODEL_H |
|
| 2 |
#define DOWNLOADQUEUESELECTIONMODEL_H |
|
| 3 |
|
|
| 4 |
#include |
|
| 5 |
#include |
|
| 6 |
|
|
| 7 |
class DownloadQueueSelectionModel : public QItemSelectionModel |
|
| 8 |
{
|
|
| 9 |
Q_OBJECT |
|
| 10 |
public: |
|
| 11 |
DownloadQueueSelectionModel(DownloadQueueModel *model, QObject *parent = 0); |
|
| 12 |
|
|
| 13 |
private: |
|
| 14 |
QModelIndex deselectedSourceParent; |
|
| 15 |
int deselectedSourceStart; |
|
| 16 |
|
|
| 17 |
signals: |
|
| 18 |
|
|
| 19 |
public slots: |
|
| 20 |
void onRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow); |
|
| 21 |
void onRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow); |
|
| 22 |
}; |
|
| 23 |
|
|
| 24 |
#endif // DOWNLOADQUEUESELECTIONMODEL_H |
|
| trunk/client/gui_qt/DownloadQueueSelectionModel.cpp (revision 1781) | ||
|---|---|---|
| 1 |
#include "DownloadQueueSelectionModel.h" |
|
| 2 |
|
|
| 3 |
DownloadQueueSelectionModel::DownloadQueueSelectionModel(DownloadQueueModel *model, QObject *parent) : |
|
| 4 |
QItemSelectionModel(model, parent) |
|
| 5 |
{
|
|
| 6 |
connect(model, SIGNAL(rowsAboutToBeMoved(const QModelIndex&,int,int,const QModelIndex&,int)), SLOT(onRowsAboutToBeMoved(const QModelIndex&,int,int,const QModelIndex&,int))); |
|
| 7 |
connect(model, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), SLOT(onRowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); |
|
| 8 |
} |
|
| 9 |
|
|
| 10 |
void DownloadQueueSelectionModel::onRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) |
|
| 11 |
{
|
|
| 12 |
Q_UNUSED(sourceEnd); |
|
| 13 |
Q_UNUSED(destinationParent); |
|
| 14 |
Q_UNUSED(destinationRow); |
|
| 15 |
|
|
| 16 |
/* Is the current row selected? */ |
|
| 17 |
QModelIndex idx = sourceParent.child(sourceStart, 0); |
|
| 18 |
if (!idx.isValid()) {
|
|
| 19 |
qWarning("Invalid index");
|
|
| 20 |
} |
|
| 21 |
if (isSelected(idx)) {
|
|
| 22 |
/* Deselect the row and keep track of it so we can re-select it after the move has completed */ |
|
| 23 |
select(sourceParent.child(sourceStart, 0), Toggle | Rows); |
|
| 24 |
deselectedSourceParent = sourceParent; |
|
| 25 |
deselectedSourceStart = sourceStart; |
|
| 26 |
|
|
| 27 |
if (destinationRow > sourceStart) {
|
|
| 28 |
destinationRow--; |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
QModelIndex idx = destinationParent.child(destinationRow, 0); |
|
| 32 |
if (!idx.isValid()) {
|
|
| 33 |
qWarning("Invalid index");
|
|
| 34 |
} |
|
| 35 |
select(idx, Toggle | Rows); |
|
| 36 |
} else {
|
|
| 37 |
deselectedSourceParent = QModelIndex(); |
|
| 38 |
deselectedSourceStart = -1; |
|
| 39 |
} |
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
void DownloadQueueSelectionModel::onRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) |
|
| 43 |
{
|
|
| 44 |
Q_UNUSED(sourceEnd); |
|
| 45 |
|
|
| 46 |
/* Was the original row selected? */ |
|
| 47 |
if (deselectedSourceParent != sourceParent || |
|
| 48 |
deselectedSourceStart != sourceStart) {
|
|
| 49 |
|
|
| 50 |
return; |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
//QModelIndex idx = destinationParent.child(destinationRow, 0); |
|
| 54 |
//if (!idx.isValid()) {
|
|
| 55 |
// qWarning("Invalid index");
|
|
| 56 |
//} |
|
| 57 |
//select(idx, Toggle | Rows); |
|
| 58 |
} |
|
Also available in: Unified diff
NNTPGrab

