feat:增加‘图例’的显示/隐藏配置
This commit is contained in:
parent
892964c8ce
commit
3cf3c88b1e
|
|
@ -104,12 +104,14 @@ protected:
|
||||||
|
|
||||||
QString dataID;
|
QString dataID;
|
||||||
QString synchronizeTagging; //同步配置数据时的标记,new、update两种,没有的就是要被删除
|
QString synchronizeTagging; //同步配置数据时的标记,new、update两种,没有的就是要被删除
|
||||||
|
QString name; //用户legend图例展示用
|
||||||
|
|
||||||
Graph()
|
Graph()
|
||||||
{
|
{
|
||||||
dataID = "";
|
dataID = "";
|
||||||
//qGraph = nullptr;
|
//qGraph = nullptr;
|
||||||
synchronizeTagging = "noTagging";
|
synchronizeTagging = "noTagging";
|
||||||
|
name = "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,8 @@ void dpConfigurationDialog::initialize()
|
||||||
connect(ui->btnReomve_type, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_type()));
|
connect(ui->btnReomve_type, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_type()));
|
||||||
connect(ui->btnReomve_source, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_source()));
|
connect(ui->btnReomve_source, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_source()));
|
||||||
|
|
||||||
|
//connect(ui->radioBtn_showLegend, &QRadioButton::toggled, this, &dpConfigurationDialog::onRadioBtnToggled);
|
||||||
|
|
||||||
connect(ui->typeSourceList, &QListView::clicked, this, &dpConfigurationDialog::onItemClicked_typeSource);
|
connect(ui->typeSourceList, &QListView::clicked, this, &dpConfigurationDialog::onItemClicked_typeSource);
|
||||||
connect(ui->dataSourceList, &QListView::clicked, this, &dpConfigurationDialog::onItemClicked_dataSource);
|
connect(ui->dataSourceList, &QListView::clicked, this, &dpConfigurationDialog::onItemClicked_dataSource);
|
||||||
|
|
||||||
|
|
@ -246,6 +248,7 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel)
|
||||||
// ui->typeSelectedList->setModel(m_pModel_typeSelected);
|
// ui->typeSelectedList->setModel(m_pModel_typeSelected);
|
||||||
ui->serviceIP->setText(pPanel->m_cofigurationResults.dataServiceIP);
|
ui->serviceIP->setText(pPanel->m_cofigurationResults.dataServiceIP);
|
||||||
ui->servicePort->setText(QString::number(pPanel->m_cofigurationResults.dataServicePort));
|
ui->servicePort->setText(QString::number(pPanel->m_cofigurationResults.dataServicePort));
|
||||||
|
ui->radioBtn_showLegend->setChecked(pPanel->m_cofigurationResults.showLegend);
|
||||||
|
|
||||||
DataPanelType panelType = pPanel->getType();
|
DataPanelType panelType = pPanel->getType();
|
||||||
switch (panelType)
|
switch (panelType)
|
||||||
|
|
@ -335,6 +338,7 @@ void dpConfigurationDialog::onBtnClicked_confirm()
|
||||||
copyModelData(m_pModel_dataSelected, m_pDataPanel->m_cofigurationResults.m_pModel_dataSource);
|
copyModelData(m_pModel_dataSelected, m_pDataPanel->m_cofigurationResults.m_pModel_dataSource);
|
||||||
m_pDataPanel->m_cofigurationResults.dataServiceIP = ui->serviceIP->text();
|
m_pDataPanel->m_cofigurationResults.dataServiceIP = ui->serviceIP->text();
|
||||||
m_pDataPanel->m_cofigurationResults.dataServicePort = ui->servicePort->text().toInt();
|
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();
|
m_pDataPanel->m_cofigurationResults.arrangement = (AxisArrangementMode)ui->axisArrangement->currentIndex();
|
||||||
m_pDataPanel->m_cofigurationResults.axisCfgMap = m_axisCfgMap;
|
m_pDataPanel->m_cofigurationResults.axisCfgMap = m_axisCfgMap;
|
||||||
m_pDataPanel->configurationComplete();
|
m_pDataPanel->configurationComplete();
|
||||||
|
|
@ -550,3 +554,8 @@ void dpConfigurationDialog::onBtnClicked_remove_source()
|
||||||
removeDataSelected(nCurrentRow);
|
removeDataSelected(nCurrentRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpConfigurationDialog::onRadioBtnToggled(bool checked)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ public slots:
|
||||||
void onBtnClicked_cancle();
|
void onBtnClicked_cancle();
|
||||||
void onBtnClicked_remove_type();
|
void onBtnClicked_remove_type();
|
||||||
void onBtnClicked_remove_source();
|
void onBtnClicked_remove_source();
|
||||||
|
void onRadioBtnToggled(bool checked);
|
||||||
|
|
||||||
void onItemClicked_typeSource(const QModelIndex&);
|
void onItemClicked_typeSource(const QModelIndex&);
|
||||||
void onItemClicked_dataSource(const QModelIndex&);
|
void onItemClicked_dataSource(const QModelIndex&);
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ struct configurationResults
|
||||||
QStandardItemModel* m_pModel_dataSource;
|
QStandardItemModel* m_pModel_dataSource;
|
||||||
QString dataServiceIP;
|
QString dataServiceIP;
|
||||||
int dataServicePort;
|
int dataServicePort;
|
||||||
|
bool showLegend;
|
||||||
AxisArrangementMode arrangement;
|
AxisArrangementMode arrangement;
|
||||||
QHash<RealTimeDataType, AxisCfgInfo> axisCfgMap; //可能有多个轴(数据类别)
|
QHash<RealTimeDataType, AxisCfgInfo> axisCfgMap; //可能有多个轴(数据类别)
|
||||||
|
|
||||||
|
|
@ -51,6 +52,7 @@ struct configurationResults
|
||||||
dataServiceIP = "127.0.0.1";
|
dataServiceIP = "127.0.0.1";
|
||||||
dataServicePort = 1987;
|
dataServicePort = 1987;
|
||||||
|
|
||||||
|
showLegend = false;
|
||||||
arrangement = AlternateSides;
|
arrangement = AlternateSides;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ dpLineChart::dpLineChart(QWidget* parent)
|
||||||
|
|
||||||
m_timeRange = 60 * 1000;
|
m_timeRange = 60 * 1000;
|
||||||
m_axisArrangementMode = AlternateSides;
|
m_axisArrangementMode = AlternateSides;
|
||||||
|
m_showLegend = false;
|
||||||
m_updateData = false;
|
m_updateData = false;
|
||||||
|
|
||||||
QBoxLayout* mainLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
QBoxLayout* mainLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||||
|
|
@ -80,6 +81,13 @@ void dpLineChart::initQCP()
|
||||||
//qDebug() << timeTicker->dateTimeFormat();
|
//qDebug() << timeTicker->dateTimeFormat();
|
||||||
m_pCustomPlot->xAxis->setTicker(timeTicker);
|
m_pCustomPlot->xAxis->setTicker(timeTicker);
|
||||||
//qDebug() << m_pCustomPlot->xAxis->range();
|
//qDebug() << m_pCustomPlot->xAxis->range();
|
||||||
|
|
||||||
|
//Legend
|
||||||
|
m_pCustomPlot->legend->setBrush(QBrush(QColor(255,255,255,12))); //背景透明
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dpLineChart::arrangeAxes()
|
void dpLineChart::arrangeAxes()
|
||||||
|
|
@ -131,6 +139,26 @@ void dpLineChart::arrangeAxes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dpLineChart::reLayoutLegend()
|
||||||
|
{
|
||||||
|
if(!m_showLegend)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//图例放在最右侧纵坐标轴的右侧
|
||||||
|
//1.找到最右侧坐标轴
|
||||||
|
QCPAxis* rightmostAxis = m_pCustomPlot->yAxis2;
|
||||||
|
int offset = rightmostAxis->offset();
|
||||||
|
QList<QCPAxis*> axes = m_pCustomPlot->axisRect()->axes(QCPAxis::atRight);
|
||||||
|
for(QCPAxis* axis : axes)
|
||||||
|
{
|
||||||
|
if(axis->offset() > rightmostAxis->offset())
|
||||||
|
rightmostAxis = axis;
|
||||||
|
}
|
||||||
|
//2.设置图例位置
|
||||||
|
QCPLegend* legend = m_pCustomPlot->legend;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void dpLineChart::setTimeRange(TimeUnit unit)
|
void dpLineChart::setTimeRange(TimeUnit unit)
|
||||||
{
|
{
|
||||||
switch(unit)
|
switch(unit)
|
||||||
|
|
@ -406,9 +434,11 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
|
||||||
graph.dataID = graphID;
|
graph.dataID = graphID;
|
||||||
graph.dataType = dataType;
|
graph.dataType = dataType;
|
||||||
graph.synchronizeTagging = "new";
|
graph.synchronizeTagging = "new";
|
||||||
|
graph.name = cfg.m_pModel_dataSource->item(i, 0)->text();
|
||||||
QCPGraph* newGraph = m_pCustomPlot->addGraph(m_pCustomPlot->xAxis, valueAxis);
|
QCPGraph* newGraph = m_pCustomPlot->addGraph(m_pCustomPlot->xAxis, valueAxis);
|
||||||
if(newGraph)
|
if(newGraph)
|
||||||
{
|
{
|
||||||
|
newGraph->setName(graph.name);
|
||||||
if(colorData.isValid())
|
if(colorData.isValid())
|
||||||
{
|
{
|
||||||
QColor color = colorData.value<QColor>();
|
QColor color = colorData.value<QColor>();
|
||||||
|
|
@ -449,9 +479,11 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
|
||||||
if( !m_pCustomPlot->removeGraph(g.qGraph) )
|
if( !m_pCustomPlot->removeGraph(g.qGraph) )
|
||||||
qWarning() << "Failed to remove gracloxne ph:" << key;
|
qWarning() << "Failed to remove gracloxne ph:" << key;
|
||||||
}
|
}
|
||||||
|
|
||||||
//qDebug() << "graph count: " << m_graphs.count() << ", " << m_pCustomPlot->graphCount();
|
//qDebug() << "graph count: " << m_graphs.count() << ", " << m_pCustomPlot->graphCount();
|
||||||
|
|
||||||
|
//Legend
|
||||||
|
m_pCustomPlot->legend->setVisible(cfg.showLegend);
|
||||||
|
|
||||||
m_updateData = true;
|
m_updateData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ private:
|
||||||
|
|
||||||
void initQCP();
|
void initQCP();
|
||||||
void arrangeAxes();
|
void arrangeAxes();
|
||||||
|
void reLayoutLegend();
|
||||||
//void handleAssociatedGraphs();
|
//void handleAssociatedGraphs();
|
||||||
|
|
||||||
QCustomPlot* m_pCustomPlot;
|
QCustomPlot* m_pCustomPlot;
|
||||||
|
|
@ -51,6 +52,7 @@ private:
|
||||||
QVector<Axis> m_axes;
|
QVector<Axis> m_axes;
|
||||||
QHash<QString, Graph> m_graphs;
|
QHash<QString, Graph> m_graphs;
|
||||||
AxisArrangementMode m_axisArrangementMode;
|
AxisArrangementMode m_axisArrangementMode;
|
||||||
|
bool m_showLegend;
|
||||||
bool m_updateData;
|
bool m_updateData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
|
<file>images/ico_switch_off.png</file>
|
||||||
|
<file>images/ico_switch_on.png</file>
|
||||||
<file>images/down-arrow.png</file>
|
<file>images/down-arrow.png</file>
|
||||||
<file>images/branch_closed.png</file>
|
<file>images/branch_closed.png</file>
|
||||||
<file>images/branch_open.png</file>
|
<file>images/branch_open.png</file>
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
|
|
@ -44,6 +44,26 @@ font: 12pt "黑体";
|
||||||
color: rgb(250, 250, 250);
|
color: rgb(250, 250, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRadioButton
|
||||||
|
{
|
||||||
|
spacing:8px;
|
||||||
|
font: 12pt "黑体";
|
||||||
|
color: rgb(250, 250, 250);
|
||||||
|
}
|
||||||
|
QRadioButton::indicator
|
||||||
|
{
|
||||||
|
width:36px;
|
||||||
|
height:20px;
|
||||||
|
}
|
||||||
|
QRadioButton::indicator:unchecked
|
||||||
|
{
|
||||||
|
image: url(:/images/ico_switch_off.png);
|
||||||
|
}
|
||||||
|
QRadioButton::indicator:checked
|
||||||
|
{
|
||||||
|
image: url(:/images/ico_switch_on.png);
|
||||||
|
}
|
||||||
|
|
||||||
QLineEdit
|
QLineEdit
|
||||||
{
|
{
|
||||||
font: 12pt "黑体";
|
font: 12pt "黑体";
|
||||||
|
|
@ -730,6 +750,19 @@ background-color:transparent;
|
||||||
<string>Y轴排列:</string>
|
<string>Y轴排列:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QRadioButton" name="radioBtn_showLegend">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>121</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>显示图例</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_2"/>
|
<widget class="QWidget" name="page_2"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue