#include "dialogeditgroup.h"
#include "computersLocations.h"
#include <QPushButton>
#include <QRegExpValidator>

DialogEditGroup::DialogEditGroup(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogEditGroup),
    groupInput()
{
    ui->setupUi(this);
    verify();

    ui->editName->setValidator(new QRegExpValidator(QRegExp("[A-Za-zА-Яа-я0-9 _\\d]+"), this));

    ui->editName->setProperty("mandatoryField", true);
}

DialogEditGroup::~DialogEditGroup()
{
    delete ui;
}

void DialogEditGroup::setGroup(Group group)
{
    groupInput = group;

    ui->editName->setText(group.getName());

    ui->btnOK->setEnabled(false);
}

Group DialogEditGroup::getGroup()
{
    Group group = groupInput;

    group.setName(ui->editName->text());

    return group;
}

void DialogEditGroup::on_editName_textChanged(const QString &arg1)
{
    verify();
}

void DialogEditGroup::verify()
{
    if(ui->editName->text().trimmed() == QStringLiteral(""))
        ui->btnOK->setEnabled(false);
    else
        ui->btnOK->setEnabled(true);
}

void DialogEditGroup::on_btnOK_clicked()
{
    this->accept();
}
