ARWidget: Disable Edit and Remove buttons when no code is selected

Also some minor refactoring of nearby/related code:
* Make non-obvious variable types explicit instead of auto.
* Throw some consts around.
* Use setDisabled(empty) instead of setEnabled(!empty).
This commit is contained in:
Dentomologist 2024-08-25 15:33:41 -07:00
parent 5af0ae25e6
commit ee35aa49a2
2 changed files with 15 additions and 12 deletions

View File

@ -67,8 +67,8 @@ void ARCodeWidget::CreateWidgets()
m_code_list->setEnabled(!m_game_id.empty()); m_code_list->setEnabled(!m_game_id.empty());
m_code_add->setEnabled(!m_game_id.empty()); m_code_add->setEnabled(!m_game_id.empty());
m_code_edit->setEnabled(!m_game_id.empty()); m_code_edit->setEnabled(false);
m_code_remove->setEnabled(!m_game_id.empty()); m_code_remove->setEnabled(false);
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu); m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
@ -179,14 +179,18 @@ void ARCodeWidget::OnListReordered()
void ARCodeWidget::OnSelectionChanged() void ARCodeWidget::OnSelectionChanged()
{ {
auto items = m_code_list->selectedItems(); const QList<QListWidgetItem*> items = m_code_list->selectedItems();
const bool empty = items.empty();
if (items.empty()) m_code_edit->setDisabled(empty);
m_code_remove->setDisabled(empty);
if (empty)
return; return;
const auto* selected = items[0]; const QListWidgetItem* const selected = items[0];
bool user_defined = m_ar_codes[m_code_list->row(selected)].user_defined; const bool user_defined = m_ar_codes[m_code_list->row(selected)].user_defined;
m_code_remove->setEnabled(user_defined); m_code_remove->setEnabled(user_defined);
m_code_edit->setText(user_defined ? tr("&Edit Code...") : tr("Clone and &Edit Code...")); m_code_edit->setText(user_defined ? tr("&Edit Code...") : tr("Clone and &Edit Code..."));

View File

@ -166,17 +166,16 @@ void GeckoCodeWidget::ConnectWidgets()
void GeckoCodeWidget::OnSelectionChanged() void GeckoCodeWidget::OnSelectionChanged()
{ {
auto items = m_code_list->selectedItems(); const QList<QListWidgetItem*> items = m_code_list->selectedItems();
const bool empty = items.empty(); const bool empty = items.empty();
m_edit_code->setEnabled(!empty); m_edit_code->setDisabled(empty);
m_remove_code->setEnabled(!empty); m_remove_code->setDisabled(empty);
if (items.empty()) if (empty)
return; return;
auto selected = items[0]; const QListWidgetItem* const selected = items[0];
const int index = selected->data(Qt::UserRole).toInt(); const int index = selected->data(Qt::UserRole).toInt();