diff options
Diffstat (limited to '')
-rwxr-xr-x | src/ui/dialog/QuitDialog.cpp | 43 | ||||
-rwxr-xr-x | src/ui/dialog/QuitDialog.h | 4 | ||||
-rw-r--r-- | src/ui/widgets/TextEdit.cpp | 33 |
3 files changed, 40 insertions, 40 deletions
diff --git a/src/ui/dialog/QuitDialog.cpp b/src/ui/dialog/QuitDialog.cpp index 9df17ce5..7ad6f835 100755 --- a/src/ui/dialog/QuitDialog.cpp +++ b/src/ui/dialog/QuitDialog.cpp @@ -87,17 +87,17 @@ QuitDialog::QuitDialog(QWidget* parent, const QHash<int, QString>& unsavedDocs) "changes before closing?")) % std::to_string(row); auto* warn_label = new QLabel(QString::fromStdString(info.str())); - auto* warnBoxLayout = new QHBoxLayout(); - warnBoxLayout->addWidget(warn_icon); - warnBoxLayout->addWidget(warn_label); - warnBoxLayout->setAlignment(Qt::AlignLeft); - auto* warnBox = new QWidget(this); - warnBox->setLayout(warnBoxLayout); + auto* warn_box_layout = new QHBoxLayout(); + warn_box_layout->addWidget(warn_icon); + warn_box_layout->addWidget(warn_label); + warn_box_layout->setAlignment(Qt::AlignLeft); + auto* warn_box = new QWidget(this); + warn_box->setLayout(warn_box_layout); /* * Two labels on top and under the filelist */ - auto* checkLabel = new QLabel(_("Check the files you want to save:")); + auto* check_label = new QLabel(_("Check the files you want to save:")); auto* note_label = new QLabel( "<b>" + QString(_("Note")) + ":</b>" + _("If you don't save these files, all changes are lost.") + "<br/>"); @@ -105,24 +105,27 @@ QuitDialog::QuitDialog(QWidget* parent, const QHash<int, QString>& unsavedDocs) /* * Buttonbox */ - auto* buttonBox = + auto* button_box = new QDialogButtonBox(QDialogButtonBox::Discard | QDialogButtonBox::Save | QDialogButtonBox::Cancel); - connect(buttonBox, &QDialogButtonBox::accepted, this, &QuitDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, this, &QuitDialog::reject); - QPushButton* btnNoKey = buttonBox->button(QDialogButtonBox::Discard); - connect(btnNoKey, &QPushButton::clicked, this, &QuitDialog::slot_my_discard); + connect(button_box, &QDialogButtonBox::accepted, this, &QuitDialog::accept); + connect(button_box, &QDialogButtonBox::rejected, this, &QuitDialog::reject); + QPushButton* btn_no_key = button_box->button(QDialogButtonBox::Discard); + connect(btn_no_key, &QPushButton::clicked, this, + &QuitDialog::slot_my_discard); /* * Set the layout */ auto* vbox = new QVBoxLayout(); - vbox->addWidget(warnBox); - vbox->addWidget(checkLabel); + vbox->addWidget(warn_box); + vbox->addWidget(check_label); vbox->addWidget(m_fileList_); vbox->addWidget(note_label); - vbox->addWidget(buttonBox); + vbox->addWidget(button_box); this->setLayout(vbox); + + this->movePosition2CenterOfParent(); } void QuitDialog::slot_my_discard() { @@ -130,16 +133,16 @@ void QuitDialog::slot_my_discard() { reject(); } -bool QuitDialog::IsDiscarded() const { return discarded_; } +auto QuitDialog::IsDiscarded() const -> bool { return discarded_; } -QList<int> QuitDialog::GetTabIdsToSave() { - QList<int> tabIdsToSave; +auto QuitDialog::GetTabIdsToSave() -> QList<int> { + QList<int> tab_ids_to_save; for (int i = 0; i < m_fileList_->rowCount(); i++) { if (m_fileList_->item(i, 0)->checkState() == Qt::Checked) { - tabIdsToSave << m_fileList_->item(i, 2)->text().toInt(); + tab_ids_to_save << m_fileList_->item(i, 2)->text().toInt(); } } - return tabIdsToSave; + return tab_ids_to_save; } } // namespace GpgFrontend::UI diff --git a/src/ui/dialog/QuitDialog.h b/src/ui/dialog/QuitDialog.h index f6477e4e..0c25c2c8 100755 --- a/src/ui/dialog/QuitDialog.h +++ b/src/ui/dialog/QuitDialog.h @@ -55,14 +55,14 @@ class QuitDialog : public GeneralDialog { * @return true * @return false */ - [[nodiscard]] bool IsDiscarded() const; + [[nodiscard]] auto IsDiscarded() const -> bool; /** * @brief Get the Tab Ids To Save object * * @return QList<int> */ - QList<int> GetTabIdsToSave(); + auto GetTabIdsToSave() -> QList<int>; private slots: diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 76bede8c..e784ec1f 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -361,32 +361,29 @@ bool TextEdit::MaybeSaveAnyTab() { * more than one unsaved documents */ if (unsaved_docs.size() > 1) { - QHashIterator<int, QString> i(unsaved_docs); + QHashIterator<int, QString> const i(unsaved_docs); QuitDialog* dialog; - dialog = new QuitDialog(this, unsaved_docs); - int result = dialog->exec(); + dialog = new QuitDialog( + this->parentWidget() != nullptr ? this->parentWidget() : this, + unsaved_docs); + int const result = dialog->exec(); // if result is QDialog::Rejected, discard or cancel was clicked if (result == QDialog::Rejected) { // return true, if discard is clicked, so app can be closed - if (dialog->IsDiscarded()) { - return true; - } else { - return false; - } - } else { - bool all_saved = true; - QList<int> tabIdsToSave = dialog->GetTabIdsToSave(); - - for (const auto& tabId : tabIdsToSave) { - tab_widget_->setCurrentIndex(tabId); - if (!maybe_save_current_tab(false)) { - all_saved = false; - } + return dialog->IsDiscarded(); + } + + bool all_saved = true; + QList<int> const tab_ids_to_save = dialog->GetTabIdsToSave(); + for (const auto& tab_id : tab_ids_to_save) { + tab_widget_->setCurrentIndex(tab_id); + if (!maybe_save_current_tab(false)) { + all_saved = false; } - return all_saved; } + return all_saved; } // code should never reach this statement return false; |