63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
#include "SetScalesform.h"
|
||
#include "ui_SetScalesForm.h"
|
||
#include "QMessageBox"
|
||
#include <qvalidator.h>
|
||
|
||
SetScalesForm::SetScalesForm(QString m_strSacles,QWidget *parent) :
|
||
BaseWgt(parent),
|
||
ui(new Ui::SetScalesForm)
|
||
{
|
||
ui->setupUi(m_pMainWgt);
|
||
resize(500,320);
|
||
setWindowTitle("设置坐标范围");
|
||
connect(ui->Btn_OK, SIGNAL(clicked()), this, SLOT(SetScales()));
|
||
connect(ui->Btn_Cancel, SIGNAL(clicked()), this, SLOT(Cancel()));
|
||
QRegExp rx("^(-?[0-9])|(-?\\d+)(\.\\d+)$");
|
||
QRegExpValidator *validator = new QRegExpValidator(rx, this);
|
||
ui->lineEdit->setValidator(validator);
|
||
ui->lineEdit_2->setValidator(validator);
|
||
ui->lineEdit_3->setValidator(validator);
|
||
ui->lineEdit_4->setValidator(validator);
|
||
QStringList strList = m_strSacles.split(",");
|
||
ui->lineEdit->setText(strList[0]);
|
||
ui->lineEdit_2->setText(strList[1]);
|
||
ui->lineEdit_3->setText(strList[2]);
|
||
ui->lineEdit_4->setText(strList[3]);
|
||
}
|
||
|
||
SetScalesForm::~SetScalesForm()
|
||
{
|
||
delete ui;
|
||
}
|
||
void SetScalesForm::Cancel()
|
||
{
|
||
this->close();
|
||
}
|
||
void SetScalesForm::SetScales()
|
||
{
|
||
QString Xstart = ui->lineEdit->text();
|
||
QString Xend = ui->lineEdit_2->text();
|
||
QString Ystart = ui->lineEdit_3->text();
|
||
QString Yend = ui->lineEdit_4->text();
|
||
if((Xstart.length() == 0 || Xend.length() == 0) && (Ystart.length() == 0 || Yend.length() == 0))
|
||
{
|
||
MyMsgBox(QMessageBox::Question,"问题","请输入正确的坐标信息");
|
||
return;
|
||
}
|
||
if(Xstart.toFloat() > Xend.toFloat() || Ystart.toFloat() > Yend.toFloat())
|
||
{
|
||
MyMsgBox(QMessageBox::Question,"问题","请输入正确的坐标信息");
|
||
return;
|
||
}
|
||
emit sgSetScales(Xstart+","+Xend+","+Ystart + "," + Yend);
|
||
this->close();
|
||
}
|
||
void SetScalesForm::keyPressEvent(QKeyEvent *event)
|
||
{
|
||
//Enter事件好像这两个都要写,只写event->key() == Qt::Key_Enter,无法实现
|
||
if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)
|
||
{
|
||
SetScales();
|
||
}
|
||
}
|