refactor:调整坐标轴配置UI 及逻辑
This commit is contained in:
parent
9962a6718e
commit
eaaafcbce0
|
|
@ -2,6 +2,7 @@
|
||||||
#define DPBASECHART_H
|
#define DPBASECHART_H
|
||||||
|
|
||||||
#include "dpBaseWidget.h"
|
#include "dpBaseWidget.h"
|
||||||
|
#include "util/Chart/qcustomplot.h"
|
||||||
|
|
||||||
class dpBaseChart : public dpBaseWidget
|
class dpBaseChart : public dpBaseWidget
|
||||||
{
|
{
|
||||||
|
|
@ -27,12 +28,40 @@ protected:
|
||||||
QPen gridPen; //网格线画笔
|
QPen gridPen; //网格线画笔
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Axis //坐标轴配置信息
|
struct AxisConfig //坐标轴配置信息
|
||||||
{
|
{
|
||||||
QString name; //坐标轴名称,例如:电压
|
QString name; //坐标轴名称,例如:电压
|
||||||
QString unit; //坐标轴单位,例如:V
|
QString unit; //坐标轴单位,例如:V
|
||||||
RealTimeDataType dataType;
|
RealTimeDataType dataType;
|
||||||
};
|
};
|
||||||
|
struct Axis //坐标轴配置信息
|
||||||
|
{
|
||||||
|
|
||||||
|
AxisConfig _cfg;
|
||||||
|
QCPAxis* qAxis = nullptr;
|
||||||
|
|
||||||
|
Axis(const AxisConfig& cfg, QCPAxisRect* rect)
|
||||||
|
{
|
||||||
|
applyConfig(cfg);
|
||||||
|
qAxis = new QCPAxis(rect, QCPAxis::atRight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyConfig(const AxisConfig& cfg)
|
||||||
|
{
|
||||||
|
_cfg.name = cfg.name;
|
||||||
|
_cfg.unit = cfg.unit;
|
||||||
|
_cfg.dataType = cfg.dataType;
|
||||||
|
}
|
||||||
|
|
||||||
|
~Axis()
|
||||||
|
{
|
||||||
|
if(qAxis)
|
||||||
|
{
|
||||||
|
delete qAxis;
|
||||||
|
qAxis = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,8 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel)
|
||||||
{
|
{
|
||||||
ui->specialSettings->setCurrentIndex(0);
|
ui->specialSettings->setCurrentIndex(0);
|
||||||
ui->specialSettings->setVisible(true);
|
ui->specialSettings->setVisible(true);
|
||||||
|
ui->axisObject->clear();
|
||||||
|
m_axisCfgInfo.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -297,6 +299,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.arrangement = (AxisArrangementMode)ui->axisArrangement->currentIndex();
|
||||||
m_pDataPanel->configurationComplete();
|
m_pDataPanel->configurationComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -347,6 +350,22 @@ void dpConfigurationDialog::onItemClicked_typeSource(const QModelIndex& index)
|
||||||
m_pModel_typeSelected->appendRow(newItem);
|
m_pModel_typeSelected->appendRow(newItem);
|
||||||
ui->typeSelectedList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
ui->typeSelectedList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||||
|
|
||||||
|
//其它需要同步配置项
|
||||||
|
DataPanelType panelType = m_pDataPanel->getType();
|
||||||
|
switch (panelType)
|
||||||
|
{
|
||||||
|
case lineChart:
|
||||||
|
case curveChart:
|
||||||
|
case barChart:
|
||||||
|
{
|
||||||
|
m_axisCfgInfo.insert(dataType, AxisCfgInfo());
|
||||||
|
ui->axisObject->addItem(item->text(), dataType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(ui->errorTip->isVisible())
|
if(ui->errorTip->isVisible())
|
||||||
{
|
{
|
||||||
ui->errorTip->setVisible(false);
|
ui->errorTip->setVisible(false);
|
||||||
|
|
@ -379,6 +398,24 @@ void dpConfigurationDialog::onBtnClicked_remove_type()
|
||||||
for(QStandardItem* item: items)
|
for(QStandardItem* item: items)
|
||||||
delete item;
|
delete item;
|
||||||
|
|
||||||
|
//其它需要同步配置项
|
||||||
|
DataPanelType panelType = m_pDataPanel->getType();
|
||||||
|
switch (panelType)
|
||||||
|
{
|
||||||
|
case lineChart:
|
||||||
|
case curveChart:
|
||||||
|
case barChart:
|
||||||
|
{
|
||||||
|
m_axisCfgInfo.remove(itemDataType);
|
||||||
|
int index = ui->axisObject->findData(itemDataType);
|
||||||
|
if(index != -1)
|
||||||
|
ui->axisObject->removeItem(index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(m_pModel_typeSelected->rowCount() == 0)
|
if(m_pModel_typeSelected->rowCount() == 0)
|
||||||
{
|
{
|
||||||
ui->errorTip->setVisible(true);
|
ui->errorTip->setVisible(true);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define DPCONFIGURATIONDIALOG_H
|
#define DPCONFIGURATIONDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include "dpGlobals.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
@ -57,6 +58,8 @@ private:
|
||||||
//dataSource
|
//dataSource
|
||||||
QStandardItemModel* m_pModel_dataSource;
|
QStandardItemModel* m_pModel_dataSource;
|
||||||
QStandardItemModel* m_pModel_dataSelected;
|
QStandardItemModel* m_pModel_dataSelected;
|
||||||
|
|
||||||
|
QHash<RealTimeDataType, AxisCfgInfo> m_axisCfgInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,19 +21,26 @@ enum RealTimeDataType
|
||||||
current //电流
|
current //电流
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum AxisArrangementMode //坐标轴排列方式
|
||||||
|
{
|
||||||
|
AlternateSides = 0, //左右交替排列
|
||||||
|
AllRight //右侧排列
|
||||||
|
};
|
||||||
|
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
struct AxisCfgInfo
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString unit;
|
||||||
|
};
|
||||||
struct configurationResults
|
struct configurationResults
|
||||||
{
|
{
|
||||||
QStandardItemModel* m_pModel_dataType;
|
QStandardItemModel* m_pModel_dataType;
|
||||||
QStandardItemModel* m_pModel_dataSource;
|
QStandardItemModel* m_pModel_dataSource;
|
||||||
QString dataServiceIP;
|
QString dataServiceIP;
|
||||||
int dataServicePort;
|
int dataServicePort;
|
||||||
|
AxisArrangementMode arrangement;
|
||||||
struct Axis
|
QHash<RealTimeDataType, AxisCfgInfo> axisCfgInfo; //可能有多个轴(数据类别)
|
||||||
{
|
|
||||||
QString name;
|
|
||||||
QString unit;
|
|
||||||
} axisInfo;
|
|
||||||
|
|
||||||
configurationResults()
|
configurationResults()
|
||||||
{
|
{
|
||||||
|
|
@ -43,11 +50,10 @@ struct configurationResults
|
||||||
dataServiceIP = "127.0.0.1";
|
dataServiceIP = "127.0.0.1";
|
||||||
dataServicePort = 1987;
|
dataServicePort = 1987;
|
||||||
|
|
||||||
axisInfo.name = "";
|
arrangement = AlternateSides;
|
||||||
axisInfo.unit = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setParent(QObject* parent)
|
void setModelParent(QObject* parent) //为QStandardItemModel对象构造对象树,从而利用QT的资源自动管理
|
||||||
{
|
{
|
||||||
m_pModel_dataType = new QStandardItemModel(parent);
|
m_pModel_dataType = new QStandardItemModel(parent);
|
||||||
m_pModel_dataSource = new QStandardItemModel(parent);
|
m_pModel_dataSource = new QStandardItemModel(parent);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#include "dpLineChart.h"
|
#include "dpLineChart.h"
|
||||||
#include "util/Chart/qcustomplot.h"
|
|
||||||
|
|
||||||
dpLineChart::dpLineChart(QWidget* parent)
|
dpLineChart::dpLineChart(QWidget* parent)
|
||||||
:dpBaseChart(parent)
|
:dpBaseChart(parent)
|
||||||
|
|
@ -157,16 +156,40 @@ void dpLineChart::viewHistoricalData(const QDateTime& dateTime)
|
||||||
void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
|
void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
|
||||||
{
|
{
|
||||||
//Y坐标轴的数量由数据类型决定
|
//Y坐标轴的数量由数据类型决定
|
||||||
QHash<RealTimeDataType, Axis> cfgAxisMap; //将最新配置信息中的坐标轴相关数据存储在QHash中,有助于更好的判断当前坐标轴是否需要发生同步更新
|
|
||||||
|
//将最新配置信息中的坐标轴相关数据存储在QHash中,有助于更好的判断当前坐标轴是否需要发生同步更新
|
||||||
|
QHash<RealTimeDataType, AxisConfig> axisCfgMap;
|
||||||
for(int i = 0; i< cfg.m_pModel_dataType->rowCount(); i++)
|
for(int i = 0; i< cfg.m_pModel_dataType->rowCount(); i++)
|
||||||
{
|
{
|
||||||
Axis axis;
|
AxisConfig axisConfig;
|
||||||
axis.name = cfg.axisInfo.name;
|
//axisConfig.name = cfg.axisInfo.name;
|
||||||
axis.unit = cfg.axisInfo.unit;
|
//axisConfig.unit = cfg.axisInfo.unit;
|
||||||
RealTimeDataType dataType = (RealTimeDataType)cfg.m_pModel_dataType->item(i, 0)->data(Qt::UserRole + itemRole_dataType).toInt();
|
RealTimeDataType dataType = (RealTimeDataType)cfg.m_pModel_dataType->item(i, 0)->data(Qt::UserRole + itemRole_dataType).toInt();
|
||||||
axis.dataType = dataType;
|
axisConfig.dataType = dataType;
|
||||||
cfgAxisMap.insert(dataType, axis);
|
axisCfgMap.insert(dataType, axisConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//QHash::insert()的第二个参数接收的是副本(引起拷贝),所以采用指针可以减少拷贝从而提升效率
|
||||||
|
QHash<RealTimeDataType, Axis*> axesMap;
|
||||||
|
for(auto& axis : m_axes)
|
||||||
|
{
|
||||||
|
axesMap.insert(axis._cfg.dataType, &axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除轴
|
||||||
|
for(int i = 0; i < m_axes.size();)
|
||||||
|
{
|
||||||
|
Axis& axis = m_axes[i];
|
||||||
|
if(!axisCfgMap.contains(axis._cfg.dataType))
|
||||||
|
{
|
||||||
|
m_pCustomPlot->axisRect()->removeAxis(axis.qAxis);
|
||||||
|
m_axes.remove(i); //QVector::remove()会调用存储对象的析构函数
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dpLineChart::onSignal_rangeChanged_xAxis(const QCPRange& range)
|
void dpLineChart::onSignal_rangeChanged_xAxis(const QCPRange& range)
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ DataPanel::DataPanel(QWidget *parent, DataPanelType type)
|
||||||
m_pToolMenu->addAction(QString::fromWCharArray(L"放置最后"), this, SLOT(onAction_moveToBack()));
|
m_pToolMenu->addAction(QString::fromWCharArray(L"放置最后"), this, SLOT(onAction_moveToBack()));
|
||||||
|
|
||||||
createDataWidget();
|
createDataWidget();
|
||||||
m_cofigurationResults.setParent(this);
|
m_cofigurationResults.setModelParent(this);
|
||||||
|
|
||||||
connect(DataManager::instance(), &DataManager::dataUpdated, this, &DataPanel::onSignal_dataUpdated);
|
connect(DataManager::instance(), &DataManager::dataUpdated, this, &DataPanel::onSignal_dataUpdated);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ QComboBox QAbstractItemView
|
||||||
{
|
{
|
||||||
outline: 0px; /*去除选中虚线框 */
|
outline: 0px; /*去除选中虚线框 */
|
||||||
border:0px;
|
border:0px;
|
||||||
background-color:rgba(25,25,25,240);
|
background-color:rgba(25,25,25,220);
|
||||||
}
|
}
|
||||||
QComboBox QAbstractItemView::item:hover
|
QComboBox QAbstractItemView::item:hover
|
||||||
{
|
{
|
||||||
|
|
@ -91,7 +91,7 @@ background-color: rgb(43, 102, 158);
|
||||||
QComboBox QAbstractItemView::item:selected
|
QComboBox QAbstractItemView::item:selected
|
||||||
{
|
{
|
||||||
color: rgb(250, 250, 250);
|
color: rgb(250, 250, 250);
|
||||||
background-color: rgb(43, 102, 158);
|
background-color: rgba(43, 102, 158, 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeView
|
QTreeView
|
||||||
|
|
@ -613,24 +613,24 @@ background-color: rgb(24, 32, 38);
|
||||||
background-color:transparent;
|
background-color:transparent;
|
||||||
}</string>
|
}</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QLabel" name="setting_Server_2">
|
<widget class="QLabel" name="label_axisObject">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>35</y>
|
||||||
<width>41</width>
|
<width>71</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Y轴:</string>
|
<string>Y轴配置:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QComboBox" name="comboBox">
|
<widget class="QComboBox" name="axisObject">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>40</x>
|
<x>70</x>
|
||||||
<y>0</y>
|
<y>35</y>
|
||||||
<width>91</width>
|
<width>91</width>
|
||||||
<height>22</height>
|
<height>22</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
|
@ -655,7 +655,7 @@ background-color:transparent;
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>30</x>
|
<x>30</x>
|
||||||
<y>35</y>
|
<y>70</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
|
@ -668,7 +668,7 @@ background-color:transparent;
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>80</x>
|
<x>80</x>
|
||||||
<y>35</y>
|
<y>70</y>
|
||||||
<width>71</width>
|
<width>71</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
|
@ -678,7 +678,7 @@ background-color:transparent;
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>190</x>
|
<x>190</x>
|
||||||
<y>35</y>
|
<y>70</y>
|
||||||
<width>41</width>
|
<width>41</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
|
|
@ -691,12 +691,45 @@ background-color:transparent;
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>240</x>
|
<x>240</x>
|
||||||
<y>35</y>
|
<y>70</y>
|
||||||
<width>71</width>
|
<width>71</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QComboBox" name="axisArrangement">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>70</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>22</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>左右交替</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>居右排列</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_axisArrangement">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>71</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Y轴排列:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_2"/>
|
<widget class="QWidget" name="page_2"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue