From 8245f60e2bba2a574d1401efacdaffea00bc1c58 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 1 May 2025 10:17:51 -0400 Subject: [PATCH] Prefer NoScrollComboBox::setTextItem over setCurrentText --- CHANGELOG.md | 1 + forms/mainwindow.ui | 2 +- forms/mapheaderform.ui | 3 +++ forms/wildmonchart.ui | 7 ++++++- include/ui/divingmappixmapitem.h | 5 +++-- include/ui/mapheaderform.h | 3 ++- src/editor.cpp | 12 ++++++------ src/mainwindow.cpp | 10 +++++----- src/ui/connectionslistitem.cpp | 2 +- src/ui/divingmappixmapitem.cpp | 4 ++-- src/ui/encountertabledelegates.cpp | 2 +- src/ui/eventframes.cpp | 22 +++++++++++----------- src/ui/gridsettings.cpp | 2 +- src/ui/mapheaderform.cpp | 9 ++++----- src/ui/mapimageexporter.cpp | 8 ++++---- src/ui/newmapdialog.cpp | 2 +- src/ui/preferenceeditor.cpp | 2 +- src/ui/regionmapeditor.cpp | 8 ++++---- src/ui/wildmonchart.cpp | 2 +- 19 files changed, 58 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e78fe5e..5d489b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix exporting a timelapse sometimes altering the state of the current map's edit history. - Stop sliders in the Palette Editor from creating a bunch of edit history when used. - Fix scrolling on some containers locking up when the mouse stops over a spin box or combo box. +- Fix the selection index for some combo boxes differing from their displayed text. - Fix some file dialogs returning to an incorrect window when closed. - Fix bug where reloading a layout would overwrite all unsaved changes. - Fix bug where layout json and blockdata could be saved separately leading to inconsistent data. diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index bf0d2608..177f639f 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -2733,7 +2733,7 @@ - + QComboBox::SizeAdjustPolicy::AdjustToContents diff --git a/forms/mapheaderform.ui b/forms/mapheaderform.ui index 08552e2c..d4fc36f3 100644 --- a/forms/mapheaderform.ui +++ b/forms/mapheaderform.ui @@ -10,6 +10,9 @@ 380 + + Qt::FocusPolicy::ClickFocus + Form diff --git a/forms/wildmonchart.ui b/forms/wildmonchart.ui index 8d6668e4..05c0ba44 100644 --- a/forms/wildmonchart.ui +++ b/forms/wildmonchart.ui @@ -197,7 +197,7 @@ - + true @@ -237,6 +237,11 @@ QGraphicsView
QtCharts
+ + NoScrollComboBox + QComboBox +
noscrollcombobox.h
+
diff --git a/include/ui/divingmappixmapitem.h b/include/ui/divingmappixmapitem.h index 7eceba07..0a4a32c1 100644 --- a/include/ui/divingmappixmapitem.h +++ b/include/ui/divingmappixmapitem.h @@ -2,6 +2,7 @@ #define DIVINGMAPPIXMAPITEM_H #include "mapconnection.h" +#include "noscrollcombobox.h" #include #include @@ -10,7 +11,7 @@ class DivingMapPixmapItem : public QObject, public QGraphicsPixmapItem { Q_OBJECT public: - DivingMapPixmapItem(MapConnection *connection, QComboBox *combo); + DivingMapPixmapItem(MapConnection *connection, NoScrollComboBox *combo); ~DivingMapPixmapItem(); MapConnection* connection() const { return m_connection; } @@ -18,7 +19,7 @@ public: private: QPointer m_connection; - QPointer m_combo; + QPointer m_combo; void setComboText(const QString &text); static QPixmap getBasePixmap(MapConnection* connection); diff --git a/include/ui/mapheaderform.h b/include/ui/mapheaderform.h index 4f3dc775..fb4f7aa9 100644 --- a/include/ui/mapheaderform.h +++ b/include/ui/mapheaderform.h @@ -12,6 +12,7 @@ #include "mapheader.h" #include "project.h" +#include "noscrollcombobox.h" namespace Ui { class MapHeaderForm; @@ -64,7 +65,7 @@ private: QPointer m_project = nullptr; bool m_allowProjectChanges = true; - void setText(QComboBox *combo, const QString &text) const; + void setText(NoScrollComboBox *combo, const QString &text) const; void setText(QLineEdit *lineEdit, const QString &text) const; void setLocations(const QStringList &locations); void updateLocationName(); diff --git a/src/editor.cpp b/src/editor.cpp index 174d0b07..fb870dff 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -238,7 +238,7 @@ void Editor::displayWildMonTables() { labelComboStrings.sort(); labelCombo->addItems(labelComboStrings); - labelCombo->setCurrentText(labelCombo->itemText(0)); + labelCombo->setCurrentIndex(0); QStackedWidget *stack = ui->stackedWidget_WildMons; int labelIndex = 0; @@ -495,7 +495,7 @@ void Editor::configureEncounterJSON(QWidget *window) { QFrame *slotChoiceFrame = new QFrame; QVBoxLayout *slotChoiceLayout = new QVBoxLayout; if (useGroups) { - QComboBox *groupCombo = new QComboBox; + auto groupCombo = new NoScrollComboBox; connect(groupCombo, QOverload::of(&QComboBox::textActivated), [&tempFields, ¤tField, &updateTotal, index](QString newGroupName) { for (EncounterField &field : tempFields) { if (field.name == currentField.name) { @@ -526,7 +526,7 @@ void Editor::configureEncounterJSON(QWidget *window) { break; } } - groupCombo->setCurrentText(currentGroupName); + groupCombo->setTextItem(currentGroupName); slotChoiceLayout->addWidget(groupCombo); } slotChoiceLayout->addWidget(chanceSpinner); @@ -982,7 +982,7 @@ QString Editor::getDivingMapName(const QString &direction) const { void Editor::onDivingMapEditingFinished(NoScrollComboBox *combo, const QString &direction) { if (!setDivingMapName(combo->currentText(), direction)) { // If user input was invalid, restore the combo to the previously-valid text. - combo->setCurrentText(getDivingMapName(direction)); + combo->setTextItem(getDivingMapName(direction)); } } @@ -1281,8 +1281,8 @@ bool Editor::setLayout(QString layoutId) { ui->comboBox_PrimaryTileset->blockSignals(true); ui->comboBox_SecondaryTileset->blockSignals(true); - ui->comboBox_PrimaryTileset->setCurrentText(this->layout->tileset_primary_label); - ui->comboBox_SecondaryTileset->setCurrentText(this->layout->tileset_secondary_label); + ui->comboBox_PrimaryTileset->setTextItem(this->layout->tileset_primary_label); + ui->comboBox_SecondaryTileset->setTextItem(this->layout->tileset_secondary_label); ui->comboBox_PrimaryTileset->blockSignals(false); ui->comboBox_SecondaryTileset->blockSignals(false); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ac41f582..3fc7d4bd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1141,8 +1141,8 @@ void MainWindow::displayMapProperties() { const QSignalBlocker b_PrimaryTileset(ui->comboBox_PrimaryTileset); const QSignalBlocker b_SecondaryTileset(ui->comboBox_SecondaryTileset); - ui->comboBox_PrimaryTileset->setCurrentText(editor->map->layout()->tileset_primary_label); - ui->comboBox_SecondaryTileset->setCurrentText(editor->map->layout()->tileset_secondary_label); + ui->comboBox_PrimaryTileset->setTextItem(editor->map->layout()->tileset_primary_label); + ui->comboBox_SecondaryTileset->setTextItem(editor->map->layout()->tileset_secondary_label); ui->mapCustomAttributesFrame->table()->setAttributes(editor->map->customAttributes()); } @@ -1162,7 +1162,7 @@ void MainWindow::on_comboBox_LayoutSelector_currentTextChanged(const QString &te // New layout failed to load, restore previous layout const QSignalBlocker b(ui->comboBox_LayoutSelector); - ui->comboBox_LayoutSelector->setCurrentText(this->editor->map->layout()->id); + ui->comboBox_LayoutSelector->setTextItem(this->editor->map->layout()->id); return; } this->editor->map->setLayout(layout); @@ -1178,7 +1178,7 @@ void MainWindow::onLayoutSelectorEditingFinished() { const QString text = ui->comboBox_LayoutSelector->currentText(); if (!this->editor->project->mapLayouts.contains(text)) { const QSignalBlocker b(ui->comboBox_LayoutSelector); - ui->comboBox_LayoutSelector->setCurrentText(this->editor->layout->id); + ui->comboBox_LayoutSelector->setTextItem(this->editor->layout->id); } } @@ -2681,7 +2681,7 @@ void MainWindow::openWildMonTable(const QString &mapName, const QString &groupNa if (userSetMap(mapName)) { // Switch to the correct main tab, wild encounter group, and wild encounter type tab. on_mainTabBar_tabBarClicked(MainTab::WildPokemon); - ui->comboBox_EncounterGroupLabel->setCurrentText(groupName); + ui->comboBox_EncounterGroupLabel->setTextItem(groupName); QWidget *w = ui->stackedWidget_WildMons->currentWidget(); if (w) static_cast(w)->setCurrentField(fieldName); } diff --git a/src/ui/connectionslistitem.cpp b/src/ui/connectionslistitem.cpp index 86df9525..b773f752 100644 --- a/src/ui/connectionslistitem.cpp +++ b/src/ui/connectionslistitem.cpp @@ -106,7 +106,7 @@ void ConnectionsListItem::commitDirection() { if (MapConnection::isDiving(direction)) { // Diving maps are displayed separately, no support right now for replacing a list item with a diving map. // For now just restore the original direction. - ui->comboBox_Direction->setCurrentText(this->connection->direction()); + ui->comboBox_Direction->setTextItem(this->connection->direction()); return; } diff --git a/src/ui/divingmappixmapitem.cpp b/src/ui/divingmappixmapitem.cpp index b774b1e9..550e0037 100644 --- a/src/ui/divingmappixmapitem.cpp +++ b/src/ui/divingmappixmapitem.cpp @@ -1,7 +1,7 @@ #include "divingmappixmapitem.h" #include "config.h" -DivingMapPixmapItem::DivingMapPixmapItem(MapConnection *connection, QComboBox *combo) +DivingMapPixmapItem::DivingMapPixmapItem(MapConnection *connection, NoScrollComboBox *combo) : QGraphicsPixmapItem(getBasePixmap(connection)) { m_connection = connection; @@ -38,5 +38,5 @@ void DivingMapPixmapItem::onTargetMapChanged() { } void DivingMapPixmapItem::setComboText(const QString &text) { - if (m_combo) m_combo->setCurrentText(text); + if (m_combo) m_combo->setTextItem(text); } diff --git a/src/ui/encountertabledelegates.cpp b/src/ui/encountertabledelegates.cpp index 2d46f54f..12e105bb 100644 --- a/src/ui/encountertabledelegates.cpp +++ b/src/ui/encountertabledelegates.cpp @@ -28,7 +28,7 @@ QWidget *SpeciesComboDelegate::createEditor(QWidget *parent, const QStyleOptionV void SpeciesComboDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString species = index.data(Qt::EditRole).toString(); NoScrollComboBox *combo = static_cast(editor); - combo->setCurrentText(species); + combo->setTextItem(species); } void SpeciesComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { diff --git a/src/ui/eventframes.cpp b/src/ui/eventframes.cpp index 95a31557..51293dd5 100644 --- a/src/ui/eventframes.cpp +++ b/src/ui/eventframes.cpp @@ -181,7 +181,7 @@ void EventFrame::populateDropdown(NoScrollComboBox * combo, const QStringList &i const QString savedText = combo->currentText(); combo->clear(); combo->addItems(items); - combo->setCurrentText(savedText); + combo->setTextItem(savedText); } void EventFrame::populateScriptDropdown(NoScrollComboBox * combo, Project * project) { @@ -419,7 +419,7 @@ void ObjectFrame::initialize() { this->spinner_radius_y->setValue(this->object->getRadiusY()); // script - this->combo_script->setCurrentText(this->object->getScript()); + this->combo_script->setTextItem(this->object->getScript()); if (porymapConfig.textEditorGotoLine.isEmpty()) this->button_script->hide(); @@ -430,7 +430,7 @@ void ObjectFrame::initialize() { this->combo_trainer_type->setTextItem(this->object->getTrainerType()); // sight berry - this->combo_radius_treeid->setCurrentText(this->object->getSightRadiusBerryTreeID()); + this->combo_radius_treeid->setTextItem(this->object->getSightRadiusBerryTreeID()); } void ObjectFrame::populate(Project *project) { @@ -515,7 +515,7 @@ void CloneObjectFrame::connectSignals(MainWindow *window) { connect(this->combo_target_map, &QComboBox::currentTextChanged, [this, project](const QString &mapName) { this->clone->setTargetMap(mapName); this->clone->getPixmapItem()->render(project); - this->combo_sprite->setCurrentText(this->clone->getGfx()); + this->combo_sprite->setTextItem(this->clone->getGfx()); this->clone->modify(); populateIdNameDropdown(this->combo_target_id, project, mapName, Event::Group::Object); }); @@ -526,7 +526,7 @@ void CloneObjectFrame::connectSignals(MainWindow *window) { connect(this->combo_target_id, &QComboBox::currentTextChanged, [this, project](const QString &text) { this->clone->setTargetID(text); this->clone->getPixmapItem()->render(project); - this->combo_sprite->setCurrentText(this->clone->getGfx()); + this->combo_sprite->setTextItem(this->clone->getGfx()); this->clone->modify(); }); @@ -552,10 +552,10 @@ void CloneObjectFrame::initialize() { this->line_edit_local_id->setText(this->clone->getIdName()); // sprite - this->combo_sprite->setCurrentText(this->clone->getGfx()); + this->combo_sprite->setTextItem(this->clone->getGfx()); // target id - this->combo_target_id->setCurrentText(this->clone->getTargetID()); + this->combo_target_id->setTextItem(this->clone->getTargetID()); // target map this->combo_target_map->setTextItem(this->clone->getTargetMap()); @@ -672,7 +672,7 @@ void WarpFrame::initialize() { this->combo_dest_map->setTextItem(this->warp->getDestinationMap()); // dest id - this->combo_dest_warp->setCurrentText(this->warp->getDestinationWarpID()); + this->combo_dest_warp->setTextItem(this->warp->getDestinationWarpID()); } void WarpFrame::populate(Project *project) { @@ -753,13 +753,13 @@ void TriggerFrame::initialize() { EventFrame::initialize(); // script - this->combo_script->setCurrentText(this->trigger->getScriptLabel()); + this->combo_script->setTextItem(this->trigger->getScriptLabel()); // var this->combo_var->setTextItem(this->trigger->getScriptVar()); // var value - this->combo_var_value->setCurrentText(this->trigger->getScriptVarValue()); + this->combo_var_value->setTextItem(this->trigger->getScriptVarValue()); } void TriggerFrame::populate(Project *project) { @@ -876,7 +876,7 @@ void SignFrame::initialize() { this->combo_facing_dir->setTextItem(this->sign->getFacingDirection()); // script - this->combo_script->setCurrentText(this->sign->getScriptLabel()); + this->combo_script->setTextItem(this->sign->getScriptLabel()); } void SignFrame::populate(Project *project) { diff --git a/src/ui/gridsettings.cpp b/src/ui/gridsettings.cpp index 87e0896a..4e36b60d 100644 --- a/src/ui/gridsettings.cpp +++ b/src/ui/gridsettings.cpp @@ -144,7 +144,7 @@ void GridSettingsDialog::updateInput() { ui->colorInput->setColor(m_settings->color.rgb()); const QSignalBlocker b_Style(ui->comboBox_Style); - ui->comboBox_Style->setCurrentText(GridSettings::getStyleName(m_settings->style)); + ui->comboBox_Style->setTextItem(GridSettings::getStyleName(m_settings->style)); } void GridSettingsDialog::setWidth(int value) { diff --git a/src/ui/mapheaderform.cpp b/src/ui/mapheaderform.cpp index a2a0b8b5..991fe1c5 100644 --- a/src/ui/mapheaderform.cpp +++ b/src/ui/mapheaderform.cpp @@ -1,6 +1,5 @@ #include "mapheaderform.h" #include "ui_mapheaderform.h" -#include "project.h" MapHeaderForm::MapHeaderForm(QWidget *parent) : QWidget(parent) @@ -94,7 +93,7 @@ void MapHeaderForm::setLocations(const QStringList &locations) { const QString before = ui->comboBox_Location->currentText(); ui->comboBox_Location->clear(); ui->comboBox_Location->addItems(locations); - ui->comboBox_Location->setCurrentText(before); + ui->comboBox_Location->setTextItem(before); } // Assign a MapHeader that the form will keep in sync with the UI. @@ -187,10 +186,10 @@ void MapHeaderForm::setAllowsBiking(bool allowsBiking) { ui->checkBox_ 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 we always call setText / setTextItem the user's cursor may move to the end of the text while they're typing. +void MapHeaderForm::setText(NoScrollComboBox *combo, const QString &text) const { if (combo->currentText() != text) - combo->setCurrentText(text); + combo->setTextItem(text); } void MapHeaderForm::setText(QLineEdit *lineEdit, const QString &text) const { if (lineEdit->text() != text) diff --git a/src/ui/mapimageexporter.cpp b/src/ui/mapimageexporter.cpp index 732d3e83..05664aef 100644 --- a/src/ui/mapimageexporter.cpp +++ b/src/ui/mapimageexporter.cpp @@ -101,11 +101,11 @@ void MapImageExporter::setModeSpecificUi() { ui->comboBox_MapSelection->clear(); if (m_map) { ui->comboBox_MapSelection->addItems(m_project->mapNames); - ui->comboBox_MapSelection->setCurrentText(m_map->name()); + ui->comboBox_MapSelection->setTextItem(m_map->name()); ui->label_MapSelection->setText(m_mode == ImageExporterMode::Stitch ? QStringLiteral("Starting Map") : QStringLiteral("Map")); } else if (m_layout) { ui->comboBox_MapSelection->addItems(m_project->layoutIds); - ui->comboBox_MapSelection->setCurrentText(m_layout->id); + ui->comboBox_MapSelection->setTextItem(m_layout->id); ui->label_MapSelection->setText(QStringLiteral("Layout")); } @@ -146,7 +146,7 @@ void MapImageExporter::setLayout(Layout *layout) { void MapImageExporter::setSelectionText(const QString &text) { const QSignalBlocker b(ui->comboBox_MapSelection); - ui->comboBox_MapSelection->setCurrentText(text); + ui->comboBox_MapSelection->setTextItem(text); updateMapSelection(); } @@ -171,7 +171,7 @@ void MapImageExporter::updateMapSelection() { // Ensure text in the combo box remains valid const QSignalBlocker b(ui->comboBox_MapSelection); - ui->comboBox_MapSelection->setCurrentText(m_map ? m_map->name() : m_layout->id); + ui->comboBox_MapSelection->setTextItem(m_map ? m_map->name() : m_layout->id); if (m_map != oldMap && (!m_map || !oldMap)) { // Switching to or from layout-only mode diff --git a/src/ui/newmapdialog.cpp b/src/ui/newmapdialog.cpp index caa1e839..36819404 100644 --- a/src/ui/newmapdialog.cpp +++ b/src/ui/newmapdialog.cpp @@ -167,7 +167,7 @@ void NewMapDialog::on_lineEdit_Name_textChanged(const QString &text) { // Changing the map name updates the layout ID field to match. if (ui->comboBox_LayoutID->isEnabled()) { - ui->comboBox_LayoutID->setCurrentText(Layout::layoutConstantFromName(text)); + ui->comboBox_LayoutID->setTextItem(Layout::layoutConstantFromName(text)); } } diff --git a/src/ui/preferenceeditor.cpp b/src/ui/preferenceeditor.cpp index f9071ec2..1289fe79 100644 --- a/src/ui/preferenceeditor.cpp +++ b/src/ui/preferenceeditor.cpp @@ -44,7 +44,7 @@ void PreferenceEditor::initFields() { } void PreferenceEditor::updateFields() { - themeSelector->setCurrentText(porymapConfig.theme); + themeSelector->setTextItem(porymapConfig.theme); if (porymapConfig.eventSelectionShapeMode == QGraphicsPixmapItem::MaskShape) { ui->radioButton_OnSprite->setChecked(true); } else if (porymapConfig.eventSelectionShapeMode == QGraphicsPixmapItem::BoundingRectShape) { diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index 493ea78e..0415e0f0 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -657,7 +657,7 @@ void RegionMapEditor::displayRegionMapLayoutOptions() { void RegionMapEditor::updateRegionMapLayoutOptions(int index) { const QSignalBlocker b_ConnectedMap(ui->comboBox_RM_ConnectedMap); - this->ui->comboBox_RM_ConnectedMap->setCurrentText(this->region_map->squareMapSection(index)); + this->ui->comboBox_RM_ConnectedMap->setTextItem(this->region_map->squareMapSection(index)); this->ui->pushButton_RM_Options_delete->setEnabled(this->region_map->squareHasMap(index)); @@ -736,7 +736,7 @@ void RegionMapEditor::updateRegionMapEntryOptions(QString section) { this->ui->pushButton_entryActivate->setEnabled(section != this->region_map->default_map_section); this->ui->pushButton_entryActivate->setText(enabled ? "Remove" : "Add"); - this->ui->comboBox_RM_Entry_MapSection->setCurrentText(section); + this->ui->comboBox_RM_Entry_MapSection->setTextItem(section); this->activeEntry = section; this->region_map_entries_item->currentSection = section; MapSectionEntry entry = enabled ? this->region_map_entries[section] : MapSectionEntry(); @@ -1296,11 +1296,11 @@ void RegionMapEditor::setLocations(const QStringList &locations) { auto before = ui->comboBox_RM_ConnectedMap->currentText(); ui->comboBox_RM_ConnectedMap->clear(); ui->comboBox_RM_ConnectedMap->addItems(locations); - ui->comboBox_RM_ConnectedMap->setCurrentText(before); + ui->comboBox_RM_ConnectedMap->setTextItem(before); const QSignalBlocker b_MapSection(ui->comboBox_RM_Entry_MapSection); before = ui->comboBox_RM_Entry_MapSection->currentText(); ui->comboBox_RM_Entry_MapSection->clear(); ui->comboBox_RM_Entry_MapSection->addItems(locations); - ui->comboBox_RM_Entry_MapSection->setCurrentText(before); + ui->comboBox_RM_Entry_MapSection->setTextItem(before); } diff --git a/src/ui/wildmonchart.cpp b/src/ui/wildmonchart.cpp index 521706d6..c6e18284 100644 --- a/src/ui/wildmonchart.cpp +++ b/src/ui/wildmonchart.cpp @@ -312,7 +312,7 @@ QBarSet* WildMonChart::createLevelDistributionBarSet(const QString &species, con const QSignalBlocker blocker1(ui->groupBox_Species); const QSignalBlocker blocker2(ui->comboBox_Species); ui->groupBox_Species->setChecked(true); - ui->comboBox_Species->setCurrentText(species); + ui->comboBox_Species->setTextItem(species); refreshLevelDistributionChart(); }); }