From 2edd28068782b9a8a0a4fda86c3300b4f7255fe8 Mon Sep 17 00:00:00 2001 From: mohamedsayed18 Date: Wed, 17 Jun 2020 18:48:10 +0300 Subject: [PATCH] code style Signed-off-by: mohamedsayed18 --- include/ignition/gui/plugins/KeyPublisher.hh | 23 ++++++++---- include/ignition/gui/plugins/KeyPublisher.qml | 17 +++++++++ src/plugins/KeyPublisher.cc | 35 ++++++++----------- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/include/ignition/gui/plugins/KeyPublisher.hh b/include/ignition/gui/plugins/KeyPublisher.hh index 64871dd91..7afd4a297 100644 --- a/include/ignition/gui/plugins/KeyPublisher.hh +++ b/include/ignition/gui/plugins/KeyPublisher.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Open Source Robotics Foundation + * Copyright (C) 2020 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,28 +15,39 @@ * */ -#ifndef IGNITION_GUI_KEYPUBLISHER_HH_ -#define IGNITION_GUI_KEYPUBLISHER_HH_ +#ifndef IGNITION_GUI_PLUGINS_KEYPUBLISHER_HH_ +#define IGNITION_GUI_PLUGINS_KEYPUBLISHER_HH_ #include #include #include - namespace ignition { namespace gui { class KeyPublisherPrivate; + /// \brief Publish keyboard stokes to "keyboard/keypress" topic. + /// + /// ## Configuration + /// This plugin doesn't accept any custom configuration. class KeyPublisher : public ignition::gui::Plugin //inherited from Qobject { Q_OBJECT - public: KeyPublisher(); //constructor - public: virtual ~KeyPublisher(); //destructor + /// \brief Constructor + public: KeyPublisher(); + + /// \brief Destructor + public: virtual ~KeyPublisher(); + // Documentation inherited public: virtual void LoadConfig(const tinyxml2::XMLElement *) override; + + /// \brief Filter events in Qt + /// \param[in] _obj The watched object + /// \param[in] _event Event that happen in Qt protected: bool eventFilter(QObject *_obj, QEvent *_event) override; /// \internal diff --git a/include/ignition/gui/plugins/KeyPublisher.qml b/include/ignition/gui/plugins/KeyPublisher.qml index 43526b34e..5308f64d9 100644 --- a/include/ignition/gui/plugins/KeyPublisher.qml +++ b/include/ignition/gui/plugins/KeyPublisher.qml @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + import QtQuick 2.0 import QtQuick.Controls 2.0 diff --git a/src/plugins/KeyPublisher.cc b/src/plugins/KeyPublisher.cc index 55e6cc06f..2ff812b09 100644 --- a/src/plugins/KeyPublisher.cc +++ b/src/plugins/KeyPublisher.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Open Source Robotics Foundation + * Copyright (C) 2020 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,17 @@ namespace gui { class KeyPublisherPrivate { + /// \brief Node for communication public: ignition::transport::Node node; + + /// \brief Publisher public: ignition::transport::Node::Publisher pub; + + /// \brief Topic public: std::string topic = "keyboard/keypress"; + + /// \brief Publish keyboard strokes + /// \param[in] key_press Pointer to the keyevent public: void KeyPub(QKeyEvent *key_press) { ignition::msgs::Int32 Msg; @@ -45,33 +53,31 @@ namespace gui using namespace ignition; using namespace gui; +///////////////////////////////////////////////// KeyPublisher::KeyPublisher(): Plugin(), dataPtr(new KeyPublisherPrivate) { + // Advertise publisher node this->dataPtr->pub = this->dataPtr->node.Advertise(this->dataPtr->topic); } - +///////////////////////////////////////////////// KeyPublisher::~KeyPublisher() { } - +///////////////////////////////////////////////// void KeyPublisher::LoadConfig(const tinyxml2::XMLElement *) { - //it loads the XML file which contains the UI file of Qt if (this->title.empty()) - { this->title = "Key tool"; - } + ignition::gui::App()->findChild ()->QuickWindow()->installEventFilter(this); } - - +///////////////////////////////////////////////// bool KeyPublisher::eventFilter(QObject *_obj, QEvent *_event) { - //dataPtr(new KeyPublisherPrivate) if (_event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(_event); @@ -80,17 +86,6 @@ bool KeyPublisher::eventFilter(QObject *_obj, QEvent *_event) return QObject::eventFilter(_obj, _event); } -/* -void KeyPublisher::KeyPub(QKeyEvent *key_press) -{ - - https://doc.qt.io/archives/qtjambi-4.5.2_01/com/trolltech/qt/core/Qt.Key.html - - ignition::msgs::Int32 Msg; - Msg.set_data(key_press->key()); - this->dataPtr->pub.Publish(Msg); -} -*/ // Register this plugin IGNITION_ADD_PLUGIN(ignition::gui::KeyPublisher, ignition::gui::Plugin)