diff --git a/PropertyEditor/CMakeLists.txt b/PropertyEditor/CMakeLists.txt index fb4c221..11b6312 100644 --- a/PropertyEditor/CMakeLists.txt +++ b/PropertyEditor/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12) project(PropertyEditor CXX) -find_package(Qt6 COMPONENTS Core Widgets Gui QuickWidgets QuickTemplates2 QuickControls2 REQUIRED) +find_package(Qt6 COMPONENTS Core Widgets Gui GuiPrivate QuickWidgets QuickTemplates2 QuickControls2 REQUIRED) qt6_add_resources(QRC_FILE resources.qrc) diff --git a/PropertyEditor/resources/Qml/ValueEditor/ColorBox.qml b/PropertyEditor/resources/Qml/ValueEditor/ColorBox.qml index 4312120..5fc7ca0 100644 --- a/PropertyEditor/resources/Qml/ValueEditor/ColorBox.qml +++ b/PropertyEditor/resources/Qml/ValueEditor/ColorBox.qml @@ -1,33 +1,91 @@ -import QtQuick; -import QtQuick.Controls; +import QtQuick +import QtQuick.Controls import QtQuick.Dialogs -Item{ +Item { id: control property color value implicitHeight: 25 - signal asValueChanged(text:var) + implicitWidth: 150 + signal asValueChanged(text: var) - function setValue(newValue:var){ - if(newValue !== value){ + // 计算颜色代码(hex格式) + function getColorCode(color) { + if (color.a === 1) { + // 不透明颜色 + return color.toString().toUpperCase() + } else { + // 透明颜色 + return Qt.rgba(color.r, color.g, color.b, color.a).toString() + } + } + + function setValue(newValue: var) { + if (newValue !== value) { value = newValue asValueChanged(value) } } - Button{ - anchors.margins: 2 + Row { anchors.fill: parent - palette { - button: value - } - background: Rectangle { + spacing: 5 + + // 左边颜色显示矩形 + Rectangle { + id: colorRect + width: 25 + height: parent.height + radius: 2 + border.width: 1 + border.color: Qt.darker(colorRect.color, 1.5) color: value + + MouseArea { + anchors.fill: parent + onClicked: { + colorDialog.open() + } + } } - onClicked: { - colorDialog.open() + + // 右边颜色代码显示(不可编辑) + Rectangle { + width: parent.width - colorRect.width - parent.spacing + height: parent.height + radius: 2 + border.width: 1 + border.color: "#cccccc" + + Text { + id: colorText + anchors.fill: parent + anchors.margins: 2 + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + text: getColorCode(value) + font.pixelSize: 12 + elide: Text.ElideRight + + // 颜色值改变时更新文本 + Connections { + target: control + function onValueChanged() { + colorText.text = getColorCode(control.value) + } + } + } + + // 点击整个右侧区域也可以打开颜色选择 + MouseArea { + anchors.fill: parent + onClicked: { + colorDialog.open() + } + } } } + ColorDialog { id: colorDialog selectedColor: value @@ -35,6 +93,4 @@ Item{ control.setValue(selectedColor) } } - } - diff --git a/diagramCavas/CMakeLists.txt b/diagramCavas/CMakeLists.txt index 61c9479..679bddb 100644 --- a/diagramCavas/CMakeLists.txt +++ b/diagramCavas/CMakeLists.txt @@ -51,6 +51,9 @@ set(DIAGRAMCAVAS_HEADER_FILES include/structDataCauseEditDlg.h include/structDataActionParaDlg.h include/bayMeasureDlg.h + include/basePropertyProxy.h + include/basePannelPropertyProxy.h + include/dataSourceDlg.h include/diagramEditor/editPanel.h include/diagramEditor/editView.h include/diagramEditor/editScene.h @@ -129,6 +132,7 @@ set(DIAGRAMCAVAS_HEADER_FILES include/propertyType/CustomGadget.h include/propertyType/CustomType.h include/propertyType/PropertyTypeCustomization_CustomType.h + include/propertyType/pannelColorGadget.h ../common/include/httpInterface.h ../common/include/tools.h ../common/include/global.h @@ -188,6 +192,9 @@ set(DIAGRAMCAVAS_SOURCE_FILES source/structDataCauseEditDlg.cpp source/structDataActionParaDlg.cpp source/bayMeasureDlg.cpp + source/basePropertyProxy.cpp + source/basePannelPropertyProxy.cpp + source/dataSourceDlg.cpp source/diagramEditor/editPanel.cpp source/diagramEditor/editView.cpp source/diagramEditor/editScene.cpp @@ -264,6 +271,7 @@ set(DIAGRAMCAVAS_SOURCE_FILES source/instance/extraPropertyManager.cpp source/propertyType/PropertyTypeCustomization_CustomType.cpp + source/propertyType/pannelColorGadget.cpp ../common/source/httpInterface.cpp ../common/source/baseProperty.cpp ../common/source/tools.cpp @@ -298,6 +306,7 @@ set(UI_FILES ui/diagramConnectSetting.ui ui/structDataPreviewDlg.ui ui/bayMeasureDlg.ui + ui/dataSourceDlg.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) diff --git a/diagramCavas/include/baseDrawingPanel.h b/diagramCavas/include/baseDrawingPanel.h index 2d3d844..90d8094 100644 --- a/diagramCavas/include/baseDrawingPanel.h +++ b/diagramCavas/include/baseDrawingPanel.h @@ -17,11 +17,11 @@ class StatusBar; class PowerEntity; class ProjectDiagramNameInput; class BayManagerDlg; +class BasePannelPropertyProxy; class BaseDrawingPanel : public QWidget { Q_OBJECT - public: BaseDrawingPanel(PowerEntity* pEntity,QWidget *parent = nullptr,DiagramMode mode = DM_edit); ~BaseDrawingPanel(); @@ -50,10 +50,13 @@ public: QString getGenerateByPanel() {return _sGenerateByPanel;} PowerEntity* getEntity() {return _pEntity;} + BasePannelPropertyProxy* getPropertyProxy(){return _pPropertyProxy;} signals: void panelDelete(const QString&,int); protected: virtual void closeEvent(QCloseEvent *closeEvent) {}; +protected: + BasePannelPropertyProxy* _pPropertyProxy; //属性页代理 protected: DesignerView* m_pGraphicsView; DesignerScene* m_pGraphicsScene; diff --git a/diagramCavas/include/basePannelPropertyProxy.h b/diagramCavas/include/basePannelPropertyProxy.h new file mode 100644 index 0000000..86d66f0 --- /dev/null +++ b/diagramCavas/include/basePannelPropertyProxy.h @@ -0,0 +1,37 @@ +#ifndef BASEPANNELPROPERTYPROXY_H +#define BASEPANNELPROPERTYPROXY_H +/**************************** + * pannel属性代理基类 + * *************************/ +#include "basePropertyProxy.h" +#include "propertyType/pannelColorGadget.h" + +class BaseDrawingPanel; + +class BasePannelPropertyProxy : public BasePropertyProxy { + Q_OBJECT +public: + Q_PROPERTY(QString Name READ getName WRITE setName) + Q_PROPERTY(QSize Size READ getSize WRITE setSize) + Q_PROPERTY(PannelColorGadget* Color READ getColorGadgetPtr WRITE setColorGadgetPtr) + //Q_PROPERTY(QColor BackColor READ getBackColor WRITE setBackColor) + //Q_PROPERTY(QColor GridColor READ getGridColor WRITE setGridColor) +public: + BasePannelPropertyProxy(BaseDrawingPanel*); + ~BasePannelPropertyProxy(); +public: + virtual QString getName() const; + virtual void setName(QString); + virtual QSize getSize() const; + virtual void setSize(QSize); + PannelColorGadget* getColorGadgetPtr(){return _pColorGadget;} + void setColorGadgetPtr(PannelColorGadget* p){_pColorGadget = p;} + // virtual QColor getBackColor() const; + // virtual void setBackColor(QColor); + // virtual QColor getGridColor() const; + // virtual void setGridColor(QColor); +protected: + BaseDrawingPanel* _pPanel; + PannelColorGadget* _pColorGadget; +}; +#endif //BASEPANNELPROPERTYPROXY_H diff --git a/diagramCavas/include/basePropertyProxy.h b/diagramCavas/include/basePropertyProxy.h new file mode 100644 index 0000000..1985f89 --- /dev/null +++ b/diagramCavas/include/basePropertyProxy.h @@ -0,0 +1,14 @@ +#ifndef BASEPROPERTYPROXY_H +#define BASEPROPERTYPROXY_H +/**************************** + * 属性页代理基类 + * *************************/ +#include + +class BasePropertyProxy : public QObject { + Q_OBJECT +public: + BasePropertyProxy(QObject* parnet = nullptr); + ~BasePropertyProxy(); +}; +#endif //BASEPROPERTYPROXY_H diff --git a/diagramCavas/include/dataSourceDlg.h b/diagramCavas/include/dataSourceDlg.h new file mode 100644 index 0000000..61b30f7 --- /dev/null +++ b/diagramCavas/include/dataSourceDlg.h @@ -0,0 +1,54 @@ +#ifndef DATASOURCEDLG_H +#define DATASOURCEDLG_H + +/*********运行时数据源选则*********/ +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class dataSourceDlg; } +QT_END_NAMESPACE + +class QStandardItemModel; +class QStandardItem; +struct ExtraProperty; +class StructDataSource; +class ExtraPropertyManager; + +class DataSourceDlg : public QDialog +{ + Q_OBJECT +public: + DataSourceDlg(QWidget *parent = nullptr); + ~DataSourceDlg(); + + void initial(); + void loadData(); + + void setExtraPropertyManager(ExtraPropertyManager* p) {_pExtraProManager = p;} + void showDlg(); +public slots: + void onOkClicked(); + void onCancelClicked(); + + void onTreeSelectionChanged(const QModelIndex& current, const QModelIndex& previous); + void addItemToView(const ExtraProperty& property, + const QString& displayMode, // "name" 或 "tag" + QStandardItem* root, + QStandardItem* pItem); +private: + void clearItems(); + void clearPropertyList(); + void loadCategoryProperties(QStandardItem* categoryItem); + QVector getCategoryPropertiesFromDataManager(const QVariantMap& categoryData); + void updatePropertyList(QVector); + bool expandToPropertyByCode(const QString& propertyCode,const QString& displayMode); //根据编码展开到属性节点 + bool expandToNodeByNames(QStandardItem* rootItem,const QStringList& nodeNames); //根据已知名称展开到对应节点 +private: + Ui::dataSourceDlg *ui; + QStandardItemModel* _treeModel; + QStandardItem* m_currentCategoryItem; //当前操作对象 + ExtraPropertyManager* _pExtraProManager; //使用外部的manager + StructDataSource* m_dataSource; +}; + +#endif diff --git a/diagramCavas/include/designerScene.h b/diagramCavas/include/designerScene.h index a19f13a..60871eb 100644 --- a/diagramCavas/include/designerScene.h +++ b/diagramCavas/include/designerScene.h @@ -24,7 +24,10 @@ public: GraphicsItemGroup* createGroup(); void destroyGroup(); - + void setBackGoundColor(QColor color) {m_backGroundColor = color;} + QColor getBackGoundColor() {return m_backGroundColor;} + void setGridColor(QColor color) {m_gridColor = color;} + QColor getGridColor() {return m_gridColor;} signals: void signalAddItem(QGraphicsItem*); protected: @@ -43,7 +46,8 @@ private: bool m_bGridVisible; QGraphicsView* m_pView; BaseDrawingPanel* m_pDrawingPanel; //保存父指针 - + QColor m_backGroundColor; + QColor m_gridColor; private: FixedPortsModel* _graphModel; }; diff --git a/diagramCavas/include/diagramCavas.h b/diagramCavas/include/diagramCavas.h index afad03d..44bd1cb 100644 --- a/diagramCavas/include/diagramCavas.h +++ b/diagramCavas/include/diagramCavas.h @@ -23,6 +23,7 @@ class DataAccessor; struct HttpRecommandInfo; class StructDataPreviewDlg; class ExtraPropertyManager; +class DataSourceDlg; class DIAGRAM_DESIGNER_PUBLIC DiagramCavas : public QMdiArea { @@ -41,6 +42,7 @@ public: void passRecommmandHttpData(HttpRecommandInfo); //传递推荐列表数据 DiagramConnectSetting* getConnectSettingDlg() {return _connectSetting;} ExtraPropertyManager* getExtraPropertyManager() {return _extraPropertyManager;} + DataSourceDlg* getDataSourceDlg() {return _dataSourceDlg;} public: void initial(); signals: @@ -48,6 +50,7 @@ signals: void prepareSelectItems(QList); void updateMonitorList(QString,QPair,int nMode = 0); //0新增1删除 void createdMonitorItems(QList); //创建的监控中item个数 + void selectTarget(QObject*); public slots: void onSignal_addDrawingPanel(PowerEntity* p,DiagramMode = DM_edit,QString parent = QString()); //parent:派生运行时的page void onSignal_addGraphicsItem(modelStateInfo&); @@ -103,6 +106,8 @@ public slots: QMap> getMapDraw() {return m_mapDrawPanel;} QMap> getMapEdit() {return m_mapEditPanel;} QMap> getMapMonitor() {return m_mapMonitorPanel;} + + void onTargetSelected(QObject*); //选中事件(属性显示) protected: void resizeEvent(QResizeEvent* event) override; private: @@ -120,6 +125,7 @@ private: DataAccessor* _dataAccessor; StructDataPreviewDlg* _structDataPreviewDlg; ExtraPropertyManager* _extraPropertyManager; + DataSourceDlg* _dataSourceDlg; }; #endif diff --git a/diagramCavas/include/graphicsItem/graphicsBaseItem.h b/diagramCavas/include/graphicsItem/graphicsBaseItem.h index 7a4cdf3..0954c41 100644 --- a/diagramCavas/include/graphicsItem/graphicsBaseItem.h +++ b/diagramCavas/include/graphicsItem/graphicsBaseItem.h @@ -541,6 +541,10 @@ protected: class GraphicsProjectModelItem : public GraphicsBaseItem //工程模item { Q_OBJECT +public: + Q_PROPERTY(QString Name READ getName WRITE setName) + Q_PROPERTY(QPointF Position READ getPosition WRITE setPosition) + Q_PROPERTY(QRectF Size READ getSize WRITE setSize) public: GraphicsProjectModelItem(QGraphicsItem *parent); GraphicsProjectModelItem(const GraphicsProjectModelItem&); @@ -588,6 +592,13 @@ public: _curMonitorStateEnable = info.bEnable; } } +public: + QString getName() const; + void setName(QString); + QPointF getPosition() const; + void setPosition(QPointF); + QRectF getSize() const; + void setSize(QRectF); protected: virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange, const QVariant&) override; virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override; diff --git a/diagramCavas/include/propertyType/pannelColorGadget.h b/diagramCavas/include/propertyType/pannelColorGadget.h new file mode 100644 index 0000000..e52cd01 --- /dev/null +++ b/diagramCavas/include/propertyType/pannelColorGadget.h @@ -0,0 +1,27 @@ +#ifndef PANNELCOLORGADGET_H +#define PANNELCOLORGADGET_H + +#include +#include + +class BaseDrawingPanel; + +class PannelColorGadget { + Q_GADGET +public: + Q_PROPERTY(QColor BackColor READ getBackColor WRITE setBackColor) + Q_PROPERTY(QColor GridColor READ getGridColor WRITE setGridColor) +public: + PannelColorGadget(BaseDrawingPanel*); + + QColor getBackColor() const; + void setBackColor(QColor); + QColor getGridColor() const; + void setGridColor(QColor); +private: + BaseDrawingPanel* _pPanel; +}; + +Q_DECLARE_METATYPE(QSharedPointer); + +#endif // PANNELCOLORGADGET_H diff --git a/diagramCavas/source/baseDrawingPanel.cpp b/diagramCavas/source/baseDrawingPanel.cpp index 03f52ea..ad0af4f 100644 --- a/diagramCavas/source/baseDrawingPanel.cpp +++ b/diagramCavas/source/baseDrawingPanel.cpp @@ -8,7 +8,9 @@ #include "util/selectorManager.h" #include "statusBar.h" #include "powerEntity.h" +#include "diagramCavas.h" #include "topologyManager.h" +#include "basePannelPropertyProxy.h" BaseDrawingPanel::BaseDrawingPanel(PowerEntity* pEntity,QWidget *parent,DiagramMode mode) : QWidget(parent) @@ -18,6 +20,7 @@ BaseDrawingPanel::BaseDrawingPanel(PowerEntity* pEntity,QWidget *parent,DiagramM ,_verticalLayout(nullptr) ,_horizontalLayout(nullptr) ,_hSplitter(nullptr) + ,_pPropertyProxy(nullptr) { _pEntity = pEntity; _pModel = new FixedPortsModel(pEntity); @@ -33,6 +36,15 @@ BaseDrawingPanel::BaseDrawingPanel(PowerEntity* pEntity,QWidget *parent,DiagramM m_pGraphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); m_pGraphicsScene->setView(m_pGraphicsView); _pModel->setScene(m_pGraphicsScene); + connect(m_pGraphicsScene, &DesignerScene::selectionChanged, this, [&](){ + QList selectedItems = m_pGraphicsScene->selectedItems(); + if(selectedItems.count() != 1) { + _pModel->getCavas()->onTargetSelected(_pPropertyProxy); + return; + } + GraphicsBaseItem *item = static_cast(selectedItems.first()); + _pModel->getCavas()->onTargetSelected(item); + }); m_pStatusBar = new StatusBar(this); m_pStatusBar->setMaximumHeight(25); @@ -54,12 +66,16 @@ BaseDrawingPanel::BaseDrawingPanel(PowerEntity* pEntity,QWidget *parent,DiagramM _verticalLayout->addWidget(m_pStatusBar); _verticalLayout->setContentsMargins(0, 0, 0, 0); _verticalLayout->setSpacing(0); + + _pPropertyProxy = new BasePannelPropertyProxy(this); } BaseDrawingPanel::~BaseDrawingPanel() { if(_pModel) delete _pModel; + if(_pPropertyProxy) + delete _pPropertyProxy; } QGraphicsScene* BaseDrawingPanel::getQGraphicsScene() @@ -79,4 +95,3 @@ SelectorManager* BaseDrawingPanel::selectorManager() const else return NULL; } - diff --git a/diagramCavas/source/basePannelPropertyProxy.cpp b/diagramCavas/source/basePannelPropertyProxy.cpp new file mode 100644 index 0000000..8ebed5d --- /dev/null +++ b/diagramCavas/source/basePannelPropertyProxy.cpp @@ -0,0 +1,58 @@ +#include "basePannelPropertyProxy.h" +#include "baseDrawingPanel.h" +#include "propertyType/pannelColorGadget.h" + +BasePannelPropertyProxy::BasePannelPropertyProxy(BaseDrawingPanel* pPanel) + : BasePropertyProxy(pPanel) + ,_pPanel(pPanel) +{ + _pColorGadget = new PannelColorGadget(_pPanel); +} + +BasePannelPropertyProxy::~BasePannelPropertyProxy() +{ + if(_pColorGadget) + delete _pColorGadget; +} + + +QString BasePannelPropertyProxy::getName() const +{ + + return _pPanel->pageName(); +} + +void BasePannelPropertyProxy::setName(QString str) +{ + _pPanel->setPageName(str); +} + +QSize BasePannelPropertyProxy::getSize() const +{ + return _pPanel->size(); +} + +void BasePannelPropertyProxy::setSize(QSize size) +{ + _pPanel->resize(size); +} + +/*QColor BasePannelPropertyProxy::getBackColor() const +{ + return _pPanel->getScene()->getBackGoundColor(); +} + +void BasePannelPropertyProxy::setBackColor(QColor color) +{ + _pPanel->getScene()->setBackGoundColor(color); +} + +QColor BasePannelPropertyProxy::getGridColor() const +{ + return _pPanel->getScene()->getGridColor(); +} + +void BasePannelPropertyProxy::setGridColor(QColor color) +{ + _pPanel->getScene()->setGridColor(color); +}*/ diff --git a/diagramCavas/source/basePropertyProxy.cpp b/diagramCavas/source/basePropertyProxy.cpp new file mode 100644 index 0000000..38d0b04 --- /dev/null +++ b/diagramCavas/source/basePropertyProxy.cpp @@ -0,0 +1,12 @@ +#include "basePropertyProxy.h" + +BasePropertyProxy::BasePropertyProxy(QObject *parent) + : QObject(parent) +{ + +} + +BasePropertyProxy::~BasePropertyProxy() +{ + +} diff --git a/diagramCavas/source/dataSourceDlg.cpp b/diagramCavas/source/dataSourceDlg.cpp new file mode 100644 index 0000000..4230f09 --- /dev/null +++ b/diagramCavas/source/dataSourceDlg.cpp @@ -0,0 +1,325 @@ +#include "dataSourceDlg.h" +#include "ui_dataSourceDlg.h" +#include +#include "structDataSource.h" +#include "instance/extraPropertyManager.h" +#include "global.h" + +DataSourceDlg::DataSourceDlg(QWidget *parent) + : QDialog(parent) + , ui(new Ui::dataSourceDlg) + ,_treeModel(nullptr) + ,m_currentCategoryItem(nullptr) + ,_pExtraProManager(nullptr) +{ + ui->setupUi(this); + this->setWindowFlags(Qt::FramelessWindowHint | windowFlags()); + initial(); +} + +DataSourceDlg::~DataSourceDlg() +{ + delete ui; +} + +void DataSourceDlg::initial() +{ + connect(ui->btn_ok,&QPushButton::clicked,this,&DataSourceDlg::onOkClicked); + connect(ui->btn_cancel,&QPushButton::clicked,this,&DataSourceDlg::onCancelClicked); + + m_dataSource = new StructDataSource(this); + _treeModel = new QStandardItemModel(this); + _treeModel->setHorizontalHeaderLabels(QStringList() << "属性层级结构"); + ui->treeView->setModel(_treeModel); +} + +void DataSourceDlg::loadData() +{ + if(_pExtraProManager) + m_dataSource->loadExtrapro(_pExtraProManager->geAlltProperty()); +} + +void DataSourceDlg::showDlg() +{ + if(_pExtraProManager) + { + show(); + clearItems(); + auto& mapExtra = m_dataSource->allProperties; + QStandardItem* root = _treeModel->invisibleRootItem(); + for(auto& pro:mapExtra){ + QStandardItem* propertyItem = new QStandardItem(); + addItemToView(pro,"name",root,propertyItem); + } + + ui->treeView->expandAll(); + } +} + +void DataSourceDlg::addItemToView(const ExtraProperty& property, + const QString& displayMode, // "name" 或 "tag" + QStandardItem* root, + QStandardItem* pItem) +{ + // 设置叶子节点的显示文本(使用name或tag) + if (displayMode == "name") { + pItem->setText(property.name.isEmpty() ? "未命名属性" : property.name); + } else { + pItem->setText(property.tag.isEmpty() ? "unknown_property" : property.tag); + } + + // 在叶子节点存储完整的属性信息 + QVariantMap propertyData; + propertyData["property"] = QVariant::fromValue(property); + propertyData["displayMode"] = displayMode; + propertyData["code"] = property.code; + pItem->setData(propertyData, Qt::UserRole + 1); + + QVector levels = { + {(displayMode == "name") ? property.grid_name : property.grid_tag, + property.grid_name, property.grid_tag, true, + (displayMode == "name") ? "未命名电网" : "unknown_grid"}, + + {(displayMode == "name") ? property.zone_name : property.zone_tag, + property.zone_name, property.zone_tag, true, + (displayMode == "name") ? "未命名区域" : "unknown_zone"}, + + {(displayMode == "name") ? property.station_name : property.station_tag, + property.station_name, property.station_tag, true, + (displayMode == "name") ? "未命名站点" : "unknown_station"}, + + {property.currentLevel, + property.currentLevel, property.currentLevel, false, + (displayMode == "name") ? "通用层级" : "common_level"}, + + {(displayMode == "name") ? property.bay_name : property.bay_tag, + property.bay_name, property.bay_tag, false, + (displayMode == "name") ? "间隔" : "bay"}, + + {property.component_name.isEmpty() ? + (displayMode == "name") ? "未命名设备" : property.component_uuid.toString() : + (displayMode == "name") ? property.component_name : property.component_uuid.toString(), + property.component_name, property.component_uuid.toString(), true, + (displayMode == "name") ? "未命名设备" : "unknown_component"} + }; +} + +void DataSourceDlg::onOkClicked() +{ + hide(); +} + +void DataSourceDlg::onCancelClicked() +{ + hide(); +} + +void DataSourceDlg::onTreeSelectionChanged(const QModelIndex& current, const QModelIndex& previous) { + Q_UNUSED(previous); + + if (!current.isValid()) { + clearPropertyList(); + return; + } + + QStandardItem* item = _treeModel->itemFromIndex(current); + if (!item) { + clearPropertyList(); + return; + } + + QVariantMap itemData = item->data(Qt::UserRole + 1).toMap(); + QString levelType = itemData.value("levelType", "").toString(); + + if (levelType == "category") { + // 点击分类节点,从category节点获取属性 + loadCategoryProperties(item); + }else{ + clearPropertyList(); + } +} + +void DataSourceDlg::clearPropertyList() +{ + ui->listWidget->clear(); + m_currentCategoryItem = nullptr; +} + +void DataSourceDlg::loadCategoryProperties(QStandardItem* categoryItem) { + m_currentCategoryItem = categoryItem; + + // 从category节点获取属性列表 + QVariantMap categoryData = categoryItem->data(Qt::UserRole + 1).toMap(); + QVector properties = categoryData["properties"].value>(); + + if (properties.isEmpty()) { + // 如果没有属性,从DataManager重新获取 + properties = getCategoryPropertiesFromDataManager(categoryData); + } + + if (properties.isEmpty()) { + clearItems(); + return; + } + + updatePropertyList(properties); +} + +QVector DataSourceDlg::getCategoryPropertiesFromDataManager(const QVariantMap& categoryData) { + QString groupTag = categoryData.value("groupTag").toString(); + QString modelName = categoryData.value("modelName").toString(); + QString paraType = categoryData.value("paraType").toString(); + QString sourceType = categoryData.value("sourceType").toString(); + QString componentUuid = categoryData.value("component_uuid").toString(); + + QVector result; + + for (auto it = m_dataSource->allProperties.begin(); + it != m_dataSource->allProperties.end(); ++it) { + const ExtraProperty& prop = it.value(); + + bool match = (prop.group_tag == groupTag) && + (prop.sourceType == sourceType) && + (prop.type_tag == paraType) && + (prop.component_uuid.toString() == componentUuid); + + if (sourceType == "property") { + match = match && (prop.sourceConfig.value("modelName").toString() == modelName); + } + + if (match) { + result.append(prop); + } + } + + return result; +} + +void DataSourceDlg::updatePropertyList(QVector vec) +{ + for(auto& pro:vec){ + QListWidgetItem* pItem = new QListWidgetItem(pro.code); + pItem->setData(Qt::UserRole,pro.connect_para); + ui->listWidget->addItem(pItem); + } +} + +bool DataSourceDlg::expandToPropertyByCode(const QString& propertyCode, + const QString& displayMode) { + // 在树中搜索对应编码的节点 + QStandardItemModel* model = qobject_cast(ui->treeView->model()); + if (!model) { + return false; + } + + QModelIndexList matches = model->match( + model->index(0, 0), + Qt::UserRole + 1, // 搜索用户数据 + QVariant(), // 任意值 + -1, // 搜索所有 + Qt::MatchRecursive | Qt::MatchContains + ); + + for (const QModelIndex& index : matches) { + QStandardItem* item = model->itemFromIndex(index); + if (item) { + QVariantMap itemData = item->data(Qt::UserRole + 1).toMap(); + + // 检查是否是属性节点 + if (itemData.contains("property")) { + ExtraProperty property = itemData["property"].value(); + if (property.code == propertyCode) { + // 构建从根节点到该节点的路径 + QStringList nodeNames; + QModelIndex currentIndex = index; + + while (currentIndex.isValid()) { + QStandardItem* currentItem = model->itemFromIndex(currentIndex); + if (currentItem) { + nodeNames.prepend(currentItem->text()); + } + currentIndex = currentIndex.parent(); + } + + // 去掉根节点 + if (!nodeNames.isEmpty()) { + nodeNames.removeFirst(); + } + + // 展开到该节点 + QStandardItem* rootItem = model->invisibleRootItem(); + return expandToNodeByNames(rootItem, nodeNames); + } + } + } + } + + return false; +} + +bool DataSourceDlg::expandToNodeByNames(QStandardItem* rootItem, + const QStringList& nodeNames) { + if (!rootItem || nodeNames.isEmpty()) { + return false; + } + + QStandardItem* currentItem = rootItem; + QTreeView* treeView = ui->treeView; + + for (int i = 0; i < nodeNames.size(); ++i) { + const QString& targetName = nodeNames[i]; + bool found = false; + + // 在当前节点的子节点中查找 + for (int row = 0; row < currentItem->rowCount(); ++row) { + QStandardItem* childItem = currentItem->child(row, 0); + if (childItem && childItem->text() == targetName) { + // 展开当前节点 + QModelIndex currentIndex = currentItem->index(); + treeView->expand(currentIndex); + + // 如果是最后一层,选中该节点 + if (i == nodeNames.size() - 1) { + QModelIndex childIndex = childItem->index(); + treeView->scrollTo(childIndex); + treeView->selectionModel()->select( + childIndex, + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows + ); + return true; + } + + // 继续查找下一层 + currentItem = childItem; + found = true; + break; + } + } + + if (!found) { + // 没有找到对应的节点 + qWarning() << "Node not found at level" << i << ":" << targetName; + + // 展开到已找到的层级 + if (currentItem != rootItem) { + QModelIndex currentIndex = currentItem->index(); + treeView->expand(currentIndex); + treeView->scrollTo(currentIndex); + } + return false; + } + } + + return true; +} + +void DataSourceDlg::clearItems() +{ + if(_treeModel){ + QStandardItem *root = _treeModel->invisibleRootItem(); //先清空model + int rowCount = root->rowCount(); + if (rowCount > 0) { + _treeModel->removeRows(0, rowCount); + } + } +} diff --git a/diagramCavas/source/designerScene.cpp b/diagramCavas/source/designerScene.cpp index a953fa4..e0eeb68 100644 --- a/diagramCavas/source/designerScene.cpp +++ b/diagramCavas/source/designerScene.cpp @@ -32,6 +32,8 @@ DesignerScene::DesignerScene(FixedPortsModel* graphModel, QObject *parent) m_bGridVisible = true; m_pView = nullptr; m_pDrawingPanel = dynamic_cast(parent); + m_backGroundColor = Qt::white; + m_gridColor = Qt::darkCyan; } DesignerScene::~DesignerScene() { @@ -40,13 +42,13 @@ DesignerScene::~DesignerScene() void DesignerScene::drawBackground(QPainter* painter, const QRectF& rect) { QGraphicsScene::drawBackground(painter, rect); - painter->fillRect(sceneRect(), Qt::white); + painter->fillRect(sceneRect(), m_backGroundColor); if(!m_bGridVisible) return; QRectF sceneRect = this->sceneRect(); QPen pen; - pen.setBrush(Qt::darkCyan);//藏青色 + pen.setBrush(m_gridColor);//藏青色 pen.setStyle(Qt::DashLine); pen.setWidthF(0.2); painter->setPen(pen); diff --git a/diagramCavas/source/diagramCavas.cpp b/diagramCavas/source/diagramCavas.cpp index 38d166a..5ec4a7b 100644 --- a/diagramCavas/source/diagramCavas.cpp +++ b/diagramCavas/source/diagramCavas.cpp @@ -27,6 +27,7 @@ #include "monitorConfigDlg.h" #include "structDataPreviewDlg.h" #include "instance/extraPropertyManager.h" +#include "dataSourceDlg.h" DiagramCavas::DiagramCavas(QWidget *parent) : QMdiArea(parent) @@ -36,6 +37,7 @@ DiagramCavas::DiagramCavas(QWidget *parent) ,_dataAccessor(nullptr) ,_structDataPreviewDlg(nullptr) ,_extraPropertyManager(nullptr) + ,_dataSourceDlg(nullptr) { _pageIndex = 0; } @@ -173,6 +175,10 @@ void DiagramCavas::initial() _structDataPreviewDlg = new StructDataPreviewDlg(this); _structDataPreviewDlg->setExtraPropertyManager(_extraPropertyManager); _structDataPreviewDlg->loadData(); + + _dataSourceDlg = new DataSourceDlg(this); + _dataSourceDlg->setExtraPropertyManager(_extraPropertyManager); + _dataSourceDlg->loadData(); } void DiagramCavas::onSignal_addDrawingPanel(PowerEntity* pItem,DiagramMode mode,QString parent) @@ -595,6 +601,11 @@ void DiagramCavas::resizeEvent(QResizeEvent* event) _cornerButton->positionAtCorner(); } +void DiagramCavas::onTargetSelected(QObject* obj) +{ + emit selectTarget(obj); +} + /*******************************************************/ void DiagramCavas::onSignal_createEditPanel(QString sName,QUuid uid) diff --git a/diagramCavas/source/graphicsItem/graphicsBaseItem.cpp b/diagramCavas/source/graphicsItem/graphicsBaseItem.cpp index 3b62892..975bbfa 100644 --- a/diagramCavas/source/graphicsItem/graphicsBaseItem.cpp +++ b/diagramCavas/source/graphicsItem/graphicsBaseItem.cpp @@ -580,6 +580,41 @@ void GraphicsProjectModelItem::syncRotationDataFromParent(const double& data) m_dSyncRotationByParent += 360; } +QString GraphicsProjectModelItem::getName() const +{ + if(_property) + return _property->name(); + return QString(); +} + +void GraphicsProjectModelItem::setName(QString str) +{ + if(_property) + _property->setName(str); +} + +QPointF GraphicsProjectModelItem::getPosition() const +{ + return pos(); +} + +void GraphicsProjectModelItem::setPosition(QPointF pos) +{ + setPos(pos); +} + +QRectF GraphicsProjectModelItem::getSize() const +{ + return m_boundingRect; +} + +void GraphicsProjectModelItem::setSize(QRectF rec) +{ + prepareGeometryChange(); + m_boundingRect = rec; + update(); +} + QVariant GraphicsProjectModelItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant& value) { if (change == QGraphicsItem::ItemSelectedHasChanged) diff --git a/diagramCavas/source/propertyType/pannelColorGadget.cpp b/diagramCavas/source/propertyType/pannelColorGadget.cpp new file mode 100644 index 0000000..da7df25 --- /dev/null +++ b/diagramCavas/source/propertyType/pannelColorGadget.cpp @@ -0,0 +1,28 @@ +#include "propertyType/pannelColorGadget.h" +#include "baseDrawingPanel.h" + +PannelColorGadget::PannelColorGadget(BaseDrawingPanel* pPanel) + :_pPanel(pPanel) +{ + +} + +QColor PannelColorGadget::getBackColor() const +{ + return _pPanel->getScene()->getBackGoundColor(); +} + +void PannelColorGadget::setBackColor(QColor color) +{ + _pPanel->getScene()->setBackGoundColor(color); +} + +QColor PannelColorGadget::getGridColor() const +{ + return _pPanel->getScene()->getGridColor(); +} + +void PannelColorGadget::setGridColor(QColor color) +{ + _pPanel->getScene()->setGridColor(color); +} \ No newline at end of file diff --git a/diagramCavas/ui/dataSourceDlg.ui b/diagramCavas/ui/dataSourceDlg.ui new file mode 100644 index 0000000..bfe5ee4 --- /dev/null +++ b/diagramCavas/ui/dataSourceDlg.ui @@ -0,0 +1,210 @@ + + + dataSourceDlg + + + + 0 + 0 + 698 + 436 + + + + Dialog + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 16777215 + 25 + + + + background-color: rgb(199, 199, 199); + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 数据源选择 + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + + + Qt::Orientation::Horizontal + + + + + 4 + + + 10 + + + 10 + + + 5 + + + 10 + + + + + 层级关系 + + + + + + + + + + + + 4 + + + 5 + + + 10 + + + 10 + + + 10 + + + + + 包含属性 + + + + + + + + + + + + + + + 4 + + + 10 + + + 10 + + + 10 + + + 10 + + + + + 选中属性 + + + + + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + 确定 + + + + + + + 取消 + + + + + + + + + + diff --git a/source/mainwindow.cpp b/source/mainwindow.cpp index 181f2f5..67005b1 100644 --- a/source/mainwindow.cpp +++ b/source/mainwindow.cpp @@ -135,12 +135,15 @@ void CMainWindow::initializeDockUi() connect(&ProjectModelManager::instance(),&ProjectModelManager::modelChange,m_pElectricElementsBox,&ElectricElementsBox::onSignal_modelChanged); m_pPropertiesEditorView = new QDetailsView(); - QDockWidget* PropertyEditorDock = new QDockWidget(QString::fromWCharArray(L"属性面板"),this); + BaseDockWidget* PropertyEditorDock = new BaseDockWidget(QString::fromWCharArray(L"属性面板"),this); PropertyEditorDock->setWidget(m_pPropertiesEditorView); - PropertyEditorDock->setMinimumSize(200,150); + PropertyEditorDock->setMinimumSize(350,150); m_pPropertiesEditorView->setObject(m_pDiagramCavas); PropertyEditorDock->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea); this->addDockWidget(Qt::RightDockWidgetArea,PropertyEditorDock); + connect(m_pDiagramCavas,&DiagramCavas::selectTarget,this,[&](QObject* obj){ + m_pPropertiesEditorView->setObject(obj); + }); } void CMainWindow::initializeAction()