8 #include "G4UIcommandTree.hh" 33 QSplitter *splitter =
new QSplitter(Qt::Vertical);
38 QSplitter *treesplitter =
new QSplitter(Qt::Horizontal);
42 QVBoxLayout *helpLayout =
new QVBoxLayout(treesplitter);
45 fHelpTreeWidget =
new QTreeWidget();
46 fHelpTreeWidget = CreateHelpTree();
48 helpLayout->addWidget(fHelpTreeWidget);
52 fHelpArea =
new QTextEdit(treesplitter);
53 fHelpArea->setReadOnly(
true);
60 treesplitter->setSizes(tlist);
63 QVBoxLayout *layoutTop =
new QVBoxLayout(topWidget);
64 layoutTop->addWidget(treesplitter);
70 fCommandHistoryArea =
new QListWidget();
71 fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
72 fCommandHistoryArea->installEventFilter(
this);
73 connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
78 fCommandArea =
new QLineEdit();
79 fCommandArea->installEventFilter(
this);
80 fCommandArea->activateWindow();
81 fCommandArea->setFocusPolicy ( Qt::StrongFocus );
82 fCommandArea->setFocus(Qt::TabFocusReason);
83 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
86 QVBoxLayout *layoutBottom =
new QVBoxLayout(bottomWidget);
87 layoutBottom->addWidget(
new QLabel(
"History:"));
88 layoutBottom->addWidget(fCommandHistoryArea);
89 layoutBottom->addWidget(
new QLabel(
"Press Enter to Execute Command:"));
90 layoutBottom->addWidget(fCommandArea);
97 splitter->setSizes(list);
102 QVBoxLayout *mainLayout =
new QVBoxLayout;
103 mainLayout->addWidget(splitter);
104 setLayout(mainLayout);
115 cout << hd_msg <<
" g4 Dialog Widget Deleted." << endl;
121 void g4dialog::CommandHistoryCallback()
123 QListWidgetItem* item = NULL;
124 if (!fCommandHistoryArea)
129 QList<QListWidgetItem *> list = fCommandHistoryArea->selectedItems();
137 fCommandArea->setText(item->text());
144 void g4dialog::CommandEnteredCallback()
147 if(fCommandArea->text().trimmed() !=
"")
149 fCommandHistoryArea->addItem(fCommandArea->text());
151 UImanager->ApplyCommand(fCommandArea->text().toStdString().c_str());
153 fCommandHistoryArea->clearSelection();
154 fCommandHistoryArea->setCurrentItem(NULL);
155 fCommandArea->setText(
"");
162 QTreeWidget* g4dialog::CreateHelpTree()
165 G4UIcommandTree *treeTop =
UImanager->GetTree();
169 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
172 labels << QString(
"Command");
173 fHelpTreeWidget->setHeaderLabels(labels);
175 G4int treeSize = treeTop->GetTreeEntry();
176 QTreeWidgetItem * newItem;
178 for (
int a=0;a<treeSize;a++)
181 newItem =
new QTreeWidgetItem(fHelpTreeWidget);
182 newItem->setText(0, QString((
char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
185 CreateChildTree(newItem, treeTop->GetTree(a+1));
189 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged() ),
this, SLOT(HelpTreeClicCallback() ) );
190 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,
int) ),
this, SLOT(HelpTreeDoubleClicCallback()));
192 return fHelpTreeWidget;
198 void g4dialog::CreateChildTree(QTreeWidgetItem *aParent,G4UIcommandTree *aCommandTree)
200 if (aParent == NULL)
return;
201 if (aCommandTree == NULL)
return;
205 QTreeWidgetItem * newItem;
208 for (
int a=0;a<aCommandTree->GetTreeEntry();a++)
211 newItem =
new QTreeWidgetItem(aParent);
212 newItem->setText(0,QString((
char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed());
214 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
218 for (
int a=0;a<aCommandTree->GetCommandEntry();a++)
220 QStringList stringList;
221 newItem =
new QTreeWidgetItem(aParent);
222 newItem->setText(0, QString((
char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
223 newItem->setExpanded(
false);
230 void g4dialog::HelpTreeClicCallback()
232 QTreeWidgetItem* item = NULL;
233 if(!fHelpTreeWidget || !fHelpArea)
236 QList<QTreeWidgetItem *> list = fHelpTreeWidget->selectedItems();
246 G4UIcommandTree *treeTop =
UImanager->GetTree();
248 string itemText = item->text(0).toStdString();
249 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
254 fHelpArea->setText(GetCommandList(command));
259 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
264 fHelpArea->setText(path->GetTitle().data());
270 QString g4dialog::GetCommandList (
const G4UIcommand *aCommand)
274 if (aCommand == NULL)
277 G4String commandPath = aCommand->GetCommandPath();
278 G4String rangeString = aCommand->GetRange();
279 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
280 G4int n_parameterEntry = aCommand->GetParameterEntries();
282 if ((commandPath ==
"") &&
283 (rangeString ==
"") &&
284 (n_guidanceEntry == 0) &&
285 (n_parameterEntry == 0)) {
289 if((commandPath.length()-1)!=
'/')
291 txt +=
"Command " + QString((
char*)(commandPath).data()) +
"\n";
293 txt +=
"Guidance :\n";
295 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
297 txt += QString((
char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) +
"\n";
299 if( ! rangeString.isNull() )
301 txt +=
" Range of parameters : " + QString((
char*)(rangeString).data()) +
"\n";
303 if( n_parameterEntry > 0 )
305 G4UIparameter *param;
308 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
310 param = aCommand->GetParameter(i_thParameter);
311 txt +=
"\nParameter : " + QString((
char*)(param->GetParameterName()).data()) +
"\n";
312 if( ! param->GetParameterGuidance().isNull() )
313 txt += QString((
char*)(param->GetParameterGuidance()).data())+
"\n" ;
314 txt +=
" Parameter type : " + QString(QChar(param->GetParameterType())) +
"\n";
315 if(param->IsOmittable())
317 txt +=
" Omittable : True\n";
321 txt +=
" Omittable : False\n";
323 if( param->GetCurrentAsDefault() )
325 txt +=
" Default value : taken from the current value\n";
327 else if( ! param->GetDefaultValue().isNull() )
329 txt +=
" Default value : " + QString((
char*)(param->GetDefaultValue()).data())+
"\n";
331 if( ! param->GetParameterRange().isNull() )
333 txt +=
" Parameter range : " + QString((
char*)(param->GetParameterRange()).data())+
"\n";
335 if( ! param->GetParameterCandidates().isNull() )
337 txt +=
" Candidates : " + QString((
char*)(param->GetParameterCandidates()).data())+
"\n";
346 void g4dialog::HelpTreeDoubleClicCallback()
348 HelpTreeClicCallback();
350 QTreeWidgetItem* item = NULL;
352 if(!fHelpTreeWidget || !fHelpArea)
355 QList<QTreeWidgetItem *> list = fHelpTreeWidget->selectedItems();
364 fCommandArea->clear();
365 fCommandArea->setText(item->text(0));
g4dialog(QWidget *parent, goptions *)
map< string, aopt > optMap
Options map.