ApplicationDatabaseController.cpp
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 
26 
27 #include "../gui/applicationdatabaseitem.h"
28 
31 
32 #include <QMessageBox>
33 
34 using namespace ScenarioManager;
35 using namespace Controller;
36 using namespace Data_Structure;
37 using namespace Exec;
38 using namespace armarx;
39 
41  PackageVectorPtr packages,
42  ExecutorPtr executor, QObject* parent)
43  : QObject(parent),
44  treemodel(),
46  packages(packages),
47  executor(executor)
48 {
49  //Q_DECLARE_METATYPE(FilterableTreeModelSortFilterProxyModelPtr);
50  //qRegisterMetaType<FilterableTreeModelSortFilterProxyModelPtr>();
51  qRegisterMetaType<FilterableTreeModelSortFilterProxyModelPtr>("FilterableTreeModelSortFilterProxyModelPtr");
52  model->setSourceModel(&treemodel);
53 }
54 
56 {
57 
58 }
59 
61 {
62  return model;
63 }
64 
66 {
67  treemodel.clear();
68 
69  ApplicationDatabaseItem* rootItem = treemodel.getRootItem();
70 
71  for (const auto& package : *packages)
72  {
73  ApplicationDatabaseItem* packageItem = new ApplicationDatabaseItem(package);
74 
75  for (const auto& application : *package->getApplications())
76  {
77  ApplicationDatabaseItem* applicationItem = new ApplicationDatabaseItem(application);
78 
79  if (!application->getFound())
80  {
81  applicationItem->setEnabled(false);
82  }
83 
84  packageItem->appendChild(applicationItem);
85  }
86 
87  rootItem->appendChild(packageItem);
88  }
89 
90  treemodel.update();
91  // For some unknown reason, resetting the smart pointer is necessary to see an updated results list.
92  model.reset(new FilterableTreeModelSortFilterProxyModel());
93  model->setSourceModel(&treemodel);
94 
95  emit modelUpdated(model);
96 }
97 
99 {
100  //emit showApplication mit app pointer;
102 
103  if (appItem == nullptr)
104  {
105  return;
106  }
107 
108  if (!appItem->isEnabled())
109  {
110  QMessageBox message;
111  message.setText("Could not find Application " + appItem->data(0).toString() + " at " + QString::fromStdString(appItem->getApplication()->getPathToExecutable()) + ".");
112  message.exec();
113  return;
114  }
115 
116  //ApplicationInstance is clicked
117  if (index.parent().isValid())
118  {
119  //appItem = reinterpret_cast<ApplicationDatabaseItem*>(rootItem->child(index.parent().row())->child(index.row()));
120  std::string cacheDir = Parser::IceParser::getCacheDir();
121 
122  // executor->loadAndSetCachedProperties(appItem->getApplication(), cacheDir);
123  // emit applicationClicked(appItem->getApplication());
124  }
125  else //scenario clicked
126  {
127  //appItem = reinterpret_cast<ApplicationDatabaseItem*>(rootItem->child(index.row()));
128  emit packageClicked(appItem->getPackage());
129  }
130 }
ScenarioManager::Controller::ApplicationDatabaseController::modelUpdated
void modelUpdated(FilterableTreeModelSortFilterProxyModelPtr model)
iceparser.h
index
uint8_t index
Definition: EtherCATFrame.h:59
ScenarioManager::Controller::ApplicationDatabaseController::updatePackages
void updatePackages()
Updates the packages displayed in the ApplicationDatabaseView by reloading all packages and applicati...
Definition: ApplicationDatabaseController.cpp:65
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:64
ScenarioManager::Controller::ApplicationDatabaseController::getModel
FilterableTreeModelSortFilterProxyModelPtr getModel()
Returns the model used by the ApplicationDatabaseView and managed by this controller.
Definition: ApplicationDatabaseController.cpp:60
TreeItem::appendChild
void appendChild(TreeItem *child)
Definition: treeitem.cpp:43
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:164
ScenarioManager::Data_Structure::PackageVectorPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition: Package.h:122
ApplicationDatabaseItem
This class represents an item in the ApplicationDatabaseView.
Definition: applicationdatabaseitem.h:34
ScenarioManager::Controller::ApplicationDatabaseController::packageClicked
void packageClicked(Data_Structure::PackagePtr package)
Gets emitted after a Package gets clicked in the ApplicationDatabaseView.
APPLICATIONITEMSOURCE
@ APPLICATIONITEMSOURCE
Definition: treeitem.h:41
ApplicationDatabaseModel::getRootItem
ApplicationDatabaseItem * getRootItem()
Definition: applicationdatabasemodel.cpp:137
ScenarioManager::Controller::ApplicationDatabaseController::~ApplicationDatabaseController
~ApplicationDatabaseController() override
Definition: ApplicationDatabaseController.cpp:55
ApplicationDatabaseModel::update
void update()
Updates the model.
Definition: applicationdatabasemodel.cpp:129
ScenarioManager::Controller::ApplicationDatabaseController::on_itemClicked
void on_itemClicked(const QModelIndex &index)
Finds out whether an Application or a Scenario has been clicked and sends a signal with the correspon...
Definition: ApplicationDatabaseController.cpp:98
TreeItem::isEnabled
bool isEnabled()
Definition: treeitem.cpp:89
ApplicationDatabaseModel::clear
void clear() override
Clears and resets this model as if it was newly constructed.
Definition: applicationdatabasemodel.cpp:66
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:65
FilterableTreeModelSortFilterProxyModel
Model of the FilterableTreeView.
Definition: filterabletreemodelsortfilterproxymodel.h:41
TreeItem::setEnabled
void setEnabled(bool enabled)
Definition: treeitem.cpp:84
ScenarioManager::Controller::ApplicationDatabaseController::ApplicationDatabaseController
ApplicationDatabaseController(Data_Structure::PackageVectorPtr packages, Exec::ExecutorPtr executor, QObject *parent=0)
Constructor that takes the data structure this controller operates on and optionally the parent objec...
Definition: ApplicationDatabaseController.cpp:40
ApplicationDatabaseController.h
ScenarioManager::Parser::IceParser::getCacheDir
static std::string getCacheDir()
Definition: iceparser.cpp:304
ApplicationDatabaseItem::getPackage
ScenarioManager::Data_Structure::PackagePtr getPackage()
Returns the Package displayed in this item.
Definition: applicationdatabaseitem.cpp:50
ScenarioManager
Definition: Application.cpp:166
ApplicationDatabaseItem::getApplication
ScenarioManager::Data_Structure::ApplicationPtr getApplication()
Returns the Application displayed in this item.
Definition: applicationdatabaseitem.cpp:55
Logging.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28