code_app/app/scanner2/dialog_input.cpp

93 lines
2.1 KiB
C++
Raw Permalink Normal View History

#include "dialog_input.h"
#include "ui_dialog_input.h"
#include <qmessagebox.h>
#include <QRegularExpression>
#include <QRegExpValidator>
Dialog_Input::Dialog_Input(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_Input)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
setWindowTitle(tr("configuration scheme name change"));
ui->lineEdit->setMaxLength(20);
QRegExp rx("[^\\s]+$");
QRegExpValidator* validator = new QRegExpValidator(rx, this);
ui->lineEdit->setValidator(validator);
}
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;
// }
if (ui->lineEdit->text().isEmpty())
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("The content can not be empty"), QMessageBox::Ok, this);
msg.exec();
return;
}
val_ = QString::fromStdString(str);
accept();
}
void Dialog_Input::on_pushButton_2_clicked()
{
reject();
}
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_;
}
QString Dialog_Input::getText()
{
QString text = ui->lineEdit->text();
return text.toUtf8();
}
void Dialog_Input::setEditText(const QString& text)
{
ui->lineEdit->setText(text);
ui->lineEdit->selectAll();
}