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

Method AddButton

source/interfaces/implementation/src/G4UIQt.cc:3772–3820  ·  view source on GitHub ↗

Add a new button to a menu @param aMenu : parent menu @param aLabel : label to display @param aCommand : command to execute as a callback */

Source from the content-addressed store, hash-verified

3770 @param aCommand : command to execute as a callback
3771 */
3772void G4UIQt::AddButton(const char* aMenu, const char* aLabel, const char* aCommand)
3773{
3774 if (aMenu == nullptr) return; // TO KEEP
3775 if (aLabel == nullptr) return; // TO KEEP
3776 if (aCommand == nullptr) return; // TO KEEP
3777
3778 QMenu* parentTmp = (QMenu*)GetInteractor(aMenu);
3779
3780 if (parentTmp == nullptr) {
3781 G4UImanager* UImanager = G4UImanager::GetUIpointer();
3782 G4int verbose = UImanager->GetVerboseLevel();
3783
3784 if (verbose >= 2) {
3785 G4cout << "Menu name " << aMenu << " does not exist, please define it before using it."
3786 << G4endl;
3787 }
3788 return;
3789 }
3790
3791 // Find the command in the command tree
3792 G4UImanager* UI = G4UImanager::GetUIpointer();
3793 if (UI == nullptr) return;
3794 G4UIcommandTree* treeTop = UI->GetTree();
3795
3796 G4String cmd = aCommand;
3797 std::size_t cmdEndPos = cmd.find_first_of(" \t");
3798 if (cmdEndPos != std::string::npos) {
3799 cmd.erase(cmdEndPos);
3800 }
3801
3802 if (treeTop->FindPath(cmd) == nullptr) {
3803 if (cmd != "ls" && cmd.substr(0, 3) != "ls " && cmd != "pwd" && cmd != "cd" &&
3804 cmd.substr(0, 3) != "cd " && cmd != "help" && cmd.substr(0, 5) != "help " &&
3805 cmd[0] != '?' && cmd != "hist" && cmd != "history" && cmd[0] != '!' && cmd != "exit" &&
3806 cmd != "cont" && cmd != "continue")
3807 {
3808 G4UImanager* UImanager = G4UImanager::GetUIpointer();
3809 G4int verbose = UImanager->GetVerboseLevel();
3810
3811 if (verbose >= 2) {
3812 G4cout << "Warning: command '" << cmd
3813 << "' does not exist, please define it before using it." << G4endl;
3814 }
3815 }
3816 }
3817
3818 QString cmd_tmp = QString(aCommand);
3819 parentTmp->addAction(aLabel, this, [this, cmd_tmp]() { this->ButtonCallback(cmd_tmp); });
3820}
3821
3822/**
3823 special case for the "open" icon. It will open a file selector and map the return file to the given

Callers 1

BuildMenuTreeMethod · 0.45

Calls 6

ButtonCallbackMethod · 0.95
FindPathMethod · 0.80
substrMethod · 0.80
QStringClass · 0.50
GetVerboseLevelMethod · 0.45
GetTreeMethod · 0.45

Tested by

no test coverage detected