101 lines
2.1 KiB
C++
101 lines
2.1 KiB
C++
#include "QtGDALProcessBar.h"
|
|
#include <QCoreApplication>
|
|
|
|
|
|
QtGDALProcessBar::QtGDALProcessBar(QWidget *parent)
|
|
: QProgressBar(parent)
|
|
{
|
|
//ui.setupUi(this);
|
|
this->setTextVisible(true);
|
|
m_dPosition = 0.0;
|
|
m_iStepCount = 100;
|
|
m_iCurStep = 0;
|
|
|
|
|
|
}
|
|
|
|
QtGDALProcessBar::~QtGDALProcessBar()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @brief 设置进度信息
|
|
* @param pszMsg 进度信息
|
|
*/
|
|
void QtGDALProcessBar::SetMessage(const char* pszMsg)
|
|
{
|
|
if (pszMsg != NULL)
|
|
{
|
|
m_strMessage = pszMsg;
|
|
//setLabelText(QString(pszMsg));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 设置进度值
|
|
* @param dPosition 进度值
|
|
*/
|
|
bool QtGDALProcessBar::SetPosition(double dPosition)
|
|
{
|
|
m_dPosition = dPosition;
|
|
//cout << "m_dPosition " << m_dPosition << endl;
|
|
//current_value = value();
|
|
int temp_value = int(m_start_value +std::min(100u, (uint)(m_dPosition * 100.0 )) * m_scale);
|
|
|
|
setValue(temp_value);
|
|
//setFormat(tr("%1%").arg(temp_value));
|
|
//cout << "StepIt " << temp_value << "\t" << "current_value" << int(m_start_value + temp_value * m_scale) << endl;
|
|
//QCoreApplication::instance()->processEvents();
|
|
//this->update();
|
|
//if (this->wasCanceled())
|
|
// return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool QtGDALProcessBar::SetStartEndValue(int i_start_value, int i_end_value)
|
|
{
|
|
if (i_end_value< i_start_value )
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
m_start_value = i_start_value;
|
|
m_end_value = i_end_value;
|
|
m_scale = (m_end_value - m_start_value) / 100.0;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief 进度条前进一步,返回false表示终止操作
|
|
*/
|
|
bool QtGDALProcessBar::StepIt()
|
|
{
|
|
m_iCurStep++;
|
|
m_dPosition = m_iCurStep * 1.0 / m_iStepCount;
|
|
//current_value = value();
|
|
int temp_value = std::min(100u, (uint)(m_dPosition * 100.0));
|
|
setValue(int(m_start_value + temp_value * m_scale));
|
|
//setFormat(QString("当前进度为:%1%").arg(temp_value));
|
|
//cout << "StepIt " << temp_value <<"\t"<<"current_value"<< current_value << endl;
|
|
|
|
//QCoreApplication::instance()->processEvents();
|
|
|
|
//if (this->wasCanceled())
|
|
// return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void QtGDALProcessBar::updateProgress(int step)
|
|
{
|
|
this->setValue(step);
|
|
//this->update();
|
|
//cout << "updateProgress " << step << endl;
|
|
//QCoreApplication::instance()->processEvents();
|
|
}
|
|
|
|
|