diff --git a/include/ui/mapheaderform.h b/include/ui/mapheaderform.h index 7f246d6d..4f3dc775 100644 --- a/include/ui/mapheaderform.h +++ b/include/ui/mapheaderform.h @@ -64,6 +64,8 @@ private: QPointer m_project = nullptr; bool m_allowProjectChanges = true; + void setText(QComboBox *combo, const QString &text) const; + void setText(QLineEdit *lineEdit, const QString &text) const; void setLocations(const QStringList &locations); void updateLocationName(); diff --git a/src/ui/mapheaderform.cpp b/src/ui/mapheaderform.cpp index 65fe6ead..a2a0b8b5 100644 --- a/src/ui/mapheaderform.cpp +++ b/src/ui/mapheaderform.cpp @@ -174,19 +174,29 @@ void MapHeaderForm::updateLocationName() { } // Set data in UI -void MapHeaderForm::setSong(const QString &song) { ui->comboBox_Song->setCurrentText(song); } -void MapHeaderForm::setLocation(const QString &location) { ui->comboBox_Location->setCurrentText(location); } -void MapHeaderForm::setLocationName(const QString &locationName) { ui->lineEdit_LocationName->setText(locationName); } +void MapHeaderForm::setSong(const QString &song) { setText(ui->comboBox_Song, song); } +void MapHeaderForm::setLocation(const QString &location) { setText(ui->comboBox_Location, location); } +void MapHeaderForm::setLocationName(const QString &locationName) { setText(ui->lineEdit_LocationName, locationName); } void MapHeaderForm::setRequiresFlash(bool requiresFlash) { ui->checkBox_RequiresFlash->setChecked(requiresFlash); } -void MapHeaderForm::setWeather(const QString &weather) { ui->comboBox_Weather->setCurrentText(weather); } -void MapHeaderForm::setType(const QString &type) { ui->comboBox_Type->setCurrentText(type); } -void MapHeaderForm::setBattleScene(const QString &battleScene) { ui->comboBox_BattleScene->setCurrentText(battleScene); } +void MapHeaderForm::setWeather(const QString &weather) { setText(ui->comboBox_Weather, weather); } +void MapHeaderForm::setType(const QString &type) { setText(ui->comboBox_Type, type); } +void MapHeaderForm::setBattleScene(const QString &battleScene) { setText(ui->comboBox_BattleScene, battleScene); } void MapHeaderForm::setShowsLocationName(bool showsLocationName) { ui->checkBox_ShowLocationName->setChecked(showsLocationName); } void MapHeaderForm::setAllowsRunning(bool allowsRunning) { ui->checkBox_AllowRunning->setChecked(allowsRunning); } void MapHeaderForm::setAllowsBiking(bool allowsBiking) { ui->checkBox_AllowBiking->setChecked(allowsBiking); } void MapHeaderForm::setAllowsEscaping(bool allowsEscaping) { ui->checkBox_AllowEscaping->setChecked(allowsEscaping); } void MapHeaderForm::setFloorNumber(int floorNumber) { ui->spinBox_FloorNumber->setValue(floorNumber); } +// If we always call setText / setCurrentText the user's cursor may move to the end of the text while they're typing. +void MapHeaderForm::setText(QComboBox *combo, const QString &text) const { + if (combo->currentText() != text) + combo->setCurrentText(text); +} +void MapHeaderForm::setText(QLineEdit *lineEdit, const QString &text) const { + if (lineEdit->text() != text) + lineEdit->setText(text); +} + // Read data from UI QString MapHeaderForm::song() const { return ui->comboBox_Song->currentText(); } QString MapHeaderForm::location() const { return ui->comboBox_Location->currentText(); } diff --git a/src/ui/maplisttoolbar.cpp b/src/ui/maplisttoolbar.cpp index 2584c4fd..304d6490 100644 --- a/src/ui/maplisttoolbar.cpp +++ b/src/ui/maplisttoolbar.cpp @@ -121,7 +121,9 @@ void MapListToolBar::applyFilter(const QString &filterText) { return; const QSignalBlocker b(ui->lineEdit_filterBox); - ui->lineEdit_filterBox->setText(filterText); + if (ui->lineEdit_filterBox->text() != filterText) { + ui->lineEdit_filterBox->setText(filterText); + } // The clear button does not properly disappear when filterText is empty. // It seems like this is because blocking the QLineEdit's signals prevents