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
33
34using namespace ScenarioManager;
35using namespace Controller;
36using namespace Data_Structure;
37using namespace Exec;
38using 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
59
62{
63 return model;
64}
65
66void
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.
95 model->setSourceModel(&treemodel);
96
97 emit modelUpdated(model);
98}
99
100void
102{
103 //emit showApplication mit app pointer;
104 ApplicationDatabaseItem* appItem =
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}
uint8_t index
This class represents an item in the ApplicationDatabaseView.
ScenarioManager::Data_Structure::PackagePtr getPackage()
Returns the Package displayed in this item.
ScenarioManager::Data_Structure::ApplicationPtr getApplication()
Returns the Application displayed in this item.
void packageClicked(Data_Structure::PackagePtr package)
Gets emitted after a Package gets clicked in the ApplicationDatabaseView.
void on_itemClicked(const QModelIndex &index)
Finds out whether an Application or a Scenario has been clicked and sends a signal with the correspon...
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...
void modelUpdated(FilterableTreeModelSortFilterProxyModelPtr model)
FilterableTreeModelSortFilterProxyModelPtr getModel()
Returns the model used by the ApplicationDatabaseView and managed by this controller.
void updatePackages()
Updates the packages displayed in the ApplicationDatabaseView by reloading all packages and applicati...
static std::string getCacheDir()
void appendChild(TreeItem *child)
Definition treeitem.cpp:44
virtual QVariant data(int column) const
Definition treeitem.cpp:69
void setEnabled(bool enabled)
Definition treeitem.cpp:92
bool isEnabled()
Definition treeitem.cpp:98
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition Package.h:123
std::shared_ptr< Executor > ExecutorPtr
Definition Executor.h:175
This file offers overloads of toIce() and fromIce() functions for STL container types.
@ APPLICATIONITEMSOURCE
Definition treeitem.h:42