15 #include "G4UIcommandTree.hh" 41 QSplitter *splitter =
new QSplitter(Qt::Vertical);
48 QSplitter *treesplitter =
new QSplitter(Qt::Horizontal);
52 QVBoxLayout *helpLayout =
new QVBoxLayout(treesplitter);
55 fHelpTreeWidget =
new QTreeWidget();
56 fHelpTreeWidget = CreateHelpTree();
58 helpLayout->addWidget(fHelpTreeWidget);
62 fHelpArea =
new QTextEdit(treesplitter);
63 fHelpArea->setReadOnly(
true);
70 treesplitter->setSizes(tlist);
73 QVBoxLayout *layoutTop =
new QVBoxLayout(topWidget);
74 layoutTop->addWidget(treesplitter);
83 fCommandHistoryArea =
new QListWidget();
84 fCommandHistoryArea->setSelectionMode(QAbstractItemView::SingleSelection);
85 fCommandHistoryArea->installEventFilter(
this);
86 connect(fCommandHistoryArea, SIGNAL(itemSelectionChanged()), SLOT(CommandHistoryCallback()));
91 fCommandArea =
new QLineEdit();
92 fCommandArea->installEventFilter(
this);
93 fCommandArea->activateWindow();
94 fCommandArea->setFocusPolicy ( Qt::StrongFocus );
95 fCommandArea->setFocus(Qt::TabFocusReason);
96 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(CommandEnteredCallback()));
99 QVBoxLayout *layoutBottom =
new QVBoxLayout(bottomWidget);
100 layoutBottom->addWidget(
new QLabel(
"History:"));
101 layoutBottom->addWidget(fCommandHistoryArea);
102 layoutBottom->addWidget(
new QLabel(
"Press Enter to Execute Command:"));
103 layoutBottom->addWidget(fCommandArea);
110 splitter->setSizes(list);
117 QVBoxLayout *mainLayout =
new QVBoxLayout;
118 mainLayout->addWidget(splitter);
119 setLayout(mainLayout);
131 cout << hd_msg <<
" g4 Dialog Widget Deleted." << endl;
137 void g4dialog::CommandHistoryCallback()
139 QListWidgetItem* item = NULL;
140 if (!fCommandHistoryArea)
145 QList<QListWidgetItem *> list = fCommandHistoryArea->selectedItems();
153 fCommandArea->setText(item->text());
160 void g4dialog::CommandEnteredCallback()
163 if(fCommandArea->text().trimmed() !=
"")
165 fCommandHistoryArea->addItem(fCommandArea->text());
167 UImanager->ApplyCommand(fCommandArea->text().toStdString().c_str());
169 fCommandHistoryArea->clearSelection();
170 fCommandHistoryArea->setCurrentItem(NULL);
171 fCommandArea->setText(
"");
178 QTreeWidget* g4dialog::CreateHelpTree()
181 G4UIcommandTree *treeTop =
UImanager->GetTree();
185 fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
188 labels << QString(
"Command");
189 fHelpTreeWidget->setHeaderLabels(labels);
191 G4int treeSize = treeTop->GetTreeEntry();
192 QTreeWidgetItem * newItem;
194 for (
int a=0;a<treeSize;a++)
197 newItem =
new QTreeWidgetItem(fHelpTreeWidget);
198 newItem->setText(0, QString((
char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
201 CreateChildTree(newItem, treeTop->GetTree(a+1));
205 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged() ),
this, SLOT(HelpTreeClicCallback() ) );
206 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,
int) ),
this, SLOT(HelpTreeDoubleClicCallback()));
208 return fHelpTreeWidget;
214 void g4dialog::CreateChildTree(QTreeWidgetItem *aParent,G4UIcommandTree *aCommandTree)
216 if (aParent == NULL)
return;
217 if (aCommandTree == NULL)
return;
221 QTreeWidgetItem * newItem;
224 for (
int a=0;a<aCommandTree->GetTreeEntry();a++)
227 newItem =
new QTreeWidgetItem(aParent);
228 newItem->setText(0,QString((
char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()).trimmed());
230 CreateChildTree(newItem,aCommandTree->GetTree(a+1));
234 for (
int a=0;a<aCommandTree->GetCommandEntry();a++)
236 QStringList stringList;
237 newItem =
new QTreeWidgetItem(aParent);
238 newItem->setText(0, QString((
char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed());
239 newItem->setExpanded(
false);
246 void g4dialog::HelpTreeClicCallback()
248 QTreeWidgetItem* item = NULL;
249 if(!fHelpTreeWidget || !fHelpArea)
252 QList<QTreeWidgetItem *> list = fHelpTreeWidget->selectedItems();
262 G4UIcommandTree *treeTop =
UImanager->GetTree();
264 string itemText = item->text(0).toStdString();
265 G4UIcommand* command = treeTop->FindPath(itemText.c_str());
270 fHelpArea->setText(GetCommandList(command));
275 G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
280 fHelpArea->setText(path->GetTitle().data());
286 QString g4dialog::GetCommandList (
const G4UIcommand *aCommand)
290 if (aCommand == NULL)
293 G4String commandPath = aCommand->GetCommandPath();
294 G4String rangeString = aCommand->GetRange();
295 G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
296 G4int n_parameterEntry = aCommand->GetParameterEntries();
298 if ((commandPath ==
"") &&
299 (rangeString ==
"") &&
300 (n_guidanceEntry == 0) &&
301 (n_parameterEntry == 0)) {
305 if((commandPath.length()-1)!=
'/')
307 txt +=
"Command " + QString((
char*)(commandPath).data()) +
"\n";
309 txt +=
"Guidance :\n";
311 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
313 txt += QString((
char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) +
"\n";
315 if( ! rangeString.isNull() )
317 txt +=
" Range of parameters : " + QString((
char*)(rangeString).data()) +
"\n";
319 if( n_parameterEntry > 0 )
321 G4UIparameter *param;
324 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
326 param = aCommand->GetParameter(i_thParameter);
327 txt +=
"\nParameter : " + QString((
char*)(param->GetParameterName()).data()) +
"\n";
328 if( ! param->GetParameterGuidance().isNull() )
329 txt += QString((
char*)(param->GetParameterGuidance()).data())+
"\n" ;
330 txt +=
" Parameter type : " + QString(QChar(param->GetParameterType())) +
"\n";
331 if(param->IsOmittable())
333 txt +=
" Omittable : True\n";
337 txt +=
" Omittable : False\n";
339 if( param->GetCurrentAsDefault() )
341 txt +=
" Default value : taken from the current value\n";
343 else if( ! param->GetDefaultValue().isNull() )
345 txt +=
" Default value : " + QString((
char*)(param->GetDefaultValue()).data())+
"\n";
347 if( ! param->GetParameterRange().isNull() )
349 txt +=
" Parameter range : " + QString((
char*)(param->GetParameterRange()).data())+
"\n";
351 if( ! param->GetParameterCandidates().isNull() )
353 txt +=
" Candidates : " + QString((
char*)(param->GetParameterCandidates()).data())+
"\n";
362 void g4dialog::HelpTreeDoubleClicCallback()
364 HelpTreeClicCallback();
366 QTreeWidgetItem* item = NULL;
368 if(!fHelpTreeWidget || !fHelpArea)
371 QList<QTreeWidgetItem *> list = fHelpTreeWidget->selectedItems();
380 fCommandArea->clear();
381 fCommandArea->setText(item->text(0));
g4dialog(QWidget *parent, gemc_opts *)
map< string, opts > args
Options map.