修复同一个群组可以重复循环打组的问题
This commit is contained in:
parent
a45c125cee
commit
da6b9d023b
|
|
@ -8,6 +8,13 @@
|
|||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPen>
|
||||
|
||||
enum ShapeType
|
||||
{
|
||||
T_undefined,
|
||||
T_item,
|
||||
T_group
|
||||
};
|
||||
|
||||
//基类采用模板形式,QGraphicsItem是默认值,也可以是别的类型,比如QGraphicsItemGroup,这样不同的基类继承可以共用一些高层的行为定义
|
||||
template <typename BaseType = QGraphicsItem>
|
||||
class AbstractShapeType : public BaseType
|
||||
|
|
@ -16,6 +23,7 @@ public:
|
|||
explicit AbstractShapeType(QGraphicsItem *parent = 0)
|
||||
: BaseType(parent)
|
||||
{
|
||||
m_type = T_undefined;
|
||||
m_pen = QPen(Qt::NoPen);
|
||||
m_brush = QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
|
||||
m_dWidth = m_dHeight = 0;
|
||||
|
|
@ -36,6 +44,8 @@ public:
|
|||
}
|
||||
|
||||
public:
|
||||
virtual ShapeType getType() {return m_type;}
|
||||
|
||||
QPen pen() { return m_pen; }
|
||||
void setPen(const QPen &pen) { m_pen = pen; }
|
||||
QColor penColor() { return m_pen.color(); }
|
||||
|
|
@ -247,6 +257,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
ShapeType m_type;
|
||||
QPen m_pen;
|
||||
QBrush m_brush;
|
||||
double m_dWidth;
|
||||
|
|
|
|||
|
|
@ -132,6 +132,12 @@ GraphicsItemGroup* DesignerScene::createGroup()
|
|||
QList<QGraphicsItem*> listItem = selectedItems();
|
||||
if(listItem.isEmpty())
|
||||
return nullptr;
|
||||
else if(listItem.count() == 1) //判断只选中了一个时是不是已经打组,如果是不做操作,防止循环打组
|
||||
{
|
||||
AbstractShape* item = qgraphicsitem_cast<AbstractShape*>(listItem.first());
|
||||
if(item && item->getType()==T_group)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GraphicsItemGroup* group = new GraphicsItemGroup();
|
||||
group->addItems(listItem);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
GraphicsBaseItem::GraphicsBaseItem(QGraphicsItem *parent)
|
||||
: AbstractShapeType<QGraphicsItem>(parent)
|
||||
{
|
||||
m_type = T_item;
|
||||
//初始化缩放操作用的handle
|
||||
m_vecHanle.reserve(H_left);
|
||||
for(int i = H_leftTop; i <= H_left; i++)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
GraphicsItemGroup::GraphicsItemGroup(QGraphicsItem *parent)
|
||||
: AbstractShapeType<QGraphicsItemGroup>(parent)
|
||||
{
|
||||
m_type = T_group;
|
||||
|
||||
m_boundingRect = QRectF();
|
||||
m_lastBoudingRect = QGraphicsItemGroup::boundingRect();
|
||||
|
||||
|
|
@ -211,7 +213,10 @@ void GraphicsItemGroup::moveOperationCopy(const QPointF& distance)
|
|||
void GraphicsItemGroup::rotateOperationCopy(const double& dAngle)
|
||||
{
|
||||
if(m_pOperationCopy)
|
||||
{
|
||||
m_pOperationCopy->setRotation(dAngle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GraphicsItemGroup::addItems(const QList<QGraphicsItem*>& items)
|
||||
|
|
|
|||
Loading…
Reference in New Issue