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

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

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

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

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

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

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->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
    else
        ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
