Qt: Random unimportant stuff

This commit is contained in:
Megamouse 2020-07-04 11:58:25 +02:00
parent 99be645fcc
commit e4a9c177e6
2 changed files with 16 additions and 18 deletions

View file

@ -197,22 +197,22 @@ namespace gui
return; return;
int item_count = table->rowCount(); int item_count = table->rowCount();
bool is_empty = item_count < 1; const bool is_empty = item_count < 1;
if (is_empty) if (is_empty)
table->insertRow(0); table->insertRow(0);
int item_height = table->rowHeight(0); const int item_height = table->rowHeight(0);
if (is_empty) if (is_empty)
{ {
table->clearContents(); table->clearContents();
table->setRowCount(0); table->setRowCount(0);
} }
int available_height = table->rect().height() - table->horizontalHeader()->height() - table->frameWidth() * 2; const int available_height = table->rect().height() - table->horizontalHeader()->height() - table->frameWidth() * 2;
if (available_height < item_height || item_height < 1) if (available_height < item_height || item_height < 1)
return; return;
int new_item_count = available_height / item_height; const int new_item_count = available_height / item_height;
if (new_item_count == item_count) if (new_item_count == item_count)
return; return;

View file

@ -103,9 +103,9 @@ save_data_list_dialog::save_data_list_dialog(const std::vector<SaveDataEntry>& e
connect(m_list, &QTableWidget::cellChanged, [&](int row, int col) connect(m_list, &QTableWidget::cellChanged, [&](int row, int col)
{ {
int originalIndex = m_list->item(row, 0)->data(Qt::UserRole).toInt(); const int originalIndex = m_list->item(row, 0)->data(Qt::UserRole).toInt();
SaveDataEntry originalEntry = m_save_entries[originalIndex]; const SaveDataEntry originalEntry = m_save_entries[originalIndex];
QString originalDirName = qstr(originalEntry.dirName); const QString originalDirName = qstr(originalEntry.dirName);
QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap(); QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
currNotes[originalDirName] = m_list->item(row, col)->text(); currNotes[originalDirName] = m_list->item(row, col)->text();
m_gui_settings->SetValue(gui::m_saveNotes, currNotes); m_gui_settings->SetValue(gui::m_saveNotes, currNotes);
@ -124,7 +124,7 @@ void save_data_list_dialog::UpdateSelectionLabel()
} }
else else
{ {
int entry = m_list->item(m_list->currentRow(), 0)->data(Qt::UserRole).toInt(); const int entry = m_list->item(m_list->currentRow(), 0)->data(Qt::UserRole).toInt();
m_entry_label->setText(tr("Currently Selected: ") + qstr(m_save_entries[entry].dirName)); m_entry_label->setText(tr("Currently Selected: ") + qstr(m_save_entries[entry].dirName));
} }
} }
@ -132,8 +132,7 @@ void save_data_list_dialog::UpdateSelectionLabel()
s32 save_data_list_dialog::GetSelection() s32 save_data_list_dialog::GetSelection()
{ {
int res = result(); if (result() == QDialog::Accepted)
if (res == QDialog::Accepted)
{ {
if (m_entry == selection_code::new_save) if (m_entry == selection_code::new_save)
{ // Save new entry { // Save new entry
@ -159,7 +158,7 @@ void save_data_list_dialog::OnSort(int logicalIndex)
m_sort_ascending = true; m_sort_ascending = true;
} }
m_sort_column = logicalIndex; m_sort_column = logicalIndex;
Qt::SortOrder sort_order = m_sort_ascending ? Qt::AscendingOrder : Qt::DescendingOrder; const Qt::SortOrder sort_order = m_sort_ascending ? Qt::AscendingOrder : Qt::DescendingOrder;
m_list->sortByColumn(m_sort_column, sort_order); m_list->sortByColumn(m_sort_column, sort_order);
} }
} }
@ -167,8 +166,7 @@ void save_data_list_dialog::OnSort(int logicalIndex)
//Display info dialog directly. //Display info dialog directly.
void save_data_list_dialog::OnEntryInfo() void save_data_list_dialog::OnEntryInfo()
{ {
int idx = m_list->currentRow(); if (const int idx = m_list->currentRow(); idx != -1)
if (idx != -1)
{ {
save_data_info_dialog* infoDialog = new save_data_info_dialog(m_save_entries[idx], this); save_data_info_dialog* infoDialog = new save_data_info_dialog(m_save_entries[idx], this);
infoDialog->setModal(true); infoDialog->setModal(true);
@ -181,7 +179,7 @@ void save_data_list_dialog::UpdateList()
m_list->clearContents(); m_list->clearContents();
m_list->setRowCount(::narrow<int>(m_save_entries.size())); m_list->setRowCount(::narrow<int>(m_save_entries.size()));
QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap(); const QVariantMap currNotes = m_gui_settings->GetValue(gui::m_saveNotes).toMap();
int row = 0; int row = 0;
for (const SaveDataEntry& entry: m_save_entries) for (const SaveDataEntry& entry: m_save_entries)
@ -218,15 +216,15 @@ void save_data_list_dialog::UpdateList()
m_list->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); m_list->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
m_list->verticalHeader()->resizeSections(QHeaderView::ResizeToContents); m_list->verticalHeader()->resizeSections(QHeaderView::ResizeToContents);
QSize tableSize = QSize const QSize table_size
( (
m_list->verticalHeader()->width() + m_list->horizontalHeader()->length() + m_list->frameWidth() * 2, m_list->verticalHeader()->width() + m_list->horizontalHeader()->length() + m_list->frameWidth() * 2,
m_list->horizontalHeader()->height() + m_list->verticalHeader()->length() + m_list->frameWidth() * 2 m_list->horizontalHeader()->height() + m_list->verticalHeader()->length() + m_list->frameWidth() * 2
); );
QSize preferredSize = minimumSize().expandedTo(sizeHint() - m_list->sizeHint() + tableSize); const QSize preferred_size = minimumSize().expandedTo(sizeHint() - m_list->sizeHint() + table_size);
QSize maxSize = QSize(preferredSize.width(), static_cast<int>(QGuiApplication::primaryScreen()->geometry().height() * 0.6)); const QSize max_size(preferred_size.width(), static_cast<int>(QGuiApplication::primaryScreen()->geometry().height() * 0.6));
resize(preferredSize.boundedTo(maxSize)); resize(preferred_size.boundedTo(max_size));
} }