From e540f867b6312f2321344bf4ddcfbe4d41f17ef4 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Wed, 22 Jan 2025 15:40:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=95=B0=E6=8D=AE=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E9=85=8D=E7=BD=AE=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dataPanel/dpConfigurationDialog.cpp | 149 ++++++++++++++++++++++++++- dataPanel/dpConfigurationDialog.h | 12 ++- dataPanel/dpGlobals.h | 5 + include/global.h | 2 + resource/PowerMaster.qrc | 3 + resource/images/icon_arrow_down.png | Bin 0 -> 223 bytes resource/images/icon_arrow_right.png | Bin 0 -> 165 bytes resource/images/icon_error.png | Bin 0 -> 597 bytes source/global.cpp | 15 +++ ui/dpConfigurationDialog.ui | 50 +++++++-- 10 files changed, 226 insertions(+), 10 deletions(-) create mode 100644 resource/images/icon_arrow_down.png create mode 100644 resource/images/icon_arrow_right.png create mode 100644 resource/images/icon_error.png diff --git a/dataPanel/dpConfigurationDialog.cpp b/dataPanel/dpConfigurationDialog.cpp index 0b6ae7e..d0618df 100644 --- a/dataPanel/dpConfigurationDialog.cpp +++ b/dataPanel/dpConfigurationDialog.cpp @@ -1,6 +1,7 @@ #include "dpConfigurationDialog.h" #include "ui_dpConfigurationDialog.h" #include "dataPanel.h" +#include "global.h" #include 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 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 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); + } + } + } +} diff --git a/dataPanel/dpConfigurationDialog.h b/dataPanel/dpConfigurationDialog.h index 0a6545a..14b2af7 100644 --- a/dataPanel/dpConfigurationDialog.h +++ b/dataPanel/dpConfigurationDialog.h @@ -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; }; diff --git a/dataPanel/dpGlobals.h b/dataPanel/dpGlobals.h index d595382..6eae477 100644 --- a/dataPanel/dpGlobals.h +++ b/dataPanel/dpGlobals.h @@ -33,4 +33,9 @@ struct configurationResults } }; +#define itemRole_tag 1 +#define itemRole_stationID 2 +#define itemRole_componentID 3 +#define itemRole_pointID 4 + #endif diff --git a/include/global.h b/include/global.h index 2bf4444..cfe248d 100644 --- a/include/global.h +++ b/include/global.h @@ -3,6 +3,7 @@ #include #include +#include enum MessageDialogType { @@ -47,6 +48,7 @@ enum TimeUnit }; extern MessageDialogBtn g_msgDlgBtn; +extern QHash g_globlaColor; extern QHash g_timeUnit; void initializeGlobalVariable(); diff --git a/resource/PowerMaster.qrc b/resource/PowerMaster.qrc index 51b7772..24f9b9a 100644 --- a/resource/PowerMaster.qrc +++ b/resource/PowerMaster.qrc @@ -1,5 +1,8 @@ + images/icon_error.png + images/icon_arrow_down.png + images/icon_arrow_right.png images/btn_remove_default.png images/btn_remove_hover.png images/icon_double-left.png diff --git a/resource/images/icon_arrow_down.png b/resource/images/icon_arrow_down.png new file mode 100644 index 0000000000000000000000000000000000000000..13d769d1bbcabf90258af99cfca9bde91ceb2fd3 GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjoCO|{#S9GG!XV7ZFl!D-#Y9gR z$B>FSZzmk&WHJqOi{zQlzXO=zd!f) zaunEcB}&}EZ1chSUYs|WUhkBApUkFJ@Xe`V?vmL{Uhj5|(^#t0cv<;LQrhayn#)h# z#$MWJ`fo?8_$61nq%>#i%N2T_ztw*})ZTe{N!iUBJ(s;tCl^1Rf1>$8|4!z20ms$~ Tt`3O+I*!59)z4*}Q$iB}Qvq0t literal 0 HcmV?d00001 diff --git a/resource/images/icon_arrow_right.png b/resource/images/icon_arrow_right.png new file mode 100644 index 0000000000000000000000000000000000000000..a717b441dffc3f06b3ec1c257afd3cf5e445c2b9 GIT binary patch literal 165 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjoCO|{#S9GG!XV7ZFl!D-MYyMn zV@SoEw^JOs8XS0-ciVq9uXE3@Gu6ylQt^>FQPk=}cDvZ5j%AuEy|W4wG8rrwW5hhu z@)*=Sr=Cz!+__(6p7)JO{(HLi)_7j{5^^+=d&b^3v;G$|Up{>;K*dMV251F?r>mdK II;Vst0N9H(MgRZ+ literal 0 HcmV?d00001 diff --git a/resource/images/icon_error.png b/resource/images/icon_error.png new file mode 100644 index 0000000000000000000000000000000000000000..968f0ee6ea5030f8df47a914897fd6aca7997f6e GIT binary patch literal 597 zcmV-b0;>IqP)DJ+7DAS8ka z`e`Lt5m7=A1VKb-5ClOGfpiQygtHy|3%Ue$>l*$6317I%Xr}J$>e@*2zzcKyUS{{% zk3~o#kw_#G697tFK=Hep2pLAz1Vm9iQ1S^1fpp>!sck^j0#F>v8a^EyMAZPiU>hjp z>vsW?09s>5q5~8^oLJ!6PC_G=O5C_VDZ$ zwvgc31dWKLRmiJN%|}TLtrpVey4wk!p+Pkp<4zD(t586jz6l2_;GcAesZ}VV&E4rf zR$y;8HnVcI+0F`F``Y+EZq#J0a&4RG-1u8r zf!m!Hz5 g_globlaColor; QHash 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")); diff --git a/ui/dpConfigurationDialog.ui b/ui/dpConfigurationDialog.ui index 71e488d..cfa8806 100644 --- a/ui/dpConfigurationDialog.ui +++ b/ui/dpConfigurationDialog.ui @@ -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 - 0 + 1 @@ -407,6 +410,9 @@ background-color:transparent; Qt::FocusPolicy::NoFocus + + false + @@ -426,8 +432,11 @@ background-color:transparent; false + + false + - 200 + 100 false @@ -517,9 +526,12 @@ background-color:rgb(24,32,38); + + true + - 380 + 385 460 71 26 @@ -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); } @@ -550,6 +566,26 @@ background-color:rgb(67,160,249); false + + + + 350 + 461 + 24 + 24 + + + + QLabel +{ +border-image: url(:/images/icon_error.png); +} + + + + + +