#include "QConvertCoordinateSystemDialog.h"
#include "ui_QConvertCoordinateSystemDialog.h"
#include <QFileDialog>
#include <QMessageBox>
#include "ImageOperatorBase.h"

QConvertCoordinateSystemDialog::QConvertCoordinateSystemDialog(QWidget *parent)
	: QDialog(parent),ui(new Ui::QConvertCoordinateSystemDialogClass)
{
	ui->setupUi(this);

	connect(ui->dialogBtn, SIGNAL(accepted()), this, SLOT(onaccepted()));
	connect(ui->dialogBtn, SIGNAL(rejected()), this, SLOT(onrejected()));
	connect(ui->btnSelectInRaster, SIGNAL(clicked(bool)), this, SLOT(onbtnSelectInRasterClicked(bool)));
	connect(ui->btnSelectOutRaster, SIGNAL(clicked(bool)), this, SLOT(onbtnSelectOutRasterClicked(bool)));

}

QConvertCoordinateSystemDialog::~QConvertCoordinateSystemDialog()
{}

void QConvertCoordinateSystemDialog::onaccepted()
{
	QString espgcodestr = this->ui->lineEditEPSGCoder->text().trimmed();

	bool espgcodeflag = false;
	long espgcodeInt = -1;
	espgcodeInt=espgcodestr.toInt(&espgcodeflag);
	if (!espgcodeflag) {
		QMessageBox::warning(this, u8"warning", u8"错误的ESPG代码");
		return;
	}
	else {}
	QString inrasterpath = this->ui->lineEditInRaster->text();
	QString outrasterpath = this->ui->lineEditOutRaster->text();


	ConvertCoordinateSystem(inrasterpath, outrasterpath, espgcodeInt);
	QMessageBox::information(this, tr(u8"info"), tr(u8"completed!!!!"));
}

void QConvertCoordinateSystemDialog::onrejected()
{
	this->close();
}

void QConvertCoordinateSystemDialog::onbtnSelectInRasterClicked(bool flag)
{
	QString fileName = QFileDialog::getOpenFileName(
		this,                           // 父窗口
		tr(u8"选择影像文件"),               // 标题
		QString(),                      // 默认路径
		tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)")  // 文件过滤器
	);

	// 如果用户选择了文件
	if (!fileName.isEmpty()) {
		this->ui->lineEditInRaster->setText(fileName);

	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void QConvertCoordinateSystemDialog::onbtnSelectOutRasterClicked(bool flag)
{
	QString fileName = QFileDialog::getSaveFileName(
		this,                           // 父窗口
		tr(u8"选择影像文件"),               // 标题
		QString(),                      // 默认路径
		tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)")  // 文件过滤器
	);

	// 如果用户选择了文件
	if (!fileName.isEmpty()) {
		this->ui->lineEditOutRaster->setText(fileName);

	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}
