完善数据面板配置窗口
This commit is contained in:
parent
edde3a25a8
commit
e540f867b6
|
|
@ -1,6 +1,7 @@
|
|||
#include "dpConfigurationDialog.h"
|
||||
#include "ui_dpConfigurationDialog.h"
|
||||
#include "dataPanel.h"
|
||||
#include "global.h"
|
||||
#include <QStandardItemModel>
|
||||
|
||||
dpConfigurationDialog::dpConfigurationDialog(QWidget *parent)
|
||||
|
|
@ -10,6 +11,8 @@ dpConfigurationDialog::dpConfigurationDialog(QWidget *parent)
|
|||
, m_pDataPanel(nullptr)
|
||||
, m_pModel_typeSource(nullptr)
|
||||
, m_pModel_typeSelected(nullptr)
|
||||
, m_pModel_dataSource(nullptr)
|
||||
, m_pModel_dataSelected(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
|
||||
|
|
@ -23,6 +26,23 @@ dpConfigurationDialog::~dpConfigurationDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::showEvent(QShowEvent* event)
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(0);
|
||||
if(m_pModel_typeSelected && m_pModel_typeSelected->rowCount() == 0)
|
||||
{
|
||||
ui->errorTip->setVisible(true);
|
||||
ui->errorTip->setToolTip(QString::fromStdWString(L"要至少选择一个数据类型"));
|
||||
ui->btnConfirm->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->errorTip->setVisible(false);
|
||||
//ui->errorTip->setToolTip(QString::fromStdWString(L"要至少选择一个数据类型"));
|
||||
ui->btnConfirm->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::initialize()
|
||||
{
|
||||
ui->tabDataType->setProperty("index", 0);
|
||||
|
|
@ -42,7 +62,9 @@ void dpConfigurationDialog::initialize()
|
|||
connect(ui->btnReomve_source, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_source()));
|
||||
|
||||
connect(ui->typeSourceList, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onItemClicked_typeSource(const QModelIndex&)));
|
||||
connect(ui->dataSourceList, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onItemClicked_dataSource(const QModelIndex&)));
|
||||
|
||||
///数据类型
|
||||
//typeSourceList
|
||||
m_pModel_typeSource = new QStandardItemModel(this);
|
||||
ui->typeSourceList->setModel(m_pModel_typeSource);
|
||||
|
|
@ -58,6 +80,15 @@ void dpConfigurationDialog::initialize()
|
|||
ui->typeSelectedList->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_pModel_typeSelected = new QStandardItemModel(this);
|
||||
ui->typeSelectedList->setModel(m_pModel_typeSelected);
|
||||
///数据源
|
||||
//dataSourceList
|
||||
m_pModel_dataSource = new QStandardItemModel(this);
|
||||
ui->dataSourceList->setModel(m_pModel_dataSource);
|
||||
createDataSourceList();
|
||||
//sourceSelectedList
|
||||
ui->dataSelectedList->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_pModel_dataSelected = new QStandardItemModel(this);
|
||||
ui->dataSelectedList->setModel(m_pModel_dataSelected);
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::copyModelData(QStandardItemModel* sourceModel, QStandardItemModel* destModel)
|
||||
|
|
@ -92,10 +123,40 @@ void dpConfigurationDialog::copyModelData(QStandardItemModel* sourceModel, QStan
|
|||
}
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::createDataSourceList()
|
||||
{
|
||||
//demo先临时写死,后续改为接口动态创建
|
||||
QStandardItem* rootItem = m_pModel_dataSource->invisibleRootItem();
|
||||
QStandardItem* stationItem = new QStandardItem("测试站");
|
||||
stationItem->setEditable(false);
|
||||
stationItem->setData("station", Qt::UserRole + itemRole_tag);
|
||||
rootItem->appendRow(stationItem);
|
||||
QStandardItem* componentItem = new QStandardItem("异步电机");
|
||||
componentItem->setEditable(false);
|
||||
componentItem->setData("component", Qt::UserRole + itemRole_tag);
|
||||
stationItem->appendRow(componentItem);
|
||||
QStandardItem* currentItem = new QStandardItem("电流");
|
||||
currentItem->setEditable(false);
|
||||
currentItem->setData("point", Qt::UserRole + itemRole_tag);
|
||||
currentItem->setData(0, Qt::UserRole + itemRole_stationID);
|
||||
currentItem->setData(0, Qt::UserRole + itemRole_componentID);
|
||||
currentItem->setData(0, Qt::UserRole + itemRole_pointID);
|
||||
componentItem->appendRow(currentItem);
|
||||
QStandardItem* voltageItem = new QStandardItem("电压");
|
||||
voltageItem->setEditable(false);
|
||||
voltageItem->setData("point", Qt::UserRole + itemRole_tag);
|
||||
voltageItem->setData(0, Qt::UserRole + itemRole_stationID);
|
||||
voltageItem->setData(0, Qt::UserRole + itemRole_componentID);
|
||||
voltageItem->setData(1, Qt::UserRole + itemRole_pointID);
|
||||
componentItem->appendRow(voltageItem);
|
||||
ui->dataSourceList->expandAll();
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::setPanel(DataPanel* pPanel)
|
||||
{
|
||||
m_pDataPanel = pPanel;
|
||||
copyModelData(pPanel->m_cofigurationResults.m_pModel_dataType, m_pModel_typeSelected);
|
||||
copyModelData(pPanel->m_cofigurationResults.m_pModel_dataSource, m_pModel_dataSelected);
|
||||
// m_pModel_typeSelected = pPanel->m_cofigurationResults.m_pModel_dataType;
|
||||
// if(m_pModel_typeSelected)
|
||||
// ui->typeSelectedList->setModel(m_pModel_typeSelected);
|
||||
|
|
@ -157,6 +218,8 @@ void dpConfigurationDialog::onBtnClicked_confirm()
|
|||
//m_pDataPanel->m_cofigurationResults.m_pModel_dataType = m_pModel_typeSelected;
|
||||
copyModelData(m_pModel_typeSelected, m_pDataPanel->m_cofigurationResults.m_pModel_dataType);
|
||||
m_pDataPanel->configurationComplete();
|
||||
copyModelData(m_pModel_dataSelected, m_pDataPanel->m_cofigurationResults.m_pModel_dataSource);
|
||||
m_pDataPanel->configurationComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -185,12 +248,18 @@ void dpConfigurationDialog::onItemClicked_typeSource(const QModelIndex& index)
|
|||
if(!bIsHad && m_pModel_typeSelected)
|
||||
{
|
||||
QStandardItem* newItem = new QStandardItem(item->text());
|
||||
newItem->setEditable(false);
|
||||
m_pModel_typeSelected->appendRow(newItem);
|
||||
ui->typeSelectedList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ui->errorTip->isVisible())
|
||||
{
|
||||
ui->errorTip->setVisible(false);
|
||||
ui->btnConfirm->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void dpConfigurationDialog::onBtnClicked_remove_type()
|
||||
{
|
||||
QItemSelectionModel* selectionModel = ui->typeSelectedList->selectionModel();
|
||||
|
|
@ -200,8 +269,84 @@ void dpConfigurationDialog::onBtnClicked_remove_type()
|
|||
QList<QStandardItem*> items = m_pModel_typeSelected->takeRow(nCurrentRow);
|
||||
for(QStandardItem* item: items)
|
||||
delete item;
|
||||
|
||||
if(m_pModel_typeSelected->rowCount() == 0)
|
||||
{
|
||||
ui->errorTip->setVisible(true);
|
||||
ui->errorTip->setToolTip(QString::fromStdWString(L"要至少选择一个数据类型"));
|
||||
ui->btnConfirm->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dpConfigurationDialog::onItemClicked_dataSource(const QModelIndex& index)
|
||||
{
|
||||
QStandardItem* item = m_pModel_dataSource->itemFromIndex(index);
|
||||
if(item)
|
||||
{
|
||||
QString strTag = item->data(Qt::UserRole + itemRole_tag).toString();
|
||||
if(strTag != "point")
|
||||
return;
|
||||
|
||||
QString strText = "";
|
||||
QStandardItem* compontItme = item->parent();
|
||||
if(compontItme && compontItme->data(Qt::UserRole + itemRole_tag).toString() == "component")
|
||||
{
|
||||
QStandardItem* stationItme = compontItme->parent();
|
||||
if(stationItme && stationItme->data(Qt::UserRole + itemRole_tag).toString() == "station")
|
||||
strText = stationItme->text() + "." + compontItme->text();
|
||||
else
|
||||
strText = compontItme->text();
|
||||
}
|
||||
if(strText.isEmpty())
|
||||
strText = item->text();
|
||||
else
|
||||
strText = strText + "." + item->text();
|
||||
|
||||
bool bIsHad = false;
|
||||
for(int i = 0; i< m_pModel_dataSelected->rowCount(); i++)
|
||||
{
|
||||
QString itemText = m_pModel_dataSelected->item(i, 0)->text();
|
||||
if(itemText == strText)
|
||||
{
|
||||
bIsHad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!bIsHad && m_pModel_dataSelected)
|
||||
{
|
||||
QStandardItem* newItem = new QStandardItem(strText);
|
||||
newItem->setEditable(false);
|
||||
newItem->setData(item->data(Qt::UserRole + itemRole_stationID), Qt::UserRole + itemRole_stationID);
|
||||
newItem->setData(item->data(Qt::UserRole + itemRole_componentID), Qt::UserRole + itemRole_componentID);
|
||||
newItem->setData(item->data(Qt::UserRole + itemRole_pointID), Qt::UserRole + itemRole_pointID);
|
||||
m_pModel_dataSelected->appendRow(newItem);
|
||||
QColor color = g_globlaColor.value(newItem->row() % g_globlaColor.size());
|
||||
newItem->setData(color, Qt::DecorationRole);
|
||||
ui->dataSelectedList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
}
|
||||
}
|
||||
}
|
||||
void dpConfigurationDialog::onBtnClicked_remove_source()
|
||||
{}
|
||||
{
|
||||
QItemSelectionModel* selectionModel = ui->dataSelectedList->selectionModel();
|
||||
if(selectionModel && m_pModel_dataSelected)
|
||||
{
|
||||
int nCurrentRow = selectionModel->currentIndex().row();
|
||||
QList<QStandardItem*> items = m_pModel_dataSelected->takeRow(nCurrentRow);
|
||||
for(QStandardItem* item: items)
|
||||
delete item;
|
||||
|
||||
//更新颜色-从当前删除项往后的所有项
|
||||
for(int row = nCurrentRow; row < m_pModel_dataSelected->rowCount(); row++)
|
||||
{
|
||||
QStandardItem* item = m_pModel_dataSelected->item(row, 0);
|
||||
if(item)
|
||||
{
|
||||
QColor color = g_globlaColor.value(item->row() % g_globlaColor.size());
|
||||
item->setData(color, Qt::DecorationRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ QT_END_NAMESPACE
|
|||
|
||||
class DataPanel;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
|
||||
class dpConfigurationDialog : public QDialog
|
||||
{
|
||||
|
|
@ -33,19 +34,28 @@ public slots:
|
|||
void onBtnClicked_remove_source();
|
||||
|
||||
void onItemClicked_typeSource(const QModelIndex&);
|
||||
void onItemClicked_dataSource(const QModelIndex&);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*);
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
void copyModelData(QStandardItemModel*, QStandardItemModel*);
|
||||
void createDataSourceList();
|
||||
|
||||
Ui::dpConfigurationDialog* ui;
|
||||
QPushButton* m_curActiveTab;
|
||||
|
||||
DataPanel* m_pDataPanel;
|
||||
|
||||
//Models
|
||||
///Models
|
||||
//dataType
|
||||
QStandardItemModel* m_pModel_typeSource;
|
||||
QStandardItemModel* m_pModel_typeSelected;
|
||||
//dataSource
|
||||
QStandardItemModel* m_pModel_dataSource;
|
||||
QStandardItemModel* m_pModel_dataSelected;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,4 +33,9 @@ struct configurationResults
|
|||
}
|
||||
};
|
||||
|
||||
#define itemRole_tag 1
|
||||
#define itemRole_stationID 2
|
||||
#define itemRole_componentID 3
|
||||
#define itemRole_pointID 4
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
|
||||
enum MessageDialogType
|
||||
{
|
||||
|
|
@ -47,6 +48,7 @@ enum TimeUnit
|
|||
};
|
||||
|
||||
extern MessageDialogBtn g_msgDlgBtn;
|
||||
extern QHash<int, QColor> g_globlaColor;
|
||||
extern QHash<int, QString> g_timeUnit;
|
||||
|
||||
void initializeGlobalVariable();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/icon_error.png</file>
|
||||
<file>images/icon_arrow_down.png</file>
|
||||
<file>images/icon_arrow_right.png</file>
|
||||
<file>images/btn_remove_default.png</file>
|
||||
<file>images/btn_remove_hover.png</file>
|
||||
<file>images/icon_double-left.png</file>
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 223 B |
Binary file not shown.
|
After Width: | Height: | Size: 165 B |
Binary file not shown.
|
After Width: | Height: | Size: 597 B |
|
|
@ -2,10 +2,25 @@
|
|||
|
||||
MessageDialogBtn g_msgDlgBtn = btn_Null;
|
||||
|
||||
QHash<int, QColor> g_globlaColor;
|
||||
QHash<int, QString> g_timeUnit;
|
||||
|
||||
void initializeGlobalVariable()
|
||||
{
|
||||
//颜色
|
||||
g_globlaColor.insert(0, QColor(153, 50, 204)); //深兰花紫
|
||||
g_globlaColor.insert(1, QColor(127, 255, 170)); //绿玉\碧绿色
|
||||
g_globlaColor.insert(2, QColor(0, 206, 209)); //深绿宝石
|
||||
g_globlaColor.insert(3, QColor(46, 139, 87)); //海洋绿
|
||||
g_globlaColor.insert(4, QColor(225, 215, 0)); //金色
|
||||
g_globlaColor.insert(5, QColor(255, 165, 0)); //橙色
|
||||
g_globlaColor.insert(6, QColor(144, 238, 144)); //浅绿色
|
||||
g_globlaColor.insert(7, QColor(218, 112, 214)); //兰花的紫色
|
||||
g_globlaColor.insert(8, QColor(70, 130, 180)); //钢蓝
|
||||
g_globlaColor.insert(9, QColor(218, 165, 32)); //秋麒麟
|
||||
g_globlaColor.insert(10, QColor(240, 128, 128)); //淡珊瑚色
|
||||
g_globlaColor.insert(11, QColor(70, 130, 180)); //钢蓝
|
||||
//时间单位
|
||||
g_timeUnit.insert(TU_Year, QString::fromWCharArray(L"365d"));
|
||||
g_timeUnit.insert(TU_Month, QString::fromWCharArray(L"30d"));
|
||||
g_timeUnit.insert(TU_Day, QString::fromWCharArray(L"1d"));
|
||||
|
|
|
|||
|
|
@ -72,22 +72,25 @@ QTreeView::item
|
|||
{
|
||||
height:25px;
|
||||
}
|
||||
QTreeView::item:disabled {
|
||||
color: rgb(50, 50, 50);
|
||||
}
|
||||
QTreeView::item:selected {
|
||||
color: rgb(250, 250, 250);
|
||||
background-color: transparent;
|
||||
background-color: rgba(67,160,249, 15);
|
||||
border:0px;
|
||||
}
|
||||
QTreeView::item:hover {
|
||||
background-color: rgba(67,160,249, 30);
|
||||
background-color: rgba(67,160,249, 15);
|
||||
border:0px;
|
||||
}
|
||||
QTreeView::branch:has-children:!has-siblings:closed,
|
||||
QTreeView::branch:closed:has-children:has-siblings {
|
||||
|
||||
image: url(:/images/icon_arrow_right.png);
|
||||
}
|
||||
QTreeView::branch:open:has-children:!has-siblings,
|
||||
QTreeView::branch:open:has-children:has-siblings {
|
||||
|
||||
image: url(:/images/icon_arrow_down.png);
|
||||
}
|
||||
|
||||
QTableView
|
||||
|
|
@ -281,7 +284,7 @@ QPushButton:pressed
|
|||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="pageDataType">
|
||||
<property name="styleSheet">
|
||||
|
|
@ -407,6 +410,9 @@ background-color:transparent;
|
|||
<property name="focusPolicy">
|
||||
<enum>Qt::FocusPolicy::NoFocus</enum>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QTableView" name="dataSelectedList">
|
||||
<property name="geometry">
|
||||
|
|
@ -426,8 +432,11 @@ background-color:transparent;
|
|||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>200</number>
|
||||
<number>100</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderHighlightSections">
|
||||
<bool>false</bool>
|
||||
|
|
@ -517,9 +526,12 @@ background-color:rgb(24,32,38);
|
|||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnConfirm">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>380</x>
|
||||
<x>385</x>
|
||||
<y>460</y>
|
||||
<width>71</width>
|
||||
<height>26</height>
|
||||
|
|
@ -541,6 +553,10 @@ background-color:rgb(55,131,204);
|
|||
QPushButton:pressed
|
||||
{
|
||||
background-color:rgb(67,160,249);
|
||||
}
|
||||
QPushButton:disabled
|
||||
{
|
||||
background-color: rgb(60, 60, 60);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
|
@ -550,6 +566,26 @@ background-color:rgb(67,160,249);
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="errorTip">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>350</x>
|
||||
<y>461</y>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel
|
||||
{
|
||||
border-image: url(:/images/icon_error.png);
|
||||
}
|
||||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
|||
Loading…
Reference in New Issue