From 8fc3958f807318a61e9f7409f707368ca66a753d Mon Sep 17 00:00:00 2001 From: jb Date: Thu, 26 Apr 2012 12:29:00 +0100 Subject: [PATCH] Made the scroll event filter a member of the parent class. --- .../configcamerastabilizationwidget.cpp | 24 +---------------- .../config/configcamerastabilizationwidget.h | 1 - .../config/configstabilizationwidget.cpp | 25 +----------------- .../config/configstabilizationwidget.h | 1 - .../src/plugins/config/configtxpidwidget.cpp | 24 +---------------- .../src/plugins/config/configtxpidwidget.h | 1 - .../config/configvehicletypewidget.cpp | 24 +---------------- .../plugins/config/configvehicletypewidget.h | 1 - .../src/plugins/config/inputchannelform.cpp | 26 ++----------------- .../src/plugins/config/inputchannelform.h | 3 +-- .../src/plugins/config/outputchannelform.cpp | 26 ++----------------- .../src/plugins/config/outputchannelform.h | 6 ++--- .../uavobjectwidgetutils/configtaskwidget.cpp | 24 +++++++++++++++++ .../uavobjectwidgetutils/configtaskwidget.h | 4 +++ 14 files changed, 39 insertions(+), 151 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp index 9603fd205..86ac30080 100644 --- a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp @@ -90,16 +90,7 @@ ConfigCameraStabilizationWidget::ConfigCameraStabilizationWidget(QWidget *parent connect(m_camerastabilization->camerastabilizationSaveSD, SIGNAL(clicked()), this, SLOT(saveSettings())); connect(m_camerastabilization->camerastabilizationHelp, SIGNAL(clicked()), this, SLOT(openHelp())); - //Disable mouse wheel events - foreach( QSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QDoubleSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QSlider * sp, findChildren() ) { - sp->installEventFilter( this ); - } + disbleMouseWheelEvents(); } ConfigCameraStabilizationWidget::~ConfigCameraStabilizationWidget() @@ -107,19 +98,6 @@ ConfigCameraStabilizationWidget::~ConfigCameraStabilizationWidget() // Do nothing } - -bool ConfigCameraStabilizationWidget::eventFilter( QObject * obj, QEvent * evt ) { - //Filter all wheel events, and ignore them - if ( evt->type() == QEvent::Wheel && - (qobject_cast( obj ) || qobject_cast( obj ) )) - { - evt->ignore(); - return true; - } - return QWidget::eventFilter( obj, evt ); -} - - void ConfigCameraStabilizationWidget::connectUpdates() { // Now connect the widget to the StabilizationSettings object diff --git a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h index a4af9663a..743435adb 100644 --- a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h @@ -41,7 +41,6 @@ class ConfigCameraStabilizationWidget: public ConfigTaskWidget public: ConfigCameraStabilizationWidget(QWidget *parent = 0); ~ConfigCameraStabilizationWidget(); - bool eventFilter( QObject * obj, QEvent * evt ); private: Ui_CameraStabilizationWidget *m_camerastabilization; virtual void enableControls(bool enable); diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp index 4b249f2b9..7306475a4 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.cpp @@ -53,17 +53,7 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa connect(this,SIGNAL(widgetContentsChanged(QWidget*)),this,SLOT(processLinkedWidgets(QWidget*))); - //Disable mouse wheel events - foreach( QSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QDoubleSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QSlider * sp, findChildren() ) { - sp->installEventFilter( this ); - } - + disbleMouseWheelEvents(); } @@ -72,19 +62,6 @@ ConfigStabilizationWidget::~ConfigStabilizationWidget() // Do nothing } - -bool ConfigStabilizationWidget::eventFilter( QObject * obj, QEvent * evt ) { - //Filter all wheel events, and ignore them - if ( evt->type() == QEvent::Wheel && - (qobject_cast( obj ) || qobject_cast( obj ) )) - { - evt->ignore(); - return true; - } - return QWidget::eventFilter( obj, evt ); -} - - void ConfigStabilizationWidget::realtimeUpdatesSlot(int value) { m_stabilization->realTimeUpdates_6->setCheckState((Qt::CheckState)value); diff --git a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h index 6c299da66..266b59ae9 100644 --- a/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configstabilizationwidget.h @@ -44,7 +44,6 @@ class ConfigStabilizationWidget: public ConfigTaskWidget public: ConfigStabilizationWidget(QWidget *parent = 0); ~ConfigStabilizationWidget(); - bool eventFilter( QObject * o, QEvent * e ); private: Ui_StabilizationWidget *m_stabilization; diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp index 5b974cfc4..1d65eaf1c 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.cpp @@ -68,16 +68,7 @@ ConfigTxPIDWidget::ConfigTxPIDWidget(QWidget *parent) : ConfigTaskWidget(parent) populateWidgets(); refreshWidgetsValues(); - //Disable mouse wheel events - foreach( QSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QDoubleSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QSlider * sp, findChildren() ) { - sp->installEventFilter( this ); - } + disbleMouseWheelEvents(); } ConfigTxPIDWidget::~ConfigTxPIDWidget() @@ -85,19 +76,6 @@ ConfigTxPIDWidget::~ConfigTxPIDWidget() // Do nothing } - -bool ConfigTxPIDWidget::eventFilter( QObject * obj, QEvent * evt ) { - //Filter all wheel events, and ignore them - if ( evt->type() == QEvent::Wheel && - (qobject_cast( obj ) || qobject_cast( obj ) )) - { - evt->ignore(); - return true; - } - return QWidget::eventFilter( obj, evt ); -} - - void ConfigTxPIDWidget::refreshValues() { HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); diff --git a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h index 014494272..14eb5925d 100644 --- a/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configtxpidwidget.h @@ -37,7 +37,6 @@ class ConfigTxPIDWidget : public ConfigTaskWidget public: ConfigTxPIDWidget(QWidget *parent = 0); ~ConfigTxPIDWidget(); - bool eventFilter( QObject * obj, QEvent * evt ); private: Ui_TxPIDWidget *m_txpid; diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp index 1c3e1d117..943aaf6d4 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp @@ -233,16 +233,7 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi setupGroundVehicleUI( m_aircraft->groundVehicleType->currentText() ); setupFixedWingUI( m_aircraft->fixedWingType->currentText() ); - //Disable mouse wheel events - foreach( QSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QDoubleSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QSlider * sp, findChildren() ) { - sp->installEventFilter( this ); - } + disbleMouseWheelEvents(); } @@ -254,19 +245,6 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget() // Do nothing } - -bool ConfigVehicleTypeWidget::eventFilter( QObject * obj, QEvent * evt ) { - //Filter all wheel events, and ignore them - if ( evt->type() == QEvent::Wheel && - (qobject_cast( obj ) || qobject_cast( obj ) )) - { - evt->ignore(); - return true; - } - return QWidget::eventFilter( obj, evt ); -} - - /** Slot for switching the airframe type. We do it explicitely rather than a signal in the UI, because we want to force a fitInView of the quad shapes. diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h index a1721de66..9c6daf16e 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h @@ -46,7 +46,6 @@ class ConfigVehicleTypeWidget: public ConfigTaskWidget public: ConfigVehicleTypeWidget(QWidget *parent = 0); ~ConfigVehicleTypeWidget(); - bool eventFilter( QObject * obj, QEvent * evt ); private: Ui_AircraftWidget *m_aircraft; diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp index 5288c5e84..dbab48cac 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.cpp @@ -4,7 +4,7 @@ #include "manualcontrolsettings.h" inputChannelForm::inputChannelForm(QWidget *parent,bool showlegend) : - QWidget(parent), + ConfigTaskWidget(parent), ui(new Ui::inputChannelForm) { ui->setupUi(this); @@ -37,16 +37,7 @@ inputChannelForm::inputChannelForm(QWidget *parent,bool showlegend) : connect(ui->channelNumberDropdown,SIGNAL(currentIndexChanged(int)),this,SLOT(channelDropdownUpdated(int))); connect(ui->channelNumber,SIGNAL(valueChanged(int)),this,SLOT(channelNumberUpdated(int))); - //Disable mouse wheel events - foreach( QSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QDoubleSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QSlider * sp, findChildren() ) { - sp->installEventFilter( this ); - } + disbleMouseWheelEvents(); } @@ -55,19 +46,6 @@ inputChannelForm::~inputChannelForm() delete ui; } - -bool inputChannelForm::eventFilter( QObject * obj, QEvent * evt ) { - //Filter all wheel events, and ignore them - if ( evt->type() == QEvent::Wheel && - (qobject_cast( obj ) || qobject_cast( obj ) )) - { - evt->ignore(); - return true; - } - return QWidget::eventFilter( obj, evt ); -} - - void inputChannelForm::setName(QString &name) { ui->channelName->setText(name); diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.h b/ground/openpilotgcs/src/plugins/config/inputchannelform.h index 6ccc92391..606ef2d78 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.h +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.h @@ -7,14 +7,13 @@ namespace Ui { class inputChannelForm; } -class inputChannelForm : public QWidget +class inputChannelForm : public ConfigTaskWidget { Q_OBJECT public: explicit inputChannelForm(QWidget *parent = 0,bool showlegend=false); ~inputChannelForm(); - bool eventFilter( QObject * obj, QEvent * evt ); friend class ConfigInputWidget; void setName(QString &name); private slots: diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp index 3fb396f3a..530244777 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.cpp @@ -29,7 +29,7 @@ #include "configoutputwidget.h" OutputChannelForm::OutputChannelForm(const int index, QWidget *parent, const bool showLegend) : - QWidget(parent), + ConfigTaskWidget(parent), ui(), m_index(index), m_inChannelTest(false) @@ -71,16 +71,7 @@ OutputChannelForm::OutputChannelForm(const int index, QWidget *parent, const boo connect(ui.actuatorLink, SIGNAL(toggled(bool)), this, SLOT(linkToggled(bool))); - //Disable mouse wheel events - foreach( QSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QDoubleSpinBox * sp, findChildren() ) { - sp->installEventFilter( this ); - } - foreach( QSlider * sp, findChildren() ) { - sp->installEventFilter( this ); - } + disbleMouseWheelEvents(); } OutputChannelForm::~OutputChannelForm() @@ -88,19 +79,6 @@ OutputChannelForm::~OutputChannelForm() // Do nothing } - -bool OutputChannelForm::eventFilter( QObject * obj, QEvent * evt ) { - //Filter all wheel events, and ignore them - if ( evt->type() == QEvent::Wheel && - (qobject_cast( obj ) || qobject_cast( obj ) )) - { - evt->ignore(); - return true; - } - return QWidget::eventFilter( obj, evt ); -} - - /** * Restrict UI to protect users from accidental misuse. */ diff --git a/ground/openpilotgcs/src/plugins/config/outputchannelform.h b/ground/openpilotgcs/src/plugins/config/outputchannelform.h index d365c4c50..873a5ea50 100644 --- a/ground/openpilotgcs/src/plugins/config/outputchannelform.h +++ b/ground/openpilotgcs/src/plugins/config/outputchannelform.h @@ -29,17 +29,15 @@ #include #include "ui_outputchannelform.h" +#include "configtaskwidget.h" -class ConfigOnputWidget; - -class OutputChannelForm : public QWidget +class OutputChannelForm : public ConfigTaskWidget { Q_OBJECT public: explicit OutputChannelForm(const int index, QWidget *parent = NULL, const bool showLegend = false); ~OutputChannelForm(); - bool eventFilter( QObject * obj, QEvent * evt ); friend class ConfigOnputWidget; void setAssignment(const QString &assignment); diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp index 932c5fa6b..51bafbb2d 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp @@ -1145,6 +1145,30 @@ void ConfigTaskWidget::loadWidgetLimits(QWidget * widget,UAVObjectField * field, } } +void ConfigTaskWidget::disbleMouseWheelEvents() +{ + //Disable mouse wheel events + foreach( QSpinBox * sp, findChildren() ) { + sp->installEventFilter( this ); + } + foreach( QDoubleSpinBox * sp, findChildren() ) { + sp->installEventFilter( this ); + } + foreach( QSlider * sp, findChildren() ) { + sp->installEventFilter( this ); + } +} + +bool ConfigTaskWidget::eventFilter( QObject * obj, QEvent * evt ) { + //Filter all wheel events, and ignore them + if ( evt->type() == QEvent::Wheel && + (qobject_cast( obj ) || qobject_cast( obj ) )) + { + evt->ignore(); + return true; + } + return QWidget::eventFilter( obj, evt ); +} /** @} @} diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h index deb297e32..a0e1feb7b 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h @@ -46,6 +46,7 @@ #include "uavobjectwidgetutils_global.h" #include #include +#include class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget: public QWidget { @@ -85,6 +86,9 @@ public: ConfigTaskWidget(QWidget *parent = 0); ~ConfigTaskWidget(); + void disbleMouseWheelEvents(); + bool eventFilter( QObject * obj, QEvent * evt ); + void saveObjectToSD(UAVObject *obj); UAVObjectManager* getObjectManager(); static double listMean(QList list);