1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include "populateconfigdialog.h"
#include "ui_populateconfigdialog.h"
#include "plugins/populateplugin.h"
#include "services/populatemanager.h"
#include "formmanager.h"
#include "configmapper.h"
#include "mainwindow.h"
#include "uiutils.h"
#include <QPushButton>
#include <QDebug>
#include <QSpinBox>
PopulateConfigDialog::PopulateConfigDialog(PopulateEngine* engine, const QString& column, const QString& pluginName, QWidget *parent) :
QDialog(parent),
ui(new Ui::PopulateConfigDialog),
engine(engine),
column(column),
pluginName(pluginName)
{
init();
}
PopulateConfigDialog::~PopulateConfigDialog()
{
safe_delete(configMapper);
delete ui;
}
int PopulateConfigDialog::exec()
{
QString formName = engine->getPopulateConfigFormName();
if (formName.isNull())
{
qCritical() << "Null form name from populating engine.";
return QDialog::Rejected;
}
innerWidget = FORMS->createWidget(formName);
if (!innerWidget)
return QDialog::Rejected;
configMapper->bindToConfig(innerWidget);
ui->contents->layout()->addWidget(innerWidget);
adjustSize();
validateEngine();
return QDialog::exec();
}
void PopulateConfigDialog::init()
{
ui->setupUi(this);
limitDialogWidth(this);
QString headerString = tr("Configuring <b>%1</b> for column <b>%2</b>").arg(pluginName, column);
ui->headerLabel->setText(headerString );
configMapper = new ConfigMapper(engine->getConfig());
connect(configMapper, SIGNAL(modified(QWidget*)), this, SLOT(validateEngine()));
connect(POPULATE_MANAGER, SIGNAL(validationResultFromPlugin(bool,CfgEntry*,QString)), this, SLOT(validationResultFromPlugin(bool,CfgEntry*,QString)));
connect(POPULATE_MANAGER, SIGNAL(stateUpdateRequestFromPlugin(CfgEntry*,bool,bool)), this, SLOT(stateUpdateRequestFromPlugin(CfgEntry*,bool,bool)));
connect(POPULATE_MANAGER, SIGNAL(widgetPropertyFromPlugin(CfgEntry*,QString,QVariant)), this, SLOT(widgetPropertyFromPlugin(CfgEntry*,QString,QVariant)));
}
void PopulateConfigDialog::validateEngine()
{
engine->validateOptions();
}
void PopulateConfigDialog::validationResultFromPlugin(bool valid, CfgEntry* key, const QString& msg)
{
QWidget* w = configMapper->getBindWidgetForConfig(key);
if (w)
setValidState(w, valid, msg);
if (valid == pluginConfigOk.contains(key)) // if state changed
{
if (!valid)
pluginConfigOk[key] = false;
else
pluginConfigOk.remove(key);
}
updateState();
}
void PopulateConfigDialog::stateUpdateRequestFromPlugin(CfgEntry* key, bool visible, bool enabled)
{
QWidget* w = configMapper->getBindWidgetForConfig(key);
if (!w)
return;
w->setVisible(visible);
w->setEnabled(enabled);
}
void PopulateConfigDialog::widgetPropertyFromPlugin(CfgEntry* key, const QString& propName, const QVariant& value)
{
QWidget* w = configMapper->getBindWidgetForConfig(key);
if (!w)
return;
w->setProperty(propName.toLatin1().constData(), value);
}
void PopulateConfigDialog::updateState()
{
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(pluginConfigOk.size() == 0);
}
void PopulateConfigDialog::showEvent(QShowEvent* e)
{
QVariant prop = innerWidget->property("initialSize");
if (prop.isValid())
resize(prop.toSize() + QSize(0, ui->headerLabel->height() + ui->line->height()));
QDialog::showEvent(e);
}
|