[20] | 1 | #include "window.h" |
---|
| 2 | |
---|
| 3 | using namespace std; |
---|
| 4 | |
---|
| 5 | using namespace morpheo::tools::viewer::parser; |
---|
| 6 | using namespace morpheo::tools::viewer::bdd; |
---|
| 7 | using namespace morpheo::tools::viewer::graphics; |
---|
| 8 | |
---|
[32] | 9 | /*parameters window constructor*/ |
---|
[20] | 10 | void Window::wparameters() |
---|
| 11 | { |
---|
[32] | 12 | wparam = new QMainWindow(); |
---|
| 13 | // wparam = new QWidget(); |
---|
[21] | 14 | parameters = new QBoxLayout(QBoxLayout::TopToBottom,0); |
---|
[20] | 15 | wparam->setWindowTitle("parameters"); |
---|
[32] | 16 | wparam->setFixedSize(370,415); |
---|
| 17 | wparam->move(628,255); |
---|
| 18 | wparam->setLayout(parameters); |
---|
| 19 | sc = new QScrollArea(wparam); |
---|
| 20 | wscroll = new QWidget(); |
---|
| 21 | sc->setWidgetResizable(false); |
---|
| 22 | sc->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
---|
| 23 | sc->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
---|
| 24 | sc->setGeometry(2,2,365,410); |
---|
| 25 | wparam->show(); |
---|
| 26 | } |
---|
[21] | 27 | |
---|
[32] | 28 | /*display the parameters*/ |
---|
| 29 | void Window::display_param(){ |
---|
| 30 | |
---|
| 31 | pbox = new QBoxLayout(QBoxLayout::TopToBottom,0); |
---|
| 32 | |
---|
| 33 | string scpu; |
---|
| 34 | string lgroup; |
---|
| 35 | string sparam; |
---|
| 36 | string ecart; |
---|
[21] | 37 | |
---|
[32] | 38 | if(!apply_display){ |
---|
| 39 | QPushButton *apply = new QPushButton("apply",wparam); |
---|
| 40 | connect(apply,SIGNAL(clicked()),this,SLOT(_apply())); |
---|
| 41 | apply->setFixedSize(310,25); |
---|
| 42 | pbox->addWidget(apply); |
---|
| 43 | apply_display = true; |
---|
| 44 | } |
---|
[26] | 45 | |
---|
[32] | 46 | /*top level name display*/ |
---|
| 47 | QLabel *cpu = new QLabel(); |
---|
| 48 | scpu.append("CPU : "); |
---|
| 49 | scpu.append(parse->getTopLevelName()); |
---|
| 50 | scpu.append(" \n"); |
---|
| 51 | cpu ->setText(QString::fromStdString(scpu)); |
---|
[33] | 52 | cpu->setFixedSize(350,50); |
---|
[32] | 53 | pbox->addWidget(cpu); |
---|
| 54 | |
---|
| 55 | /*architecture in tree view display*/ |
---|
| 56 | group = base->getGroups(); |
---|
| 57 | for(QList<Group>::iterator it=group->begin();it!=group->end();++it){ |
---|
| 58 | QLabel *lg = new QLabel(); |
---|
| 59 | lgroup = ""; |
---|
| 60 | lg->setFixedSize(200,30); |
---|
| 61 | ecart = ""; |
---|
| 62 | if(it->getLevel() == 1) |
---|
| 63 | ecart.append(" "); |
---|
| 64 | if(it->getLevel() == 2) |
---|
| 65 | ecart.append(" "); |
---|
| 66 | if(it->getLevel() == 3) |
---|
| 67 | ecart.append(" "); |
---|
| 68 | if(it->getLevel() == 4) |
---|
| 69 | ecart.append(" "); |
---|
| 70 | if(it->getLevel() == 5) |
---|
| 71 | ecart.append(" "); |
---|
| 72 | lgroup.append(ecart); |
---|
| 73 | lgroup.append("<"); |
---|
| 74 | lgroup.append(it->getName()); |
---|
| 75 | lgroup.append(">"); |
---|
| 76 | lg->setText(QString::fromStdString(lgroup)); |
---|
| 77 | pbox->addWidget(lg); |
---|
| 78 | param = it->getParam(); |
---|
| 79 | for(QList<Param>::iterator it2=param.begin();it2!=param.end();++it2){ |
---|
[21] | 80 | |
---|
[32] | 81 | if(it2->getName() == "id"){ |
---|
| 82 | QBoxLayout *b = new QBoxLayout(QBoxLayout::LeftToRight,0); |
---|
| 83 | QLabel *l = new QLabel(); |
---|
| 84 | QString st2 = " "; |
---|
| 85 | QString st; |
---|
| 86 | st2.append(QString::fromStdString(ecart)); |
---|
| 87 | st2.append("nb_"); |
---|
| 88 | st2.append(QString::fromStdString(it->getName())); |
---|
| 89 | |
---|
| 90 | st.append("nb_"); |
---|
| 91 | st.append(QString::fromStdString(it->getName())); |
---|
| 92 | LimitParam lp = base->searchLimitParam(st.toStdString()); |
---|
| 93 | |
---|
| 94 | QLabel *lab = new QLabel(); |
---|
| 95 | QString s = " "; |
---|
| 96 | s.append(QString::fromStdString(ecart)); |
---|
| 97 | s.append(QString::fromStdString(it2->getName())); |
---|
| 98 | s.append(" : "); |
---|
| 99 | stringstream out; |
---|
| 100 | string str; |
---|
| 101 | out << it2->getValue(); |
---|
| 102 | str = out.str(); |
---|
| 103 | s.append(QString::fromStdString(str)); |
---|
| 104 | lab->setText(s); |
---|
| 105 | pbox->addWidget(lab); |
---|
| 106 | l->setText(st2); |
---|
| 107 | QSpinBox *spin = new QSpinBox(); |
---|
| 108 | int min = lp.getMin(); |
---|
| 109 | int max = lp.getMax(); |
---|
| 110 | QString step = QString::fromStdString(lp.getStep()); |
---|
| 111 | |
---|
| 112 | spin->setValue(base->nbGroup(it->getName())); |
---|
| 113 | |
---|
| 114 | if(step.contains("+")){ |
---|
| 115 | step = step.right(step.length()-1); |
---|
| 116 | int pas = step.toInt(0,10); |
---|
| 117 | spin->setMinimum(min); |
---|
| 118 | spin->setMaximum(max); |
---|
| 119 | spin->setSingleStep(pas); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | if(step.contains("*")){ |
---|
| 123 | step = step.right(step.length()-1); |
---|
| 124 | int pas = step.toInt(0,10); |
---|
| 125 | spin->setMinimum(min); |
---|
| 126 | spin->setMaximum(max); |
---|
| 127 | spin->setSingleStep(pas); |
---|
| 128 | } |
---|
| 129 | spin->setFixedSize(60,30); |
---|
| 130 | |
---|
| 131 | QString name_obj = (QString::fromStdString(it->getName())); |
---|
| 132 | spin->setObjectName(name_obj); |
---|
| 133 | |
---|
| 134 | b->addWidget(l); |
---|
| 135 | b->addWidget(spin); |
---|
| 136 | pbox->addLayout(b); |
---|
| 137 | |
---|
| 138 | connect(spin,SIGNAL(valueChanged(int)),this,SLOT(valueChanged(int))); |
---|
| 139 | |
---|
| 140 | } |
---|
| 141 | else{ |
---|
| 142 | QBoxLayout *b = new QBoxLayout(QBoxLayout::LeftToRight,0); |
---|
| 143 | QLabel *l = new QLabel(); |
---|
| 144 | sparam =" "; |
---|
| 145 | sparam.append(ecart); |
---|
| 146 | sparam.append(it2->getName()); |
---|
| 147 | sparam.append(" : "); |
---|
| 148 | stringstream out; |
---|
| 149 | string str; |
---|
| 150 | out << it2->getValue(); |
---|
| 151 | str = out.str(); |
---|
| 152 | sparam.append(str); |
---|
| 153 | l->setText(QString::fromStdString(sparam)); |
---|
| 154 | l->setFixedSize(200,30); |
---|
| 155 | parameters->addWidget(l); |
---|
| 156 | QComboBox *cb = new QComboBox(); |
---|
| 157 | LimitParam lp = base->searchLimitParam(it2->getName()); |
---|
| 158 | int min = lp.getMin(); |
---|
| 159 | int max = lp.getMax(); |
---|
| 160 | QString step = QString::fromStdString(lp.getStep()); |
---|
| 161 | int value = min; |
---|
| 162 | if(step.contains("+")){ |
---|
| 163 | step = step.right(step.length()-1); |
---|
| 164 | int pas = step.toInt(0,10); |
---|
| 165 | while(value!=max+pas){ |
---|
| 166 | stringstream out2; |
---|
| 167 | string str2; |
---|
| 168 | out2 << value; |
---|
| 169 | str2 = out2.str(); |
---|
| 170 | cb->addItem(QString::fromStdString(str2)); |
---|
| 171 | value = value+pas; |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | if(step.contains("*")){ |
---|
| 175 | step = step.right(step.length()-1); |
---|
| 176 | int pas = step.toInt(0,10); |
---|
| 177 | while(value!=max*pas){ |
---|
| 178 | stringstream out2; |
---|
| 179 | string str2; |
---|
| 180 | out2 << value; |
---|
| 181 | str2 = out2.str(); |
---|
| 182 | cb->addItem(QString::fromStdString(str2)); |
---|
| 183 | value = value*pas; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | stringstream out3; |
---|
| 187 | string str3; |
---|
| 188 | out3 << it2->getValue(); |
---|
| 189 | str3 = out3.str(); |
---|
| 190 | int index = cb->findText(QString::fromStdString(str3)); |
---|
| 191 | cb->setCurrentIndex(index); |
---|
| 192 | cb->setFixedSize(60,30); |
---|
| 193 | //QPushButton *pb = new QPushButton(); |
---|
| 194 | //pb->setText("change"); |
---|
| 195 | QString name_obj = (QString::fromStdString(it->getName())); |
---|
| 196 | name_obj.append(":"); |
---|
| 197 | name_obj.append( QString::fromStdString(it2->getName())); |
---|
| 198 | name_obj.append(":"); |
---|
| 199 | name_obj.append(cb->currentText()); |
---|
| 200 | cb->setObjectName(name_obj); |
---|
| 201 | //cb->setFixedSize(60,30); |
---|
| 202 | QString new_value = cb->currentText(); |
---|
| 203 | connect(cb,SIGNAL(currentIndexChanged(QString)),this,SLOT(currentIndexChanged(QString))); |
---|
| 204 | //connect(pb,SIGNAL(clicked()),this,SLOT(_change_value())); |
---|
| 205 | b->addWidget(l); |
---|
| 206 | b->addWidget(cb); |
---|
| 207 | //b->addWidget(pb); |
---|
| 208 | pbox->addLayout(b); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | wscroll->setLayout(pbox); |
---|
| 214 | parameters->addWidget(wscroll); |
---|
| 215 | sc->setWidget(wscroll); |
---|
| 216 | if(scroll_hide){ |
---|
| 217 | scroll_hide = false; |
---|
| 218 | wscroll->show(); |
---|
| 219 | } |
---|
[20] | 220 | } |
---|
| 221 | |
---|
[32] | 222 | void Window::currentIndexChanged(QString value2){ |
---|
| 223 | //cout << QObject::sender()->objectName().toStdString() << endl; |
---|
| 224 | |
---|
| 225 | QString obj = QObject::sender()->objectName(); |
---|
| 226 | |
---|
| 227 | int i,j,v; |
---|
| 228 | QString param,group,value; |
---|
| 229 | i = obj.indexOf(":"); |
---|
| 230 | group = obj.left(i); |
---|
| 231 | //cout << "group : " << group.toStdString() << endl; |
---|
| 232 | j = obj.indexOf(":",i+1); |
---|
| 233 | value = obj.right(obj.size() - j - 1); |
---|
| 234 | v = value2.toInt(0,10); |
---|
| 235 | cout << "value : " << v << endl; |
---|
| 236 | param = obj.section(":",1,1); |
---|
[33] | 237 | cout << "param : " << param.toStdString() << endl; |
---|
[20] | 238 | |
---|
[32] | 239 | base->modifyValue(group.toStdString(),param.toStdString(),v); |
---|
| 240 | wparam->close(); |
---|
| 241 | apply_display = false; |
---|
| 242 | wparameters(); |
---|
| 243 | display_param(); |
---|
| 244 | parameter_modify = true; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | void Window::valueChanged(int i){ |
---|
| 249 | |
---|
| 250 | //cout << QObject::sender()->objectName().toStdString() << endl; |
---|
| 251 | |
---|
| 252 | QString obj = QObject::sender()->objectName(); |
---|
| 253 | int v,j; |
---|
[33] | 254 | cout << "name : " << obj.toStdString() << endl; |
---|
[32] | 255 | v = i; |
---|
| 256 | //cout << "value : " << v << endl; |
---|
| 257 | |
---|
| 258 | j = base->nbGroup(obj.toStdString()); |
---|
| 259 | v = v - j; |
---|
| 260 | cout << "value : " << v << " " << j<< endl; |
---|
| 261 | if(base->modifyGroup(obj.toStdString(),v)==-1){ |
---|
| 262 | cout << "error" << endl; |
---|
| 263 | exit(1); |
---|
| 264 | } |
---|
[33] | 265 | |
---|
[32] | 266 | wparam->close(); |
---|
| 267 | apply_display = false; |
---|
| 268 | wparameters(); |
---|
| 269 | parameter_modify = true; |
---|
| 270 | display_param(); |
---|
| 271 | // base->afficheParamConsole(); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | /*apply the parameters changes*/ |
---|
[26] | 275 | void Window::_apply(){ |
---|
[32] | 276 | if(!parameter_modify){ |
---|
| 277 | QMessageBox *m = new QMessageBox(wparam); |
---|
| 278 | m->setText("no parameter changed"); |
---|
| 279 | m->addButton("ok",QMessageBox::YesRole); |
---|
| 280 | m->show(); |
---|
| 281 | } |
---|
| 282 | else{ |
---|
| 283 | parameter_modify = false; |
---|
| 284 | cout << "apply\n"; |
---|
| 285 | } |
---|
[26] | 286 | } |
---|