ok/apply/cancle button in settings dialog ok

This commit is contained in:
royqh1979@gmail.com 2021-04-18 00:08:01 +08:00
parent c7a5dda40d
commit 7153fc6f8b
2 changed files with 42 additions and 4 deletions

View File

@ -3,6 +3,7 @@
#include "settingswidget.h" #include "settingswidget.h"
#include "compilersetoptionwidget.h" #include "compilersetoptionwidget.h"
#include <QDebug> #include <QDebug>
#include <QMessageBox>
SettingsDialog::SettingsDialog(QWidget *parent) : SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
@ -57,10 +58,7 @@ void SettingsDialog::on_widgetsView_clicked(const QModelIndex &index)
return; return;
int i = index.data(GetWidgetIndexRole).toInt(); int i = index.data(GetWidgetIndexRole).toInt();
if (i>=0) { if (i>=0) {
if (ui->scrollArea->widget()!=ui->scrollAreaWidgetContents) { saveCurrentPageSettings(true);
//todo save change
}
SettingsWidget* pWidget = mSettingWidgets[i]; SettingsWidget* pWidget = mSettingWidgets[i];
ui->scrollArea->setWidget(pWidget); ui->scrollArea->setWidget(pWidget);
ui->lblWidgetCaption->setText(QString("%1 > %2").arg(pWidget->group()).arg(pWidget->name())); ui->lblWidgetCaption->setText(QString("%1 > %2").arg(pWidget->group()).arg(pWidget->name()));
@ -73,3 +71,36 @@ void SettingsDialog::widget_settings_changed(bool value)
{ {
ui->btnApply->setEnabled(value); ui->btnApply->setEnabled(value);
} }
void SettingsDialog::on_btnCancle_pressed()
{
this->close();
}
void SettingsDialog::on_btnApply_pressed()
{
saveCurrentPageSettings(false);
}
void SettingsDialog::on_btnOk_pressed()
{
saveCurrentPageSettings(false);
this->close();
}
void SettingsDialog::saveCurrentPageSettings(bool confirm)
{
if (ui->scrollArea->widget()!=ui->scrollAreaWidgetContents)
return;
SettingsWidget* pWidget = (SettingsWidget*) ui->scrollArea->widget();
if (!pWidget->isSettingsChanged())
return;
if (confirm) {
if (QMessageBox::information(this,tr("Save Changes"),
tr("There are changes in the settings, do you want to save them before swtich to other page?"),
QMessageBox::Yes, QMessageBox::No)!=QMessageBox::Yes) {
return;
}
pWidget->save();
ui->btnApply->setEnabled(false);
}

View File

@ -29,6 +29,13 @@ private slots:
void widget_settings_changed(bool value); void widget_settings_changed(bool value);
void on_widgetsView_clicked(const QModelIndex &index); void on_widgetsView_clicked(const QModelIndex &index);
void on_btnCancle_pressed();
void on_btnApply_pressed();
void on_btnOk_pressed();
private:
void saveCurrentPageSettings(bool confirm);
private: private:
Ui::SettingsDialog *ui; Ui::SettingsDialog *ui;
QList<SettingsWidget*> mSettingWidgets; QList<SettingsWidget*> mSettingWidgets;