Qt/CheatSearchWidget: Add a checkbox to force parsing a value as hexadecimal.

This commit is contained in:
Admiral H. Curtiss
2021-10-28 02:00:38 +02:00
parent b3e17d2772
commit 6e814cbb8f
4 changed files with 49 additions and 15 deletions

View File

@ -57,6 +57,7 @@ CheatSearchWidget::CheatSearchWidget(std::unique_ptr<Cheats::CheatSearchSessionB
setAttribute(Qt::WA_DeleteOnClose);
CreateWidgets();
ConnectWidgets();
OnValueSourceChanged();
UpdateGuiTable();
}
@ -157,16 +158,14 @@ void CheatSearchWidget::CreateWidgets()
session_info_label->setText(tr("%1, %2, %3, %4").arg(ranges).arg(space).arg(type).arg(aligned));
}
auto* value_layout = new QHBoxLayout();
// i18n: This label is followed by a dropdown where the user can select things like "is equal to"
// or "is less than or equal to", followed by another dropdown where the user can select "any
// value", "last value", or "this value:". These three UI elements are intended to form a sentence
// together. Because the UI elements can't be reordered by a translation, you may have to give
// up on the idea of having them form a sentence depending on the grammar of your target language.
auto* instructions_label = new QLabel(tr("Keep addresses where value in memory"));
value_layout->addWidget(instructions_label);
auto* value_layout = new QHBoxLayout();
m_compare_type_dropdown = new QComboBox();
m_compare_type_dropdown->addItem(tr("is equal to"),
QVariant::fromValue(Cheats::CompareType::Equal));
@ -194,6 +193,9 @@ void CheatSearchWidget::CreateWidgets()
m_given_value_text = new QLineEdit();
value_layout->addWidget(m_given_value_text);
m_parse_values_as_hex_checkbox = new QCheckBox(tr("Parse as Hex"));
value_layout->addWidget(m_parse_values_as_hex_checkbox);
auto* button_layout = new QHBoxLayout();
m_next_scan_button = new QPushButton(tr("Search and Filter"));
button_layout->addWidget(m_next_scan_button);
@ -212,6 +214,7 @@ void CheatSearchWidget::CreateWidgets()
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(session_info_label);
layout->addWidget(instructions_label);
layout->addLayout(value_layout);
layout->addLayout(button_layout);
layout->addWidget(m_display_values_in_hex_checkbox);
@ -234,7 +237,7 @@ void CheatSearchWidget::ConnectWidgets()
connect(m_value_source_dropdown, &QComboBox::currentTextChanged, this,
&CheatSearchWidget::OnValueSourceChanged);
connect(m_display_values_in_hex_checkbox, &QCheckBox::toggled, this,
&CheatSearchWidget::OnHexCheckboxStateChanged);
&CheatSearchWidget::OnDisplayHexCheckboxStateChanged);
}
void CheatSearchWidget::OnNextScanClicked()
@ -253,7 +256,8 @@ void CheatSearchWidget::OnNextScanClicked()
m_session->SetCompareType(m_compare_type_dropdown->currentData().value<Cheats::CompareType>());
if (filter_type == Cheats::FilterType::CompareAgainstSpecificValue)
{
if (!m_session->SetValueFromString(m_given_value_text->text().toStdString()))
if (!m_session->SetValueFromString(m_given_value_text->text().toStdString(),
m_parse_values_as_hex_checkbox->isChecked()))
{
m_info_label_1->setText(tr("Failed to parse given value into target data type."));
return;
@ -431,10 +435,12 @@ void CheatSearchWidget::OnAddressTableContextMenu()
void CheatSearchWidget::OnValueSourceChanged()
{
const auto filter_type = m_value_source_dropdown->currentData().value<Cheats::FilterType>();
m_given_value_text->setEnabled(filter_type == Cheats::FilterType::CompareAgainstSpecificValue);
const bool is_value_search = filter_type == Cheats::FilterType::CompareAgainstSpecificValue;
m_given_value_text->setEnabled(is_value_search);
m_parse_values_as_hex_checkbox->setEnabled(is_value_search && m_session->IsIntegerType());
}
void CheatSearchWidget::OnHexCheckboxStateChanged()
void CheatSearchWidget::OnDisplayHexCheckboxStateChanged()
{
if (!m_session->WasFirstSearchDone())
return;

View File

@ -52,7 +52,7 @@ private:
void OnAddressTableItemChanged(QTableWidgetItem* item);
void OnAddressTableContextMenu();
void OnValueSourceChanged();
void OnHexCheckboxStateChanged();
void OnDisplayHexCheckboxStateChanged();
bool RefreshValues();
void UpdateGuiTable();
@ -75,6 +75,7 @@ private:
QPushButton* m_next_scan_button;
QPushButton* m_refresh_values_button;
QPushButton* m_reset_button;
QCheckBox* m_parse_values_as_hex_checkbox;
QCheckBox* m_display_values_in_hex_checkbox;
QTableWidget* m_address_table;
};