Minor change

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4077 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-07-27 21:47:41 +00:00
parent bb213e7146
commit 8acbc625da
4 changed files with 23 additions and 32 deletions

View File

@@ -80,7 +80,7 @@ bool DVEventAddShape::mousePressEvent(QMouseEvent *event)
} }
//If current item isn't a polyline, add it with an undo command //If current item isn't a polyline, add it with an undo command
if (m_shape_type != QetShapeItem::Polyline) if (m_shape_type != QetShapeItem::Polygon)
{ {
m_shape_item -> setP2 (pos); m_shape_item -> setP2 (pos);
m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram)); m_diagram -> undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
@@ -139,7 +139,7 @@ bool DVEventAddShape::mouseReleaseEvent(QMouseEvent *event)
if (m_shape_item) if (m_shape_item)
{ {
//Shape is a polyline and have three points or more we just remove the last point //Shape is a polyline and have three points or more we just remove the last point
if (m_shape_type == QetShapeItem::Polyline && (m_shape_item -> pointsCount() >= 3) ) if (m_shape_type == QetShapeItem::Polygon && (m_shape_item -> pointsCount() >= 3) )
{ {
m_shape_item -> removePoints(); m_shape_item -> removePoints();
@@ -175,7 +175,7 @@ bool DVEventAddShape::mouseReleaseEvent(QMouseEvent *event)
bool DVEventAddShape::mouseDoubleClickEvent(QMouseEvent *event) bool DVEventAddShape::mouseDoubleClickEvent(QMouseEvent *event)
{ {
//If current item is a polyline, add it with an undo command //If current item is a polyline, add it with an undo command
if (m_shape_item && m_shape_type == QetShapeItem::Polyline && event -> button() == Qt::LeftButton) if (m_shape_item && m_shape_type == QetShapeItem::Polygon && event -> button() == Qt::LeftButton)
{ {
//<double clic is used to finish polyline, but they also add two points at the same pos //<double clic is used to finish polyline, but they also add two points at the same pos
//<(double clic is a double press event), so we remove the last point of polyline //<(double clic is a double press event), so we remove the last point of polyline

View File

@@ -1636,7 +1636,7 @@ void QETDiagramEditor::slot_addEllipse() {
* add polyline to current diagram * add polyline to current diagram
*/ */
void QETDiagramEditor::slot_addPolyline() { void QETDiagramEditor::slot_addPolyline() {
if (DiagramView *dv = currentDiagram()) dv -> setEventInterface(new DVEventAddShape(dv, QetShapeItem::Polyline)); if (DiagramView *dv = currentDiagram()) dv -> setEventInterface(new DVEventAddShape(dv, QetShapeItem::Polygon));
} }
/** /**

View File

@@ -41,7 +41,7 @@ QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, QGraphicsItem
m_mouse_grab_handler(false), m_mouse_grab_handler(false),
m_handler(10) m_handler(10)
{ {
if (type == Polyline) m_polygon << m_P1 << m_P2; if (type == Polygon) m_polygon << m_P1 << m_P2;
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
} }
@@ -69,7 +69,7 @@ void QetShapeItem::setStyle(Qt::PenStyle newStyle)
*/ */
void QetShapeItem::setP2(const QPointF &P2) void QetShapeItem::setP2(const QPointF &P2)
{ {
if (m_shapeType == Polyline && m_polygon.last() != P2) if (m_shapeType == Polygon && m_polygon.last() != P2)
{ {
prepareGeometryChange(); prepareGeometryChange();
m_polygon.replace(m_polygon.size()-1, P2); m_polygon.replace(m_polygon.size()-1, P2);
@@ -123,7 +123,7 @@ bool QetShapeItem::setRect(const QRectF &rect)
*/ */
bool QetShapeItem::setPolygon(const QPolygonF &polygon) bool QetShapeItem::setPolygon(const QPolygonF &polygon)
{ {
if (Q_UNLIKELY(m_shapeType != Polyline)) return false; if (Q_UNLIKELY(m_shapeType != Polygon)) return false;
prepareGeometryChange(); prepareGeometryChange();
m_polygon = polygon; m_polygon = polygon;
return true; return true;
@@ -193,7 +193,7 @@ QPainterPath QetShapeItem::shape() const
path.lineTo(m_P2); break; path.lineTo(m_P2); break;
case Rectangle: path.addRect(QRectF(m_P1, m_P2)); break; case Rectangle: path.addRect(QRectF(m_P1, m_P2)); break;
case Ellipse: path.addEllipse(QRectF(m_P1, m_P2)); break; case Ellipse: path.addEllipse(QRectF(m_P1, m_P2)); break;
case Polyline: path.addPolygon(m_polygon); break; case Polygon: path.addPolygon(m_polygon); break;
default: Q_ASSERT(false); break; default: Q_ASSERT(false); break;
} }
@@ -275,8 +275,8 @@ void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
m_handler.drawHandler(painter, m_handler.pointsForRect(QRectF(m_P1, m_P2))); m_handler.drawHandler(painter, m_handler.pointsForRect(QRectF(m_P1, m_P2)));
break; break;
case Polyline: case Polygon:
painter->drawPolyline(m_polygon); painter->drawPolygon(m_polygon);
if (isSelected()) if (isSelected())
m_handler.drawHandler(painter, m_polygon); m_handler.drawHandler(painter, m_polygon);
break; break;
@@ -319,7 +319,7 @@ void QetShapeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
case Line: vector << m_P1 << m_P2; break; case Line: vector << m_P1 << m_P2; break;
case Rectangle: vector = m_handler.pointsForRect(QRectF(m_P1, m_P2)); break; case Rectangle: vector = m_handler.pointsForRect(QRectF(m_P1, m_P2)); break;
case Ellipse: vector = m_handler.pointsForRect(QRectF(m_P1, m_P2)); break; case Ellipse: vector = m_handler.pointsForRect(QRectF(m_P1, m_P2)); break;
case Polyline: vector = m_polygon; break; case Polygon: vector = m_polygon; break;
} }
m_vector_index = m_handler.pointIsHoverHandler(event->pos(), vector); m_vector_index = m_handler.pointIsHoverHandler(event->pos(), vector);
@@ -360,7 +360,7 @@ void QetShapeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
case Rectangle: setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index)); break; case Rectangle: setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index)); break;
case Ellipse: setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index)); break; case Ellipse: setRect(m_handler.rectForPosAtIndex(QRectF(m_P1, m_P2), new_pos, m_vector_index)); break;
case Polyline: case Polygon:
prepareGeometryChange(); prepareGeometryChange();
m_polygon.replace(m_vector_index, new_pos); m_polygon.replace(m_vector_index, new_pos);
break; break;
@@ -391,11 +391,11 @@ void QetShapeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
case Line: undo = new QPropertyUndoCommand(this, "line",QLineF(m_old_P1, m_old_P2), QLineF(m_P1, m_P2)); break; case Line: undo = new QPropertyUndoCommand(this, "line",QLineF(m_old_P1, m_old_P2), QLineF(m_P1, m_P2)); break;
case Rectangle: undo = new QPropertyUndoCommand(this, "rect",QRectF(m_old_P1, m_old_P2), QRectF(m_P1, m_P2)); break; case Rectangle: undo = new QPropertyUndoCommand(this, "rect",QRectF(m_old_P1, m_old_P2), QRectF(m_P1, m_P2)); break;
case Ellipse: undo = new QPropertyUndoCommand(this, "rect",QRectF(m_old_P1, m_old_P2), QRectF(m_P1, m_P2)); break; case Ellipse: undo = new QPropertyUndoCommand(this, "rect",QRectF(m_old_P1, m_old_P2), QRectF(m_P1, m_P2)); break;
case Polyline: break; case Polygon: break;
} }
if (undo) undo->enableAnimation(); if (undo) undo->enableAnimation();
} }
else if (m_shapeType == Polyline && (m_polygon != m_old_polygon)) else if (m_shapeType == Polygon && (m_polygon != m_old_polygon))
undo = new QPropertyUndoCommand(this, "polygon", m_old_polygon, m_polygon); undo = new QPropertyUndoCommand(this, "polygon", m_old_polygon, m_polygon);
if(undo) if(undo)
@@ -431,19 +431,17 @@ bool QetShapeItem::fromXml(const QDomElement &e)
case 0: m_shapeType = Line; break; case 0: m_shapeType = Line; break;
case 1: m_shapeType = Rectangle; break; case 1: m_shapeType = Rectangle; break;
case 2: m_shapeType = Ellipse; break; case 2: m_shapeType = Ellipse; break;
case 3: m_shapeType = Polyline; break; case 3: m_shapeType = Polygon; break;
} }
} }
//For version after N°4075, shape is stored with a string //For version after N°4075, shape is stored with a string
else else
{ {
if (type == "Line") m_shapeType = Line; QMetaEnum me = metaObject()->enumerator(metaObject()->indexOfEnumerator("ShapeType"));
else if (type == "Rectangle") m_shapeType = Rectangle; m_shapeType = QetShapeItem::ShapeType(me.keysToValue(type.toStdString().data()));
else if (type == "Ellipse") m_shapeType = Ellipse;
else if (type == "polygon") m_shapeType = Polyline;
} }
if (m_shapeType != Polyline) if (m_shapeType != Polygon)
{ {
m_P1.setX(e.attribute("x1", 0).toDouble()); m_P1.setX(e.attribute("x1", 0).toDouble());
m_P1.setY(e.attribute("y1", 0).toDouble()); m_P1.setY(e.attribute("y1", 0).toDouble());
@@ -468,18 +466,11 @@ QDomElement QetShapeItem::toXml(QDomDocument &document) const
QDomElement result = document.createElement("shape"); QDomElement result = document.createElement("shape");
//write some attribute //write some attribute
QString type; QMetaEnum me = metaObject()->enumerator(metaObject()->indexOfEnumerator("ShapeType"));
switch(m_shapeType) result.setAttribute("type", me.valueToKey(m_shapeType));
{
case Line: type = "Line"; break;
case Rectangle: type = "Rectangle"; break;
case Ellipse: type = "Ellipse"; break;
case Polyline: type = "polygon"; break;
}
result.setAttribute("type", type);
result.setAttribute("style", QString::number(m_shapeStyle)); result.setAttribute("style", QString::number(m_shapeStyle));
result.setAttribute("is_movable", bool(is_movable_)); result.setAttribute("is_movable", bool(is_movable_));
if (m_shapeType != Polyline) if (m_shapeType != Polygon)
{ {
result.setAttribute("x1", QString::number(mapToScene(m_P1).x())); result.setAttribute("x1", QString::number(mapToScene(m_P1).x()));
result.setAttribute("y1", QString::number(mapToScene(m_P1).y())); result.setAttribute("y1", QString::number(mapToScene(m_P1).y()));
@@ -541,7 +532,7 @@ QString QetShapeItem::name() const {
case Line: return tr("une ligne"); case Line: return tr("une ligne");
case Rectangle: return tr("un rectangle"); case Rectangle: return tr("un rectangle");
case Ellipse: return tr("une éllipse"); case Ellipse: return tr("une éllipse");
case Polyline: return tr("une polyligne"); case Polygon: return tr("une polyligne");
default: return tr("une shape"); default: return tr("une shape");
} }
} }

View File

@@ -45,7 +45,7 @@ class QetShapeItem : public QetGraphicsItem
enum ShapeType {Line =1, enum ShapeType {Line =1,
Rectangle =2, Rectangle =2,
Ellipse =4, Ellipse =4,
Polyline =8 }; Polygon =8 };
enum { Type = UserType + 1008 }; enum { Type = UserType + 1008 };