From 919f5bc601b4585ca4382455fe1ca771ea18603a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Wed, 2 May 2018 13:33:58 +0200 Subject: [PATCH] Moved plugin storage vector to a static --- Core/Core.cc | 34 ++++++---- Core/Core.hh | 5 +- Core/PluginCommunication.cc | 4 +- Core/PluginLoader.cc | 37 ++++++----- Core/RPC.cc | 16 ++--- Core/saveSettings.cc | 3 + Core/scripting.cc | 20 +++--- common/FileTypes.cc | 6 +- common/FileTypes.hh | 9 +-- common/PluginStorage.cc | 83 +++++++++++++++++++++++++ common/PluginStorage.hh | 81 ++++++++++++++++++++++++ widgets/coreWidget/About.cc | 20 +++--- widgets/coreWidget/ContextMenu.cc | 16 ++--- widgets/coreWidget/CoreWidget.cc | 21 ++++--- widgets/coreWidget/CoreWidget.hh | 21 ++++--- widgets/coreWidget/CoreWidgetToolbar.cc | 15 ++--- widgets/coreWidget/keyHandling.cc | 52 ++++++++-------- widgets/coreWidget/viewMode.cc | 24 +++---- widgets/loadWidget/FileOptionsDialog.hh | 2 +- widgets/loadWidget/loadWidget.hh | 3 + 20 files changed, 329 insertions(+), 143 deletions(-) create mode 100644 common/PluginStorage.cc create mode 100644 common/PluginStorage.hh diff --git a/Core/Core.cc b/Core/Core.cc index 22b08117..8765c1cf 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -88,6 +88,8 @@ #include +#include + #define WIDGET_HEIGHT 800 #define WIDGET_WIDTH 800 @@ -236,7 +238,7 @@ Core::init() { Qt::AlignBottom | Qt::AlignLeft , Qt::white); } - coreWidget_ = new CoreWidget(viewModes_ , plugins_, coreSlots_); + coreWidget_ = new CoreWidget(viewModes_ , coreSlots_); spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolboxScrollArea()); spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolboxArea()); @@ -718,6 +720,12 @@ Core::~Core() //----------------------------------------------------------------------------- +std::vector& Core::plugins() { + return PluginStorage::plugins(); +}; + +//----------------------------------------------------------------------------- + void Core::slotMouseEventIdentify( QMouseEvent* _event ) { @@ -1169,8 +1177,8 @@ void Core::slotExit() { clearAll(); // Notify plugins of imminent exit. - for ( uint i = 0 ; i < plugins_.size() ; ++i ){ - BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugins_[i].plugin); + for ( uint i = 0 ; i < plugins().size() ; ++i ){ + BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugins()[i].plugin); // Dont call exit if we cannot get the Plugin if ( basePlugin ) @@ -1178,7 +1186,7 @@ void Core::slotExit() { } // Delete Plugins to actually call their destructor - for(PluginInfo p : plugins_) + for(PluginInfo p : plugins()) delete p.plugin; // close the log file to ensure everything is writeen correctly @@ -1300,9 +1308,9 @@ void Core::slotSetSlotDescription(QString _slotName, QString _slotDescrip //find plugin PluginInfo* pluginInfo = 0; - for (uint i=0; i < plugins_.size(); i++) - if (plugins_[i].plugin == sender()) - pluginInfo = &plugins_[i]; + for (uint i=0; i < plugins().size(); i++) + if (plugins()[i].plugin == sender()) + pluginInfo = &plugins()[i]; if (pluginInfo == 0){ emit log(LOGERR, tr("Unable to set slot-description. Plugin not found!")); @@ -1378,9 +1386,9 @@ void Core::slotGetDescription(QString _function, QString& _fnDescript //find plugin PluginInfo* pluginInfo = 0; - for (uint i=0; i < plugins_.size(); i++) - if (plugins_[i].rpcName == pluginName) - pluginInfo = &plugins_[i]; + for (uint i=0; i < plugins().size(); i++) + if (plugins()[i].rpcName == pluginName) + pluginInfo = &plugins()[i]; if (pluginInfo == 0){ emit log(LOGERR, tr("Unable to get slot-description. Plugin not found!")); @@ -1524,12 +1532,12 @@ void Core::writeVersionNumbers(QString _filename){ ini.add_entry( "Core" , "VersionLinux" , OpenFlipper::Options::coreVersion() ); //add pluginVersions - for (uint i=0; i < plugins_.size(); i++){ + for (uint i=0; i < plugins().size(); i++){ if ( OpenFlipper::Options::isWindows() ) - ini.add_entry( plugins_[i].name , "VersionWindows" , plugins_[i].version ); + ini.add_entry( plugins()[i].name , "VersionWindows" , plugins()[i].version ); else - ini.add_entry( plugins_[i].name , "VersionLinux" , plugins_[i].version ); + ini.add_entry( plugins()[i].name , "VersionLinux" , plugins()[i].version ); } ini.disconnect(); diff --git a/Core/Core.hh b/Core/Core.hh index 14e32b45..36958f85 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -121,7 +121,6 @@ #include -#include #include #include "SpinBoxEventFilter.hh" @@ -1214,11 +1213,9 @@ private slots: //=========================================================================== public : - const std::vector plugins() const {return plugins_; }; + std::vector& plugins(); private: - /// List of all loaded plugins_ - std::vector plugins_; /// Index of Plugins toolbox widget int toolboxindex_; diff --git a/Core/PluginCommunication.cc b/Core/PluginCommunication.cc index a7dac83d..f9a70fde 100644 --- a/Core/PluginCommunication.cc +++ b/Core/PluginCommunication.cc @@ -467,11 +467,11 @@ void connectPlugins( Core* c, const std::vector& plugins_, QString _ } void Core::slotCrossPluginConnect( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) { - connectPlugins(this, plugins_, _pluginName1, _signal, _pluginName2, _slot, false); + connectPlugins(this, plugins(), _pluginName1, _signal, _pluginName2, _slot, false); } void Core::slotCrossPluginConnectQueued( QString _pluginName1, const char* _signal, QString _pluginName2, const char* _slot) { - connectPlugins(this, plugins_, _pluginName1, _signal, _pluginName2, _slot, true); + connectPlugins(this, plugins(), _pluginName1, _signal, _pluginName2, _slot, true); } //======================================================================================== diff --git a/Core/PluginLoader.cc b/Core/PluginLoader.cc index ddf90aba..103b6038 100644 --- a/Core/PluginLoader.cc +++ b/Core/PluginLoader.cc @@ -86,6 +86,9 @@ #include #include "OpenFlipper/widgets/PluginDialog/PluginDialog.hh" +#include + + /** * The number of plugins to load simultaneously. @@ -555,7 +558,7 @@ void Core::loadPlugins() emit pluginsInitialized(); - emit log(LOGOUT,tr("Loaded %n Plugin(s)","",int(plugins_.size())) ); + emit log(LOGOUT,tr("Loaded %n Plugin(s)","",int(plugins().size())) ); } /** @brief slot for loading Plugins @@ -653,7 +656,7 @@ void Core::slotShowPlugins(){ while (ret == 0){ - PluginDialog* dialog = new PluginDialog(plugins_, coreWidget_); + PluginDialog* dialog = new PluginDialog(plugins(), coreWidget_); //connect signals connect(dialog, SIGNAL( loadPlugin() ), this, SLOT( slotLoadPlugin() )); @@ -678,9 +681,9 @@ void Core::slotBlockPlugin(const QString &_name) OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins); } - for (size_t i = 0; i < plugins_.size();++i) - if (plugins_[i].name == _name) - plugins_[i].status = PluginInfo::BLOCKED; + for (size_t i = 0; i < plugins().size();++i) + if (plugins()[i].name == _name) + plugins()[i].status = PluginInfo::BLOCKED; } void Core::slotUnBlockPlugin(const QString &_name) @@ -689,9 +692,9 @@ void Core::slotUnBlockPlugin(const QString &_name) dontLoadPlugins.removeAll(_name); OpenFlipperSettings().setValue("PluginControl/DontLoadNames",dontLoadPlugins); - for (size_t i = 0; i < plugins_.size();++i) - if (plugins_[i].name == _name) - plugins_[i].status = PluginInfo::UNLOADED; + for (size_t i = 0; i < plugins().size();++i) + if (plugins()[i].name == _name) + plugins()[i].status = PluginInfo::UNLOADED; } @@ -756,9 +759,9 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic // Check if a plugin has been loaded PluginInfo info; int alreadyLoadedAt = -1; - for (unsigned int k=0; k < plugins_.size(); k++) + for (unsigned int k=0; k < plugins().size(); k++) { - if (plugins_[k].path == _filename) + if (plugins()[k].path == _filename) alreadyLoadedAt = static_cast(k); } info.status = PluginInfo::FAILED; @@ -788,15 +791,15 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic } //Check if plugin is already loaded - for (unsigned int k=0; k < plugins_.size(); k++){ + for (unsigned int k=0; k < plugins().size(); k++){ QString name_nospace = basePlugin->name(); name_nospace.remove(" "); - if (plugins_[k].name == name_nospace && plugins_[k].path != _filename && plugins_[k].status == PluginInfo::LOADED){ + if (plugins()[k].name == name_nospace && plugins()[k].path != _filename && plugins()[k].status == PluginInfo::LOADED){ if (_silent || OpenFlipper::Options::nogui() ){ //dont load the plugin - warnings += tr("Warning: Already loaded from %1").arg( plugins_[k].path) + "\n"; + warnings += tr("Warning: Already loaded from %1").arg( plugins()[k].path) + "\n"; printPluginLoadLog(errors, warnings); @@ -807,11 +810,11 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic tr("Plugin already loaded"), tr("A Plugin with the same name was already loaded from %1.\n" "You can only load the new plugin if you unload the existing one first.\n\n" - "Do you want to unload the existing plugin first?").arg( plugins_[k].path), + "Do you want to unload the existing plugin first?").arg( plugins()[k].path), QMessageBox::Yes|QMessageBox::No, QMessageBox::No); if (ret == QMessageBox::No) { - warnings += tr("Warning: Already loaded from %1.").arg( plugins_[k].path) + "\n"; + warnings += tr("Warning: Already loaded from %1.").arg( plugins()[k].path) + "\n"; printPluginLoadLog(errors, warnings); @@ -2288,10 +2291,10 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic info.warnings = warnings; if (alreadyLoadedAt != -1) { - plugins_[alreadyLoadedAt] = info; + plugins()[alreadyLoadedAt] = info; } else - plugins_.push_back(info); + plugins().push_back(info); printPluginLoadLog(errors, warnings); diff --git a/Core/RPC.cc b/Core/RPC.cc index eaa1a57a..9690cfad 100644 --- a/Core/RPC.cc +++ b/Core/RPC.cc @@ -68,8 +68,8 @@ void Core::slotPluginExists( QString _pluginName , bool& _exists ) { - for ( int i = 0 ; i < (int)plugins_.size(); ++i ) { - if ( plugins_[i].rpcName == _pluginName ) { + for ( int i = 0 ; i < (int)plugins().size(); ++i ) { + if ( plugins()[i].rpcName == _pluginName ) { _exists = true; return; } @@ -82,8 +82,8 @@ void Core::slotFunctionExists( QString _pluginName , QString _functionName , boo //Find plugin int plugin = -1; - for ( int i = 0 ; i < (int)plugins_.size(); ++i ) { - if ( plugins_[i].rpcName == _pluginName ) { + for ( int i = 0 ; i < (int)plugins().size(); ++i ) { + if ( plugins()[i].rpcName == _pluginName ) { plugin = i; break; } @@ -94,15 +94,15 @@ void Core::slotFunctionExists( QString _pluginName , QString _functionName , boo return; } - _exists = plugins_[plugin].rpcFunctions.contains(_functionName); + _exists = plugins()[plugin].rpcFunctions.contains(_functionName); } void Core::slotCall( QString _pluginName , QString _functionName , bool& _success ) { //Find plugin int plugin = -1; - for ( int i = 0 ; i < (int)plugins_.size(); ++i ) { - if ( plugins_[i].rpcName == _pluginName ) { + for ( int i = 0 ; i < (int)plugins().size(); ++i ) { + if ( plugins()[i].rpcName == _pluginName ) { plugin = i; break; } @@ -114,7 +114,7 @@ void Core::slotCall( QString _pluginName , QString _functionName , bool& _succes return; } - if ( !plugins_[plugin].rpcFunctions.contains(_functionName) ) { + if ( !plugins()[plugin].rpcFunctions.contains(_functionName) ) { _success = false; emit log(LOGERR, tr("Unable to call function from Plugin : ") + _pluginName); emit log(LOGERR, tr("Function ") + _functionName + tr(" not found!")); diff --git a/Core/saveSettings.cc b/Core/saveSettings.cc index aef0e181..2a0736dc 100644 --- a/Core/saveSettings.cc +++ b/Core/saveSettings.cc @@ -52,6 +52,9 @@ //#include +#include + + /// Save Settings (slot is called from CoreWidget's File-Menu) void Core::saveSettings(){ diff --git a/Core/scripting.cc b/Core/scripting.cc index b334d5f7..2acfa1a0 100644 --- a/Core/scripting.cc +++ b/Core/scripting.cc @@ -231,13 +231,13 @@ void Core::setToolBoxSide(QString _side) { //----------------------------------------------------------------------------- QWidget *Core::getToolbox(QString _pluginName, QString _toolboxName) { - std::vector::const_iterator pluginIt = plugins_.end(); - for (std::vector::const_iterator it = plugins_.begin(), it_end = plugins_.end(); it != it_end; ++it) { + std::vector::const_iterator pluginIt = plugins().end(); + for (std::vector::const_iterator it = plugins().begin(), it_end = plugins().end(); it != it_end; ++it) { if (it->name == _pluginName) { pluginIt = it; } } - if (pluginIt == plugins_.end()) return 0; + if (pluginIt == plugins().end()) return 0; for (std::vector >::const_iterator it = pluginIt->toolboxWidgets.begin(), it_end = pluginIt->toolboxWidgets.end(); it != it_end; ++it) { @@ -266,8 +266,8 @@ void Core::addToolbox(QString _name ,QWidget* _widget, QIcon* _icon, int id = -1; // Find the plugin which added this Toolbox - for ( uint i = 0 ; i < plugins_.size(); ++i ) { - if ( plugins_[i].plugin == sender() ) { + for ( uint i = 0 ; i < plugins().size(); ++i ) { + if ( plugins()[i].plugin == sender() ) { id = i; break; } @@ -275,8 +275,8 @@ void Core::addToolbox(QString _name ,QWidget* _widget, QIcon* _icon, // Find the scripting plugin because we assign this toolBox to it as we did not find the original sender if ( id == -1 ) { - for ( uint i = 0 ; i < plugins_.size(); ++i ) { - if ( plugins_[i].name == "Scripting" ) { + for ( uint i = 0 ; i < plugins().size(); ++i ) { + if ( plugins()[i].name == "Scripting" ) { id = i; break; } @@ -290,9 +290,9 @@ void Core::addToolbox(QString _name ,QWidget* _widget, QIcon* _icon, } spinBoxEventFilter_.hookUpToWidgetTree(_widget); - plugins_[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) ); - plugins_[id].toolboxIcons.push_back( _icon ); - plugins_[id].headerAreaWidgets.push_back( std::pair< QString,QWidget* >( _name , _headerAreaWidget) ); + plugins()[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) ); + plugins()[id].toolboxIcons.push_back( _icon ); + plugins()[id].headerAreaWidgets.push_back( std::pair< QString,QWidget* >( _name , _headerAreaWidget) ); // add widget name to viewMode 'all' if ( !viewModes_[0]->visibleToolboxes.contains(_name) ){ diff --git a/common/FileTypes.cc b/common/FileTypes.cc index 3d93e9a8..4f6641d5 100644 --- a/common/FileTypes.cc +++ b/common/FileTypes.cc @@ -58,7 +58,7 @@ /** * \file FileTypes.cc - * This File contains the management of file plugins. + * This File contains the file type management vectors */ @@ -66,14 +66,12 @@ #include - +// Stores information about file types supported by the file plugins. static std::vector supportedTypes_; std::vector& supportedTypes() { return supportedTypes_; } - - //============================================================================= //============================================================================= diff --git a/common/FileTypes.hh b/common/FileTypes.hh index 2a8219c7..6afa81df 100644 --- a/common/FileTypes.hh +++ b/common/FileTypes.hh @@ -58,12 +58,11 @@ /** * \file FileTypes.hh - * This File contains the management of file plugins. + * This File contains the file type management vectors */ -#ifndef FILETYPES_HH -#define FILETYPES_HH +#pragma once #include #include @@ -84,10 +83,8 @@ struct fileTypes { // Get vector of supported types DLLEXPORT -std::vector& -supportedTypes(); +std::vector& supportedTypes(); //============================================================================= -#endif // FILETYPES_HH defined //============================================================================= diff --git a/common/PluginStorage.cc b/common/PluginStorage.cc new file mode 100644 index 00000000..95cfc74f --- /dev/null +++ b/common/PluginStorage.cc @@ -0,0 +1,83 @@ +/*===========================================================================*\ +* * +* OpenFlipper * + * Copyright (c) 2001-2015, RWTH-Aachen University * + * Department of Computer Graphics and Multimedia * + * All rights reserved. * + * www.openflipper.org * + * * + *---------------------------------------------------------------------------* + * This file is part of OpenFlipper. * + *---------------------------------------------------------------------------* + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright notice, * + * this list of conditions and the following disclaimer. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the following disclaimer in the * + * documentation and/or other materials provided with the distribution. * + * * + * 3. Neither the name of the copyright holder nor the names of its * + * contributors may be used to endorse or promote products derived from * + * this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +* * +\*===========================================================================*/ + +/*===========================================================================*\ +* * +* $Revision$ * +* $LastChangedBy$ * +* $Date$ * +* * +\*===========================================================================*/ + + + + +//============================================================================= +// +// Types +// +//============================================================================= + +/** + * \file PluginStorage.cc + * This File contains the management of plugins. + */ + + +//== INCLUDES ================================================================= + +#include + + +namespace PluginStorage { + +/// reference to Core plugin list +static std::vector plugins_; + + +std::vector& plugins() { + return plugins_; +} + +} + +//============================================================================= +//============================================================================= diff --git a/common/PluginStorage.hh b/common/PluginStorage.hh new file mode 100644 index 00000000..057a281c --- /dev/null +++ b/common/PluginStorage.hh @@ -0,0 +1,81 @@ +/*===========================================================================*\ +* * +* OpenFlipper * + * Copyright (c) 2001-2015, RWTH-Aachen University * + * Department of Computer Graphics and Multimedia * + * All rights reserved. * + * www.openflipper.org * + * * + *---------------------------------------------------------------------------* + * This file is part of OpenFlipper. * + *---------------------------------------------------------------------------* + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright notice, * + * this list of conditions and the following disclaimer. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the following disclaimer in the * + * documentation and/or other materials provided with the distribution. * + * * + * 3. Neither the name of the copyright holder nor the names of its * + * contributors may be used to endorse or promote products derived from * + * this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +* * +\*===========================================================================*/ + +/*===========================================================================*\ +* * +* $Revision$ * +* $LastChangedBy$ * +* $Date$ * +* * +\*===========================================================================*/ + + + + +//============================================================================= +// +// Types +// +//============================================================================= + +/** + * \file PluginStorage.hh + * This File contains the management vector for the plugins. + */ + +#pragma once + +#include + + +//== INCLUDES ================================================================= + + +namespace PluginStorage { + + /// Get the vector of all PluginInfos + std::vector& plugins(); + +} + + +//============================================================================= +//============================================================================= diff --git a/widgets/coreWidget/About.cc b/widgets/coreWidget/About.cc index 6a36dc96..77cad931 100644 --- a/widgets/coreWidget/About.cc +++ b/widgets/coreWidget/About.cc @@ -61,8 +61,10 @@ #include #include "CoreWidget.hh" +#include #include + #include #ifndef WIN32 @@ -753,23 +755,23 @@ void CoreWidget::showAboutWidget( ) { aboutWidget_->OpenFlipperAbout->append(tr("Loaded Plugins:")); aboutWidget_->OpenFlipperAbout->setCurrentFont(standardFont); - for ( uint i = 0 ; i < plugins_.size() ; ++i ) { + for ( uint i = 0 ; i < plugins().size() ; ++i ) { aboutWidget_->OpenFlipperAbout->setCurrentFont(boldFont); - aboutWidget_->OpenFlipperAbout->append( "\t" + plugins_[i].name ); + aboutWidget_->OpenFlipperAbout->append( "\t" + plugins()[i].name ); aboutWidget_->OpenFlipperAbout->setCurrentFont(standardFont); - aboutWidget_->OpenFlipperAbout->append( "\t\t Version: \t\t" + plugins_[i].version ); - aboutWidget_->OpenFlipperAbout->append( "\t\t Description: \t" + plugins_[i].description ); - aboutWidget_->OpenFlipperAbout->append( "\t\t Path \t\t" + plugins_[i].path ); + aboutWidget_->OpenFlipperAbout->append( "\t\t Version: \t\t" + plugins()[i].version ); + aboutWidget_->OpenFlipperAbout->append( "\t\t Description: \t" + plugins()[i].description ); + aboutWidget_->OpenFlipperAbout->append( "\t\t Path \t\t" + plugins()[i].path ); - if ( !plugins_[i].warnings.isEmpty() ) { + if ( !plugins()[i].warnings.isEmpty() ) { aboutWidget_->OpenFlipperAbout->setTextColor(Qt::darkYellow); - aboutWidget_->OpenFlipperAbout->append( "\t\t Warnings: \t\t" + plugins_[i].warnings ); + aboutWidget_->OpenFlipperAbout->append( "\t\t Warnings: \t\t" + plugins()[i].warnings ); aboutWidget_->OpenFlipperAbout->setTextColor(Qt::black); } - if ( !plugins_[i].errors.isEmpty() ) { + if ( !plugins()[i].errors.isEmpty() ) { aboutWidget_->OpenFlipperAbout->setTextColor(Qt::darkRed); - aboutWidget_->OpenFlipperAbout->append( "\t\t Errors: \t\t" + plugins_[i].errors ); + aboutWidget_->OpenFlipperAbout->append( "\t\t Errors: \t\t" + plugins()[i].errors ); aboutWidget_->OpenFlipperAbout->setTextColor(Qt::black); } diff --git a/widgets/coreWidget/ContextMenu.cc b/widgets/coreWidget/ContextMenu.cc index 1f777184..5c1ec536 100644 --- a/widgets/coreWidget/ContextMenu.cc +++ b/widgets/coreWidget/ContextMenu.cc @@ -58,7 +58,7 @@ //== INCLUDES ================================================================= -// -------------------- mview + #include "CoreWidget.hh" //== IMPLEMENTATION ========================================================== @@ -773,8 +773,8 @@ void CoreWidget::slotAddContextItem( QAction* _entry , DataType _dataType ,Conte void CoreWidget::slotAddContextItemToViewMode( QAction* _entry ) { int id = -1; // Find the plugin which added this Context Menu - for ( uint i = 0 ; i < plugins_.size(); ++i ) { - if ( plugins_[i].plugin == sender() ) { + for ( uint i = 0 ; i < plugins().size(); ++i ) { + if ( plugins()[i].plugin == sender() ) { id = i; break; } @@ -782,8 +782,8 @@ void CoreWidget::slotAddContextItemToViewMode( QAction* _entry ) { // Find the scripting plugin because we assign this context menu to it as we did not find the original sender if ( id == -1 ) { - for ( uint i = 0 ; i < plugins_.size(); ++i ) { - if ( plugins_[i].name == "Scripting" ) { + for ( uint i = 0 ; i < plugins().size(); ++i ) { + if ( plugins()[i].name == "Scripting" ) { id = i; break; } @@ -796,11 +796,11 @@ void CoreWidget::slotAddContextItemToViewMode( QAction* _entry ) { } } - plugins_[id].contextMenus.push_back( std::pair< QString,QAction* >( plugins_[id].name + "->" + _entry->text(), _entry) ); + plugins()[id].contextMenus.push_back( std::pair< QString,QAction* >( plugins()[id].name + "->" + _entry->text(), _entry) ); // add widget name to viewMode 'all' - if ( !viewModes_[0]->visibleContextMenus.contains(plugins_[id].name + "->" + _entry->text()) ){ - viewModes_[0]->visibleContextMenus << plugins_[id].name + "->" + _entry->text(); + if ( !viewModes_[0]->visibleContextMenus.contains(plugins()[id].name + "->" + _entry->text()) ){ + viewModes_[0]->visibleContextMenus << plugins()[id].name + "->" + _entry->text(); viewModes_[0]->visibleContextMenus.sort(); } diff --git a/widgets/coreWidget/CoreWidget.cc b/widgets/coreWidget/CoreWidget.cc index e5281c2e..44f4b890 100644 --- a/widgets/coreWidget/CoreWidget.cc +++ b/widgets/coreWidget/CoreWidget.cc @@ -69,6 +69,8 @@ #include #include +#include + // -------------------- Qt event Includes #include @@ -136,7 +138,6 @@ QToolBar * PickMode::toolbar() const { */ CoreWidget:: CoreWidget( QVector& _viewModes, - std::vector& _plugins, QList< SlotInfo >& _coreSlots ) : QMainWindow(), coreSlots_(_coreSlots), @@ -187,7 +188,6 @@ CoreWidget( QVector& _viewModes, stereoSettingsWidget_(0), aboutWidget_(0), optionsWidget_(0), - plugins_(_plugins), stereoActive_(false), actionMode_(Viewer::PickingMode), lastActionMode_(Viewer::ExamineMode), @@ -661,6 +661,13 @@ CoreWidget::~CoreWidget() { //----------------------------------------------------------------------------- + +std::vector& CoreWidget::plugins() { + return PluginStorage::plugins(); +}; + +//----------------------------------------------------------------------------- + /** Set viewer to Fullscreen Mode and back */ void @@ -782,10 +789,10 @@ void CoreWidget::showToolBar( bool _state ) if ( ! viewerToolbar_->isFloating() ) viewerToolbar_->hide(); - for (uint p=0; p < plugins_.size(); p++) - for ( uint j = 0 ; j < plugins_[p].toolbars.size(); ++j ) { - if ( ! plugins_[p].toolbars[j].second->isFloating() ) - plugins_[p].toolbars[j].second->hide(); + for (uint p=0; p < plugins().size(); p++) + for ( uint j = 0 ; j < plugins()[p].toolbars.size(); ++j ) { + if ( ! plugins()[p].toolbars[j].second->isFloating() ) + plugins()[p].toolbars[j].second->hide(); } } else @@ -911,7 +918,7 @@ void CoreWidget::showOptionsWidget() { return; if ( optionsWidget_ == 0 ) { - optionsWidget_ = new OptionsWidget(plugins_, coreKeys_, invKeys_, 0); + optionsWidget_ = new OptionsWidget(plugins(), coreKeys_, invKeys_, 0); connect(optionsWidget_,SIGNAL(applyOptions()),this,SIGNAL(applyOptions())); connect(optionsWidget_,SIGNAL(saveOptions()),this,SIGNAL(saveOptions())); connect(optionsWidget_,SIGNAL(addKeyMapping(int,Qt::KeyboardModifiers,QObject*,int)), diff --git a/widgets/coreWidget/CoreWidget.hh b/widgets/coreWidget/CoreWidget.hh index e5396593..0be14814 100644 --- a/widgets/coreWidget/CoreWidget.hh +++ b/widgets/coreWidget/CoreWidget.hh @@ -292,7 +292,7 @@ public: friend class Core; /// constructor - CoreWidget( QVector& _viewModes, std::vector& _plugins, QList< SlotInfo >& _coreSlots ); + CoreWidget( QVector& _viewModes, QList< SlotInfo >& _coreSlots ); /// destructor ~CoreWidget(); @@ -451,6 +451,19 @@ public: /** @} */ + + //=========================================================================== + /** @name GUI creation + * @{ */ + //=========================================================================== + + private: + + /// Convenient way to access plugin list + std::vector& plugins(); + + /** @} */ + //=========================================================================== /** @name Video Capturing * @{ */ @@ -1278,12 +1291,6 @@ public: /** @} */ - private : - - /// reference to Core plugin list - std::vector& plugins_; - - //=========================================================================== /** @name Viewer Controls * @{ */ diff --git a/widgets/coreWidget/CoreWidgetToolbar.cc b/widgets/coreWidget/CoreWidgetToolbar.cc index e38029c0..19fee9c1 100644 --- a/widgets/coreWidget/CoreWidgetToolbar.cc +++ b/widgets/coreWidget/CoreWidgetToolbar.cc @@ -58,11 +58,8 @@ //== INCLUDES ================================================================= -// -------------------- mview -#include "CoreWidget.hh" -// -------------------- ACG -// -------------------- Qt +#include "CoreWidget.hh" //== IMPLEMENTATION ========================================================== @@ -71,8 +68,8 @@ void CoreWidget::slotAddToolbar(QToolBar* _toolbar) { int id = -1; // Find the plugin which added this Toolbox - for ( unsigned int i = 0 ; i < plugins_.size(); ++i ) { - if ( plugins_[i].plugin == sender() ) { + for ( unsigned int i = 0 ; i < plugins().size(); ++i ) { + if ( plugins()[i].plugin == sender() ) { id = i; break; } @@ -80,8 +77,8 @@ void CoreWidget::slotAddToolbar(QToolBar* _toolbar) { // Find the scripting plugin because we assign this toolBox to it as we did not find the original sender if ( id == -1 ) { - for ( unsigned int i = 0 ; i < plugins_.size(); ++i ) { - if ( plugins_[i].name == "Scripting" ) { + for ( unsigned int i = 0 ; i < plugins().size(); ++i ) { + if ( plugins()[i].name == "Scripting" ) { id = i; break; } @@ -108,7 +105,7 @@ void CoreWidget::slotAddToolbar(QToolBar* _toolbar) { // Remember which plugin this toolbar belongs to if ( id != -1 ) - plugins_[id].toolbars.push_back( std::pair< QString,QToolBar* >( _toolbar->windowTitle() , _toolbar) ); + plugins()[id].toolbars.push_back( std::pair< QString,QToolBar* >( _toolbar->windowTitle() , _toolbar) ); // add widget name to viewMode 'all' if ( !viewModes_[0]->visibleToolbars.contains( _toolbar->windowTitle() ) ){ diff --git a/widgets/coreWidget/keyHandling.cc b/widgets/coreWidget/keyHandling.cc index 59384e7b..56e6990b 100644 --- a/widgets/coreWidget/keyHandling.cc +++ b/widgets/coreWidget/keyHandling.cc @@ -57,9 +57,9 @@ KeyBinding CoreWidget::getKeyBinding(QObject* _plugin, int _keyIndex ){ if (_plugin == 0) return coreKeys_[_keyIndex]; - for (uint i=0; i < plugins_.size(); i++){ - if (plugins_[i].plugin == _plugin) - return plugins_[i].keys[_keyIndex]; + for (uint i=0; i < plugins().size(); i++){ + if (plugins()[i].plugin == _plugin) + return plugins()[i].keys[_keyIndex]; } emit log(LOGERR,tr("ERROR: could not get KeyBinding")); @@ -70,9 +70,9 @@ QString CoreWidget::getRPCName(QObject* _plugin ){ if (_plugin == 0) return ""; - for (uint i=0; i < plugins_.size(); i++){ - if (plugins_[i].plugin == _plugin) - return plugins_[i].rpcName; + for (uint i=0; i < plugins().size(); i++){ + if (plugins()[i].plugin == _plugin) + return plugins()[i].rpcName; } emit log(LOGERR,tr("ERROR: could not get rpcname")); @@ -225,13 +225,13 @@ void CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QSt //then check if the key is already registered by a different plugin if (!found) - for (uint i=0; i < plugins_.size(); i++) - for (int k=0; k < plugins_[i].keys.count(); k++) - if (plugins_[i].keys[k].key == _key - && plugins_[i].keys[k].modifiers == _modifiers){ + for (uint i=0; i < plugins().size(); i++) + for (int k=0; k < plugins()[i].keys.count(); k++) + if (plugins()[i].keys[k].key == _key + && plugins()[i].keys[k].modifiers == _modifiers){ found = true; - multi = plugins_[i].keys[k].multiUse; - name = plugins_[i].name; + multi = plugins()[i].keys[k].multiUse; + name = plugins()[i].name; break; } @@ -260,9 +260,9 @@ void CoreWidget::slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QSt //find plugin PluginInfo* pluginInfo = 0; - for (uint i=0; i < plugins_.size(); i++) - if (plugins_[i].plugin == sender()) - pluginInfo = &plugins_[i]; + for (uint i=0; i < plugins().size(); i++) + if (plugins()[i].plugin == sender()) + pluginInfo = &plugins()[i]; if (pluginInfo == 0){ emit log(LOGERR, tr("Unable to register key. Plugin not found!")); @@ -309,26 +309,26 @@ void CoreWidget::slotRegisterSlotKeyBindings(){ } //check all plugins - for (uint i=0; i < plugins_.size(); i++) + for (uint i=0; i < plugins().size(); i++) - for (int j=0; j < plugins_[i].rpcFunctions.count(); j++){ + for (int j=0; j < plugins()[i].rpcFunctions.count(); j++){ //only consider functions without arguments - if ( !plugins_[i].rpcFunctions[j].contains( "()" ) - || plugins_[i].rpcFunctions[j] == "version()") + if ( !plugins()[i].rpcFunctions[j].contains( "()" ) + || plugins()[i].rpcFunctions[j] == "version()") continue; KeyBinding kb; kb.key = -1; kb.modifiers = 0; - kb.description = plugins_[i].rpcFunctions[j]; + kb.description = plugins()[i].rpcFunctions[j]; kb.multiUse = true; kb.slot = true; - plugins_[i].keys.append( kb ); + plugins()[i].keys.append( kb ); - keys_.insert( std::make_pair( std::make_pair(-1, (QFlags)0) , std::make_pair(plugins_[i].plugin, plugins_[i].keys.size()-1) ) ); - invKeys_.insert( std::make_pair( std::make_pair(plugins_[i].plugin, plugins_[i].keys.size()-1) , std::make_pair(-1, (QFlags)0) ) ); + keys_.insert( std::make_pair( std::make_pair(-1, (QFlags)0) , std::make_pair(plugins()[i].plugin, plugins()[i].keys.size()-1) ) ); + invKeys_.insert( std::make_pair( std::make_pair(plugins()[i].plugin, plugins()[i].keys.size()-1) , std::make_pair(-1, (QFlags)0) ) ); } } @@ -440,9 +440,9 @@ void CoreWidget::loadKeyBindings(INIFile& _ini){ if (pluginNames[i] != "Core" ){ //search for the plugin - for (uint i=0; i < plugins_.size(); i++) - if (plugins_[i].rpcName == pluginNames[i] ){ - plugin = plugins_[i].plugin; + for (uint i=0; i < plugins().size(); i++) + if (plugins()[i].rpcName == pluginNames[i] ){ + plugin = plugins()[i].plugin; break; } diff --git a/widgets/coreWidget/viewMode.cc b/widgets/coreWidget/viewMode.cc index ddaa9051..9d30b8e6 100644 --- a/widgets/coreWidget/viewMode.cc +++ b/widgets/coreWidget/viewMode.cc @@ -370,12 +370,12 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr //find all widgets that should be visible for (int i=0; i < _toolboxWidgets.size(); i++) { - for (uint p=0; p < plugins_.size(); p++){ - for ( uint j = 0 ; j < plugins_[p].toolboxWidgets.size(); ++j ) - if (_toolboxWidgets[i] == plugins_[p].toolboxWidgets[j].first ) { + for (uint p=0; p < plugins().size(); p++){ + for ( uint j = 0 ; j < plugins()[p].toolboxWidgets.size(); ++j ) + if (_toolboxWidgets[i] == plugins()[p].toolboxWidgets[j].first ) { bool skip = false; - if (toolBox_->plugins().contains(plugins_[p].plugin)) { + if (toolBox_->plugins().contains(plugins()[p].plugin)) { // account for the case, where a plugin can have several // toolboxes, for example 'Scripting' if (toolBox_->names().contains(_toolboxWidgets[i])) @@ -384,17 +384,17 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr // only add items that have not been added yet if (!skip) { - toolBox_->addItem (plugins_[p].plugin, plugins_[p].toolboxWidgets[j].second, plugins_[p].toolboxWidgets[j].first, plugins_[p].toolboxIcons[j], plugins_[p].headerAreaWidgets[j].second ); + toolBox_->addItem (plugins()[p].plugin, plugins()[p].toolboxWidgets[j].second, plugins()[p].toolboxWidgets[j].first, plugins()[p].toolboxIcons[j], plugins()[p].headerAreaWidgets[j].second ); // move item to the correct position if (i < toolBox_->lastPos_) { - toolBox_->moveItemToPosition(plugins_[p].plugin, _toolboxWidgets[i], i); + toolBox_->moveItemToPosition(plugins()[p].plugin, _toolboxWidgets[i], i); } else toolBox_->lastPos_ = i; // check if we have to restore the state // of toolboxes added via scripts - if (plugins_[p].name == "Scripting") { + if (plugins()[p].name == "Scripting") { QFile statesFile(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "WindowStates.dat"); @@ -428,12 +428,12 @@ void CoreWidget::slotChangeView(QString _mode, QStringList _toolboxWidgets, QStr if ( ! OpenFlipperSettings().value("Core/Gui/Toolbar/hidden",false).toBool()) { //find all Toolbars that should be visible and hide the others - for (uint p=0; p < plugins_.size(); p++) - for ( uint j = 0 ; j < plugins_[p].toolbars.size(); ++j ) - if (_toolbars.contains( plugins_[p].toolbars[j].first ) ) - plugins_[p].toolbars[j].second->show(); + for (uint p=0; p < plugins().size(); p++) + for ( uint j = 0 ; j < plugins()[p].toolbars.size(); ++j ) + if (_toolbars.contains( plugins()[p].toolbars[j].first ) ) + plugins()[p].toolbars[j].second->show(); else - plugins_[p].toolbars[j].second->hide(); + plugins()[p].toolbars[j].second->hide(); // Check the Main Toolbar: diff --git a/widgets/loadWidget/FileOptionsDialog.hh b/widgets/loadWidget/FileOptionsDialog.hh index 7f52e397..938cf074 100644 --- a/widgets/loadWidget/FileOptionsDialog.hh +++ b/widgets/loadWidget/FileOptionsDialog.hh @@ -52,7 +52,7 @@ #include - +#include class FileOptionsDialog : public QDialog { diff --git a/widgets/loadWidget/loadWidget.hh b/widgets/loadWidget/loadWidget.hh index 23c9a1a3..52f504ad 100644 --- a/widgets/loadWidget/loadWidget.hh +++ b/widgets/loadWidget/loadWidget.hh @@ -56,6 +56,9 @@ #include +#include + + class LoadWidget : public QFileDialog { Q_OBJECT -- GitLab