feat:完成纵对每个纵坐标轴的详细配置(名称、单位)
This commit is contained in:
parent
3cf3c88b1e
commit
2b10e7e9ef
|
|
@ -56,7 +56,10 @@ protected:
|
|||
bIsDefaultAxis = isDefualtAxis;
|
||||
if(qAxis)
|
||||
{
|
||||
if(_cfg.unit.isEmpty())
|
||||
qAxis->setLabel(_cfg.name);
|
||||
else
|
||||
qAxis->setLabel(QString("%1(%2)").arg(_cfg.name,_cfg.unit));
|
||||
qAxis->setSubTicks(false);
|
||||
//颜色
|
||||
qAxis->setBasePen(style.axisColor);
|
||||
|
|
@ -77,6 +80,14 @@ protected:
|
|||
_cfg.name = cfg.name;
|
||||
_cfg.unit = cfg.unit;
|
||||
_cfg.dataType = cfg.dataType;
|
||||
|
||||
if(qAxis) //更新轴的名称
|
||||
{
|
||||
if(_cfg.unit.isEmpty())
|
||||
qAxis->setLabel(_cfg.name);
|
||||
else
|
||||
qAxis->setLabel(QString("%1(%2)").arg(_cfg.name,_cfg.unit));
|
||||
}
|
||||
}
|
||||
|
||||
void setStyle(const ChartStyle chartStyle)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ void dpConfigurationDialog::showEvent(QShowEvent* event)
|
|||
|
||||
void dpConfigurationDialog::initialize()
|
||||
{
|
||||
m_curAxisComboBoxIndex = -1;
|
||||
|
||||
ui->tabDataType->setProperty("index", 0);
|
||||
connect(ui->tabDataType, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
|
||||
ui->tabDataSource->setProperty("index", 1);
|
||||
|
|
@ -261,14 +263,31 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel)
|
|||
ui->specialSettings->setVisible(true);
|
||||
ui->axisObject->clear();
|
||||
m_axisCfgMap.clear();
|
||||
|
||||
ui->axisName->setText("");
|
||||
ui->axisUnit->setText("");
|
||||
m_axisCfgMap = pPanel->m_cofigurationResults.axisCfgMap;
|
||||
disconnect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
|
||||
for(int i = 0; i< m_pModel_typeSelected->rowCount(); i++)
|
||||
{
|
||||
RealTimeDataType dataType = (RealTimeDataType)m_pModel_typeSelected->item(i, 0)->data(Qt::UserRole + itemRole_dataType).toInt();
|
||||
QString itemText = m_pModel_typeSelected->item(i, 0)->text();
|
||||
ui->axisObject->addItem(itemText, dataType);
|
||||
}
|
||||
m_axisCfgMap = pPanel->m_cofigurationResults.axisCfgMap;
|
||||
if(ui->axisObject->count() > 0)
|
||||
{
|
||||
m_curAxisComboBoxIndex = ui->axisObject->currentIndex();
|
||||
RealTimeDataType itemDataType = (RealTimeDataType)ui->axisObject->currentData().toInt();
|
||||
if(m_axisCfgMap.contains(itemDataType))
|
||||
{
|
||||
ui->axisName->setText(m_axisCfgMap.value(itemDataType).name);
|
||||
ui->axisUnit->setText(m_axisCfgMap.value(itemDataType).unit);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_curAxisComboBoxIndex = -1;
|
||||
}
|
||||
connect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -340,6 +359,13 @@ void dpConfigurationDialog::onBtnClicked_confirm()
|
|||
m_pDataPanel->m_cofigurationResults.dataServicePort = ui->servicePort->text().toInt();
|
||||
m_pDataPanel->m_cofigurationResults.showLegend = ui->radioBtn_showLegend->isChecked();
|
||||
m_pDataPanel->m_cofigurationResults.arrangement = (AxisArrangementMode)ui->axisArrangement->currentIndex();
|
||||
RealTimeDataType itemDataType = (RealTimeDataType)ui->axisObject->currentData().toInt();
|
||||
if(m_axisCfgMap.contains(itemDataType))
|
||||
{
|
||||
if(!ui->axisName->text().isEmpty())
|
||||
m_axisCfgMap[itemDataType].name = ui->axisName->text();
|
||||
m_axisCfgMap[itemDataType].unit = ui->axisUnit->text();
|
||||
}
|
||||
m_pDataPanel->m_cofigurationResults.axisCfgMap = m_axisCfgMap;
|
||||
m_pDataPanel->configurationComplete();
|
||||
}
|
||||
|
|
@ -409,7 +435,12 @@ void dpConfigurationDialog::onItemClicked_typeSource(const QModelIndex& index)
|
|||
AxisCfgInfo cfg;
|
||||
cfg.name = item->text();
|
||||
m_axisCfgMap.insert(dataType, cfg);
|
||||
disconnect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
|
||||
ui->axisObject->addItem(item->text(), dataType);
|
||||
m_curAxisComboBoxIndex = ui->axisObject->currentIndex();
|
||||
if(ui->axisName->text().isEmpty())
|
||||
ui->axisName->setText(ui->axisObject->currentText());
|
||||
connect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -459,7 +490,15 @@ void dpConfigurationDialog::onBtnClicked_remove_type()
|
|||
m_axisCfgMap.remove(itemDataType);
|
||||
int index = ui->axisObject->findData(itemDataType);
|
||||
if(index != -1)
|
||||
{
|
||||
disconnect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
|
||||
ui->axisObject->removeItem(index);
|
||||
if(ui->axisObject->count() == 0)
|
||||
m_curAxisComboBoxIndex = -1;
|
||||
else
|
||||
m_curAxisComboBoxIndex = ui->axisObject->currentIndex();
|
||||
connect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -555,6 +594,28 @@ void dpConfigurationDialog::onBtnClicked_remove_source()
|
|||
}
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::onComboBoxIndexChanged_axis(int index)
|
||||
{
|
||||
if(m_curAxisComboBoxIndex == -1)
|
||||
return;
|
||||
|
||||
RealTimeDataType itemDataType = (RealTimeDataType)ui->axisObject->itemData(m_curAxisComboBoxIndex).toInt();
|
||||
if(m_axisCfgMap.contains(itemDataType))
|
||||
{
|
||||
if(!ui->axisName->text().isEmpty())
|
||||
m_axisCfgMap[itemDataType].name = ui->axisName->text();
|
||||
m_axisCfgMap[itemDataType].unit = ui->axisUnit->text();
|
||||
|
||||
m_curAxisComboBoxIndex = ui->axisObject->currentIndex();
|
||||
itemDataType = (RealTimeDataType)ui->axisObject->itemData(m_curAxisComboBoxIndex).toInt();
|
||||
if(m_axisCfgMap.contains(itemDataType))
|
||||
{
|
||||
ui->axisName->setText(m_axisCfgMap.value(itemDataType).name);
|
||||
ui->axisUnit->setText(m_axisCfgMap.value(itemDataType).unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::onRadioBtnToggled(bool checked)
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public slots:
|
|||
void onItemClicked_typeSource(const QModelIndex&);
|
||||
void onItemClicked_dataSource(const QModelIndex&);
|
||||
|
||||
void onComboBoxIndexChanged_axis(int index);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*);
|
||||
|
||||
|
|
@ -61,6 +63,7 @@ private:
|
|||
QStandardItemModel* m_pModel_dataSelected;
|
||||
|
||||
QHash<RealTimeDataType, AxisCfgInfo> m_axisCfgMap;
|
||||
int m_curAxisComboBoxIndex;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ void dpLineChart::initQCP()
|
|||
m_pCustomPlot->legend->setBorderPen(QPen(QColor(255,255,255,0))); //边框透明
|
||||
m_pCustomPlot->legend->setFont(m_chartStyle.labelFont);
|
||||
m_pCustomPlot->legend->setTextColor( m_chartStyle.labelColor);
|
||||
m_pCustomPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignTop);
|
||||
//m_pCustomPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignRight|Qt::AlignTop);
|
||||
}
|
||||
|
||||
void dpLineChart::arrangeAxes()
|
||||
|
|
@ -129,7 +129,6 @@ void dpLineChart::arrangeAxes()
|
|||
for(QCPGraph* graph : affectedGraphs)
|
||||
graph->setValueAxis(qcpAxis);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//计算偏移量
|
||||
|
|
@ -141,7 +140,7 @@ void dpLineChart::arrangeAxes()
|
|||
|
||||
void dpLineChart::reLayoutLegend()
|
||||
{
|
||||
if(!m_showLegend)
|
||||
/*if(!m_showLegend)
|
||||
return;
|
||||
|
||||
//图例放在最右侧纵坐标轴的右侧
|
||||
|
|
@ -155,8 +154,7 @@ void dpLineChart::reLayoutLegend()
|
|||
rightmostAxis = axis;
|
||||
}
|
||||
//2.设置图例位置
|
||||
QCPLegend* legend = m_pCustomPlot->legend;
|
||||
|
||||
QCPLegend* legend = m_pCustomPlot->legend;*/
|
||||
}
|
||||
|
||||
void dpLineChart::setTimeRange(TimeUnit unit)
|
||||
|
|
@ -226,20 +224,33 @@ void dpLineChart::setDateTime(const QDateTime& dateTime)
|
|||
{
|
||||
qint64 timeValue = dateTime.toMSecsSinceEpoch() / 1000.0;
|
||||
//qint64 timeValue = QCPAxisTickerDateTime::dateTimeToKey(dateTime);
|
||||
m_pCustomPlot->xAxis->setRange(timeValue, m_timeRange / 1000.0, Qt::AlignRight);
|
||||
m_pCustomPlot->replot();
|
||||
m_curDateTime = dateTime;
|
||||
|
||||
if(m_updateData)
|
||||
{
|
||||
//模拟数据展示
|
||||
double min = 0, max = 5.0;
|
||||
static double min = 0, max = 10.0, marginFactor = 1.0;
|
||||
for(auto it = m_graphs.begin(); it != m_graphs.end(); ++it)
|
||||
{
|
||||
double randomFloat = min + QRandomGenerator::global()->generateDouble() * (max - min);
|
||||
//调整所在轴的范围
|
||||
QCPRange range = it.value().qGraph->valueAxis()->range();
|
||||
if(randomFloat > range.upper)
|
||||
{
|
||||
double upper = randomFloat + marginFactor;
|
||||
it.value().qGraph->valueAxis()->setRangeUpper(upper);
|
||||
}
|
||||
else if(randomFloat < range.lower)
|
||||
{
|
||||
double lower = randomFloat - marginFactor;
|
||||
it.value().qGraph->valueAxis()->setRangeLower(lower);
|
||||
}
|
||||
it.value().qGraph->addData(timeValue, randomFloat);
|
||||
}
|
||||
}
|
||||
|
||||
m_pCustomPlot->xAxis->setRange(timeValue, m_timeRange / 1000.0, Qt::AlignRight);
|
||||
m_pCustomPlot->replot();
|
||||
}
|
||||
|
||||
void dpLineChart::viewHistoricalData(const QDateTime& dateTime)
|
||||
|
|
@ -255,13 +266,6 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
|
|||
|
||||
//将最新配置信息中的坐标轴相关数据存储在QHash中,有助于更好的判断当前坐标轴是否需要发生同步更新
|
||||
QHash<RealTimeDataType, AxisConfig> axisCfgMap;
|
||||
/*for(int i = 0; i< cfg.m_pModel_dataType->rowCount(); i++)
|
||||
{
|
||||
AxisConfig axisConfig;
|
||||
RealTimeDataType dataType = (RealTimeDataType)cfg.m_pModel_dataType->item(i, 0)->data(Qt::UserRole + itemRole_dataType).toInt();
|
||||
axisConfig.dataType = dataType;
|
||||
axisCfgMap.insert(dataType, axisConfig);
|
||||
}*/
|
||||
for(auto it = cfg.axisCfgMap.begin(); it != cfg.axisCfgMap.end(); ++it)
|
||||
{
|
||||
AxisConfig axisConfig;
|
||||
|
|
@ -344,7 +348,8 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
|
|||
//RealTimeDataType dataType = it.key();
|
||||
if(axesMap.contains(dataType)) //更新配置
|
||||
{
|
||||
|
||||
AxisConfig axisCfg = axisCfgMap.value(dataType);
|
||||
axesMap.value(dataType)->applyConfig(axisCfg);
|
||||
}
|
||||
else //新增轴
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue