Prefer NoScrollComboBox::setTextItem over setCurrentText

This commit is contained in:
GriffinR 2025-05-01 10:17:51 -04:00
parent 22a36d4664
commit 8245f60e2b
19 changed files with 58 additions and 48 deletions

View File

@ -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.

View File

@ -2733,7 +2733,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_EncounterGroupLabel">
<widget class="NoScrollComboBox" name="comboBox_EncounterGroupLabel">
<property name="sizeAdjustPolicy">
<enum>QComboBox::SizeAdjustPolicy::AdjustToContents</enum>
</property>

View File

@ -10,6 +10,9 @@
<height>380</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::ClickFocus</enum>
</property>
<property name="windowTitle">
<string>Form</string>
</property>

View File

@ -197,7 +197,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_Species">
<widget class="NoScrollComboBox" name="comboBox_Species">
<property name="editable">
<bool>true</bool>
</property>
@ -237,6 +237,11 @@
<extends>QGraphicsView</extends>
<header>QtCharts</header>
</customwidget>
<customwidget>
<class>NoScrollComboBox</class>
<extends>QComboBox</extends>
<header>noscrollcombobox.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/images.qrc"/>

View File

@ -2,6 +2,7 @@
#define DIVINGMAPPIXMAPITEM_H
#include "mapconnection.h"
#include "noscrollcombobox.h"
#include <QGraphicsPixmapItem>
#include <QPointer>
@ -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<MapConnection> m_connection;
QPointer<QComboBox> m_combo;
QPointer<NoScrollComboBox> m_combo;
void setComboText(const QString &text);
static QPixmap getBasePixmap(MapConnection* connection);

View File

@ -12,6 +12,7 @@
#include "mapheader.h"
#include "project.h"
#include "noscrollcombobox.h"
namespace Ui {
class MapHeaderForm;
@ -64,7 +65,7 @@ private:
QPointer<Project> 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();

View File

@ -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<const QString &>::of(&QComboBox::textActivated), [&tempFields, &currentField, &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);

View File

@ -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<MonTabWidget *>(w)->setCurrentField(fieldName);
}

View File

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

View File

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

View File

@ -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<NoScrollComboBox *>(editor);
combo->setCurrentText(species);
combo->setTextItem(species);
}
void SpeciesComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {

View File

@ -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) {

View File

@ -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) {

View File

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

View File

@ -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

View File

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

View File

@ -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) {

View File

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

View File

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