[qet] [4255] Minor change |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4255
Author: blacksun
Date: 2015-11-09 21:20:11 +0100 (Mon, 09 Nov 2015)
Log Message:
-----------
Minor change
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagramevent/diagrameventaddelement.cpp
trunk/sources/diagramevent/diagrameventinterface.cpp
trunk/sources/diagramevent/diagrameventinterface.h
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2015-11-09 06:54:36 UTC (rev 4254)
+++ trunk/sources/diagram.cpp 2015-11-09 20:20:11 UTC (rev 4255)
@@ -169,14 +169,7 @@
*/
void Diagram::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface) {
- if (m_event_interface -> mouseDoubleClickEvent(event)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->mouseDoubleClickEvent(event)) return;
QGraphicsScene::mouseDoubleClickEvent(event);
}
@@ -188,14 +181,7 @@
*/
void Diagram::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface) {
- if (m_event_interface -> mousePressEvent(event)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->mousePressEvent(event)) return;
QGraphicsScene::mousePressEvent(event);
}
@@ -207,14 +193,7 @@
*/
void Diagram::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface) {
- if (m_event_interface -> mouseMoveEvent(event)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->mouseMoveEvent(event)) return;
QGraphicsScene::mouseMoveEvent(event);
}
@@ -226,14 +205,7 @@
*/
void Diagram::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (m_event_interface) {
- if (m_event_interface -> mouseReleaseEvent(event)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->mouseReleaseEvent(event)) return;
QGraphicsScene::mouseReleaseEvent(event);
}
@@ -245,14 +217,9 @@
*/
void Diagram::wheelEvent(QGraphicsSceneWheelEvent *event)
{
- if (m_event_interface) {
- if (m_event_interface -> wheelEvent(event)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->wheelEvent(event)) return;
+
+ QGraphicsScene::wheelEvent(event);
}
/**
@@ -263,14 +230,7 @@
*/
void Diagram::keyPressEvent(QKeyEvent *e)
{
- if (m_event_interface) {
- if (m_event_interface -> keyPressEvent(e)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->keyPressEvent(e)) return;
bool transmit_event = true;
if (!isReadOnly()) {
@@ -301,14 +261,7 @@
*/
void Diagram::keyReleaseEvent(QKeyEvent *e)
{
- if (m_event_interface) {
- if (m_event_interface -> KeyReleaseEvent(e)) {
- if (m_event_interface->isFinish()) {
- delete m_event_interface; m_event_interface = nullptr;
- }
- return;
- }
- }
+ if (m_event_interface && m_event_interface->KeyReleaseEvent(e)) return;
bool transmit_event = true;
if (!isReadOnly()) {
@@ -334,6 +287,8 @@
* Diagram become the ownership of event_interface
* If there is a previous interface, they will be delete before
* and call init() to the new interface.
+ * The derivated class of DiagramEventInterface need to emit the signal "finish" when the job is done,
+ * diagram use this signal to delete the interface. If the signal isn't send, the interface will never be deleted.
* @param event_interface
*/
void Diagram::setEventInterface(DiagramEventInterface *event_interface)
@@ -344,6 +299,7 @@
event_interface -> init();
}
m_event_interface = event_interface;
+ connect (m_event_interface, &DiagramEventInterface::finish, this, [this]() { delete this->m_event_interface; this->m_event_interface = nullptr;}, Qt::QueuedConnection);
}
/**
Modified: trunk/sources/diagramevent/diagrameventaddelement.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventaddelement.cpp 2015-11-09 06:54:36 UTC (rev 4254)
+++ trunk/sources/diagramevent/diagrameventaddelement.cpp 2015-11-09 20:20:11 UTC (rev 4255)
@@ -95,7 +95,7 @@
/**
* @brief DiagramEventAddElement::mouseReleaseEvent
- * Right button finish this event (isRunning = false)
+ * Right button finish this event (isRunning = false) and emit finish.
* Left button add an element to diagram
* @param event
* @return always true
@@ -109,6 +109,7 @@
delete m_element;
m_element = nullptr;
m_running = false;
+ emit finish();
}
else if (event->button() == Qt::LeftButton)
{
@@ -121,7 +122,7 @@
/**
* @brief DiagramEventAddElement::mouseDoubleClickEvent
- * If mouse left double clic, finish this event (isRunning = false)
+ * If mouse left double clic, finish this event (isRunning = false) and emit finish
* @param event
* @return always true
*/
@@ -132,6 +133,7 @@
delete m_element;
m_element = nullptr;
m_running = false;
+ emit finish();
}
return true;
Modified: trunk/sources/diagramevent/diagrameventinterface.cpp
===================================================================
--- trunk/sources/diagramevent/diagrameventinterface.cpp 2015-11-09 06:54:36 UTC (rev 4254)
+++ trunk/sources/diagramevent/diagrameventinterface.cpp 2015-11-09 20:20:11 UTC (rev 4255)
@@ -81,9 +81,5 @@
return m_running;
}
-bool DiagramEventInterface::isFinish() const {
- return !m_running;
-}
-
void DiagramEventInterface::init()
{}
Modified: trunk/sources/diagramevent/diagrameventinterface.h
===================================================================
--- trunk/sources/diagramevent/diagrameventinterface.h 2015-11-09 06:54:36 UTC (rev 4254)
+++ trunk/sources/diagramevent/diagrameventinterface.h 2015-11-09 20:20:11 UTC (rev 4255)
@@ -29,8 +29,7 @@
* @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 started but not finish. By default return false.
- * isFinish() return true when the action is finish, or not started. By default return true.
+ * isRunning() return true if action is running (do something). By default return false.
*
* ##USE DiagramEventInterface##
* This class is the basic interface for manage event on a diagram.
@@ -41,8 +40,7 @@
* 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)
- * after that, the diagram call interface::isRunning(), if true diagram do nothing, else if false,
- * that mean interface has finish is action (interface::isFinish return true) so the diagram will delete this interface.
+ * 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.
*
@@ -62,7 +60,6 @@
virtual bool keyPressEvent (QKeyEvent *event);
virtual bool KeyReleaseEvent (QKeyEvent *event);
virtual bool isRunning () const;
- virtual bool isFinish () const;
virtual void init();
signals: