Fix Warnings in MouseEventFilter.cpp

/retroshare-gui/src/util/MouseEventFilter.cpp:56: warning: catching
polymorphic type 'class std::bad_cast' by value [-Wcatch-value=]
/retroshare-gui/src/util/MouseEventFilter.cpp:77: warning: catching
polymorphic type 'class std::bad_cast' by value [-Wcatch-value=]
This commit is contained in:
Phenom 2018-10-08 19:27:48 +02:00
parent da6778934d
commit a30e2c3400

View File

@ -17,90 +17,90 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, * Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include <util/MouseEventFilter.h> #include <util/MouseEventFilter.h>
#include <QEvent> #include <QEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <exception> #include <exception>
#include <typeinfo> #include <typeinfo>
MouseMoveEventFilter::MouseMoveEventFilter(QObject * receiver, const char * member) MouseMoveEventFilter::MouseMoveEventFilter(QObject * receiver, const char * member)
: EventFilter(receiver, member) { : EventFilter(receiver, member) {
} }
bool MouseMoveEventFilter::eventFilter(QObject * watched, QEvent * event) { bool MouseMoveEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::MouseMove) { if (event->type() == QEvent::MouseMove) {
filter(event); filter(event);
return false; return false;
} }
return EventFilter::eventFilter(watched, event); return EventFilter::eventFilter(watched, event);
} }
MousePressEventFilter::MousePressEventFilter(QObject * receiver, const char * member, Qt::MouseButton button) MousePressEventFilter::MousePressEventFilter(QObject * receiver, const char * member, Qt::MouseButton button)
: EventFilter(receiver, member), : EventFilter(receiver, member),
_button(button) { _button(button) {
} }
bool MousePressEventFilter::eventFilter(QObject * watched, QEvent * event) { bool MousePressEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::MouseButtonPress) { if (event->type() == QEvent::MouseButtonPress) {
try { try {
QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *>(event); QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *>(event);
if ((_button == Qt::NoButton) || (mouseEvent->button() == _button)) { if ((_button == Qt::NoButton) || (mouseEvent->button() == _button)) {
filter(event); filter(event);
return false; return false;
} }
} catch (std::bad_cast) { } catch (const std::bad_cast&) {
//LOG_FATAL("exception when casting a QEvent to a QMouseEvent"); //LOG_FATAL("exception when casting a QEvent to a QMouseEvent");
} }
} }
return EventFilter::eventFilter(watched, event); return EventFilter::eventFilter(watched, event);
} }
MouseReleaseEventFilter::MouseReleaseEventFilter(QObject * receiver, const char * member, Qt::MouseButton button) MouseReleaseEventFilter::MouseReleaseEventFilter(QObject * receiver, const char * member, Qt::MouseButton button)
: EventFilter(receiver, member), : EventFilter(receiver, member),
_button(button) { _button(button) {
} }
bool MouseReleaseEventFilter::eventFilter(QObject * watched, QEvent * event) { bool MouseReleaseEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::MouseButtonRelease) { if (event->type() == QEvent::MouseButtonRelease) {
try { try {
QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *>(event); QMouseEvent * mouseEvent = dynamic_cast<QMouseEvent *>(event);
if ((_button == Qt::NoButton) || (mouseEvent->button() == _button)) { if ((_button == Qt::NoButton) || (mouseEvent->button() == _button)) {
filter(event); filter(event);
return false; return false;
} }
} catch (std::bad_cast) { } catch (const std::bad_cast&) {
//LOG_FATAL("exception when casting a QEvent to a QMouseEvent"); //LOG_FATAL("exception when casting a QEvent to a QMouseEvent");
} }
} }
return EventFilter::eventFilter(watched, event); return EventFilter::eventFilter(watched, event);
} }
MouseHoverEnterEventFilter::MouseHoverEnterEventFilter(QObject * receiver, const char * member) MouseHoverEnterEventFilter::MouseHoverEnterEventFilter(QObject * receiver, const char * member)
: EventFilter(receiver, member) { : EventFilter(receiver, member) {
} }
bool MouseHoverEnterEventFilter::eventFilter(QObject * watched, QEvent * event) { bool MouseHoverEnterEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::HoverEnter) { if (event->type() == QEvent::HoverEnter) {
filter(event); filter(event);
return false; return false;
} }
return EventFilter::eventFilter(watched, event); return EventFilter::eventFilter(watched, event);
} }
MouseHoverLeaveEventFilter::MouseHoverLeaveEventFilter(QObject * receiver, const char * member) MouseHoverLeaveEventFilter::MouseHoverLeaveEventFilter(QObject * receiver, const char * member)
: EventFilter(receiver, member) { : EventFilter(receiver, member) {
} }
bool MouseHoverLeaveEventFilter::eventFilter(QObject * watched, QEvent * event) { bool MouseHoverLeaveEventFilter::eventFilter(QObject * watched, QEvent * event) {
if (event->type() == QEvent::HoverLeave) { if (event->type() == QEvent::HoverLeave) {
filter(event); filter(event);
return false; return false;
} }
return EventFilter::eventFilter(watched, event); return EventFilter::eventFilter(watched, event);
} }