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 "../gui/treemodel.h"
29 #include "../gui/settingsview.h"
30 #include "../gui/settingsmodel.h"
31 #include "../gui/settingsitem.h"
32 #include "../gui/packageadderview.h"
38 #include <QObject>
39 #include <string>
40 #include <vector>
41 
43 {
44  /**
45  * @class SettingsController
46  * @ingroup controller
47  * @brief This controller manages the signals and model of the SettingsView.
48  * Any signals involving the settings need to be connected to the corresponding slots in this controller.
49  * This controller also manages settings that get saved between sessions, as well as the Executor configuration.
50  */
51  class SettingsController : public QObject
52  {
53  Q_OBJECT
54  public:
55  /**
56  * Constructor that sets the data structure this controller operates on, the executor which gets configured by this controller
57  * and optionally the parent object.
58  * @param packages list of packages. Need to contain the Packages displayed in the SettingsView.
59  * @param executor executor which gets configured by the settings
60  * @param parent standard QT option to specify a parent
61  */
62  SettingsController(Data_Structure::PackageVectorPtr packages, Exec::ExecutorPtr executor, QObject* parent = 0);
63 
64  void init();
65 
66  /**
67  * Destructor.
68  */
69  ~SettingsController() override;
70 
71  signals:
72  /**
73  * Emitted when a package gets added in the settings. Allows other controllers to update their models
74  * with the new package.
75  * @param name name of the new package
76  */
77  void packageAdded(std::string name);
78 
79  /**
80  * Emitted when a package gets removed. Other packages need to update their models.
81  */
82  void packageRemoved();
83 
84  void setExecutorState(int killMethodIndex, int delay, int stopStrategyIndex);
85 
86 
87  public slots:
88  /**
89  * Shows the settings dialog.
90  */
91  void showSettings();
92 
93  /**
94  * Shows a view that allows the user to add new packages.
95  */
96  void showPackageAdderView();
97 
98  /**
99  * Adds a new package to the settings.
100  */
101  void addPackage(std::string name);
102 
103  /**
104  * Removes a package from the settings.
105  * @param row row of the package
106  * @param column column of the package
107  * @param parent index of the package to be removed
108  */
109  void removePackage(int row, int column, QModelIndex parent);
110 
111  /**
112  * Configures the Executor.
113  * @param killMethod "StopAndKill" or "Stop"
114  * @param delay length of the delay in the StopAndKill stop-method
115  * @param stopMethod "By Name" or "By Pid"
116  */
117  void setExecutorStopStrategy(std::string killMethod, int delay, std::string stopMethod);
118 
119  /**
120  * Updates the packages displayed in the settingsview by reloading all packages into the model.
121  */
122  void updateModel();
123 
124  void clearXmlCache();
125  void clearPidCache();
127 
128 
129  private:
130 
131  ScenarioManager::Exec::StopStrategyFactory stopStrategyFactory;
134 
135  SettingsModelPtr treemodel;
138  Exec::ExecutorPtr executor;
139  SettingsView settingsDialog;
140  PackageAdderView packageAdderView;
141  };
142 }
143 
144 
ScenarioManager::Controller::SettingsController::init
void init()
Definition: SettingsController.cpp:95
ScenarioManager::Controller::SettingsController
This controller manages the signals and model of the SettingsView. Any signals involving the settings...
Definition: SettingsController.h:51
ScenarioManager::Controller::SettingsController::updateModel
void updateModel()
Updates the packages displayed in the settingsview by reloading all packages into the model.
Definition: SettingsController.cpp:248
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:45
ScenarioManager::Controller
Definition: ApplicationDatabaseController.h:39
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:62
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:171
ScenarioManager::Data_Structure::PackageVectorPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition: Package.h:122
ScenarioManager::Controller::SettingsController::showSettings
void showSettings()
Shows the settings dialog.
Definition: SettingsController.cpp:114
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:68
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:265
ScenarioManager::Controller::SettingsController::showPackageAdderView
void showPackageAdderView()
Shows a view that allows the user to add new packages.
Definition: SettingsController.cpp:136
Executor.h
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:65
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:166
ScenarioManager::Controller::SettingsController::setExecutorStopStrategy
void setExecutorStopStrategy(std::string killMethod, int delay, std::string stopMethod)
Configures the Executor.
Definition: SettingsController.cpp:203
SettingsView
Definition: settingsview.h:38
ScenarioManager::Controller::SettingsController::addPackage
void addPackage(std::string name)
Adds a new package to the settings.
Definition: SettingsController.cpp:141
ScenarioManager::Controller::SettingsController::~SettingsController
~SettingsController() override
Destructor.
Definition: SettingsController.cpp:90
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:270
ScenarioManager::Controller::SettingsController::closeUnavailablePackages
void closeUnavailablePackages()
Definition: SettingsController.cpp:276