00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 enum ParEditColumns { fiColName=0, fiColType=1, fiColValue=2, fiColComment=3 };
00025
00026 void TGo4ParaEdit::init()
00027 {
00028 fItems = 0;
00029 PleaseUpdateLabel->setShown(false);
00030 adjustSize();
00031
00032 ParamNameLbl->setText("");
00033 ParamClassLbl->setText("");
00034
00035 fItemName = "";
00036 }
00037
00038 void TGo4ParaEdit::destroy()
00039 {
00040 if (fItems!=0) {
00041 delete fItems;
00042 fItems = 0;
00043 }
00044 }
00045
00046 bool TGo4ParaEdit::IsAcceptDrag(const char* itemname, TClass* cl, int kind)
00047 {
00048 if (kind==TGo4Access::kndGo4Param) return true;
00049
00050 return (cl==0) ? false : cl->InheritsFrom(TGo4Parameter::Class());
00051 }
00052
00053 void TGo4ParaEdit::DropItem(const char* itemname, TClass* cl, int kind)
00054 {
00055 if ((kind==TGo4Access::kndGo4Param) ||
00056 ((cl!=0) && cl->InheritsFrom(TGo4Parameter::Class())))
00057 WorkWithParameter(itemname, false);
00058 }
00059
00060 void TGo4ParaEdit::linkedObjectUpdated(const char* linkname, TObject* obj)
00061 {
00062
00063
00064 if (strcmp(linkname,"Parameter")==0)
00065 RefreshWidget(dynamic_cast<TGo4Parameter*> (obj));
00066 else
00067 if (strcmp(linkname,"ParStatus")==0)
00068 RefreshWidget(dynamic_cast<TGo4ParameterStatus*> (obj));
00069
00070
00071 }
00072
00073 void TGo4ParaEdit::linkedObjectRemoved( const char * linkname )
00074 {
00075
00076
00077
00078
00079 if (strcmp(linkname,"Fitter")!=0)
00080 ShootCloseWidget();
00081
00082
00083 }
00084
00085 void TGo4ParaEdit::WorkWithParameter(const char* itemname, bool isrefresh)
00086 {
00087
00088
00089 if (PleaseUpdateLabel->isShown() && !isrefresh) {
00090 TGo4Parameter* par = dynamic_cast<TGo4Parameter*> (GetLinked("Parameter",0));
00091 const char* previtem = GetLinkedName("Parameter");
00092 if ((par!=0) && (previtem!=0)) {
00093 int res = QMessageBox::warning(this, "Parameter editor",
00094 QString("Current parameter ")+previtem+" is modified!\n"+
00095 "New parameter " + itemname + " is selected.",
00096 QString("Continue with current"),
00097 QString("Start with new"), QString::null, 0);
00098
00099 if (res==0) return;
00100
00101 }
00102 }
00103
00104
00105
00106 ResetWidget();
00107
00108
00109
00110
00111 ParamNameLbl->setText(itemname);
00112
00113 fItemName = itemname;
00114
00115 QString iconname = "right.png";
00116 QString tooltip = "Refresh parameter values from analysis";
00117
00118 if (BrowserItemRemote(itemname)) {
00119 TGo4Slot* tgtslot = AddSlot("ParStatus");
00120 TGo4BrowserProxy* br = Browser();
00121 if (br!=0)
00122 br->RequestObjectStatus(itemname, tgtslot);
00123
00124 AddLink(itemname, "ParameterLock");
00125 } else {
00126 iconname = "refresh.png";
00127 tooltip = "Refresh parameter values from source";
00128 AddLink(itemname, "Parameter");
00129 TGo4Parameter* par = dynamic_cast<TGo4Parameter*> (GetLinked("Parameter",2));
00130 if (par!=0) RefreshWidget(par);
00131 }
00132
00133 RefreshButton->setIconSet( QIconSet( QPixmap::fromMimeSource(iconname) ) );
00134 QToolTip::remove(RefreshButton);
00135 QToolTip::add(RefreshButton, tooltip);
00136
00137 setFocus();
00138
00139
00140
00141 }
00142
00143 void TGo4ParaEdit::ResetWidget()
00144 {
00145 QGo4Widget::ResetWidget();
00146
00147 ParamNameLbl->setText("");
00148 ParamClassLbl->setText("");
00149
00150 fItemName="";
00151
00152 RefreshButton->setEnabled(FALSE);
00153 ApplyButton->setEnabled(FALSE);
00154
00155 delete fItems;
00156 fItems = 0;
00157
00158 ShowVisibleItems();
00159
00160 PleaseUpdateLabel->setShown(false);
00161 }
00162
00163 void TGo4ParaEdit::RefreshWidget(TGo4Parameter* par)
00164 {
00165 RefreshButton->setEnabled(par!=0);
00166 ApplyButton->setEnabled(par!=0);
00167
00168 delete fItems;
00169 fItems = new TObjArray(100);
00170 fItems->SetOwner(kTRUE);
00171
00172 if (par!=0) {
00173 par->GetMemberValues(fItems);
00174 ParamClassLbl->setText(QString(" - ")+par->ClassName());
00175 }
00176
00177 ShowVisibleItems();
00178
00179 PleaseUpdateLabel->setShown(false);
00180 }
00181
00182
00183 void TGo4ParaEdit::RefreshWidget(TGo4ParameterStatus* status)
00184 {
00185
00186
00187 RefreshButton->setEnabled(status!=0);
00188 ApplyButton->setEnabled(status!=0);
00189
00190
00191
00192 delete fItems;
00193 fItems = 0;
00194
00195
00196
00197 if (status!=0) {
00198 fItems = status->GetMemberValues(kTRUE);
00199 ParamClassLbl->setText(QString(" - ") + status->GetObjectClass());
00200 }
00201
00202 ShowVisibleItems();
00203
00204 PleaseUpdateLabel->setShown(false);
00205
00206
00207 }
00208
00209 void TGo4ParaEdit::ShowVisibleItems()
00210 {
00211 if (fItems==0) {
00212 MemberTable->setNumRows(0);
00213 return;
00214 }
00215
00216 MemberTable->hide();
00217
00218 MemberTable->horizontalHeader()->setLabel(fiColType,"Type");
00219 MemberTable->horizontalHeader()->setLabel(fiColName,"Name");
00220 MemberTable->horizontalHeader()->setLabel(fiColValue,"Value");
00221 MemberTable->horizontalHeader()->setLabel(fiColComment,"Comments");
00222
00223 int memnum = fItems->GetLast()+1;
00224 MemberTable->setNumRows(memnum);
00225 MemberTable->setColumnReadOnly(fiColType,true);
00226 MemberTable->setColumnReadOnly(fiColName,true);
00227 MemberTable->setColumnReadOnly(fiColComment,true);
00228 MemberTable->setLeftMargin(0);
00229 MemberTable->verticalHeader()->hide();
00230 TString buf;
00231 for(int row=0; row<memnum; row++) {
00232 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(row);
00233 MemberTable->setText(row, fiColType, info->GetTypeName());
00234 MemberTable->setText(row, fiColName, info->GetFullName(buf));
00235
00236 MemberTable->setText(row, fiColValue, info->GetStrValue());
00237 MemberTable->setText(row,fiColComment, info->GetTitle());
00238
00239 QTableItem* item=MemberTable->item(row, fiColValue);
00240 if(item!=0) item->setEnabled(info->CanStrEdit());
00241
00242 if(info->IsVisible())
00243 MemberTable->showRow(row);
00244 else
00245 MemberTable->hideRow(row);
00246 }
00247
00248 MemberTable->show();
00249 polish();
00250 update();
00251 show();
00252 raise();
00253 MemberTable->show();
00254 }
00255
00256 void TGo4ParaEdit::clearTextFields()
00257 {
00258 if (fItems==0) return;
00259
00260 for(int n=0;n<=fItems->GetLast();n++) {
00261 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(n);
00262 info->SetStrValue("");
00263 }
00264
00265 PleaseUpdateLabel->setShown(true);
00266
00267 ShowVisibleItems();
00268 }
00269
00270 void TGo4ParaEdit::ChangedTable( int row, int col )
00271 {
00272 if (col==fiColValue) {
00273 QString txt = MemberTable->text(row, col);
00274 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(row);
00275 info->SetStrValue(txt.latin1());
00276 PleaseUpdateLabel->setShown(true);
00277 }
00278 }
00279
00280 void TGo4ParaEdit::TableDoubleClick( int row, int col )
00281 {
00282 if(col!=fiColName) return;
00283
00284 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(row);
00285
00286 if (info->IsArrayItem()) {
00287 fiCurrentRow = row;
00288 ExpandShrinkArray();
00289 } else
00290 if (info->IsFitterItem()) {
00291 fiCurrentRow = row;
00292 EditFitter();
00293 }
00294 }
00295
00296 void TGo4ParaEdit::ContextMenu( int row, int col )
00297 {
00298 if(col!=fiColName) return;
00299
00300 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(row);
00301
00302 if (info->IsArrayItem()) {
00303 fiCurrentRow = row;
00304 QPopupMenu contextMenu(this );
00305 QLabel* caption = new QLabel( "<font color=darkblue><u><b>"
00306 "Array View</b></u></font>", this );
00307 caption->setAlignment( Qt::AlignCenter );
00308 contextMenu.insertItem( caption );
00309
00310 if (row<fItems->GetLast()) {
00311 TGo4ParameterMember* next = (TGo4ParameterMember*) fItems->At(row+1);
00312 if ((next->GetMemberId() == info->GetMemberId()) && !next->IsVisible())
00313 contextMenu.insertItem( "++ \t(next index)", this, SLOT(IncArrayIndex()));
00314 }
00315
00316 if (row>0) {
00317 TGo4ParameterMember* prev = (TGo4ParameterMember*) fItems->At(row-1);
00318 if ((prev->GetMemberId() == info->GetMemberId()) && !prev->IsVisible())
00319 contextMenu.insertItem( "-- \t(prev index)", this, SLOT(DecArrayIndex()));
00320 }
00321
00322 contextMenu.insertItem( "Expand/Shrink", this, SLOT(ExpandShrinkArray()));
00323 contextMenu.exec(QCursor::pos());
00324 } else
00325
00326 if (info->IsFitterItem()) {
00327 fiCurrentRow = row;
00328 QPopupMenu contextMenu(this );
00329 QLabel *caption = new QLabel( "<font color=darkblue><u><b>"
00330 "Modify Fitter</b></u></font>", this);
00331 caption->setAlignment( Qt::AlignCenter );
00332 contextMenu.insertItem( caption );
00333 contextMenu.insertItem( "Edit...", this, SLOT(EditFitter()));
00334
00335 TGo4Fitter* fitter = 0;
00336 ServiceCall("GetFitterFromFitPanel", &fitter);
00337 if ((fitter!=0) && (info->GetObject()!=fitter))
00338 contextMenu.insertItem( "Get from FitPanel", this, SLOT(GetFitterFromEditor()));
00339 contextMenu.exec(QCursor::pos());
00340 }
00341 }
00342
00343 void TGo4ParaEdit::ExpandShrinkArray()
00344 {
00345 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(fiCurrentRow);
00346
00347 Int_t memberid = info->GetMemberId();
00348 for(int n=0;n<=fItems->GetLast();n++) {
00349 TGo4ParameterMember* item = (TGo4ParameterMember*) fItems->At(n);
00350 if (item->GetMemberId()==memberid)
00351 item->SetVisible(!item->IsVisible());
00352 }
00353 info->SetVisible(kTRUE);
00354 ShowVisibleItems();
00355 }
00356
00357 void TGo4ParaEdit::IncArrayIndex()
00358 {
00359 if (fiCurrentRow>fItems->GetLast()) return;
00360 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(fiCurrentRow);
00361 TGo4ParameterMember* next = (TGo4ParameterMember*) fItems->At(fiCurrentRow+1);
00362 if (next->GetMemberId() == info->GetMemberId()) {
00363 info->SetVisible(kFALSE);
00364 next->SetVisible(kTRUE);
00365 ShowVisibleItems();
00366 }
00367 }
00368
00369 void TGo4ParaEdit::DecArrayIndex()
00370 {
00371 if (fiCurrentRow==0) return;
00372 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(fiCurrentRow);
00373 TGo4ParameterMember* prev = (TGo4ParameterMember*) fItems->At(fiCurrentRow-1);
00374 if (prev->GetMemberId() == info->GetMemberId()) {
00375 info->SetVisible(kFALSE);
00376 prev->SetVisible(kTRUE);
00377 ShowVisibleItems();
00378 }
00379 }
00380
00381 void TGo4ParaEdit::EditFitter()
00382 {
00383 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(fiCurrentRow);
00384 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (info->GetObject());
00385
00386 if(fitter==0) {
00387 fitter= new TGo4Fitter("Fitter","Fitter from parameter editor");
00388 info->SetObject(fitter, kTRUE);
00389 }
00390
00391 TGo4Slot* fitterslot = AddSlot("Fitter");
00392 fitterslot->AssignObject(fitter, kFALSE);
00393 EditObjectInSlot(fitterslot);
00394 PleaseUpdateLabel->setShown(true);
00395 }
00396
00397 void TGo4ParaEdit::GetFitterFromEditor()
00398 {
00399 TGo4ParameterMember* info = (TGo4ParameterMember*) fItems->At(fiCurrentRow);
00400 if ((info==0) || !info->IsFitterItem()) return;
00401
00402 TGo4Fitter* fitter = 0;
00403 ServiceCall("CloneFitterFromFitPanel", &fitter);
00404
00405 if (fitter!=0) info->SetObject(fitter, kTRUE);
00406 }
00407
00408 void TGo4ParaEdit::saveFile()
00409 {
00410 TGo4LockGuard lock;
00411
00412 if (fItems==0) return;
00413
00414 if (GetLinkedName("Parameter")!=0) {
00415 TGo4Parameter* par = dynamic_cast<TGo4Parameter*> (GetLinked("Parameter",0));
00416 if (par==0) return;
00417 if (par->SetMemberValues(fItems))
00418 if (SaveItemToFile(GetLinkedName("Parameter"), "Parameters"))
00419 PleaseUpdateLabel->setShown(false);
00420 } else
00421 if (fItemName.length()>0) {
00422 const char* parclass = Browser()->ItemClassName(fItemName.latin1());
00423 if (parclass==0) return;
00424 if (gROOT->GetClass(parclass)==0) {
00425 QMessageBox::warning(this, "Parameter editor",
00426 QString("Parameter class ") + parclass + " not known to gui");
00427 return;
00428 }
00429 TString foldname, parname;
00430 TGo4Slot::ProduceFolderAndName(fItemName.latin1(), foldname, parname);
00431
00432 TGo4ParameterStatus status(parname, parclass, (TObjArray*)fItems->Clone());
00433
00434 TGo4Parameter* par = status.CreateParameter();
00435
00436 if (par==0) {
00437 QMessageBox::warning(this, "Parameter editor",
00438 QString("Can not crate parameter object of class ") + parclass);
00439 return;
00440 }
00441
00442 QFileDialog fd(this, "Save parameter", kTRUE );
00443 fd.setMode( QFileDialog::AnyFile);
00444 fd.setCaption(QString("Save ") + fItemName + " in root file");
00445 fd.setFilters(QString("ROOT (*.root);;ROOT XML (*.xml)"));
00446 fd.setSelection("file.root");
00447 if (fd.exec() != QDialog::Accepted) return;
00448
00449 TFile* f = TFile::Open(fd.selectedFile().latin1(),"UPDATE");
00450 if (f!=0) {
00451 f->WriteTObject(par, par->GetName(), "WriteDelete") > 0;
00452 delete f;
00453 }
00454 }
00455 }
00456
00457 void TGo4ParaEdit::RefreshClicked()
00458 {
00459
00460
00461 WorkWithParameter(ParamNameLbl->text(), true);
00462
00463
00464 }
00465
00466 void TGo4ParaEdit::ApplyClicked()
00467 {
00468 TGo4LockGuard lock;
00469
00470 if ((fItemName.length()==0) || (fItems==0)) return;
00471
00472 TString foldname, parname;
00473 TGo4Slot::ProduceFolderAndName(fItemName.latin1(), foldname, parname);
00474
00475 const char* parclass = Browser()->ItemClassName(fItemName.latin1());
00476 if (parclass==0) return;
00477
00478 TGo4ParameterStatus status(parname, parclass, (TObjArray*)fItems->Clone());
00479
00480 if (UpdateItemInAnalysis(fItemName, &status))
00481 if (BrowserItemRemote(fItemName))
00482 RefreshClicked();
00483 else
00484 PleaseUpdateLabel->setShown(false);
00485 }
00486
00487