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 #include "UseCaseSelectorItem.h"
26 #include <QPushButton>
28 #include <ArmarXGui/applications/ArmarXGui/ui_GuiUseCaseSelector.h>
29 #include <filesystem>
30 namespace armarx
31 {
32 
33  GuiUseCaseSelector::GuiUseCaseSelector(ArmarXMainWindow* mainWindow, bool doNotShowAgain, QWidget* parent) :
34  QDialog(parent),
35  ui(new Ui::GuiUseCaseSelector)
36  {
37  ui->setupUi(this);
38  ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Open selected use case");
39  ui->buttonBox->button(QDialogButtonBox::Ok)->setToolTip("Opens the selected use case and loads the associated preconfigured widgets.");
40  ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("Open empty GUI");
41  ui->buttonBox->button(QDialogButtonBox::Cancel)->setToolTip("Opens an empty gui.");
42  for (auto& p : mainWindow->getDefaultPackageNames())
43  {
44  CMakePackageFinder f(p);
45  if (!f.packageFound())
46  {
47  continue;
48  }
49  std::filesystem::path path = f.getDataDir();
50  path /= p;
51  path /= "GuiDefaultConfigs";
52  if (!std::filesystem::exists(path))
53  {
54  continue;
55  }
56  int i = 1;
57  for (std::filesystem::recursive_directory_iterator end, dir(path);
58  dir != end ; ++dir, i++)
59  {
60  if (dir->path().extension() == ".armarxgui")
61  {
62  addDefaultConfig(dir->path().string().c_str(), p.c_str());
63  }
64 
65  if (i % 100 == 0)
66  {
67  ARMARX_INFO_S << "Scanning file " << i << ": " << dir->path().c_str();
68  }
69  }
70  }
71  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
72  ui->checkBoxDoNotShowAgain->setChecked(doNotShowAgain);
73  }
74 
76  {
77  delete ui;
78  }
79 
81  {
82  for (int i = 0; i < ui->verticalLayout_3->count(); ++i)
83  {
84  UseCaseSelectorItem* item = qobject_cast<UseCaseSelectorItem*>(ui->verticalLayout_3->itemAt(i)->widget());
85  if (item && item->isHighlighted())
86  {
87  return item->getConfigFilePath();
88  }
89  }
90  return "";
91  }
92 
94  {
95  return ui->checkBoxDoNotShowAgain->isChecked();
96  }
97 
99  {
100  ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
101  }
102 
103  void GuiUseCaseSelector::addDefaultConfig(QString configPath, QString packageName)
104  {
105  ARMARX_VERBOSE_S << "Adding " << configPath;
106  QSettings s(configPath, QSettings::IniFormat);
107  UseCaseSelectorItem* item = new UseCaseSelectorItem(s.value("ConfigTitle").toString(),
108  s.value("ConfigDescription").toString(),
109  configPath,
110  packageName,
111  s.value("IconPath").toString(),
112  this);
113  ui->verticalLayout_3->addWidget(item);
114  connect(item, SIGNAL(selected(QString)), this, SLOT(setSelection(QString)));
115  connect(item, SIGNAL(doubleClicked()), this, SLOT(accept()));
116  }
117 
118  void GuiUseCaseSelector::setSelection(QString selectedUseCase)
119  {
120  for (int i = 0; i < ui->verticalLayout_3->count(); ++i)
121  {
122  UseCaseSelectorItem* item = qobject_cast<UseCaseSelectorItem*>(ui->verticalLayout_3->itemAt(i)->widget());
123  if (item)
124  {
125  if (item->getConfigFilePath() == selectedUseCase)
126  {
127  item->highlight(true);
128  }
129  else
130  {
131  item->highlight(false);
132  };
133  }
134  }
135  ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
136 
137  }
138 
139 } // namespace armarx
armarx::UseCaseSelectorItem::isHighlighted
bool isHighlighted() const
Definition: UseCaseSelectorItem.cpp:93
armarx::GuiUseCaseSelector::~GuiUseCaseSelector
~GuiUseCaseSelector() override
Definition: GuiUseCaseSelector.cpp:75
armarx::CMakePackageFinder::packageFound
bool packageFound() const
Returns whether or not this package was found with cmake.
Definition: CMakePackageFinder.cpp:485
UseCaseSelectorItem.h
armarx::UseCaseSelectorItem::getConfigFilePath
QString getConfigFilePath() const
Definition: UseCaseSelectorItem.cpp:88
armarx::GuiUseCaseSelector::getSelectedConfigFilePath
QString getSelectedConfigFilePath() const
Definition: GuiUseCaseSelector.cpp:80
armarx::ArmarXMainWindow
The ArmarXMainWindow class.
Definition: ArmarXMainWindow.h:76
armarx::CMakePackageFinder
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
Definition: CMakePackageFinder.h:53
armarx::UseCaseSelectorItem
Definition: UseCaseSelectorItem.h:35
armarx::GuiUseCaseSelector::setSelection
void setSelection(QString selectedUseCase)
Definition: GuiUseCaseSelector.cpp:118
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
ArmarXMainWindow.h
GuiUseCaseSelector.h
armarx::CMakePackageFinder::getDataDir
std::string getDataDir() const
Definition: CMakePackageFinder.h:176
armarx::ArmarXMainWindow::getDefaultPackageNames
std::vector< std::string > getDefaultPackageNames()
getDefaultPackageNames returns the names of all packages which are searched for plugins when the Arma...
Definition: ArmarXMainWindow.cpp:623
armarx::GuiUseCaseSelector::GuiUseCaseSelector
GuiUseCaseSelector(ArmarXMainWindow *mainWindow, bool doNotShowAgain=false, QWidget *parent=0)
Definition: GuiUseCaseSelector.cpp:33
armarx::UseCaseSelectorItem::highlight
void highlight(bool highlight)
Definition: UseCaseSelectorItem.cpp:98
armarx::GuiUseCaseSelector::setCancelButtonText
void setCancelButtonText(QString text)
Definition: GuiUseCaseSelector.cpp:98
ARMARX_VERBOSE_S
#define ARMARX_VERBOSE_S
Definition: Logging.h:200
armarx::GuiUseCaseSelector::addDefaultConfig
void addDefaultConfig(QString configPath, QString packageName)
Definition: GuiUseCaseSelector.cpp:103
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
armarx::GuiUseCaseSelector
Definition: GuiUseCaseSelector.h:40
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::GuiUseCaseSelector::getDoNotShowAgain
bool getDoNotShowAgain() const
Definition: GuiUseCaseSelector.cpp:93
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28