Commit 4133625d authored by Volker Krause's avatar Volker Krause
Browse files

Implement editing of surveys

parent c247b065
......@@ -40,7 +40,7 @@ SurveyDialog::~SurveyDialog() = default;
Survey SurveyDialog::survey() const
{
Survey s;
Survey s = m_survey;
s.setName(ui->name->text());
s.setUrl(QUrl(ui->url->text()));
s.setTarget(ui->targetExpression->toPlainText());
......@@ -49,6 +49,7 @@ Survey SurveyDialog::survey() const
void SurveyDialog::setSurvey(const Survey& survey)
{
m_survey = survey;
ui->name->setText(survey.name());
ui->url->setText(survey.url().toString());
ui->targetExpression->setPlainText(survey.target());
......
......@@ -18,6 +18,8 @@
#ifndef USERFEEDBACK_CONSOLE_SURVEYDIALOG_H
#define USERFEEDBACK_CONSOLE_SURVEYDIALOG_H
#include <core/survey.h>
#include <QDialog>
#include <memory>
......@@ -32,8 +34,6 @@ namespace Ui
class SurveyDialog;
}
class Survey;
class SurveyDialog : public QDialog
{
Q_OBJECT
......@@ -45,6 +45,7 @@ public:
void setSurvey(const Survey &survey);
private:
Survey m_survey;
std::unique_ptr<Ui::SurveyDialog> ui;
};
......
......@@ -35,16 +35,16 @@ SurveyEditor::SurveyEditor(QWidget* parent) :
{
ui->setupUi(this);
ui->surveyView->setModel(m_surveyModel);
ui->surveyView->addActions({ ui->actionAddSurvey, ui->actionDeleteSurvey });
ui->surveyView->addActions({ ui->actionAddSurvey, ui->actionEditSurvey, ui->actionDeleteSurvey });
connect(ui->surveyView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SurveyEditor::updateActions);
connect(ui->surveyView, &QAbstractItemView::doubleClicked, this, &SurveyEditor::editSurvey);
connect(m_surveyModel, &QAbstractItemModel::modelReset, this, &SurveyEditor::updateActions);
ui->actionAddSurvey->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
connect(ui->actionAddSurvey, &QAction::triggered, this, &SurveyEditor::createSurvey);
ui->actionDeleteSurvey->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
connect(ui->actionEditSurvey, &QAction::triggered, this, &SurveyEditor::editSurvey);
connect(ui->actionDeleteSurvey, &QAction::triggered, this, &SurveyEditor::deleteSurvey);
addActions({ ui->actionAddSurvey, ui->actionDeleteSurvey });
addActions({ ui->actionAddSurvey, ui->actionEditSurvey, ui->actionDeleteSurvey });
updateActions();
}
......@@ -79,6 +79,29 @@ void SurveyEditor::createSurvey()
});
}
void SurveyEditor::editSurvey()
{
if (!m_product.isValid())
return;
const auto selection = ui->surveyView->selectionModel()->selectedRows();
if (selection.isEmpty())
return;
const auto survey = selection.first().data(SurveyModel::SurveyRole).value<Survey>();
SurveyDialog dlg;
dlg.setSurvey(survey);
if (dlg.exec() != QDialog::Accepted)
return;
auto reply = RESTApi::updateSurvey(m_restClient, dlg.survey());
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
if (reply->error() != QNetworkReply::NoError)
return;
emit logMessage(QString::fromUtf8(reply->readAll()));
m_surveyModel->reload();
});
}
void SurveyEditor::deleteSurvey()
{
if (!m_product.isValid())
......@@ -108,5 +131,7 @@ void SurveyEditor::deleteSurvey()
void SurveyEditor::updateActions()
{
ui->actionAddSurvey->setEnabled(m_product.isValid());
ui->actionDeleteSurvey->setEnabled(!ui->surveyView->selectionModel()->selectedRows().isEmpty());
const auto hasSelection = !ui->surveyView->selectionModel()->selectedRows().isEmpty();
ui->actionEditSurvey->setEnabled(hasSelection);
ui->actionDeleteSurvey->setEnabled(hasSelection);
}
......@@ -50,6 +50,7 @@ signals:
private:
void createSurvey();
void editSurvey();
void deleteSurvey();
void updateActions();
......
......@@ -38,14 +38,22 @@
</item>
</layout>
<action name="actionAddSurvey">
<property name="icon">
<iconset theme="list-add">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Add Survey...</string>
</property>
<property name="toolTip">
<string>Add new survery.</string>
<string>Add new survey.</string>
</property>
</action>
<action name="actionDeleteSurvey">
<property name="icon">
<iconset theme="list-remove">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Delete Survey</string>
</property>
......@@ -53,6 +61,18 @@
<string>Delete a survey.</string>
</property>
</action>
<action name="actionEditSurvey">
<property name="icon">
<iconset theme="document-edit">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;Edit Survey...</string>
</property>
<property name="toolTip">
<string>Edit the currently selected survey.</string>
</property>
</action>
</widget>
<resources/>
<connections/>
......
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