Merge pull request #3657 from ward:manage-filters-up-down

This commit is contained in:
Ale Martinez
2020-11-08 19:37:16 -03:00
2 changed files with 52 additions and 2 deletions

View File

@@ -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();

View File

@@ -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();
};