diff --git a/dataPanel/dpBaseChart.h b/dataPanel/dpBaseChart.h index 41c73c5..33cae5d 100644 --- a/dataPanel/dpBaseChart.h +++ b/dataPanel/dpBaseChart.h @@ -104,12 +104,14 @@ protected: QString dataID; QString synchronizeTagging; //同步配置数据时的标记,new、update两种,没有的就是要被删除 + QString name; //用户legend图例展示用 Graph() { dataID = ""; //qGraph = nullptr; synchronizeTagging = "noTagging"; + name = ""; } }; }; diff --git a/dataPanel/dpConfigurationDialog.cpp b/dataPanel/dpConfigurationDialog.cpp index 0c5ad34..a92fec5 100644 --- a/dataPanel/dpConfigurationDialog.cpp +++ b/dataPanel/dpConfigurationDialog.cpp @@ -64,6 +64,8 @@ void dpConfigurationDialog::initialize() connect(ui->btnReomve_type, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_type())); 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->dataSourceList, &QListView::clicked, this, &dpConfigurationDialog::onItemClicked_dataSource); @@ -246,6 +248,7 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel) // ui->typeSelectedList->setModel(m_pModel_typeSelected); ui->serviceIP->setText(pPanel->m_cofigurationResults.dataServiceIP); ui->servicePort->setText(QString::number(pPanel->m_cofigurationResults.dataServicePort)); + ui->radioBtn_showLegend->setChecked(pPanel->m_cofigurationResults.showLegend); DataPanelType panelType = pPanel->getType(); switch (panelType) @@ -335,6 +338,7 @@ void dpConfigurationDialog::onBtnClicked_confirm() copyModelData(m_pModel_dataSelected, m_pDataPanel->m_cofigurationResults.m_pModel_dataSource); m_pDataPanel->m_cofigurationResults.dataServiceIP = ui->serviceIP->text(); 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.axisCfgMap = m_axisCfgMap; m_pDataPanel->configurationComplete(); @@ -550,3 +554,8 @@ void dpConfigurationDialog::onBtnClicked_remove_source() removeDataSelected(nCurrentRow); } } + +void dpConfigurationDialog::onRadioBtnToggled(bool checked) +{ + +} diff --git a/dataPanel/dpConfigurationDialog.h b/dataPanel/dpConfigurationDialog.h index 03a6096..64e6191 100644 --- a/dataPanel/dpConfigurationDialog.h +++ b/dataPanel/dpConfigurationDialog.h @@ -33,6 +33,7 @@ public slots: void onBtnClicked_cancle(); void onBtnClicked_remove_type(); void onBtnClicked_remove_source(); + void onRadioBtnToggled(bool checked); void onItemClicked_typeSource(const QModelIndex&); void onItemClicked_dataSource(const QModelIndex&); diff --git a/dataPanel/dpGlobals.h b/dataPanel/dpGlobals.h index 133d87e..ace87d9 100644 --- a/dataPanel/dpGlobals.h +++ b/dataPanel/dpGlobals.h @@ -40,6 +40,7 @@ struct configurationResults QStandardItemModel* m_pModel_dataSource; QString dataServiceIP; int dataServicePort; + bool showLegend; AxisArrangementMode arrangement; QHash axisCfgMap; //可能有多个轴(数据类别) @@ -51,6 +52,7 @@ struct configurationResults dataServiceIP = "127.0.0.1"; dataServicePort = 1987; + showLegend = false; arrangement = AlternateSides; } diff --git a/dataPanel/dpLineChart.cpp b/dataPanel/dpLineChart.cpp index a596e8f..3df38db 100644 --- a/dataPanel/dpLineChart.cpp +++ b/dataPanel/dpLineChart.cpp @@ -11,6 +11,7 @@ dpLineChart::dpLineChart(QWidget* parent) m_timeRange = 60 * 1000; m_axisArrangementMode = AlternateSides; + m_showLegend = false; m_updateData = false; QBoxLayout* mainLayout = new QBoxLayout(QBoxLayout::LeftToRight); @@ -80,6 +81,13 @@ void dpLineChart::initQCP() //qDebug() << timeTicker->dateTimeFormat(); m_pCustomPlot->xAxis->setTicker(timeTicker); //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() @@ -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 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) { switch(unit) @@ -406,9 +434,11 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) graph.dataID = graphID; graph.dataType = dataType; graph.synchronizeTagging = "new"; + graph.name = cfg.m_pModel_dataSource->item(i, 0)->text(); QCPGraph* newGraph = m_pCustomPlot->addGraph(m_pCustomPlot->xAxis, valueAxis); if(newGraph) { + newGraph->setName(graph.name); if(colorData.isValid()) { QColor color = colorData.value(); @@ -449,9 +479,11 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) if( !m_pCustomPlot->removeGraph(g.qGraph) ) qWarning() << "Failed to remove gracloxne ph:" << key; } - //qDebug() << "graph count: " << m_graphs.count() << ", " << m_pCustomPlot->graphCount(); + //Legend + m_pCustomPlot->legend->setVisible(cfg.showLegend); + m_updateData = true; } diff --git a/dataPanel/dpLineChart.h b/dataPanel/dpLineChart.h index 1a3bc74..1190f9e 100644 --- a/dataPanel/dpLineChart.h +++ b/dataPanel/dpLineChart.h @@ -42,6 +42,7 @@ private: void initQCP(); void arrangeAxes(); + void reLayoutLegend(); //void handleAssociatedGraphs(); QCustomPlot* m_pCustomPlot; @@ -51,6 +52,7 @@ private: QVector m_axes; QHash m_graphs; AxisArrangementMode m_axisArrangementMode; + bool m_showLegend; bool m_updateData; }; diff --git a/resource/PowerMaster.qrc b/resource/PowerMaster.qrc index f2257b3..276c479 100644 --- a/resource/PowerMaster.qrc +++ b/resource/PowerMaster.qrc @@ -1,5 +1,7 @@ + images/ico_switch_off.png + images/ico_switch_on.png images/down-arrow.png images/branch_closed.png images/branch_open.png diff --git a/resource/images/ico_switch_off.png b/resource/images/ico_switch_off.png new file mode 100644 index 0000000..dba9e3f Binary files /dev/null and b/resource/images/ico_switch_off.png differ diff --git a/resource/images/ico_switch_on.png b/resource/images/ico_switch_on.png new file mode 100644 index 0000000..e2f19be Binary files /dev/null and b/resource/images/ico_switch_on.png differ diff --git a/ui/dpConfigurationDialog.ui b/ui/dpConfigurationDialog.ui index 268906e..9b3fc11 100644 --- a/ui/dpConfigurationDialog.ui +++ b/ui/dpConfigurationDialog.ui @@ -44,6 +44,26 @@ font: 12pt "黑体"; 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 { font: 12pt "黑体"; @@ -730,6 +750,19 @@ background-color:transparent; Y轴排列: + + + + 0 + 100 + 121 + 31 + + + + 显示图例 + +