#include "FormBuilder.h"
#include "ComboBoxWidget.h"
#include "LineEditWidget.h"
#include "charcode.h"
#include "PathSelectorWidget.h"
#include "TagEditWidget.h"
#include "AutoCompleteTagEditWidget.h"
#include "DateTimeWidget.h"
#include "charcode.h"

FormBuilder::FormBuilder(QObject *parent)
	: QObject(parent)
    , mainWidget(nullptr)
	, factorys(new WidgetFactory(this))
{
}

FormBuilder::~FormBuilder()
{
}

void FormBuilder::clear()
{
    foreach(auto &item, ixWidgets)
    {
        item.second->clearInput();
    }
}

void FormBuilder::onSavePressed()
{
    foreach(auto &item, ixWidgets)
    {
        if(item.first->getRequired() && item.second->isValueNull() )
        {
            QMessageBox::warning(nullptr, "提示", QString("请输入 %1 ！").arg(item.first->getDescription()));
            return;
        }
    }
    ((QDialog*)(mainWidget->parent()))->accept();
}

QLabel *FormBuilder::buildLabel(QString text, bool required, QWidget *parent)
{
    QLabel* label = new QLabel(parent);
    if (required)
        text = "<span style='color:red;font-size:12pt'>*</span>" + text;
    text += ":";
    label->setText(text);
    return label;
}


bool FormBuilder::isInput(qx::IxDataMember *dataMember)
{
    if (dataMember->getIsPrimaryKey() || dataMember->getPropertyBag("notInput").toBool())
        return false;
    return true;
}





