[qet] qet/qet: [5706] Minor refactoring of diagram event interface |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5706
Author: blacksun
Date: 2019-01-14 19:25:43 +0100 (Mon, 14 Jan 2019)
Log Message:
-----------
Minor refactoring of diagram event interface
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagramevent/diagrameventaddelement.cpp
trunk/sources/diagramevent/diagrameventaddelement.h
trunk/sources/diagramevent/diagrameventaddimage.cpp
trunk/sources/diagramevent/diagrameventaddimage.h
trunk/sources/diagramevent/diagrameventaddshape.cpp
trunk/sources/diagramevent/diagrameventaddshape.h
trunk/sources/diagramevent/diagrameventaddtext.cpp
trunk/sources/diagramevent/diagrameventaddtext.h
trunk/sources/diagramevent/diagrameventinterface.cpp
trunk/sources/diagramevent/diagrameventinterface.h
trunk/sources/qetdiagrameditor.cpp
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagram.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -182,15 +182,14 @@
*/
void Diagram::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface)
- if(m_event_interface->mouseDoubleClickEvent(event))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ event->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->mouseDoubleClickEvent(event);
+ if (event->isAccepted()) {
return;
}
+ }
QGraphicsScene::mouseDoubleClickEvent(event);
}
@@ -202,15 +201,14 @@
*/
void Diagram::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface)
- if(m_event_interface->mousePressEvent(event))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ event->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->mousePressEvent(event);
+ if (event->isAccepted()) {
return;
}
+ }
QGraphicsScene::mousePressEvent(event);
}
@@ -222,15 +220,14 @@
*/
void Diagram::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface)
- if(m_event_interface->mouseMoveEvent(event))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ event->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->mouseMoveEvent(event);
+ if (event->isAccepted()) {
return;
}
+ }
QGraphicsScene::mouseMoveEvent(event);
}
@@ -242,15 +239,14 @@
*/
void Diagram::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface)
- if(m_event_interface->mouseReleaseEvent(event))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ event->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->mouseReleaseEvent(event);
+ if (event->isAccepted()) {
return;
}
+ }
QGraphicsScene::mouseReleaseEvent(event);
}
@@ -262,15 +258,14 @@
*/
void Diagram::wheelEvent(QGraphicsSceneWheelEvent *event)
{
- if (m_event_interface)
- if(m_event_interface->wheelEvent(event))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ event->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->wheelEvent(event);
+ if (event->isAccepted()) {
return;
}
+ }
QGraphicsScene::wheelEvent(event);
}
@@ -283,15 +278,14 @@
*/
void Diagram::keyPressEvent(QKeyEvent *event)
{
- if (m_event_interface)
- if(m_event_interface->keyPressEvent(event))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ event->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->keyPressEvent(event);
+ if (event->isAccepted()) {
return;
}
+ }
if (!isReadOnly())
{
@@ -373,15 +367,14 @@
*/
void Diagram::keyReleaseEvent(QKeyEvent *e)
{
- if (m_event_interface)
- if(m_event_interface->keyReleaseEvent(e))
- {
- if(!m_event_interface->isRunning())
- {
- delete m_event_interface; m_event_interface = nullptr;
- }
+ e->setAccepted(false);
+
+ if (m_event_interface) {
+ m_event_interface->keyReleaseEvent(e);
+ if (e->isAccepted()) {
return;
}
+ }
bool transmit_event = true;
if (!isReadOnly()) {
@@ -417,6 +410,12 @@
event_interface -> init();
}
m_event_interface = event_interface;
+
+ connect(m_event_interface, &DiagramEventInterface::finish, [this]()
+ {
+ delete this->m_event_interface;
+ this->m_event_interface = nullptr;
+ });
}
/**
Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -67,27 +67,25 @@
/**
* @brief DiagramEventAddElement::mouseMoveEvent
* Move the element to new pos of mouse
+ * the event is always accepted
* @param event
- * @return always true
*/
-bool DiagramEventAddElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddElement::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_element)
- m_element -> setPos(Diagram::snapToGrid(event->scenePos()));
-
- return true;
+ if (m_element) {
+ m_element->setPos(Diagram::snapToGrid(event->scenePos()));
+ }
+ event->setAccepted(true);
}
/**
* @brief DiagramEventAddElement::mousePressEvent
* Do nothing, but return true for not transit the event to other thing in diagram.
+ * the event is always accepted
* @param event
- * @return always true
*/
-bool DiagramEventAddElement::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_UNUSED(event);
- return true;
+void DiagramEventAddElement::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+ event->setAccepted(true);
}
/**
@@ -94,10 +92,10 @@
* @brief DiagramEventAddElement::mouseReleaseEvent
* Right button finish this event (isRunning = false) and emit finish.
* Left button add an element to diagram
+ * the event is always accepted
* @param event
- * @return always true
*/
-bool DiagramEventAddElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddElement::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (m_element)
{
@@ -114,16 +112,16 @@
}
}
- return true;
+ event->setAccepted(true);
}
/**
* @brief DiagramEventAddElement::mouseDoubleClickEvent
* If mouse left double clic, finish this event (isRunning = false) and emit finish
+ * the event is always accepted
* @param event
- * @return always true
*/
-bool DiagramEventAddElement::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddElement::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (m_element && (event -> button() == Qt::LeftButton))
{
@@ -132,8 +130,8 @@
m_running = false;
emit finish();
}
-
- return true;
+
+ event->setAccepted(true);
}
/**
@@ -141,17 +139,17 @@
* Press space key rotate the element to 90° (return true)
* else call DiagramEventInterface::keyPressEvent(event), and return the value.
* @param event
- * @return
*/
-bool DiagramEventAddElement::keyPressEvent(QKeyEvent *event)
+void DiagramEventAddElement::keyPressEvent(QKeyEvent *event)
{
if (m_element && event->key() == Qt::Key_Space)
{
m_element->setRotation(m_element->rotation() + 90);
- return true;
+ event->setAccepted(true);
}
-
- return DiagramEventInterface::keyPressEvent(event);
+ else {
+ DiagramEventInterface::keyPressEvent(event);
+ }
}
/**
Modified: trunk/sources/diagramevent/diagrameventaddelement.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.h 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddelement.h 2019-01-14 18:25:43 UTC (rev 5706)
@@ -36,11 +36,11 @@
DiagramEventAddElement(ElementsLocation &location, Diagram *diagram, QPointF pos = QPointF(0,0));
~DiagramEventAddElement() override;
- bool mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
- bool mousePressEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
- bool keyPressEvent (QKeyEvent *event) override;
+ void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
+ void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
+ void keyPressEvent (QKeyEvent *event) override;
void init() override;
private:
Modified: trunk/sources/diagramevent/diagrameventaddimage.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddimage.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddimage.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -53,9 +53,8 @@
* @brief DiagramEventAddImage::mousePressEvent
* Action when mouse is pressed
* @param event : event of mouse pressed
- * @return : true if this event is handled, otherwise false
*/
-bool DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (m_image && event -> button() == Qt::LeftButton)
{
@@ -64,21 +63,19 @@
pos.ry() -= m_image->boundingRect().height()/2;
m_diagram -> undoStack().push (new AddItemCommand<DiagramImageItem *>(m_image, m_diagram, pos));
- foreach (QGraphicsView *view, m_diagram->views())
+ for (QGraphicsView *view : m_diagram->views()) {
view->setContextMenuPolicy((Qt::DefaultContextMenu));
+ }
m_running = false;
emit finish();
- return true;
+ event->setAccepted(true);
}
-
- if (m_image && event -> button() == Qt::RightButton)
+ else if (m_image && event -> button() == Qt::RightButton)
{
m_image->setRotation(m_image->rotation() + 90);
- return true;
+ event->setAccepted(true);
}
-
- return false;
}
/**
@@ -85,25 +82,27 @@
* @brief DiagramEventAddImage::mouseMoveEvent
* Action when mouse move
* @param event : event of mouse move
- * @return : true if this event is handled, otherwise false
*/
-bool DiagramEventAddImage::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddImage::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if (!m_image || event -> buttons() != Qt::NoButton) return false;
+ if (!m_image || event->buttons() != Qt::NoButton) {
+ return;
+ };
QPointF pos = event->scenePos();
if (!m_is_added)
{
- foreach (QGraphicsView *view, m_diagram->views())
+ for (QGraphicsView *view : m_diagram->views()) {
view->setContextMenuPolicy((Qt::NoContextMenu));
+ }
- m_diagram -> addItem(m_image);
+ m_diagram->addItem(m_image);
m_is_added = true;
}
- m_image -> setPos(pos - m_image -> boundingRect().center());
- return true;
+ m_image->setPos(pos - m_image->boundingRect().center());
+ event->setAccepted(true);
}
/**
@@ -111,12 +110,9 @@
* This method is only use to overwrite double click.
* When double click, image propertie dialog isn't open.
* @param event : event of mouse double click.
- * @return : true if this event is handled, otherwise false
*/
-bool DiagramEventAddImage::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_UNUSED(event);
- return true;
+void DiagramEventAddImage::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+ event->setAccepted(true);
}
/**
@@ -123,18 +119,20 @@
* @brief DiagramEventAddImage::wheelEvent
* Action when mouse wheel is rotate
* @param event: evet of mouse wheel
- * @return : true if this event is handled, otherwise false
*/
-bool DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event)
+void DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event)
{
- if (!m_is_added || !m_image || event -> modifiers() != Qt::CTRL) return false;
+ if (!m_is_added || !m_image || event -> modifiers() != Qt::CTRL) {
+ return;
+ }
qreal scaling = m_image->scale();
event->delta() > 1? scaling += 0.01 : scaling -= 0.01;
- if (scaling>0.01 && scaling <= 2)
+ if (scaling>0.01 && scaling <= 2) {
m_image->setScale(scaling);
+ }
- return true;
+ event->setAccepted(true);
}
/**
Modified: trunk/sources/diagramevent/diagrameventaddimage.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddimage.h 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddimage.h 2019-01-14 18:25:43 UTC (rev 5706)
@@ -35,10 +35,10 @@
DiagramEventAddImage(Diagram *diagram);
~DiagramEventAddImage() override;
- bool mousePressEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
- bool wheelEvent (QGraphicsSceneWheelEvent *event) override;
+ void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
+ void wheelEvent (QGraphicsSceneWheelEvent *event) override;
bool isNull () const;
private:
Modified: trunk/sources/diagramevent/diagrameventaddshape.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddshape.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddshape.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -57,15 +57,17 @@
* @brief DiagramEventAddShape::mousePressEvent
* Action when mouse is pressed
* @param event : event of mouse press
- * @return : true if this event is managed, otherwise false
*/
-bool DiagramEventAddShape::mousePressEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddShape::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- if (Q_UNLIKELY(m_diagram->isReadOnly())) return false;
+ if (Q_UNLIKELY(m_diagram->isReadOnly())) {
+ return;
+ }
QPointF pos = event->scenePos();
- if (event->modifiers() != Qt::ControlModifier)
+ if (event->modifiers() != Qt::ControlModifier) {
pos = Diagram::snapToGrid(pos);
+ }
//Action for left mouse click
if (event->button() == Qt::LeftButton)
@@ -75,7 +77,8 @@
{
m_shape_item = new QetShapeItem(pos, pos, m_shape_type);
m_diagram->addItem (m_shape_item);
- return true;
+ event->setAccepted(true);
+ return;
}
//If current item isn't a polyline, add it with an undo command
@@ -82,7 +85,7 @@
if (m_shape_type != QetShapeItem::Polygon)
{
m_shape_item->setP2 (pos);
- if(m_shape_item->shapeType() == QetShapeItem::Rectangle || m_shape_item->shapeType() == QetShapeItem::Ellipse) {
+ if (m_shape_item->shapeType() == QetShapeItem::Rectangle || m_shape_item->shapeType() == QetShapeItem::Ellipse) {
m_shape_item->setRect(m_shape_item->rect().normalized());
}
m_diagram->undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
@@ -94,14 +97,13 @@
m_shape_item->setNextPoint (pos);
}
- return true;
+ event->setAccepted(true);
+ return;
}
- if (event->button() == Qt::RightButton)
- return true;
-
- return false;
-
+ if (event->button() == Qt::RightButton) {
+ event->setAccepted(true);
+ }
}
/**
@@ -108,9 +110,8 @@
* @brief DiagramEventAddShape::mouseMoveEvent
* Action when mouse move
* @param event : event of mouse move
- * @return : true if this event is managed, otherwise false
*/
-bool DiagramEventAddShape::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddShape::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
updateHelpCross(event->scenePos());
@@ -117,14 +118,13 @@
if (m_shape_item && event->buttons() == Qt::NoButton)
{
QPointF pos = event->scenePos();
- if (event->modifiers() != Qt::ControlModifier)
+ if (event->modifiers() != Qt::ControlModifier) {
pos = Diagram::snapToGrid(pos);
+ }
m_shape_item->setP2 (pos);
- return true;
+ event->setAccepted(true);
}
-
- return false;
}
/**
@@ -131,9 +131,8 @@
* @brief DiagramEventAddShape::mouseReleaseEvent
* Action when mouse button is released
* @param event : event of mouse release
- * @return : true if this event is managed, otherwise false
*/
-bool DiagramEventAddShape::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddShape::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::RightButton)
{
@@ -150,7 +149,8 @@
pos = Diagram::snapToGrid(pos);
m_shape_item->setP2(pos); //Set the new last point under the cursor
- return true;
+ event->setAccepted(true);
+ return;
}
//For other case, we remove item from scene
@@ -157,7 +157,8 @@
m_diagram->removeItem(m_shape_item);
delete m_shape_item;
m_shape_item = nullptr;
- return true;
+ event->setAccepted(true);
+ return;
}
//Else (no shape), we set to false the running status
@@ -164,10 +165,8 @@
//for indicate to the owner of this event that everything is done
m_running = false;
emit finish();
- return true;
+ event->setAccepted(true);
}
-
- return false;
}
/**
@@ -174,9 +173,8 @@
* @brief DiagramEventAddShape::mouseDoubleClickEvent
* Action when mouse button is double clicked
* @param event : event of mouse double click
- * @return : true if this event is managed, otherwise false
*/
-bool DiagramEventAddShape::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddShape::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
//If current item is a polyline, add it with an undo command
if (m_shape_item && m_shape_type == QetShapeItem::Polygon && event->button() == Qt::LeftButton)
@@ -186,10 +184,8 @@
m_shape_item->removePoints();
m_diagram->undoStack().push (new AddItemCommand<QetShapeItem *> (m_shape_item, m_diagram));
m_shape_item = nullptr; //< set to nullptr for create new shape at next left clic
- return true;
+ event->setAccepted(true);
}
-
- return false;
}
void DiagramEventAddShape::init()
Modified: trunk/sources/diagramevent/diagrameventaddshape.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddshape.h 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddshape.h 2019-01-14 18:25:43 UTC (rev 5706)
@@ -33,10 +33,10 @@
DiagramEventAddShape(Diagram *diagram, QetShapeItem::ShapeType shape_type);
~DiagramEventAddShape() override;
- bool mousePressEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
- bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
+ void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
+ void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
void init() override;
private:
Modified: trunk/sources/diagramevent/diagrameventaddtext.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddtext.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddtext.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -39,9 +39,8 @@
/**
* @brief DiagramEventAddText::mousePressEvent
* @param event : event of mouse press event.
- * @return : true if this event is handled, otherwise false
*/
-bool DiagramEventAddText::mousePressEvent(QGraphicsSceneMouseEvent *event)
+void DiagramEventAddText::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
@@ -50,7 +49,6 @@
text->setTextInteractionFlags(Qt::TextEditorInteraction);
text->setFocus(Qt::MouseFocusReason);
emit finish();
- return true;
+ event->setAccepted(true);
}
- return false;
}
Modified: trunk/sources/diagramevent/diagrameventaddtext.h
===================================================================
--- trunk/sources/diagramevent/diagrameventaddtext.h 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventaddtext.h 2019-01-14 18:25:43 UTC (rev 5706)
@@ -34,7 +34,7 @@
DiagramEventAddText(Diagram *diagram);
~DiagramEventAddText() override;
- bool mousePressEvent (QGraphicsSceneMouseEvent *event) override;
+ void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
};
#endif // DIAGRAMEVENTADDTEXT_H
Modified: trunk/sources/diagramevent/diagrameventinterface.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventinterface.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventinterface.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -31,29 +31,24 @@
DiagramEventInterface::~DiagramEventInterface() {};
-bool DiagramEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
+void DiagramEventInterface::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
- return false;
}
-bool DiagramEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) {
+void DiagramEventInterface::mousePressEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
- return false;
}
-bool DiagramEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+void DiagramEventInterface::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
- return false;
}
-bool DiagramEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
+void DiagramEventInterface::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
- return false;
}
-bool DiagramEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) {
+void DiagramEventInterface::wheelEvent(QGraphicsSceneWheelEvent *event) {
Q_UNUSED (event);
- return false;
}
/**
@@ -60,21 +55,20 @@
* @brief DiagramEventInterface::keyPressEvent
* By default, press escape key abort the curent action
* @param event
- * @return
*/
-bool DiagramEventInterface::keyPressEvent(QKeyEvent *event) {
- if (event->key() == Qt::Key_Escape) {
+void DiagramEventInterface::keyPressEvent(QKeyEvent *event)
+{
+ if (event->key() == Qt::Key_Escape)
+ {
m_running = false;
m_abort = true;
emit finish();
- return true;
+ event->setAccepted(true);
}
- return false;
}
-bool DiagramEventInterface::keyReleaseEvent(QKeyEvent *event) {
+void DiagramEventInterface::keyReleaseEvent(QKeyEvent *event){
Q_UNUSED (event);
- return false;
}
bool DiagramEventInterface::isRunning() const {
Modified: trunk/sources/diagramevent/diagrameventinterface.h
===================================================================
--- trunk/sources/diagramevent/diagrameventinterface.h 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/diagramevent/diagrameventinterface.h 2019-01-14 18:25:43 UTC (rev 5706)
@@ -27,8 +27,6 @@
/**
* @brief The DiagramEventInterface class
- * Each method return a bool: True if the methode do something else return false.
- * Each method of DVEventInterface return false;
* isRunning() return true if action is running (do something). By default return false.
*
* ##USE DiagramEventInterface##
@@ -35,11 +33,10 @@
* This class is the basic interface for manage event on a diagram.
* To create a behavior for event diagram, we need to herite this class.
* This interface work like this :
- * You need to create an interface and call diagram::setEventInterface(*your_interface).
+ * You need to create an interface and call diagram::setEventInterface(pointer_of_your_interface).
* When a diagram get an event (mouse or key) if they have an event interface,
- * they send the event to the interface (for exemple mousePressEvent).
- * If the interface do something with this event, you need to return true to signal the diagram you work with this event.
- * (if you do nothing by defaut the interface return false, so diagram do nothing)
+ * they send the event (with the status accepted to false) to the interface (for exemple mousePressEvent).
+ * If the interface do something with this event, you need to set to true the accepted status of the event, then diagram do nothing.
* When the interface job is done, we need to emit the signal finish(), the diagram use this signal to delete the interface.
* Be carreful with the destructor, diagram can at any time (even if interface is still running) delete the interface,
* the bool m_abort is here for that at destruction time.
@@ -52,13 +49,13 @@
public:
DiagramEventInterface(Diagram *diagram);
~DiagramEventInterface() override = 0;
- virtual bool mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
- virtual bool mousePressEvent (QGraphicsSceneMouseEvent *event);
- virtual bool mouseMoveEvent (QGraphicsSceneMouseEvent *event);
- virtual bool mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
- virtual bool wheelEvent (QGraphicsSceneWheelEvent *event);
- virtual bool keyPressEvent (QKeyEvent *event);
- virtual bool keyReleaseEvent (QKeyEvent *event);
+ virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event);
+ virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);
+ virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event);
+ virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event);
+ virtual void wheelEvent (QGraphicsSceneWheelEvent *event);
+ virtual void keyPressEvent (QKeyEvent *event);
+ virtual void keyReleaseEvent (QKeyEvent *event);
virtual bool isRunning () const;
virtual void init();
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2019-01-13 16:56:12 UTC (rev 5705)
+++ trunk/sources/qetdiagrameditor.cpp 2019-01-14 18:25:43 UTC (rev 5706)
@@ -1319,7 +1319,7 @@
if (diagram_event)
{
d->setEventInterface(diagram_event);
- connect(diagram_event, &DiagramEventInterface::finish, [action](){action->setChecked(false);});
+ connect(diagram_event, &DiagramEventInterface::destroyed, [action]() {action->setChecked(false);});
}
}