MCPcopy Create free account
hub / github.com/Geant4/geant4 / CreateCommandWidget

Method CreateCommandWidget

source/interfaces/implementation/src/G4UIQt.cc:4345–4616  ·  view source on GitHub ↗

Create a widget with the command parameters inside @param command: command line @parent : parent widget @isDialog : true if we want apply/cancel button and close at end, false if we want only apply */

Source from the content-addressed store, hash-verified

4343 @isDialog : true if we want apply/cancel button and close at end, false if we want only apply
4344*/
4345G4bool G4UIQt::CreateCommandWidget(G4UIcommand* aCommand, QWidget* aParent, G4bool isDialog)
4346{
4347 if (aCommand == nullptr) {
4348 return false;
4349 }
4350
4351 // parameters
4352 auto n_parameterEntry = (G4int)aCommand->GetParameterEntries();
4353 if (n_parameterEntry > 0) {
4354 G4UIparameter* param;
4355
4356 // Re-implementation of G4UIparameter.cc
4357 auto paramWidget = new QWidget();
4358 auto gridLayout = new QGridLayout();
4359 paramWidget->setLayout(gridLayout);
4360
4361 // Special case for colour, try to display a color chooser if we found red/green/blue parameter
4362 unsigned int nbColorParameter = 0;
4363 G4bool isStillColorParameter = false;
4364 G4bool isColorDialogAdded = false;
4365 QLabel* redLabel = nullptr;
4366 QLabel* greenLabel = nullptr;
4367 QString redDefaultStr = "";
4368 QString greenDefaultStr = "";
4369 QString blueDefaultStr = "";
4370 QWidget* redInput = nullptr;
4371 QWidget* greenInput = nullptr;
4372
4373 for (G4int i_thParameter = 0; i_thParameter < n_parameterEntry; i_thParameter++) {
4374 QString txt;
4375 param = aCommand->GetParameter(i_thParameter);
4376 auto label = new QLabel(QString((char*)(param->GetParameterName()).data()));
4377
4378 if ((label->text() == "red") || (label->text() == "red_or_string")) {
4379 nbColorParameter++;
4380 isStillColorParameter = true;
4381 }
4382 else if ((label->text() == "green") && isStillColorParameter) {
4383 nbColorParameter++;
4384 }
4385 else if ((label->text() == "blue") && isStillColorParameter) {
4386 nbColorParameter++;
4387 }
4388 else if (! isColorDialogAdded) {
4389 // not following red/green/blue parameters ?
4390 if (nbColorParameter == 1) {
4391 gridLayout->addWidget(redLabel, i_thParameter - 1, 0);
4392 gridLayout->addWidget(redInput, i_thParameter - 1, 1);
4393 }
4394 else if (nbColorParameter == 2) {
4395 gridLayout->addWidget(redLabel, i_thParameter - 2, 0);
4396 gridLayout->addWidget(redInput, i_thParameter - 2, 1);
4397 gridLayout->addWidget(greenLabel, i_thParameter - 1, 0);
4398 gridLayout->addWidget(greenInput, i_thParameter - 1, 1);
4399 }
4400 nbColorParameter = 0;
4401 }
4402 // Check parameter type, could be NULL if not found

Callers

nothing calls this directly

Calls 15

ChangeColorCallbackMethod · 0.95
VisParameterCallbackMethod · 0.95
QPixmapClass · 0.85
GetParameterEntriesMethod · 0.80
GetParameterMethod · 0.80
GetParameterTypeMethod · 0.80
addButtonMethod · 0.80
IsOmittableMethod · 0.80
GetCurrentAsDefaultMethod · 0.80
setDefaultMethod · 0.80
QStringClass · 0.50
dataMethod · 0.45

Tested by

no test coverage detected