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 <QMessageBox>
28 
31 
32 #include "../gui/applicationdatabaseitem.h"
33 
34 using namespace ScenarioManager;
35 using namespace Controller;
36 using namespace Data_Structure;
37 using namespace Exec;
38 using namespace armarx;
39 
41  ExecutorPtr executor,
42  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>(
52  "FilterableTreeModelSortFilterProxyModelPtr");
53  model->setSourceModel(&treemodel);
54 }
55 
57 {
58 }
59 
62 {
63  return model;
64 }
65 
66 void
68 {
69  treemodel.clear();
70 
71  ApplicationDatabaseItem* rootItem = treemodel.getRootItem();
72 
73  for (const auto& package : *packages)
74  {
75  ApplicationDatabaseItem* packageItem = new ApplicationDatabaseItem(package);
76 
77  for (const auto& application : *package->getApplications())
78  {
79  ApplicationDatabaseItem* applicationItem = new ApplicationDatabaseItem(application);
80 
81  if (!application->getFound())
82  {
83  applicationItem->setEnabled(false);
84  }
85 
86  packageItem->appendChild(applicationItem);
87  }
88 
89  rootItem->appendChild(packageItem);
90  }
91 
92  treemodel.update();
93  // For some unknown reason, resetting the smart pointer is necessary to see an updated results list.
94  model.reset(new FilterableTreeModelSortFilterProxyModel());
95  model->setSourceModel(&treemodel);
96 
97  emit modelUpdated(model);
98 }
99 
100 void
102 {
103  //emit showApplication mit app pointer;
104  ApplicationDatabaseItem* appItem =
105  model->data(index, APPLICATIONITEMSOURCE).value<ApplicationDatabaseItem*>();
106 
107  if (appItem == nullptr)
108  {
109  return;
110  }
111 
112  if (!appItem->isEnabled())
113  {
114  QMessageBox message;
115  message.setText("Could not find Application " + appItem->data(0).toString() + " at " +
116  QString::fromStdString(appItem->getApplication()->getPathToExecutable()) +
117  ".");
118  message.exec();
119  return;
120  }
121 
122  //ApplicationInstance is clicked
123  if (index.parent().isValid())
124  {
125  //appItem = reinterpret_cast<ApplicationDatabaseItem*>(rootItem->child(index.parent().row())->child(index.row()));
126  std::string cacheDir = Parser::IceParser::getCacheDir();
127 
128  // executor->loadAndSetCachedProperties(appItem->getApplication(), cacheDir);
129  // emit applicationClicked(appItem->getApplication());
130  }
131  else //scenario clicked
132  {
133  //appItem = reinterpret_cast<ApplicationDatabaseItem*>(rootItem->child(index.row()));
134  emit packageClicked(appItem->getPackage());
135  }
136 }
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:67
TreeItem::data
virtual QVariant data(int column) const
Definition: treeitem.cpp:69
ScenarioManager::Controller::ApplicationDatabaseController::getModel
FilterableTreeModelSortFilterProxyModelPtr getModel()
Returns the model used by the ApplicationDatabaseView and managed by this controller.
Definition: ApplicationDatabaseController.cpp:61
TreeItem::appendChild
void appendChild(TreeItem *child)
Definition: treeitem.cpp:44
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:175
ScenarioManager::Data_Structure::PackageVectorPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition: Package.h:124
ApplicationDatabaseItem
This class represents an item in the ApplicationDatabaseView.
Definition: applicationdatabaseitem.h:36
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:42
ApplicationDatabaseModel::getRootItem
ApplicationDatabaseItem * getRootItem()
Definition: applicationdatabasemodel.cpp:146
ScenarioManager::Controller::ApplicationDatabaseController::~ApplicationDatabaseController
~ApplicationDatabaseController() override
Definition: ApplicationDatabaseController.cpp:56
ApplicationDatabaseModel::update
void update()
Updates the model.
Definition: applicationdatabasemodel.cpp:137
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:101
TreeItem::isEnabled
bool isEnabled()
Definition: treeitem.cpp:98
ApplicationDatabaseModel::clear
void clear() override
Clears and resets this model as if it was newly constructed.
Definition: applicationdatabasemodel.cpp:69
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:68
FilterableTreeModelSortFilterProxyModel
Model of the FilterableTreeView.
Definition: filterabletreemodelsortfilterproxymodel.h:43
TreeItem::setEnabled
void setEnabled(bool enabled)
Definition: treeitem.cpp:92
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:318
ApplicationDatabaseItem::getPackage
ScenarioManager::Data_Structure::PackagePtr getPackage()
Returns the Package displayed in this item.
Definition: applicationdatabaseitem.cpp:53
ScenarioManager
Definition: Application.cpp:180
ApplicationDatabaseItem::getApplication
ScenarioManager::Data_Structure::ApplicationPtr getApplication()
Returns the Application displayed in this item.
Definition: applicationdatabaseitem.cpp:59
Logging.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27