SettingsController.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #pragma once
27 
28 #include <string>
29 #include <vector>
30 
31 #include <QObject>
32 
38 
39 #include "../gui/packageadderview.h"
40 #include "../gui/settingsitem.h"
41 #include "../gui/settingsmodel.h"
42 #include "../gui/settingsview.h"
43 #include "../gui/treemodel.h"
44 
46 {
47  /**
48  * @class SettingsController
49  * @ingroup controller
50  * @brief This controller manages the signals and model of the SettingsView.
51  * Any signals involving the settings need to be connected to the corresponding slots in this controller.
52  * This controller also manages settings that get saved between sessions, as well as the Executor configuration.
53  */
54  class SettingsController : public QObject
55  {
56  Q_OBJECT
57  public:
58  /**
59  * Constructor that sets the data structure this controller operates on, the executor which gets configured by this controller
60  * and optionally the parent object.
61  * @param packages list of packages. Need to contain the Packages displayed in the SettingsView.
62  * @param executor executor which gets configured by the settings
63  * @param parent standard QT option to specify a parent
64  */
66  Exec::ExecutorPtr executor,
67  QObject* parent = 0);
68 
69  void init();
70 
71  /**
72  * Destructor.
73  */
74  ~SettingsController() override;
75 
76  signals:
77  /**
78  * Emitted when a package gets added in the settings. Allows other controllers to update their models
79  * with the new package.
80  * @param name name of the new package
81  */
82  void packageAdded(std::string name);
83 
84  /**
85  * Emitted when a package gets removed. Other packages need to update their models.
86  */
87  void packageRemoved();
88 
89  void setExecutorState(int killMethodIndex, int delay, int stopStrategyIndex);
90 
91 
92  public slots:
93  /**
94  * Shows the settings dialog.
95  */
96  void showSettings();
97 
98  /**
99  * Shows a view that allows the user to add new packages.
100  */
101  void showPackageAdderView();
102 
103  /**
104  * Adds a new package to the settings.
105  */
106  void addPackage(std::string name);
107 
108  /**
109  * Removes a package from the settings.
110  * @param row row of the package
111  * @param column column of the package
112  * @param parent index of the package to be removed
113  */
114  void removePackage(int row, int column, QModelIndex parent);
115 
116  /**
117  * Configures the Executor.
118  * @param killMethod "StopAndKill" or "Stop"
119  * @param delay length of the delay in the StopAndKill stop-method
120  * @param stopMethod "By Name" or "By Pid"
121  */
122  void setExecutorStopStrategy(std::string killMethod, int delay, std::string stopMethod);
123 
124  /**
125  * Updates the packages displayed in the settingsview by reloading all packages into the model.
126  */
127  void updateModel();
128 
129  void clearXmlCache();
130  void clearPidCache();
132 
133 
134  private:
135  ScenarioManager::Exec::StopStrategyFactory stopStrategyFactory;
138 
139  SettingsModelPtr treemodel;
142  Exec::ExecutorPtr executor;
143  SettingsView settingsDialog;
144  PackageAdderView packageAdderView;
145  };
146 } // namespace ScenarioManager::Controller
ScenarioManager::Controller::SettingsController::init
void init()
Definition: SettingsController.cpp:104
ScenarioManager::Controller::SettingsController
This controller manages the signals and model of the SettingsView. Any signals involving the settings...
Definition: SettingsController.h:54
ScenarioManager::Controller::SettingsController::updateModel
void updateModel()
Updates the packages displayed in the settingsview by reloading all packages into the model.
Definition: SettingsController.cpp:285
PackageAdderView
View that allows the user to find and add new packages.
Definition: packageadderview.h:39
SettingsModelPtr
std::shared_ptr< SettingsModel > SettingsModelPtr
Definition: settingsmodel.h:46
ScenarioManager::Controller
Definition: ApplicationDatabaseController.h:40
StopperFactory.h
ScenarioManager::Controller::SettingsController::SettingsController
SettingsController(Data_Structure::PackageVectorPtr packages, Exec::ExecutorPtr executor, QObject *parent=0)
Constructor that sets the data structure this controller operates on, the executor which gets configu...
Definition: SettingsController.cpp:49
ScenarioManager::Exec::StarterFactoryPtr
std::shared_ptr< ScenarioManager::Exec::StarterFactory > StarterFactoryPtr
Definition: StarterFactory.h:58
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:175
ScenarioManager::Data_Structure::PackageVectorPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition: Package.h:124
ScenarioManager::Controller::SettingsController::showSettings
void showSettings()
Shows the settings dialog.
Definition: SettingsController.cpp:131
ScenarioManager::Controller::SettingsController::setExecutorState
void setExecutorState(int killMethodIndex, int delay, int stopStrategyIndex)
ScenarioManager::Exec::StopperFactoryPtr
std::shared_ptr< ScenarioManager::Exec::StopperFactory > StopperFactoryPtr
Definition: StopperFactory.h:65
ScenarioManager::Exec::StopStrategyFactory
Creates different instances of StopStrategy. This Factory creates different types of stop-strategies.
Definition: StopStrategyFactory.h:39
Package.h
ScenarioManager::Controller::SettingsController::clearPidCache
void clearPidCache()
Definition: SettingsController.cpp:303
ScenarioManager::Controller::SettingsController::showPackageAdderView
void showPackageAdderView()
Shows a view that allows the user to add new packages.
Definition: SettingsController.cpp:161
Executor.h
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:68
StarterFactoryLinux.h
ScenarioManager::Controller::SettingsController::packageRemoved
void packageRemoved()
Emitted when a package gets removed.
ScenarioManager::Controller::SettingsController::removePackage
void removePackage(int row, int column, QModelIndex parent)
Removes a package from the settings.
Definition: SettingsController.cpp:194
ScenarioManager::Controller::SettingsController::setExecutorStopStrategy
void setExecutorStopStrategy(std::string killMethod, int delay, std::string stopMethod)
Configures the Executor.
Definition: SettingsController.cpp:235
SettingsView
Definition: settingsview.h:39
ScenarioManager::Controller::SettingsController::addPackage
void addPackage(std::string name)
Adds a new package to the settings.
Definition: SettingsController.cpp:167
ScenarioManager::Controller::SettingsController::~SettingsController
~SettingsController() override
Destructor.
Definition: SettingsController.cpp:99
ScenarioManager::Controller::SettingsController::packageAdded
void packageAdded(std::string name)
Emitted when a package gets added in the settings.
StopStrategyFactory.h
ScenarioManager::Controller::SettingsController::clearXmlCache
void clearXmlCache()
Definition: SettingsController.cpp:309
ScenarioManager::Controller::SettingsController::closeUnavailablePackages
void closeUnavailablePackages()
Definition: SettingsController.cpp:315