add HMI visibility control
This commit is contained in:
parent
fda44ec246
commit
8287f5a685
|
|
@ -12,6 +12,8 @@
|
|||
#include <QFormLayout>
|
||||
#include <QFileDialog>
|
||||
#include "propertyType/configEventData.h"
|
||||
#include "dataSourceDlg.h"
|
||||
#include "propertyType/dataSourceType.h"
|
||||
|
||||
class EventPropertyEditor : public QDialog {
|
||||
Q_OBJECT
|
||||
|
|
@ -206,15 +208,35 @@ private:
|
|||
|
||||
QLineEdit* varNameEdit = new QLineEdit();
|
||||
varNameEdit->setObjectName("varNameEdit");
|
||||
varNameEdit->setPlaceholderText("输入变量名,如: isVisible");
|
||||
varNameEdit->setPlaceholderText("变量名");
|
||||
|
||||
QPushButton* browseButton = new QPushButton("...");
|
||||
browseButton->setObjectName("browseButton");
|
||||
browseButton->setFixedSize(30, 25); // 设置固定大小,保持按钮紧凑
|
||||
|
||||
// 创建水平布局,将变量名输入框和按钮放在一起
|
||||
QHBoxLayout* nameLayout = new QHBoxLayout();
|
||||
nameLayout->addWidget(varNameEdit);
|
||||
nameLayout->addWidget(browseButton);
|
||||
nameLayout->setSpacing(5); // 设置间距
|
||||
|
||||
QLineEdit* varValueEdit = new QLineEdit();
|
||||
varValueEdit->setObjectName("varValueEdit");
|
||||
varValueEdit->setPlaceholderText("输入变量值,如: true, false, 123");
|
||||
varValueEdit->setPlaceholderText("变量值");
|
||||
|
||||
layout->addRow("变量名:", varNameEdit);
|
||||
layout->addRow("变量名:", nameLayout); // 使用水平布局作为行
|
||||
layout->addRow("变量值:", varValueEdit);
|
||||
|
||||
// 在创建按钮后添加
|
||||
QObject::connect(browseButton, &QPushButton::clicked, [=]() {
|
||||
DataSourceDlg dlg;
|
||||
DataSourceType customType;
|
||||
dlg.showDlg(customType);
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
DataSourceType setType = dlg.getCurData();
|
||||
varNameEdit->setText(setType.sPara);
|
||||
}
|
||||
});
|
||||
return page;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public:
|
|||
QMap<QUuid,GraphicsFunctionModelItem*>& allGraphicItems() {return _graphicItem;}
|
||||
bool addNodeItem(QUuid uuid,GraphicsFunctionModelItem*);
|
||||
bool addGraphicItem(QUuid uuid,GraphicsFunctionModelItem*);
|
||||
QString addNodeItem(QUuid id,QPointF pos,double width = 0,double height = 0,double rotate = 0);
|
||||
GraphicsFunctionModelItem* addNodeItem(QUuid id,QPointF pos,double width = 0,double height = 0,double rotate = 0);
|
||||
GraphicsFunctionModelItem* addGraphicItem(QUuid id,QString name,QPointF pos,int type,QString sContent = "",double width = 0,double height = 0,double rotate = 0); //0图形1文字
|
||||
GraphicsFunctionModelItem* nodeItem(QUuid uuid);
|
||||
BaseProperty* addNodeData(QUuid id,int type,QString name,QString modelName); //对应component数据,一个data可对应多个item(id,类型,名称,工程模名)
|
||||
|
|
@ -153,6 +153,7 @@ public:
|
|||
void startHttpRequest(); //开始请求数据(运行时)
|
||||
void setCavas(QPointer<DiagramCavas> p) {_cavas = p;} //设置所属顶层容器
|
||||
DiagramCavas* getCavas();
|
||||
int getCurMode(); //获取当前模式
|
||||
|
||||
QMap<QUuid,GraphicsFunctionModelItem*> getHMIItems(){return _nodeItem;}
|
||||
QMap<QUuid,ElectricBayItem*> getProjectBayItems(){return _bayItem;}
|
||||
|
|
|
|||
|
|
@ -3,18 +3,36 @@
|
|||
|
||||
/*****************自定义图形类*******************/
|
||||
#include "electricFunctionModelSvgItem.h"
|
||||
#include <QFont>
|
||||
|
||||
class ElectricFunctionModelSvgItemImage :public ElectricFunctionModelSvgItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY(QString Text READ getText WRITE setText)
|
||||
Q_PROPERTY(QColor TextColor READ getTextColor WRITE setTextColor)
|
||||
Q_PROPERTY(int TextSize READ getFontSize WRITE setFontSize)
|
||||
public:
|
||||
ElectricFunctionModelSvgItemImage(const QRect &rect,QGraphicsItem *parent = 0);
|
||||
virtual ~ElectricFunctionModelSvgItemImage();
|
||||
virtual void setImage_1(QFileInfo) override;
|
||||
|
||||
void setText(const QString& text);
|
||||
QString getText() {return m_text;}
|
||||
|
||||
void setTextColor(const QColor& color) {m_textColor = color;}
|
||||
QColor getTextColor() {return m_textColor;}
|
||||
|
||||
void setFontSize(int n);
|
||||
int getFontSize() {return m_font.pointSize();}
|
||||
protected:
|
||||
virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
|
||||
private:
|
||||
void initial();
|
||||
private:
|
||||
QString m_text;
|
||||
QColor m_textColor;
|
||||
QFont m_font = QFont("Arial", 12);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ void CreateHMIdlg::onCancelClicked()
|
|||
void CreateHMIdlg::onSaveClicked()
|
||||
{
|
||||
QString sName = ui->cb_structure->currentText();
|
||||
if(sName != "无")
|
||||
emit createHMI(ui->lineEdit->text(),sName);
|
||||
emit createHMI(ui->lineEdit->text(),sName);
|
||||
hide();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,10 +334,20 @@ void DiagramCavas::onSignal_loadMonitor(PowerEntity* p)
|
|||
onSignal_addDrawingPanel(p,DiagramMode::DM_run);
|
||||
QJsonObject context = DataBase::GetInstance()->getHMIContextByTag(p->name());
|
||||
m_mapMonitorPanel[p->name()].first->loadNodes(context);
|
||||
|
||||
QJsonObject pageObj = context["pageAttr"].toObject();
|
||||
int x = pageObj["x"].toInt();
|
||||
int y = pageObj["y"].toInt();
|
||||
int nWidth = pageObj["width"].toInt();
|
||||
int nHeight = pageObj["height"].toInt();
|
||||
if(nWidth && nHeight){
|
||||
m_mapMonitorPanel[p->name()].second->setGeometry(x,y,nWidth,nHeight);
|
||||
}
|
||||
}
|
||||
else //已存在
|
||||
{
|
||||
m_mapMonitorPanel[p->name()].first->show();
|
||||
setActiveSubWindow(m_mapMonitorPanel[p->name()].second);
|
||||
}
|
||||
onTargetSelected(m_mapMonitorPanel[p->name()].first->getPropertyProxy());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ GraphicsFunctionModelItem* FixedPortsModel::addGraphicItem(QUuid id,QString name
|
|||
return item;
|
||||
}
|
||||
|
||||
QString FixedPortsModel::addNodeItem(QUuid id,QPointF pos,double width,double height,double rotate)
|
||||
GraphicsFunctionModelItem* FixedPortsModel::addNodeItem(QUuid id,QPointF pos,double width,double height,double rotate)
|
||||
{
|
||||
//todo:load图形时必有拓扑实体,关联到对应的entity
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ QString FixedPortsModel::addNodeItem(QUuid id,QPointF pos,double width,double he
|
|||
int type = pro->type();
|
||||
//int type = pro->graphicsType();
|
||||
if(type == 8) //GIT_link 电缆对象外部处理
|
||||
return QString("err");
|
||||
return item;
|
||||
QString sMeta = pro->metaModelName();
|
||||
QString sProModel = pro->modelName();
|
||||
|
||||
|
|
@ -800,10 +800,10 @@ QString FixedPortsModel::addNodeItem(QUuid id,QPointF pos,double width,double he
|
|||
connect(item->eventContext().data(),&GraphicsEventContext::variableSet,this,&FixedPortsModel::onVariantSet);
|
||||
connect(item->eventContext().data(),&GraphicsEventContext::scriptExecuted,this,&FixedPortsModel::onScriptExec);
|
||||
}
|
||||
return pro->name();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return QString("err");
|
||||
return item;
|
||||
}
|
||||
|
||||
BaseProperty* FixedPortsModel::addNodeData(QUuid id,int type,QString name,QString modelName)
|
||||
|
|
@ -1798,6 +1798,11 @@ DiagramCavas* FixedPortsModel::getCavas()
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
int FixedPortsModel::getCurMode()
|
||||
{
|
||||
return _cavas->getCurMode();
|
||||
}
|
||||
|
||||
void FixedPortsModel::addPortsToItem_json(PortState sta,QJsonArray jArr,GraphicsBaseItem* pItem)
|
||||
{
|
||||
for(QJsonValueRef portJson:jArr)
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@ void ElectricFunctionModelSvgItemImage::paint(QPainter* painter, const QStyleOpt
|
|||
painter->drawRect(m_boundingRect);
|
||||
}
|
||||
|
||||
painter->setFont(m_font);
|
||||
painter->setPen(m_textColor);
|
||||
//QRectF textRect = m_boundingRect.adjusted(2, 2, -2, -2);
|
||||
painter->drawText(m_boundingRect, Qt::AlignCenter, m_text);
|
||||
ElectricFunctionModelSvgItem::paint(painter,option,widget);
|
||||
}
|
||||
|
||||
|
|
@ -73,3 +77,23 @@ void ElectricFunctionModelSvgItemImage::initial()
|
|||
setFunctionHandleEnaable(false);
|
||||
}
|
||||
|
||||
void ElectricFunctionModelSvgItemImage::setText(const QString& text)
|
||||
{
|
||||
if (m_text != text) {
|
||||
m_text = text;
|
||||
update(); // 触发重绘
|
||||
// 标记为已修改
|
||||
setItemChanged(true);
|
||||
auto pPro = dynamic_cast<GraphicProperty*>(getProperty());
|
||||
if(pPro){
|
||||
pPro->setContent(text); //同步修改属性值
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ElectricFunctionModelSvgItemImage::setFontSize(int n)
|
||||
{
|
||||
if(n>0 && n <100){
|
||||
m_font.setPointSize(n);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "graphicsDataModel/fixedPortsModel.h"
|
||||
#include "graphicsItem/functionModelItem/graphicsFunctionModelItem.h"
|
||||
#include "graphicsItem/functionModelItem/electricFunctionModelItemText.h"
|
||||
#include "graphicsItem/functionModelItem/electricFunctionModelSvgItemImage.h"
|
||||
#include "powerEntity.h"
|
||||
#include "statusBar.h"
|
||||
#include "baseProperty.h"
|
||||
|
|
@ -139,7 +140,14 @@ QJsonObject MonitorPanel::getDiagramInfo()
|
|||
QJsonArray arr;
|
||||
if(_pModel)
|
||||
{
|
||||
QMap<QUuid,ItemPageInfo> map = _pModel->allNodePos();
|
||||
QJsonObject pageObj;
|
||||
pageObj["x"] = pos().x();
|
||||
pageObj["y"] = pos().y();
|
||||
pageObj["width"] = width();
|
||||
pageObj["height"] = height();
|
||||
obj["pageAttr"] = pageObj;
|
||||
|
||||
/*QMap<QUuid,ItemPageInfo> map = _pModel->allNodePos();
|
||||
for(auto iter = map.begin();iter != map.end();++iter)
|
||||
{
|
||||
QJsonObject node;
|
||||
|
|
@ -150,6 +158,22 @@ QJsonObject MonitorPanel::getDiagramInfo()
|
|||
node["height"] = iter.value().dHeight;
|
||||
node["rotate"] = iter.value().dRotate;
|
||||
arr.append(node);
|
||||
}*/
|
||||
for(auto pItem:_pModel->allItems()){
|
||||
double dWidth = pItem->boundingRect().width();
|
||||
double dHeight = pItem->boundingRect().height();
|
||||
QPointF pos = pItem->scenePos();
|
||||
double rotation = pItem->rotation();
|
||||
|
||||
QJsonObject node;
|
||||
node["id"] = pItem->itemId().toString();
|
||||
node["x"] = pos.x();
|
||||
node["y"] = pos.y();
|
||||
node["width"] = dWidth;
|
||||
node["height"] = dHeight;
|
||||
node["rotate"] = rotation;
|
||||
node["events"] = pItem->getEvents().toJson();
|
||||
arr.append(node);
|
||||
}
|
||||
obj["nodes"] = arr;
|
||||
|
||||
|
|
@ -171,6 +195,7 @@ QJsonObject MonitorPanel::getDiagramInfo()
|
|||
node["width"] = dWidth;
|
||||
node["height"] = dHeight;
|
||||
node["rotate"] = rotation;
|
||||
node["events"] = pItem->getEvents().toJson();
|
||||
|
||||
GraphicProperty* pPro = dynamic_cast<GraphicProperty*>(pItem->getProperty());
|
||||
if(pPro){
|
||||
|
|
@ -187,6 +212,13 @@ QJsonObject MonitorPanel::getDiagramInfo()
|
|||
node["fontSize"] = pText->getFontSize();
|
||||
}
|
||||
}
|
||||
else if(pPro->getGraphicType() == 0){ //图像类
|
||||
auto pImg = dynamic_cast<ElectricFunctionModelSvgItemImage*>(pItem);
|
||||
if(pImg){
|
||||
node["color"] = pImg->getTextColor().name();
|
||||
node["fontSize"] = pImg->getFontSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
arrGraphic.append(node);
|
||||
}
|
||||
|
|
@ -239,8 +271,16 @@ QJsonObject MonitorPanel::getDiagramInfo()
|
|||
|
||||
void MonitorPanel::loadNodes(QJsonObject obj)
|
||||
{
|
||||
QJsonArray nodesJsonArray = obj["nodes"].toArray();
|
||||
QJsonObject pageObj = obj["pageAttr"].toObject();
|
||||
int x = pageObj["x"].toInt();
|
||||
int y = pageObj["y"].toInt();
|
||||
int nWidth = pageObj["width"].toInt();
|
||||
int nHeight = pageObj["height"].toInt();
|
||||
if(nWidth && nHeight){
|
||||
setGeometry(x,y,nWidth,nHeight);
|
||||
}
|
||||
|
||||
QJsonArray nodesJsonArray = obj["nodes"].toArray();
|
||||
QList<QPair<QString,QUuid>> lst;
|
||||
QList<QUuid> lstId; //通知外部拓扑列表使用
|
||||
for (QJsonValueRef nodeJson : nodesJsonArray)
|
||||
|
|
@ -252,13 +292,18 @@ void MonitorPanel::loadNodes(QJsonObject obj)
|
|||
double dWidth = node["width"].toDouble();
|
||||
double dHeight = node["height"].toDouble();
|
||||
double dRotate = node["rotate"].toDouble();
|
||||
QJsonArray pageObj = node["events"].toArray();
|
||||
|
||||
if(_pModel)
|
||||
{
|
||||
QString sName = _pModel->addNodeItem(QUuid(uuid),QPointF(dX,dY),dWidth,dHeight,dRotate);
|
||||
if(sName != "err"){
|
||||
lst.append(qMakePair(sName,QUuid(uuid)));
|
||||
GraphicsFunctionModelItem* pItem = _pModel->addNodeItem(QUuid(uuid),QPointF(dX,dY),dWidth,dHeight,dRotate);
|
||||
if(pItem){
|
||||
auto pPro = pItem->getProperty();
|
||||
lst.append(qMakePair(pPro->name(),QUuid(uuid)));
|
||||
lstId.append(QUuid(uuid));
|
||||
EventList eventLst; //事件
|
||||
eventLst.fromJson(pageObj);
|
||||
pItem->setEvents(eventLst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -286,6 +331,7 @@ void MonitorPanel::loadNodes(QJsonObject obj)
|
|||
double dWidth = node["width"].toDouble();
|
||||
double dHeight = node["height"].toDouble();
|
||||
double dRotate = node["rotate"].toDouble();
|
||||
QJsonArray pageObj = node["events"].toArray();
|
||||
|
||||
if(_pModel)
|
||||
{
|
||||
|
|
@ -302,6 +348,12 @@ void MonitorPanel::loadNodes(QJsonObject obj)
|
|||
}
|
||||
if(!mapData.isEmpty())
|
||||
_pModel->updateCustomById(itemId,mapData); //更新item引用的图片
|
||||
auto pImg = dynamic_cast<ElectricFunctionModelSvgItemImage*>(pItem);
|
||||
if(pImg){
|
||||
pImg->setText(sContent);
|
||||
pImg->setTextColor(color);
|
||||
pImg->setFontSize(nFontSize);
|
||||
}
|
||||
}
|
||||
else if(nType == 1){ //文字类型
|
||||
auto pText = dynamic_cast<ElectricFunctionModelItemText*>(pItem);
|
||||
|
|
@ -312,6 +364,9 @@ void MonitorPanel::loadNodes(QJsonObject obj)
|
|||
pText->setBackColor(backColor);
|
||||
}
|
||||
}
|
||||
EventList eventLst; //事件
|
||||
eventLst.fromJson(pageObj);
|
||||
pItem->setEvents(eventLst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ void BaseSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, DesignerScen
|
|||
QList<QGraphicsItem *> items = scene->selectedItems();
|
||||
if (items.count() == 1) //只有一个选中
|
||||
{
|
||||
GraphicsProjectModelItem* item = qgraphicsitem_cast<GraphicsProjectModelItem*>(items.first());
|
||||
GraphicsFunctionModelItem* item = qgraphicsitem_cast<GraphicsFunctionModelItem*>(items.first());
|
||||
if(item)
|
||||
{
|
||||
GraphicsItemType tpe = item->getItemType();
|
||||
|
|
@ -231,6 +231,9 @@ void BaseSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, DesignerScen
|
|||
auto pPro = item->getProperty();
|
||||
if(pPro)
|
||||
_model->monitorItemSelected(pPro->uuid());
|
||||
|
||||
if(_model->getCurMode() == 1) //运行中
|
||||
item->triggerEvents("click");
|
||||
}
|
||||
}
|
||||
else if (items.count() > 1) //选中多个
|
||||
|
|
@ -549,8 +552,10 @@ void BaseSelector::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, Design
|
|||
if(pro){
|
||||
QString modelName = pro->modelName();
|
||||
QUuid uuid = item->itemId();
|
||||
_model->showModelDlg(modelName,uuid,item);
|
||||
//_model->showModelDlg(modelName,uuid,item);
|
||||
}
|
||||
if(_model->getCurMode() == 1) //运行中
|
||||
item->triggerEvents("doubleClick");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ void DiagramView::onItemChanged(QStandardItem *item)
|
|||
|
||||
void DiagramView::onItemClicked(const QModelIndex &index)
|
||||
{
|
||||
QModelIndex firstIndex = index.sibling(0,index.column()); //取行首item
|
||||
QModelIndex firstIndex = index.sibling(index.row(),0); //取行首item
|
||||
if(firstIndex.isValid()){
|
||||
QStandardItem* item = _pModel->itemFromIndex(firstIndex);
|
||||
QStandardItem* parent = item->parent();
|
||||
|
|
|
|||
Loading…
Reference in New Issue