#include "RasterVRT2ENVIdataDialog.h"
#include "ui_RasterVRT2ENVIdataDialog.h"
#include "BaseConstVariable.h"
#include "BaseTool.h"
#include "RasterToolBase.h"
#include "LogInfoCls.h"
#include <QMessageBox>
#include <QFileDialog>
#include "ImageOperatorBase.h"

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

	connect(ui->pushButtonVRTSelect, SIGNAL(clicked()), this, SLOT(onpushButtonVRTSelect_clicked()));
	connect(ui->pushButtonENVIDatSelect, SIGNAL(clicked()), this, SLOT(onpushButtonENVIDatSelect_clicked()));
	connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted()));
	connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected()));

}

RasterVRT2ENVIdataDialog::~RasterVRT2ENVIdataDialog()
{}

void RasterVRT2ENVIdataDialog::onpushButtonVRTSelect_clicked()
{
	QString  fileNames = QFileDialog::getOpenFileName(
		this,                            // 父窗口
		tr(u8"选择L1B数据文件"),               // 标题
		QString(),                       // 默认路径
		tr(ENVI_FILE_FORMAT_FILTER)  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNames.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditVRTPath->setText(fileNames);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void RasterVRT2ENVIdataDialog::onpushButtonENVIDatSelect_clicked()
{
	QString  fileNames = QFileDialog::getSaveFileName(
		this,                            // 父窗口
		tr(u8"选择ENVIData数据文件"),               // 标题
		QString(),                       // 默认路径
		tr(ENVI_FILE_FORMAT_FILTER)  // 文件过滤器
	);
	// 如果用户选择了文件
	if (!fileNames.isEmpty()) {
		QString message = "选择的文件有：\n";
		this->ui->lineEditENVIDatPath->setText(fileNames);
	}
	else {
		QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
	}
}

void RasterVRT2ENVIdataDialog::onbuttonBox_accepted()
{
	QString vrtrasterpath = ui->lineEditVRTPath->text();
	QString envidatapath = ui->lineEditENVIDatPath->text();

	ConvertVrtToEnvi(vrtrasterpath, envidatapath);


	QMessageBox::information(this, tr(u8"提示"), tr(u8"完成"));
}

void RasterVRT2ENVIdataDialog::onbuttonBox_rejected()
{
	this->close();
}
