Commit e04722ed authored by Volker Krause's avatar Volker Krause
Browse files

Validate survey editor input

parent 2863331e
......@@ -66,6 +66,6 @@ set(console_srcs
add_executable(UserFeedbackConsoleApplication ${console_srcs})
set_target_properties(UserFeedbackConsoleApplication PROPERTIES OUTPUT_NAME UserFeedbackConsole)
target_link_libraries(UserFeedbackConsoleApplication Qt5::Widgets Qt5::Network Qt5::Charts UserFeedbackWidgets UserFeedbackConsole)
target_link_libraries(UserFeedbackConsoleApplication Qt5::Widgets Qt5::Network Qt5::Charts UserFeedbackWidgets UserFeedbackConsole UserFeedbackCommon)
install(TARGETS UserFeedbackConsoleApplication ${INSTALL_TARGETS_DEFAULT_ARGS})
......@@ -20,6 +20,8 @@
#include <core/survey.h>
#include <common/surveytargetexpressionparser.h>
#include <QIcon>
#include <QPushButton>
#include <QUrl>
......@@ -34,6 +36,11 @@ SurveyDialog::SurveyDialog(QWidget *parent) :
setWindowIcon(QIcon::fromTheme(QStringLiteral("dialog-question")));
connect(ui->buttonBox->button(QDialogButtonBox::Discard), &QPushButton::clicked, this, &QDialog::reject);
connect(ui->name, &QLineEdit::textChanged, this, &SurveyDialog::updateState);
connect(ui->url, &QLineEdit::textChanged, this, &SurveyDialog::updateState);
connect(ui->targetExpression, &QPlainTextEdit::textChanged, this, &SurveyDialog::updateState);
updateState();
}
SurveyDialog::~SurveyDialog() = default;
......@@ -53,4 +60,20 @@ void SurveyDialog::setSurvey(const Survey& survey)
ui->name->setText(survey.name());
ui->url->setText(survey.url().toString());
ui->targetExpression->setPlainText(survey.target());
updateState();
}
void SurveyDialog::updateState()
{
bool valid = true;
valid &= !ui->name->text().isEmpty();
const auto url = QUrl(ui->url->text());
valid &= url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty();
if (!ui->targetExpression->toPlainText().isEmpty()) {
SurveyTargetExpressionParser p;
valid &= p.parse(ui->targetExpression->toPlainText());
}
ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid);
}
......@@ -45,6 +45,8 @@ public:
void setSurvey(const Survey &survey);
private:
void updateState();
Survey m_survey;
std::unique_ptr<Ui::SurveyDialog> ui;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment