GuiUseCaseSelector.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 ArmarX
19 * @author Mirko Waechter( mirko.waechter 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#include "GuiUseCaseSelector.h"
25
26#include <filesystem>
27
28#include <QPushButton>
29
31#include <ArmarXGui/applications/ArmarXGui/ui_GuiUseCaseSelector.h>
32
33#include "UseCaseSelectorItem.h"
34
35namespace armarx
36{
37
39 bool doNotShowAgain,
40 QWidget* parent) :
41 QDialog(parent), ui(new Ui::GuiUseCaseSelector)
42 {
43 ui->setupUi(this);
44 ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Open selected use case");
45 ui->buttonBox->button(QDialogButtonBox::Ok)
46 ->setToolTip(
47 "Opens the selected use case and loads the associated preconfigured widgets.");
48 ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("Open empty GUI");
49 ui->buttonBox->button(QDialogButtonBox::Cancel)->setToolTip("Opens an empty gui.");
50 for (auto& p : mainWindow->getDefaultPackageNames())
51 {
52 CMakePackageFinder f(p);
53 if (!f.packageFound())
54 {
55 continue;
56 }
57 std::filesystem::path path = f.getDataDir();
58 path /= p;
59 path /= "GuiDefaultConfigs";
60 if (!std::filesystem::exists(path))
61 {
62 continue;
63 }
64 int i = 1;
65 for (std::filesystem::recursive_directory_iterator end, dir(path); dir != end;
66 ++dir, i++)
67 {
68 if (dir->path().extension() == ".armarxgui")
69 {
70 addDefaultConfig(dir->path().string().c_str(), p.c_str());
71 }
72
73 if (i % 100 == 0)
74 {
75 ARMARX_INFO_S << "Scanning file " << i << ": " << dir->path().c_str();
76 }
77 }
78 }
79 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
80 ui->checkBoxDoNotShowAgain->setChecked(doNotShowAgain);
81 }
82
84 {
85 delete ui;
86 }
87
88 QString
90 {
91 for (int i = 0; i < ui->verticalLayout_3->count(); ++i)
92 {
94 qobject_cast<UseCaseSelectorItem*>(ui->verticalLayout_3->itemAt(i)->widget());
95 if (item && item->isHighlighted())
96 {
97 return item->getConfigFilePath();
98 }
99 }
100 return "";
101 }
102
103 bool
105 {
106 return ui->checkBoxDoNotShowAgain->isChecked();
107 }
108
109 void
111 {
112 ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
113 }
114
115 void
116 GuiUseCaseSelector::addDefaultConfig(QString configPath, QString packageName)
117 {
118 ARMARX_VERBOSE_S << "Adding " << configPath;
119 QSettings s(configPath, QSettings::IniFormat);
120 UseCaseSelectorItem* item = new UseCaseSelectorItem(s.value("ConfigTitle").toString(),
121 s.value("ConfigDescription").toString(),
122 configPath,
123 packageName,
124 s.value("IconPath").toString(),
125 this);
126 ui->verticalLayout_3->addWidget(item);
127 connect(item, SIGNAL(selected(QString)), this, SLOT(setSelection(QString)));
128 connect(item, SIGNAL(doubleClicked()), this, SLOT(accept()));
129 }
130
131 void
132 GuiUseCaseSelector::setSelection(QString selectedUseCase)
133 {
134 for (int i = 0; i < ui->verticalLayout_3->count(); ++i)
135 {
136 UseCaseSelectorItem* item =
137 qobject_cast<UseCaseSelectorItem*>(ui->verticalLayout_3->itemAt(i)->widget());
138 if (item)
139 {
140 if (item->getConfigFilePath() == selectedUseCase)
141 {
142 item->highlight(true);
143 }
144 else
145 {
146 item->highlight(false);
147 };
148 }
149 }
150 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
151 }
152
153} // namespace armarx
if(!yyvaluep)
Definition Grammar.cpp:645
The ArmarXMainWindow class.
void setCancelButtonText(QString text)
void setSelection(QString selectedUseCase)
QString getSelectedConfigFilePath() const
GuiUseCaseSelector(ArmarXMainWindow *mainWindow, bool doNotShowAgain=false, QWidget *parent=0)
void addDefaultConfig(QString configPath, QString packageName)
#define ARMARX_INFO_S
Definition Logging.h:202
#define ARMARX_VERBOSE_S
Definition Logging.h:207
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.