diff --git a/src/Core/NamedSearch.cpp b/src/Core/NamedSearch.cpp index ae6576aad..88cdc3f0c 100644 --- a/src/Core/NamedSearch.cpp +++ b/src/Core/NamedSearch.cpp @@ -289,9 +289,13 @@ EditNamedSearches::EditNamedSearches(QWidget *parent, Context *context) : QDialo #endif searchList->header()->setStretchLastSection(true); - // delete button + // up/down/delete button QHBoxLayout *row4 = new QHBoxLayout; layout->addLayout(row4); + upButton = new QPushButton(tr("Up"), this); + row4->addWidget(upButton); + downButton = new QPushButton(tr("Down"), this); + row4->addWidget(downButton); row4->addStretch(); deleteButton = new QPushButton(tr("Delete"), this); row4->addWidget(deleteButton); @@ -314,6 +318,8 @@ EditNamedSearches::EditNamedSearches(QWidget *parent, Context *context) : QDialo connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked())); connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked())); connect(updateButton, SIGNAL(clicked()), this, SLOT(updateClicked())); + connect(upButton, SIGNAL(clicked()), this, SLOT(upClicked())); + connect(downButton, SIGNAL(clicked()), this, SLOT(downClicked())); } void @@ -373,6 +379,46 @@ EditNamedSearches::updateClicked() selectionChanged(); // QT signals whilst rows are being removed, this is very confusing } +void +EditNamedSearches::upClicked() +{ + if (active || searchList->currentItem() == NULL) return; + active = true; + + int index = searchList->invisibleRootItem()->indexOfChild(searchList->currentItem()); + int newIndex = index - 1; + + if (index > 0) { + context->athlete->namedSearches->getList().swapItemsAt(newIndex, index); + QTreeWidgetItem* child = searchList->invisibleRootItem()->takeChild(index); + searchList->invisibleRootItem()->insertChild(newIndex, child); + searchList->setCurrentItem(child); + } + + active = false; + selectionChanged(); // QT signals whilst rows are being removed, this is very confusing +} + +void +EditNamedSearches::downClicked() +{ + if (active || searchList->currentItem() == NULL) return; + active = true; + + int index = searchList->invisibleRootItem()->indexOfChild(searchList->currentItem()); + int newIndex = index + 1; + + if (index < (context->athlete->namedSearches->getList().size() - 1)) { + context->athlete->namedSearches->getList().swapItemsAt(newIndex, index); + QTreeWidgetItem* child = searchList->invisibleRootItem()->takeChild(index); + searchList->invisibleRootItem()->insertChild(newIndex, child); + searchList->setCurrentItem(child); + } + + active = false; + selectionChanged(); // QT signals whilst rows are being removed, this is very confusing +} + void EditNamedSearches::deleteClicked() { @@ -391,7 +437,7 @@ EditNamedSearches::deleteClicked() void EditNamedSearches::closeEvent(QCloseEvent*) { writeSearches(); } void EditNamedSearches::reject() { writeSearches(); } -void +void EditNamedSearches::writeSearches() { context->athlete->namedSearches->write(); diff --git a/src/Core/NamedSearch.h b/src/Core/NamedSearch.h index e9c60ab8a..c3b30bee9 100644 --- a/src/Core/NamedSearch.h +++ b/src/Core/NamedSearch.h @@ -113,12 +113,16 @@ class EditNamedSearches : public QDialog QTreeWidget *searchList; QPushButton *addButton, *updateButton, + *upButton, + *downButton, *deleteButton; QIcon searchIcon, filterIcon; private slots: void addClicked(); void updateClicked(); + void upClicked(); + void downClicked(); void deleteClicked(); void selectionChanged(); };