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 // getFound() is cached, and this list is only rebuilt when the packages change, so
82 // refresh it here rather than showing whatever was true when the package was parsed.
83 application->updateFound();
84 if (!application->getFound())
85 {
86 applicationItem->setEnabled(false);
87 }
88
89 packageItem->appendChild(applicationItem);
90 }
91
92 rootItem->appendChild(packageItem);
93 }
94
95 treemodel.update();
96 // For some unknown reason, resetting the smart pointer is necessary to see an updated results list.
98 model->setSourceModel(&treemodel);
99
100 emit modelUpdated(model);
101}
102
103void
105{
106 //emit showApplication mit app pointer;
107 ApplicationDatabaseItem* appItem =
109
110 if (appItem == nullptr)
111 {
112 return;
113 }
114
115 if (!appItem->isEnabled())
116 {
117 QMessageBox message;
118 message.setText("Could not find Application " + appItem->data(0).toString() + " at " +
119 QString::fromStdString(appItem->getApplication()->getPathToExecutable()) +
120 ".");
121 message.exec();
122 return;
123 }
124
125 //ApplicationInstance is clicked
126 if (index.parent().isValid())
127 {
128 //appItem = reinterpret_cast<ApplicationDatabaseItem*>(rootItem->child(index.parent().row())->child(index.row()));
129 std::string cacheDir = Parser::IceParser::getCacheDir();
130
131 // executor->loadAndSetCachedProperties(appItem->getApplication(), cacheDir);
132 // emit applicationClicked(appItem->getApplication());
133 }
134 else //scenario clicked
135 {
136 //appItem = reinterpret_cast<ApplicationDatabaseItem*>(rootItem->child(index.row()));
137 emit packageClicked(appItem->getPackage());
138 }
139}
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:210
This file offers overloads of toIce() and fromIce() functions for STL container types.
@ APPLICATIONITEMSOURCE
Definition treeitem.h:42