#include <WRCharting/WRDirMapControl.h>
#include "WRDirMapDataSourceT.h"
#define WRDIRMAPFIRSTGAUGE (WRDirMapGaugeElement*)(m_hScroll->next())
//执行控件的初始化。
void WRDirMapControl::initialize(void)
{
writeFlag(WRDIRMAPCONTROL_HOLDSTATUS, false);
m_backColor.update(98, 108, 123);
m_dataProcMethod = ShowMaxValue;
m_vAxis = new WRDirMapVAxisElement();
m_hAxis = new WRDirMapHAxisElement();
m_vScroll = new WRDirMapVScrollElement();
m_hScroll = new WRDirMapHScrollElement();
m_dataView = new WRDirMapDataViewElement();
addLast(m_dataView);
addLast(m_vAxis);
addLast(m_hAxis);
addLast(m_vScroll);
addLast(m_hScroll);
}
//清理当前对象所占用的相关资源。
WRDirMapControl::~WRDirMapControl(void)
{
m_backSource->release();
m_currSource->release();
}
//当布局时调用此方法。
void WRDirMapControl::onLayout(const WRRect& rect)
{
WRChartControl::arrange(rect, m_hAxis, m_vAxis, m_hScroll, m_vScroll, m_dataView);
//执行测量元旦布局
WRDirMapGaugeElement* gauge = WRDIRMAPFIRSTGAUGE;
while (gauge)
{
gauge->arrange();
gauge =(WRDirMapGaugeElement*) gauge->next();
}
}
//键盘按下处理,如果需要重绘,则返回True。
bool WRDirMapControl::onKeyDown(const QKeyEvent& e)
{
if (((e.modifiers() & Qt::ControlModifier) == Qt::ControlModifier))
{
if (e.key() == Qt::Key_Left)
{
if (m_dataView->width() >= m_showDataRange.pointCount())
{
if (m_showDataRange.pointBegin() > 0)
{
changeShowDataPointRange(WRChartSampleRange(m_showDataRange.pointBegin() - 1, m_showDataRange.pointCount()));
return true;
}
}
else
{
WRChartSampleRange showPointRange(m_showDataRange.pointRange());
doMouseMoveH(showPointRange, 1, 0, m_dataView->width());
if (changeShowDataPointRange(showPointRange))
{
return true;
}
}
}
else if (e.key() == Qt::Key_Right)
{
if (m_dataView->width() >= m_showDataRange.pointCount())
{
if (m_showDataRange.pointBegin() + m_showDataRange.pointCount() < m_currSource->points())
{
changeShowDataPointRange(WRChartSampleRange(m_showDataRange.pointBegin() + 1, m_showDataRange.pointCount()));
return true;
}
}
else
{
WRChartSampleRange showPointRange(m_showDataRange.pointRange());
doMouseMoveH(showPointRange, 0, 1, m_dataView->width());
if (changeShowDataPointRange(showPointRange))
{
return true;
}
}
}
else if (e.key() == Qt::Key_Up)
{
WRChartDValueRange showAngleRange(m_showDataRange.angleRange());
doMouseMoveV(showAngleRange, 1, 0, m_dataView->height());
if (changeShowDataAngleRange(showAngleRange))
{
return true;
}
}
else if (e.key() == Qt::Key_Down)
{
WRChartDValueRange showAngleRange(m_showDataRange.angleRange());
doMouseMoveV(showAngleRange, 0, 1, m_dataView->height());
if (changeShowDataAngleRange(showAngleRange))
{
return true;
}
}
}
return false;
}
//键盘释放处理,如果需要重绘,则返回True。
bool WRDirMapControl::onKeyUp(const QKeyEvent&)
{
return false;
}
//执行绘制处理操作。
void WRDirMapControl::onPaint(QPainter& painter)
{
painter.fillRect(rect(), m_backColor);//填充背景
}
//执行所有绘制后,如果元素捕获了鼠标或者鼠标正处于此元素之上,将调用此方法进行相应的绘制处理。
void WRDirMapControl::onPaintMouseFeedback(QPainter&)
{
//add code here
}
//验证图形,如果需要重新绘制,则返回True。
bool WRDirMapControl::validate(void)
{
bool changed = false;
//验证数据源
WRDirMapDataSource* dataSource = 0;
if (!holdStatus())
{
WRSynch synch(m_mutex);
if (m_backSource != m_currSource)
{
changed = true;
dataSource = m_currSource;
m_currSource = m_backSource;
m_currSource->addRef();
m_currSource->validate();
m_dataView->invalidate();
}
else
{
long version = m_currSource->version();
if (m_currSource->validate() != version)
{
changed = true;
m_dataView->invalidate();
}
}
}
if (dataSource)
{
dataSource->release();
emit dataChanged();
resetShowDataRange(WRDirMapDataRange(0, m_currSource->points(), m_currSource->angleMinValue(), m_currSource->angleMaxValue()));
m_hAxis->invalidate();
m_vAxis->invalidate();
}
return changed;
}
//当显示数据范围改变后调用此方法 。
void WRDirMapControl::onShowDataRangeChanged()
{
if (effect())
{
//WRDirMapGaugeElement* element = WRDIRMAPFIRSTGAUGE;
//while (element)
//{
// if (element->type() == WRDirMapGaugeElement::Block)
// {
// element->arrange();
// }
// element =(WRDirMapGaugeElement*) element->next();
//}
}
m_dataView->onShowDataRangeChanged();
invalidate();
}
//当显示数据点范围改变后调用此方法。
void WRDirMapControl::onShowDataPointRangeChanged()
{
if (effect())
{
WRDirMapGaugeElement* element = WRDIRMAPFIRSTGAUGE;
while (element)
{
if (element->type() == WRDirMapGaugeElement::DataPointLine)
{
element->arrange();
}
element =(WRDirMapGaugeElement*) element->next();
}
}
m_hAxis->invalidate();
m_dataView->onShowDataPointRangeChanged();
}
//当显示数据角度范围改变后调用此方法。
void WRDirMapControl::onShowDataAngleRangeChanged()
{
if (effect())
{
WRDirMapGaugeElement* element = WRDIRMAPFIRSTGAUGE;
while (element)
{
if (element->type() == WRDirMapGaugeElement::DataAngleLine)
{
element->arrange();
}
element =(WRDirMapGaugeElement*) element->next();
}
}
m_vAxis->invalidate();
m_dataView->onShowDataAngleRangeChanged();
}
//设置显示数据范围。
void WRDirMapControl::setShowDataRange(const WRDirMapDataRange& value)
{
bool change = false;
if (m_showDataRange.pointRange(value.pointRange()))
{
onShowDataPointRangeChanged();
emit showDataPointRangeChanged(m_showDataRange.pointRange());
change = true;
}
if (m_showDataRange.angleRange(value.angleRange()))
{
onShowDataAngleRangeChanged();
emit showDataAngleRangeChanged(m_showDataRange.angleRange());
change = true;
}
if (change)
{
onShowDataRangeChanged();
emit showDataRangeChanged(m_showDataRange);
}
}
//设置数据点显示数据范围。
void WRDirMapControl::setShowDataPointRange(const WRChartSampleRange& value)
{
if (m_showDataRange.pointRange(value))
{
onShowDataPointRangeChanged();
onShowDataRangeChanged();
emit showDataPointRangeChanged(m_showDataRange.pointRange());
emit showDataRangeChanged(m_showDataRange);
}
}
//设置数据角度显示数据范围。
void WRDirMapControl::setShowDataAngleRange(const WRChartDValueRange& value)
{
if (m_showDataRange.angleRange(value))
{
onShowDataAngleRangeChanged();
onShowDataRangeChanged();
emit showDataAngleRangeChanged(m_showDataRange.angleRange());
emit showDataRangeChanged(m_showDataRange);
}
}
//设置显示数据范围。
bool WRDirMapControl::showDataRange(const WRDirMapDataRange& value)
{
bool change = false;
if (m_showDataRange.pointRange(value.pointRange()))
{
onShowDataPointRangeChanged();
emit showDataPointRangeChanged(m_showDataRange.pointRange());
change = true;
}
if (m_showDataRange.angleRange(value.angleRange()))
{
onShowDataAngleRangeChanged();
emit showDataAngleRangeChanged(m_showDataRange.angleRange());
change = true;
}
if (change)
{
onShowDataRangeChanged();
emit showDataRangeChanged(m_showDataRange);
return true;
}
return