Skip to content

Commit

Permalink
customizer: modernizing the for loops (#2356)
Browse files Browse the repository at this point in the history
* modernizing the for loops

* making the adding the items to the Combobox more readable

* reusing the text string for the data

* changing to more meaningful variable names

* we do not need the dereference operator here
  • Loading branch information
MichaelPFrey authored and kintel committed Mar 29, 2018
1 parent 4bebe21 commit e7c0851
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
18 changes: 9 additions & 9 deletions src/parameter/ParameterWidget.cc
Expand Up @@ -252,22 +252,23 @@ void ParameterWidget::connectWidget()
}
}
cleanScrollArea();
for (std::vector<std::string>::iterator it = groupPos.begin(); it != groupPos.end(); it++) {
if(groupMap.find(*it)!=groupMap.end()){

for (const auto &groupName : groupPos) {
if(groupMap.find(groupName)!=groupMap.end()){
QVBoxLayout* anyLayout = new QVBoxLayout();
anyLayout->setSpacing(0);
anyLayout->setContentsMargins(0,0,0,0);

std::vector<std::string> gr;
gr = groupMap[*it].parameterVector;
gr = groupMap[groupName].parameterVector;
for(unsigned int i=0;i < gr.size();i++) {
ParameterVirtualWidget * entry = CreateParameterWidget(gr[i]);
if(entry){
anyLayout->addWidget(entry);
}
}

GroupWidget *groupWidget = new GroupWidget(groupMap[*it].show, QString::fromStdString(*it));
GroupWidget *groupWidget = new GroupWidget(groupMap[groupName].show, QString::fromStdString(groupName));
groupWidget->setContentLayout(*anyLayout);
this->scrollAreaWidgetContents->layout()->addWidget(groupWidget);
}
Expand All @@ -292,9 +293,9 @@ void ParameterWidget::rebuildGroupMap(){
it++;
}
}
for (group_map::iterator it = groupMap.begin(); it != groupMap.end(); it++){
it->second.parameterVector.clear();
it->second.inList=false;
for (auto &elem : groupMap) {
elem.second.parameterVector.clear();
elem.second.inList=false;
}

groupPos.clear();
Expand All @@ -307,8 +308,7 @@ void ParameterWidget::rebuildGroupMap(){
enter.show = false;
enter.inList=true;
groupMap[groupName] = enter;
}
else {
}else {
if(groupMap[groupName].inList == false){
groupMap[groupName].inList=true;
groupPos.push_back(groupName);
Expand Down
21 changes: 11 additions & 10 deletions src/parameter/parametercombobox.cpp
Expand Up @@ -55,19 +55,20 @@ void ParameterComboBox::setValue()
this->stackedWidgetRight->hide();
comboBox->clear();
const Value::VectorType& vec = object->values->toVector();
for (Value::VectorType::const_iterator it = vec.begin(); it != vec.end(); it++) {
if ((*it)->toVector().size() > 1) {
comboBox->addItem(QString::fromStdString((*it)->toVector()[1]->toString()),
QVariant(QString::fromStdString((*it)->toVector()[0]->toString())));
}
else {
comboBox->addItem(QString::fromStdString((*it)->toString()),
QVariant(QString::fromStdString((*it)->toString())));
for (const auto &textData : vec) {
QString text, data;
if (textData->toVector().size() > 1) {
text = QString::fromStdString(textData->toVector()[1]->toString());
data = QString::fromStdString(textData->toVector()[0]->toString());
} else {
text = QString::fromStdString(textData->toString());
data = text;

}
comboBox->addItem(text, QVariant(data));
}
QString defaultText = QString::fromStdString(object->value->toString());
int idx = comboBox->findData(QVariant(defaultText));
QString defaultData = QString::fromStdString(object->value->toString());
int idx = comboBox->findData(QVariant(defaultData));
if (idx >= 0) {
comboBox->setCurrentIndex(idx);
}
Expand Down

0 comments on commit e7c0851

Please sign in to comment.