You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
prodejna/core/settingsform.cpp

65 lines
1.3 KiB
C++

#include "settingsform.h"
#include "ui_settingsform.h"
#include "settingsservice.h"
#include "context.h"
#include "iplugin.h"
#include "iform.h"
#include <QMessageBox>
SettingsForm::SettingsForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsForm)
{
ui->setupUi(this);
foreach (IPlugin *plugin, Context::instance().plugins()) {
if (plugin->settingsUi() != nullptr)
{
SettingsService srv(plugin->pluginId());
IForm *tab = qobject_cast<IForm*>(plugin->settingsUi());
if (tab != nullptr)
{
tab->loadEntity();
ui->tabWidget->addTab(tab, QIcon(), plugin->settingsTabLabel());
}
}
}
}
SettingsForm::~SettingsForm()
{
delete ui;
}
void SettingsForm::on_buttonBox_accepted()
{
accept();
}
void SettingsForm::accept()
{
if (!Context::instance().currentUser()->isAdmin())
{
QMessageBox::critical(this, tr("Permission denied"), tr("You don't have permission to save settings."));
return;
}
for (int i = 0; i < ui->tabWidget->count(); i++)
{
IForm *tab = qobject_cast<IForm*>(ui->tabWidget->widget(i));
if (tab != NULL)
{
tab->saveRecord();
}
}
QDialog::accept();
}
void SettingsForm::on_buttonBox_rejected()
{
reject();
}