Added BusSection component support by AI
This commit is contained in:
parent
b8489c8245
commit
7ee57e3be9
|
|
@ -56,6 +56,7 @@ set(H_HEADER_FILES
|
||||||
include/graphicsItem/graphicsRectItem.h
|
include/graphicsItem/graphicsRectItem.h
|
||||||
include/graphicsItem/graphicsPolygonItem.h
|
include/graphicsItem/graphicsPolygonItem.h
|
||||||
include/graphicsItem/graphicsItemGroup.h
|
include/graphicsItem/graphicsItemGroup.h
|
||||||
|
include/graphicsItem/graphicsBusSectionItem.h
|
||||||
)
|
)
|
||||||
set(CPP_SOURCE_FILES
|
set(CPP_SOURCE_FILES
|
||||||
source/main.cpp
|
source/main.cpp
|
||||||
|
|
@ -79,6 +80,7 @@ set(CPP_SOURCE_FILES
|
||||||
source/graphicsItem/graphicsRectItem.cpp
|
source/graphicsItem/graphicsRectItem.cpp
|
||||||
source/graphicsItem/graphicsPolygonItem.cpp
|
source/graphicsItem/graphicsPolygonItem.cpp
|
||||||
source/graphicsItem/graphicsItemGroup.cpp
|
source/graphicsItem/graphicsItemGroup.cpp
|
||||||
|
source/graphicsItem/graphicsBusSectionItem.cpp
|
||||||
)
|
)
|
||||||
set(UI_FILES
|
set(UI_FILES
|
||||||
ui/mainwindow.ui
|
ui/mainwindow.ui
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ enum GraphicsItemType
|
||||||
GIT_rect = QGraphicsItem::UserType + 3,
|
GIT_rect = QGraphicsItem::UserType + 3,
|
||||||
GIT_roundRect = QGraphicsItem::UserType + 4,
|
GIT_roundRect = QGraphicsItem::UserType + 4,
|
||||||
GIT_ellipse = QGraphicsItem::UserType + 5,
|
GIT_ellipse = QGraphicsItem::UserType + 5,
|
||||||
GIT_polygon = QGraphicsItem::UserType + 6
|
GIT_polygon = QGraphicsItem::UserType + 6,
|
||||||
|
GIT_busSection = QGraphicsItem::UserType + 7
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef GRAPHICSBUSSECTIONITEM_H
|
||||||
|
#define GRAPHICSBUSSECTIONITEM_H
|
||||||
|
|
||||||
|
#include "graphicsItem/graphicsBaseItem.h"
|
||||||
|
|
||||||
|
class GraphicsBusSectionItem : public GraphicsBaseItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit GraphicsBusSectionItem(QGraphicsItem *parent = nullptr);
|
||||||
|
virtual ~GraphicsBusSectionItem();
|
||||||
|
|
||||||
|
void resize(int, double, double, const QPointF&) override;
|
||||||
|
void updateCoordinate() override;
|
||||||
|
void move(const QPointF&) override;
|
||||||
|
void editShape(int, const QPointF&) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual QPainterPath shape() override;
|
||||||
|
virtual void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void updateHandles() override;
|
||||||
|
|
||||||
|
QRectF m_lastBoudingRect;
|
||||||
|
double m_dRatioX;
|
||||||
|
double m_dRatioY;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GRAPHICSBUSSECTIONITEM_H
|
||||||
|
|
@ -13,6 +13,8 @@ GraphicElementsPanel::GraphicElementsPanel(QWidget *parent)
|
||||||
connect(ui->pushBtn_roundRect, SIGNAL(clicked()), this, SLOT(onBtnClicked_GraphicsItem()));
|
connect(ui->pushBtn_roundRect, SIGNAL(clicked()), this, SLOT(onBtnClicked_GraphicsItem()));
|
||||||
ui->pushBtn_polygon->setProperty("shap",GIT_polygon);
|
ui->pushBtn_polygon->setProperty("shap",GIT_polygon);
|
||||||
connect(ui->pushBtn_polygon, SIGNAL(clicked()), this, SLOT(onBtnClicked_GraphicsItem()));
|
connect(ui->pushBtn_polygon, SIGNAL(clicked()), this, SLOT(onBtnClicked_GraphicsItem()));
|
||||||
|
ui->pushBtn_busSection->setProperty("shap",GIT_busSection);
|
||||||
|
connect(ui->pushBtn_busSection, SIGNAL(clicked()), this, SLOT(onBtnClicked_GraphicsItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicElementsPanel::~GraphicElementsPanel()
|
GraphicElementsPanel::~GraphicElementsPanel()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
#include "graphicsItem/graphicsBusSectionItem.h"
|
||||||
|
#include "graphicsItem/itemControlHandle.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
GraphicsBusSectionItem::GraphicsBusSectionItem(QGraphicsItem *parent)
|
||||||
|
: GraphicsBaseItem(parent), m_dRatioX(1 / 10.0), m_dRatioY(1 / 10.0)
|
||||||
|
{
|
||||||
|
m_pen = QPen(Qt::blue, 2);
|
||||||
|
m_brush = QBrush(QColor(100, 150, 255, 50));
|
||||||
|
m_lastBoudingRect = QRectF(-10, -10, 20, 20);
|
||||||
|
m_boundingRect = QRectF(-10, -10, 20, 20);
|
||||||
|
m_dWidth = 20;
|
||||||
|
m_dHeight = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsBusSectionItem::~GraphicsBusSectionItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainterPath GraphicsBusSectionItem::shape()
|
||||||
|
{
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRect(m_boundingRect);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsBusSectionItem::updateHandles()
|
||||||
|
{
|
||||||
|
GraphicsBaseItem::updateHandles();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsBusSectionItem::updateCoordinate()
|
||||||
|
{
|
||||||
|
if (!parentItem())
|
||||||
|
{
|
||||||
|
QPointF pt1, pt2, delta;
|
||||||
|
pt1 = mapToScene(QPointF(0, 0));
|
||||||
|
pt2 = mapToScene(m_boundingRect.center());
|
||||||
|
delta = pt1 - pt2;
|
||||||
|
|
||||||
|
prepareGeometryChange();
|
||||||
|
m_boundingRect = QRectF(-m_dWidth / 2, -m_dHeight / 2, m_dWidth, m_dHeight);
|
||||||
|
moveBy(-delta.x(), -delta.y());
|
||||||
|
updateHandles();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastBoudingRect = m_boundingRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsBusSectionItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||||
|
{
|
||||||
|
painter->setPen(m_pen);
|
||||||
|
painter->setBrush(m_brush);
|
||||||
|
painter->drawRect(m_boundingRect);
|
||||||
|
|
||||||
|
// 绘制Bus Section标签
|
||||||
|
painter->setPen(Qt::blue);
|
||||||
|
painter->setFont(QFont("Arial", 10, QFont::Bold));
|
||||||
|
painter->drawText(m_boundingRect, Qt::AlignCenter, "BUS");
|
||||||
|
|
||||||
|
if (option->state & QStyle::State_Selected)
|
||||||
|
{
|
||||||
|
int nPenWidth = 1;
|
||||||
|
painter->setPen(QPen(QColor(70, 70, 70), nPenWidth, Qt::DashLine));
|
||||||
|
painter->setBrush(Qt::NoBrush);
|
||||||
|
painter->drawRect(m_boundingRect_selected);
|
||||||
|
|
||||||
|
// 绘制变换原点
|
||||||
|
QPointF originPoint = transformOriginPoint();
|
||||||
|
painter->setBrush(Qt::red);
|
||||||
|
painter->drawEllipse(originPoint, 4, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsBusSectionItem::resize(int nHandle, double dSX, double dSY, const QPointF& basePoint)
|
||||||
|
{
|
||||||
|
switch (nHandle)
|
||||||
|
{
|
||||||
|
case H_left:
|
||||||
|
case H_right:
|
||||||
|
dSY = 1;
|
||||||
|
break;
|
||||||
|
case H_top:
|
||||||
|
case H_bottom:
|
||||||
|
dSX = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTransform trans;
|
||||||
|
trans.translate(basePoint.x(), basePoint.y());
|
||||||
|
trans.scale(dSX, dSY);
|
||||||
|
trans.translate(-basePoint.x(), -basePoint.y());
|
||||||
|
|
||||||
|
prepareGeometryChange();
|
||||||
|
m_boundingRect = trans.mapRect(m_lastBoudingRect);
|
||||||
|
m_dWidth = m_boundingRect.width();
|
||||||
|
m_dHeight = m_boundingRect.height();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsBusSectionItem::move(const QPointF& delta)
|
||||||
|
{
|
||||||
|
moveBy(delta.x(), delta.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsBusSectionItem::editShape(int nHandle, const QPointF& point)
|
||||||
|
{
|
||||||
|
// Bus Section没有特殊的编辑点
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "util/creatingSelector.h"
|
#include "util/creatingSelector.h"
|
||||||
#include "graphicsItem/graphicsRectItem.h"
|
#include "graphicsItem/graphicsRectItem.h"
|
||||||
#include "graphicsItem/graphicsPolygonItem.h"
|
#include "graphicsItem/graphicsPolygonItem.h"
|
||||||
|
#include "graphicsItem/graphicsBusSectionItem.h"
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
|
||||||
|
|
@ -49,6 +50,12 @@ void CreatingSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, Designer
|
||||||
m_pCreatingItem = new GraphicPolygonItem();
|
m_pCreatingItem = new GraphicPolygonItem();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case GIT_busSection:
|
||||||
|
{
|
||||||
|
m_creatingMethod = CM_drag;
|
||||||
|
m_pCreatingItem = new GraphicsBusSectionItem();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,19 @@
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>电力图元</string>
|
<string>电力图元</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<widget class="QPushButton" name="pushBtn_busSection">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>51</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Bus Section</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue