Changeset 695


Ignore:
Timestamp:
Jan 24, 2008, 7:06:27 PM (16 years ago)
Author:
garnier
Message:

debut de la zone de recherche sur le Help

Location:
trunk/geant4/interfaces/basic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/interfaces/basic/include/G4UIQt.hh

    r688 r695  
    3939
    4040#include <qobject.h>
     41#include <qhash.h>
    4142
    4243class QMainWindow;
     
    7475//
    7576// Class description - end :
     77
    7678
    7779class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession {
     
    119121  void ExitHelp();// have to be implemeted because we heritate from G4VBasicShell
    120122  bool eventFilter(QObject*,QEvent*);
     123  void ActivateCommand(G4String);
     124  QHash<QString, int> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
     125
    121126
    122127private:
     
    139144#endif
    140145  QDialog *fHelpDialog;
    141 
     146  QLineEdit *helpLine;
     147 
    142148signals :
    143149  void myClicked(const QString &text);
     
    152158  void ShowHelpCallback();
    153159  void CommandHistoryCallback();
     160  void lookForHelpStringCallback();
    154161};
    155162
  • trunk/geant4/interfaces/basic/src/G4UIQt.cc

    r688 r695  
    3030// L. Garnier
    3131
    32 //#define GEANT4_QT_DEBUG
     32#define GEANT4_QT_DEBUG
    3333
    3434#ifdef G4UI_BUILD_QT_SESSION
     
    541541#endif
    542542    QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog);
     543    helpLine = new QLineEdit("Look for...",fHelpDialog);
    543544    QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog);
    544545    QPushButton *exitButton = new QPushButton("Exit",fHelpDialog);
    545546    connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
     547    connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) );
     548
    546549
    547550    // the help tree
     
    646649  }
    647650
     651  ActivateCommand(newCommand);
     652
     653#if QT_VERSION < 0x040000
     654  fHelpDialog->setCaption( tr( "Help on commands" ));
     655#else
     656  fHelpDialog->setWindowTitle(tr("Help on commands"));
     657#endif
     658  fHelpDialog->resize(800,600);
     659  fHelpDialog->move(QPoint(400,150));
     660  fHelpDialog->show();
     661  fHelpDialog->raise();
     662#if QT_VERSION < 0x040000
     663  fHelpDialog->setActiveWindow();
     664#else
     665  fHelpDialog->activateWindow();
     666#endif
     667}
     668
     669void G4UIQt::ActivateCommand(
     670 G4String newCommand
     671)
     672{
    648673  // Look for the choosen command "newCommand"
    649674  size_t i = newCommand.index(" ");
     
    743768    }
    744769  }
    745 #if QT_VERSION < 0x040000
    746   fHelpDialog->setCaption( tr( "Help on commands" ));
    747 #else
    748   fHelpDialog->setWindowTitle(tr("Help on commands"));
    749 #endif
    750   fHelpDialog->resize(800,600);
    751   fHelpDialog->move(QPoint(400,150));
    752   fHelpDialog->show();
    753   fHelpDialog->raise();
    754 #if QT_VERSION < 0x040000
    755   fHelpDialog->setActiveWindow();
    756 #else
    757   fHelpDialog->activateWindow();
    758 #endif
    759 }
    760 
    761 
     770}
    762771
    763772/**   Fill the Help Tree Widget
     
    13011310}
    13021311
    1303 #endif
     1312/**   Callback called when user give a new string to look for<br>
     1313   Display a list of matching commands descriptions.
     1314*/
     1315void G4UIQt::lookForHelpStringCallback(
     1316)
     1317{
     1318  QString found = "";
     1319  // the help tree
     1320  G4UImanager* UI = G4UImanager::GetUIpointer();
     1321  if(UI==NULL) return;
     1322  G4UIcommandTree * treeTop = UI->GetTree();
     1323#ifdef GEANT4_QT_DEBUG
     1324  printf("1111 %s\n",helpLine->text().toStdString().c_str());
     1325#endif
     1326 
     1327  G4int treeSize = treeTop->GetTreeEntry();
     1328  int tmp = 0;
     1329  for (int a=0;a<treeSize;a++) {
     1330#ifdef GEANT4_QT_DEBUG
     1331    printf("Command %s\n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data());
     1332#endif
     1333    G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
     1334    tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
     1335    if (tmp >0) {
     1336#ifdef GEANT4_QT_DEBUG
     1337      printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp);
     1338#endif
     1339    }
     1340    // look for childs
     1341    LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
     1342    tmp = 0;
     1343  }
     1344}
     1345
     1346QHash<QString, int> G4UIQt::LookForHelpStringInChildTree(
     1347 G4UIcommandTree *aCommandTree
     1348 ,const QString & text
     1349)
     1350{
     1351  QHash<QString, int> found;
     1352  if (aCommandTree == NULL) return found;
     1353
     1354  // Get the Sub directories
     1355  int tmp = 0;
     1356  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
     1357    const G4UIcommand* command = aCommandTree->GetGuidance();
     1358#ifdef GEANT4_QT_DEBUG
     1359    //    printf("Command %s\n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data());
     1360    //    printf("%s \n",GetCommandList (command).toStdString().c_str());
     1361#endif
     1362    tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
     1363    if (tmp >0) {
     1364      found.insert(QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()),tmp);
     1365#ifdef GEANT4_QT_DEBUG
     1366      printf("---Command %s match %d times \n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data(),tmp);
     1367#endif
     1368    }
     1369    // look for childs
     1370    LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
     1371  }
     1372
     1373  // Get the Commands
     1374
     1375  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
     1376    const G4UIcommand* command = aCommandTree->GetCommand(a+1);
     1377#ifdef GEANT4_QT_DEBUG
     1378    //    printf("Command Finale %s\n");
     1379    //    printf("%s \n",GetCommandList (command).toStdString().c_str());
     1380#endif
     1381    tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
     1382    if (tmp >0) {
     1383      found.insert(QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()),tmp);
     1384#ifdef GEANT4_QT_DEBUG
     1385      printf("---Command Finale %s match %d times \n",(char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data(),tmp);
     1386#endif
     1387    }
     1388   
     1389  }
     1390  return found;
     1391}
     1392#endif
Note: See TracChangeset for help on using the changeset viewer.