From 33a177f1eda90b4d1fff92976635beaa59f85172 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Tue, 29 Dec 2020 02:42:07 -0500 Subject: profiles dialog: - added select button - select new profile in the list after creating --- src/profilesdialog.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/profilesdialog.cpp') diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index f1468688..d71a4531 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -115,11 +115,29 @@ void ProfilesDialog::showEvent(QShowEvent *event) } } -void ProfilesDialog::on_closeButton_clicked() +void ProfilesDialog::on_close_clicked() { close(); } +void ProfilesDialog::on_select_clicked() +{ + const Profile::Ptr currentProfile = ui->profilesList->currentItem() + ->data(Qt::UserRole) + .value(); + + if (!currentProfile) { + return; + } + + m_Selected = currentProfile->name(); + close(); +} + +std::optional ProfilesDialog::selectedProfile() const +{ + return m_Selected; +} QListWidgetItem *ProfilesDialog::addItem(const QString &name) { @@ -142,6 +160,7 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings) newItem->setData(Qt::UserRole, QVariant::fromValue(profile)); ui->profilesList->addItem(newItem); m_FailState = false; + ui->profilesList->setCurrentItem(newItem); emit profileCreated(profile.get()); } catch (const std::exception&) { m_FailState = true; @@ -157,6 +176,7 @@ void ProfilesDialog::createProfile(const QString &name, const Profile &reference newItem->setData(Qt::UserRole, QVariant::fromValue(profile)); ui->profilesList->addItem(newItem); m_FailState = false; + ui->profilesList->setCurrentItem(newItem); emit profileCreated(profile.get()); } catch (const std::exception&) { m_FailState = true; @@ -348,6 +368,11 @@ void ProfilesDialog::on_profilesList_currentItemChanged(QListWidgetItem *current } } +void ProfilesDialog::on_profilesList_itemActivated(QListWidgetItem* item) +{ + on_select_clicked(); +} + void ProfilesDialog::on_localSavesBox_stateChanged(int state) { Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); -- cgit v1.3.1