23 #include <mars/utils/misc.h> 25 #include <QVBoxLayout> 27 #include <QPushButton> 34 namespace config_map_gui {
37 DataWidget::DataWidget(
void* backwardCFG, QWidget *parent,
bool onlyCompactView,
40 pDialog(new main_gui::PropertyDialog(parent)),
46 QVBoxLayout *vLayout =
new QVBoxLayout();
48 vLayout->setContentsMargins(0,0,0,0);
50 QHBoxLayout *hLayout =
new QHBoxLayout();
51 QLabel *label =
new QLabel(
"type:");
56 hLayout->addWidget(label);
58 vLayout->addLayout(hLayout);
59 hLayout =
new QHBoxLayout();
64 QPushButton *button =
new QPushButton(
"add");
65 connect(button, SIGNAL(clicked()),
this, SLOT(
addKey2()));
66 hLayout->addWidget(button);
67 hLayout->setSpacing(4);
68 vLayout->addLayout(hLayout);
70 vLayout->setSpacing(0);
100 const std::vector<std::vector<std::string> > &values) {
125 std::string n = name;
126 for(
size_t i=0; i<n.size(); ++i) {
128 n.insert(n.begin()+i,
'/');
133 std::string path =
"..";
144 QtVariantProperty *guiElem;
147 c.setRgbF(map[
"r"],map[
"g"], map[
"b"], map[
"a"]);
164 QtVariantPropertyManager::groupTypeId(),
168 for(;it!=map.end(); ++it) {
169 std::string n = it->first;
174 for(
size_t i=0; i<n.size(); ++i) {
176 n.insert(n.begin()+i,
'/');
181 if(it->second.isVector()) {
184 else if(it->second.isMap()) {
187 else if(it->second.isAtom()) {
198 QtVariantProperty *guiElem;
207 QtVariantPropertyManager::groupTypeId(),
211 for(
unsigned long i=0; i<(
unsigned long)v.size(); ++i) {
214 sprintf(iText,
"/%d", (
int)i);
220 QtVariantPropertyManager::groupTypeId(),
227 const std::vector<std::string> &pattern) {
228 std::vector<std::string>::const_iterator it = pattern.begin();
230 for(; it!=pattern.end(); ++it, ++i) {
241 QtVariantProperty *guiElem;
242 std::map<QString, QVariant> attr;
245 bool editable =
true;
250 int type = QVariant::String;
252 type = VariantManager::filePathTypeId();
253 attr[
"directory"] =
".";
258 QStringList enumNames;
262 for(std::vector<std::string>::iterator it=
dropDownValues[index].begin();
264 enumNames << it->c_str();
270 QtVariantPropertyManager::enumTypeId(),
271 index2, NULL, &enumNames);
280 int type = QVariant::String;
282 type = VariantManager::filePathTypeId();
283 attr[
"directory"] =
".";
288 QStringList enumNames;
292 for(std::vector<std::string>::iterator it=
dropDownValues[index].begin();
294 enumNames << it->c_str();
300 QtVariantPropertyManager::enumTypeId(),
301 index2, NULL, &enumNames);
322 attr[
"singleStep"] = 0.01;
323 attr[
"decimals"] = 7;
341 guiElem->setEnabled(editable);
352 std::string path =
"..";
353 std::string n = name;
354 for(
size_t i=0; i<n.size(); ++i) {
356 n.insert(n.begin()+i,
'/');
371 std::map<std::string, QtVariantProperty*>::iterator it =
propMap.find(name);
376 c.setRgbF(map[
"r"],map[
"g"], map[
"b"], map[
"a"]);
377 it->second->setValue(c);
382 for(
size_t i=2; i<arrPath.size(); ++i) {
384 item = ((*item)[arrPath[i]]);
387 item = ((*item)[atoi(arrPath[i].c_str())]);
390 fprintf(stderr,
"ERROR: update configmap widget structure error!");
401 for(;it!=map.end(); ++it) {
403 for(
size_t i=0; i<n.size(); ++i) {
405 n.insert(n.begin()+i,
'/');
410 if(it->second.isAtom()) {
413 else if(it->second.isVector()) {
416 else if(it->second.isMap()) {
425 for(
unsigned long i=0; i<(
unsigned long)v.size(); ++i) {
428 sprintf(iText,
"/%d", (
int)i);
439 QtVariantProperty *guiElem;
449 guiElem->setValue(QVariant(QString::fromStdString(atom.
getString())));
452 guiElem->setValue(QVariant(atom.
getInt()));
455 guiElem->setValue(QVariant(atom.
getUInt()));
458 guiElem->setValue(QVariant(atom.
getDouble()));
461 guiElem->setValue(QVariant((
int)atom.
getULong()));
464 guiElem->setValue(QVariant(atom.
getBool()));
470 for(
size_t i=2; i<arrPath.size(); ++i) {
472 item = ((*item)[arrPath[i]]);
475 item = ((*item)[atoi(arrPath[i].c_str())]);
478 fprintf(stderr,
"ERROR: update configmap widget structure error!");
488 map<QtVariantProperty*, ConfigAtom*>::iterator it;
489 map<QtVariantProperty*, ConfigMap*>::iterator it2;
521 QtVariantProperty *vp =
dynamic_cast<QtVariantProperty*
>(property);
522 if(vp->valueType() == QVariant::Color) {
523 map<QtVariantProperty*, ConfigMap*>::iterator it;
526 QColor c = value.value<QColor>();
527 (*(it->second))[
"r"] = c.redF();
528 (*(it->second))[
"g"] = c.greenF();
529 (*(it->second))[
"b"] = c.blueF();
530 (*(it->second))[
"a"] = c.alphaF();
534 emit
valueChanged(n+
"/r", (*(it->second))[
"r"].toString());
535 emit
valueChanged(n+
"/g", (*(it->second))[
"g"].toString());
536 emit
valueChanged(n+
"/b", (*(it->second))[
"b"].toString());
537 emit
valueChanged(n+
"/a", (*(it->second))[
"a"].toString());
540 else if(vp->propertyType() == QtVariantPropertyManager::enumTypeId()) {
541 map<QtVariantProperty*, ConfigAtom*>::iterator it;
542 it =
dataMap.find((QtVariantProperty*)property);
546 it->second->setUnparsedString(property->valueText().toStdString());
549 it->second->setString(property->valueText().toStdString());
552 it->second->toString());
556 map<QtVariantProperty*, ConfigAtom*>::iterator it;
557 it =
dataMap.find((QtVariantProperty*)property);
561 it->second->setUnparsedString(value.toString().toStdString());
564 it->second->setString(value.toString().toStdString());
567 it->second->setInt(value.toInt());
570 it->second->setUInt(value.toUInt());
573 it->second->setDouble(value.toDouble());
576 it->second->setULong(value.toULongLong());
579 it->second->setBool(value.toBool());
582 it->second->toString());
585 map<QtVariantProperty*, std::string>::iterator it;
586 it =
checkMap.find((QtVariantProperty*)property);
622 std::string key =
keyEdit->text().toStdString();
623 std::string value =
valueEdit->text().toStdString();
624 QtVariantProperty *prop =
dynamic_cast<QtVariantProperty*
>(
pDialog->
activeItem());
628 map<QtVariantProperty*, ConfigMap*>::iterator it;
635 fprintf(stderr,
"use global config\n");
642 if(
typeBox->currentIndex() == 0) {
645 else if(
typeBox->currentIndex() == 1) {
659 map<QtVariantProperty*, ConfigVector*>::iterator it;
662 if(
typeBox->currentIndex() == 0) {
665 else if(
typeBox->currentIndex() == 1) {
671 sprintf(da,
"/%d", (
int)it->second->size()-1);
687 map<QtVariantProperty*, std::string>::iterator it =
checkMap.begin();
689 if(it->second == name) {
690 it->first->setValue(QVariant(value));
void setViewButtonVisibility(bool visible)
Sets the visibility of the view button.
void setPropCallback(PropertyCallback *pc)
Sets the callback object.
void removeGenericProperty(QtVariantProperty *property)
Removes the property.
Base object of the configmaps library!
std::list< FIFOItem< std::string, ConfigItem > >::iterator iterator
void clearButtonBox(void)
Removes all buttons from the button box.
std::list< FIFOItem< std::string, ConfigItem > >::const_iterator const_iterator
void setButtonBoxVisibility(bool visible)
Sets the visibility of the button box.
std::string getUnparsedString() const
bool hasKey(std::string key)
Copyright 2012, DFKI GmbH Robotics Innovation Center.
bool matchPattern(const std::string &pattern, const std::string &str)
basic pattern matching function
void expandTree(QtProperty *item)
Expands the branch of the property item.
void setViewMode(const ViewMode &mode)
Sets the view mode to either tree or button view mode.
QtProperty * activeItem(void)
Returns the item that is currently focused on.
std::vector< std::string > explodeString(const char c, const std::string &s)
QtVariantProperty * addGenericProperty(const std::string &path, int type, const QVariant &value, std::map< QString, QVariant > *attributes=NULL, QStringList *options=NULL)
Creates a property.