From 61282d6bb204690967dfbef3ac6fec4f1c1272e2 Mon Sep 17 00:00:00 2001 From: William Grishko Date: Tue, 10 Oct 2017 22:35:30 -0700 Subject: [PATCH 1/2] Auto sort by song number --- songwidget.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/songwidget.cpp b/songwidget.cpp index 53e9a2d..761c13f 100644 --- a/songwidget.cpp +++ b/songwidget.cpp @@ -218,6 +218,9 @@ void SongWidget::on_songbook_menu_currentIndexChanged(int index) updateButtonStates(); + // Sort by song number at initial load, and with songbook change + ui->songs_view->sortByColumn(1,Qt::AscendingOrder); + songs_model->emitLayoutChanged(); // forces the view to redraw } @@ -229,7 +232,9 @@ void SongWidget::on_song_num_spinbox_valueChanged(int value) isSpinboxEditing = true; ui->lineEditSearch->clear(); on_lineEditSearch_textEdited(""); - ui->songs_view->sortByColumn(0,Qt::AscendingOrder); + + // Sort by song number + ui->songs_view->sortByColumn(1,Qt::AscendingOrder); } //int max_num = 0; @@ -288,6 +293,9 @@ void SongWidget::on_lineEditSearch_textEdited(QString text) // If no full-text search is in progress, then filter if(!ui->pushButtonClearResults->isVisible()) { + // Sort by song number + ui->songs_view->sortByColumn(1,Qt::AscendingOrder); + // These two options are mutually exclusive: bool match_beginning = (ui->comboBoxFilterType->currentIndex() == 1); bool exact_match = (ui->comboBoxFilterType->currentIndex() == 2); From 330750dd84f2635d66ce00ac030bfddb467fe4ce Mon Sep 17 00:00:00 2001 From: William Grishko Date: Fri, 13 Oct 2017 09:37:35 -0700 Subject: [PATCH 2/2] Added logical search song sorting --- songwidget.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/songwidget.cpp b/songwidget.cpp index 761c13f..6bdc8cf 100644 --- a/songwidget.cpp +++ b/songwidget.cpp @@ -293,8 +293,18 @@ void SongWidget::on_lineEditSearch_textEdited(QString text) // If no full-text search is in progress, then filter if(!ui->pushButtonClearResults->isVisible()) { - // Sort by song number + + // If search test is numeric, sort by the number, else sort by title + bool ok; + text.toInt(&ok); + if(ok) + { ui->songs_view->sortByColumn(1,Qt::AscendingOrder); + } + else + { + ui->songs_view->sortByColumn(2,Qt::AscendingOrder); + } // These two options are mutually exclusive: bool match_beginning = (ui->comboBoxFilterType->currentIndex() == 1);