#include "dialog_input.h" #include "ui_dialog_input.h" #include #include Dialog_Input::Dialog_Input(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog_Input) { ui->setupUi(this); } Dialog_Input::~Dialog_Input() { delete ui; } void Dialog_Input::on_pushButton_clicked() { QString text = ui->lineEdit->text(); static QRegularExpression re("\\s"); text.remove(re);//Remove space std::string str(text.toStdString()); int pos = 0; while(pos < str.length() && str[pos++] == ' '); if(--pos > 0) str.erase(0, pos); pos = str.length() - 1; while(pos >= 0) { if(str[pos] != ' ') break; } str.erase(pos + 1); if(str.empty()) { QString title(QString::fromStdString("\351\224\231\350\257\257")), text(QString::fromStdString("\350\276\223\345\205\245\351\235\236\346\263\225")); QMessageBox::warning(this, title, text); return; } val_ = QString::fromStdString(str); done(1); } void Dialog_Input::on_pushButton_2_clicked() { done(0); } void Dialog_Input::init_value(const QString& str) { val_ = str; ui->lineEdit->setText(str); ui->lineEdit->setSelection(0, str.length()); } QString Dialog_Input::get_inputting_value(void) { return val_; }