Skip to content

Commit

Permalink
Search Tool: Added an optional sorting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Oct 30, 2023
1 parent b4acc7c commit b3834d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/gui/SearchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ SearchDialog::SearchDialog(QObject* parent)
conf = StelApp::getInstance().getSettings();
enableSimbadSearch(conf->value("search/flag_search_online", true).toBool());
useStartOfWords = conf->value("search/flag_start_words", false).toBool();
useLengthSorting = conf->value("search/flag_sorting_length", false).toBool();
useLockPosition = conf->value("search/flag_lock_position", true).toBool();
useFOVCenterMarker = conf->value("search/flag_fov_center_marker", true).toBool();
fovCenterMarkerState = GETSTELMODULE(SpecialMarkersMgr)->getFlagFOVCenterMarker();
Expand Down Expand Up @@ -440,6 +441,8 @@ void SearchDialog::createDialogContent()

connect(ui->checkBoxUseStartOfWords, SIGNAL(clicked(bool)), this, SLOT(enableStartOfWordsAutofill(bool)));
ui->checkBoxUseStartOfWords->setChecked(useStartOfWords);
connect(ui->checkBoxUseSortingByLength, SIGNAL(clicked(bool)), this, SLOT(enableSortingByLength(bool)));
ui->checkBoxUseSortingByLength->setChecked(useLengthSorting);

connect(ui->checkBoxFOVCenterMarker, SIGNAL(clicked(bool)), this, SLOT(enableFOVCenterMarker(bool)));
ui->checkBoxFOVCenterMarker->setChecked(useFOVCenterMarker);
Expand Down Expand Up @@ -634,6 +637,15 @@ void SearchDialog::enableStartOfWordsAutofill(bool enable)
onSearchTextChanged(ui->lineEditSearchSkyObject->text());
}

void SearchDialog::enableSortingByLength(bool enable)
{
useLengthSorting = enable;
conf->setValue("search/flag_sorting_length", useLengthSorting);

// Update search result on "Object" tab
onSearchTextChanged(ui->lineEditSearchSkyObject->text());
}

void SearchDialog::enableLockPosition(bool enable)
{
useLockPosition = enable;
Expand Down Expand Up @@ -1053,8 +1065,12 @@ QStringList SearchDialog::listMatchingRecentObjects(const QString& objPrefix, in
if (result.size() >= maxNbItem)
break;
}
stringLengthCompare comparator;
std::sort(result.begin(), result.end(), comparator);

if (useLengthSorting)
{
stringLengthCompare comparator;
std::sort(result.begin(), result.end(), comparator);
}

return result;
}
Expand Down
4 changes: 4 additions & 0 deletions src/gui/SearchDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ private slots:
//! Whether to use autofill for start of words or not.
void enableStartOfWordsAutofill(bool enable);

//! Whether to use sorting by string length or not
void enableSortingByLength(bool enable);

//! Whether to use lock position when coordinates are used or not.
void enableLockPosition(bool enable);

Expand Down Expand Up @@ -309,6 +312,7 @@ private slots:
bool flagHasSelectedText;

bool useStartOfWords;
bool useLengthSorting;
bool useLockPosition;
bool useSimbad;
bool useFOVCenterMarker;
Expand Down
7 changes: 7 additions & 0 deletions src/gui/searchDialogGui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUseSortingByLength">
<property name="text">
<string>Use sorting by string length</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxLockPosition">
<property name="text">
Expand Down

0 comments on commit b3834d1

Please sign in to comment.