code_app/modules/saneui/dialog_input.cpp

86 lines
1.8 KiB
C++
Raw Normal View History

#include "dialog_input.h"
#include "ui_dialog_input.h"
#include <qmessagebox.h>
#include <QRegularExpression>
Dialog_Input::Dialog_Input(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_Input)
{
ui->setupUi(this);
2023-06-03 09:25:56 +00:00
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
}
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);
2023-06-03 09:25:56 +00:00
// 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);
2023-06-03 09:25:56 +00:00
// return;
// }
2023-06-03 09:25:56 +00:00
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);
2023-06-03 09:25:56 +00:00
accept();
}
void Dialog_Input::on_pushButton_2_clicked()
{
2023-06-03 09:25:56 +00:00
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_;
}
2023-06-03 09:25:56 +00:00
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();
}