From 139301c5a12b769d5a13dec55589ed7fb5dc7bdf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 00:23:46 -0400 Subject: profile_select: Return int instead of u32 for GetIndex() Qt uses a signed value to represent indices. We should follow this convention where applicable to avoid unnecessary sign-conversion warnings, as well as making it easier to interoperate with other aspects of Qt. While we're at it, we can also make a sign-conversion explicit. --- src/yuzu/applets/profile_select.cpp | 2 +- src/yuzu/applets/profile_select.h | 4 ++-- src/yuzu/main.cpp | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/yuzu/applets/profile_select.cpp b/src/yuzu/applets/profile_select.cpp index 7fbc9deeb..6696cb532 100644 --- a/src/yuzu/applets/profile_select.cpp +++ b/src/yuzu/applets/profile_select.cpp @@ -136,7 +136,7 @@ bool QtProfileSelectionDialog::GetStatus() const { return ok; } -u32 QtProfileSelectionDialog::GetIndex() const { +int QtProfileSelectionDialog::GetIndex() const { return user_index; } diff --git a/src/yuzu/applets/profile_select.h b/src/yuzu/applets/profile_select.h index 1c2922e54..ff02df93b 100644 --- a/src/yuzu/applets/profile_select.h +++ b/src/yuzu/applets/profile_select.h @@ -30,11 +30,11 @@ public: void reject() override; bool GetStatus() const; - u32 GetIndex() const; + int GetIndex() const; private: bool ok = false; - u32 user_index = 0; + int user_index = 0; void SelectUser(const QModelIndex& index); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index cef2cc1ae..1e24b9028 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -246,7 +246,7 @@ void GMainWindow::ProfileSelectorSelectProfile() { } Service::Account::ProfileManager manager; - const auto uuid = manager.GetUser(dialog.GetIndex()); + const auto uuid = manager.GetUser(static_cast(dialog.GetIndex())); if (!uuid.has_value()) { emit ProfileSelectorFinishedSelection(std::nullopt); return; @@ -904,7 +904,7 @@ void GMainWindow::SelectAndSetCurrentUser() { dialog.exec(); if (dialog.GetStatus()) { - Settings::values.current_user = static_cast(dialog.GetIndex()); + Settings::values.current_user = dialog.GetIndex(); } } @@ -1055,7 +1055,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); ASSERT(program_id != 0); - const auto select_profile = [this]() -> s32 { + const auto select_profile = [this] { QtProfileSelectionDialog dialog(this); dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); @@ -1070,11 +1070,12 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target }; const auto index = select_profile(); - if (index == -1) + if (index == -1) { return; + } Service::Account::ProfileManager manager; - const auto user_id = manager.GetUser(index); + const auto user_id = manager.GetUser(static_cast(index)); ASSERT(user_id); path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, -- cgit v1.2.3 From 802dd3cc95aee9e7ba3a5005e291beb65612b52b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 00:34:42 -0400 Subject: profile_select: Remove unnecessary GetStatus() member function This behavior is already provided by the built-in exec() function. We just need to check the return value of it. --- src/yuzu/applets/profile_select.cpp | 6 ------ src/yuzu/applets/profile_select.h | 6 ++---- src/yuzu/main.cpp | 14 ++++++-------- 3 files changed, 8 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/yuzu/applets/profile_select.cpp b/src/yuzu/applets/profile_select.cpp index 6696cb532..bb8913162 100644 --- a/src/yuzu/applets/profile_select.cpp +++ b/src/yuzu/applets/profile_select.cpp @@ -122,20 +122,14 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(QWidget* parent) QtProfileSelectionDialog::~QtProfileSelectionDialog() = default; void QtProfileSelectionDialog::accept() { - ok = true; QDialog::accept(); } void QtProfileSelectionDialog::reject() { - ok = false; user_index = 0; QDialog::reject(); } -bool QtProfileSelectionDialog::GetStatus() const { - return ok; -} - int QtProfileSelectionDialog::GetIndex() const { return user_index; } diff --git a/src/yuzu/applets/profile_select.h b/src/yuzu/applets/profile_select.h index ff02df93b..1055d4809 100644 --- a/src/yuzu/applets/profile_select.h +++ b/src/yuzu/applets/profile_select.h @@ -29,15 +29,13 @@ public: void accept() override; void reject() override; - bool GetStatus() const; int GetIndex() const; private: - bool ok = false; - int user_index = 0; - void SelectUser(const QModelIndex& index); + int user_index = 0; + QVBoxLayout* layout; QTreeView* tree_view; QStandardItemModel* item_model; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 1e24b9028..cb07b64b8 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -238,9 +238,7 @@ void GMainWindow::ProfileSelectorSelectProfile() { dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); dialog.setWindowModality(Qt::WindowModal); - dialog.exec(); - - if (!dialog.GetStatus()) { + if (dialog.exec() == QDialog::Rejected) { emit ProfileSelectorFinishedSelection(std::nullopt); return; } @@ -901,11 +899,12 @@ void GMainWindow::SelectAndSetCurrentUser() { dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); dialog.setWindowModality(Qt::WindowModal); - dialog.exec(); - if (dialog.GetStatus()) { - Settings::values.current_user = dialog.GetIndex(); + if (dialog.exec() == QDialog::Rejected) { + return; } + + Settings::values.current_user = dialog.GetIndex(); } void GMainWindow::BootGame(const QString& filename) { @@ -1060,9 +1059,8 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); dialog.setWindowModality(Qt::WindowModal); - dialog.exec(); - if (!dialog.GetStatus()) { + if (dialog.exec() == QDialog::Rejected) { return -1; } -- cgit v1.2.3 From cfc9d92b38bae6d9815ae06bbe5e2d800887f897 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 00:52:47 -0400 Subject: yuzu/software_keyboard: Remove unnecessary GetStatus() member function Like with the profile selection dialog, we can just use the result of QDialog's exec() function to determine whether or not a dialog was accepted. --- src/yuzu/applets/software_keyboard.cpp | 6 ------ src/yuzu/applets/software_keyboard.h | 2 -- src/yuzu/main.cpp | 3 +-- 3 files changed, 1 insertion(+), 10 deletions(-) (limited to 'src') diff --git a/src/yuzu/applets/software_keyboard.cpp b/src/yuzu/applets/software_keyboard.cpp index 5223ec977..af36f07c6 100644 --- a/src/yuzu/applets/software_keyboard.cpp +++ b/src/yuzu/applets/software_keyboard.cpp @@ -104,13 +104,11 @@ QtSoftwareKeyboardDialog::QtSoftwareKeyboardDialog( QtSoftwareKeyboardDialog::~QtSoftwareKeyboardDialog() = default; void QtSoftwareKeyboardDialog::accept() { - ok = true; text = line_edit->text().toStdU16String(); QDialog::accept(); } void QtSoftwareKeyboardDialog::reject() { - ok = false; text.clear(); QDialog::reject(); } @@ -119,10 +117,6 @@ std::u16string QtSoftwareKeyboardDialog::GetText() const { return text; } -bool QtSoftwareKeyboardDialog::GetStatus() const { - return ok; -} - QtSoftwareKeyboard::QtSoftwareKeyboard(GMainWindow& main_window) { connect(this, &QtSoftwareKeyboard::MainWindowGetText, &main_window, &GMainWindow::SoftwareKeyboardGetText, Qt::QueuedConnection); diff --git a/src/yuzu/applets/software_keyboard.h b/src/yuzu/applets/software_keyboard.h index 78c5a042b..44bcece75 100644 --- a/src/yuzu/applets/software_keyboard.h +++ b/src/yuzu/applets/software_keyboard.h @@ -36,10 +36,8 @@ public: void reject() override; std::u16string GetText() const; - bool GetStatus() const; private: - bool ok = false; std::u16string text; QDialogButtonBox* buttons; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index cb07b64b8..92de0097e 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -259,9 +259,8 @@ void GMainWindow::SoftwareKeyboardGetText( dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); dialog.setWindowModality(Qt::WindowModal); - dialog.exec(); - if (!dialog.GetStatus()) { + if (dialog.exec() == QDialog::Rejected) { emit SoftwareKeyboardFinishedText(std::nullopt); return; } -- cgit v1.2.3