setvaluedialog.cpp 998 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "setvaluedialog.h"
  2. #include "ui_setvaluedialog.h"
  3. SetValueDialog::SetValueDialog(QWidget* parent)
  4. : QDialog(parent)
  5. , ui(new Ui::SetValueDialog)
  6. {
  7. ui->setupUi(this);
  8. }
  9. SetValueDialog::~SetValueDialog()
  10. {
  11. delete ui;
  12. }
  13. void SetValueDialog::setValue(QString& value)
  14. {
  15. ui->edtValue->setText(value);
  16. }
  17. void SetValueDialog::setCaption(QString caption)
  18. {
  19. ui->lblCaption->setText(caption + ":");
  20. }
  21. QString SetValueDialog::value()
  22. {
  23. return ui->edtValue->text();
  24. }
  25. void SetValueDialog::on_btnCancel_clicked()
  26. {
  27. reject();
  28. }
  29. void SetValueDialog::on_btnOk_clicked()
  30. {
  31. accept();
  32. }
  33. bool setValue(QString title, QString caption, QString& value)
  34. {
  35. bool f = false;
  36. SetValueDialog* dlg = new SetValueDialog(nullptr);
  37. dlg->setWindowTitle(title);
  38. dlg->setCaption(caption);
  39. dlg->setValue(value);
  40. int ret = dlg->exec();
  41. if (ret == QDialog::Accepted) {
  42. value = dlg->value();
  43. f = true;
  44. }
  45. delete dlg;
  46. return f;
  47. }