32 #include <boost/filesystem.hpp> 38 #include <QTreeWidget> 41 #include <QTextBrowser> 42 #include <QVBoxLayout> 43 #include <QDialogButtonBox> 44 #include <QPushButton> 52 const QString& object_type,
53 const QStringList& disallowed_display_names,
54 const QStringList& disallowed_class_lookup_names,
55 QString* lookup_name_output,
56 QString* display_name_output,
60 , disallowed_display_names_(disallowed_display_names)
61 , disallowed_class_lookup_names_(disallowed_class_lookup_names)
62 , lookup_name_output_(lookup_name_output)
63 , display_name_output_(display_name_output)
68 QGroupBox* type_box =
new QGroupBox(object_type +
" Type");
70 QTreeWidget*
tree =
new QTreeWidget;
71 tree->setHeaderHidden(
true);
74 QLabel* description_label =
new QLabel(
"Description:");
79 QVBoxLayout* type_layout =
new QVBoxLayout;
80 type_layout->addWidget(tree);
81 type_layout->addWidget(description_label);
84 type_box->setLayout(type_layout);
87 QGroupBox* name_box =
nullptr;
90 name_box =
new QGroupBox(object_type +
" Name");
92 QVBoxLayout* name_layout =
new QVBoxLayout;
94 name_box->setLayout(name_layout);
98 button_box_ =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
100 QVBoxLayout* main_layout =
new QVBoxLayout;
101 main_layout->addWidget(type_box);
104 main_layout->addWidget(name_box);
107 setLayout(main_layout);
110 connect(tree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
this,
112 connect(tree, SIGNAL(itemActivated(QTreeWidgetItem*,
int)),
this, SLOT(
accept()));
114 connect(
button_box_, SIGNAL(rejected()),
this, SLOT(reject()));
124 return (QSize(500, 660));
129 QIcon default_package_icon =
loadPixmap(
"package://rviz/icons/default_package_icon.png");
135 std::map<QString, QTreeWidgetItem*> package_items;
137 for (
int i = 0; i < classes.size(); i++)
139 QString lookup_name = classes[i];
140 QString
package = factory_->getClassPackage(lookup_name);
144 QTreeWidgetItem* package_item;
146 std::map<QString, QTreeWidgetItem*>::iterator mi;
147 mi = package_items.find(
package);
148 if (mi == package_items.end())
150 package_item =
new QTreeWidgetItem(tree);
151 package_item->setText(0,
package);
152 package_item->setIcon(0, default_package_icon);
154 package_item->setExpanded(
true);
155 package_items[
package] = package_item;
159 package_item = (*mi).second;
161 QTreeWidgetItem* class_item =
new QTreeWidgetItem(package_item);
165 class_item->setText(0, name);
166 class_item->setWhatsThis(0, description);
168 class_item->setData(0, Qt::UserRole, lookup_name);
175 QString html =
"<html><body>" + selected_item->whatsThis(0) +
"</body></html>";
179 QVariant user_data = selected_item->data(0, Qt::UserRole);
180 bool selection_is_valid = user_data.isValid();
181 if (selection_is_valid)
186 QString display_name = selected_item->text(0);
195 name += QString::number(counter);
225 if (display_name.size() == 0)
227 setError(
"Enter a name for the display.");
232 setError(
"Name in use. Display names must be unique.");
242 button_box_->button(QDialogButtonBox::Ok)->setToolTip(error_text);
QSize sizeHint() const override
NewObjectDialog(Factory *factory, const QString &object_type, const QStringList &disallowed_display_names, const QStringList &disallowed_class_lookup_names, QString *lookup_name_output, QString *display_name_output=nullptr, QWidget *parent=nullptr)
void onDisplaySelected(QTreeWidgetItem *selected_item)
virtual QString getClassName(const QString &class_id) const =0
QString * lookup_name_output_
const QStringList & disallowed_display_names_
QString * display_name_output_
QTextBrowser * description_
void setError(const QString &error_text)
virtual QString getClassDescription(const QString &class_id) const =0
const QStringList & disallowed_class_lookup_names_
Abstract superclass representing the ability to get a list of class IDs and the ability to get name...
QDialogButtonBox * button_box_
void fillTree(QTreeWidget *tree)
virtual QIcon getIcon(const QString &class_id) const =0
virtual QStringList getDeclaredClassIds()=0
QPixmap loadPixmap(QString url, bool fill_cache)