Changeset 697 for trunk


Ignore:
Timestamp:
Jan 25, 2008, 4:49:41 PM (16 years ago)
Author:
garnier
Message:

avancement sur la zone de recherche

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

Legend:

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

    r695 r697  
    3939
    4040#include <qobject.h>
    41 #include <qhash.h>
     41#include <qmap.h>
    4242
    4343class QMainWindow;
     
    109109  void TerminalHelp(G4String);
    110110#if QT_VERSION < 0x040000
     111  QListView * CreateHelpTree();
     112#else
     113  QTreeWidget * CreateHelpTree();
     114#endif
     115
     116#if QT_VERSION < 0x040000
    111117  void CreateChildTree(QListViewItem*,G4UIcommandTree*);
    112118  QListViewItem* FindTreeItem(QListViewItem *,const QString&);
     
    122128  bool eventFilter(QObject*,QEvent*);
    123129  void ActivateCommand(G4String);
    124   QHash<QString, int> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
     130  QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);
    125131
    126132
  • trunk/geant4/interfaces/basic/src/G4UIQt.cc

    r695 r697  
    120120#if QT_VERSION < 0x040000
    121121  fMainWindow->setCaption( tr( "G4UI Session" ));
    122   fMainWindow->resize(800,600);
     122  fMainWindow->resize(900,600);
    123123  fMainWindow->move(50,100);
    124124#else
    125125  fMainWindow->setWindowTitle( tr("G4UI Session") );
    126   fMainWindow->resize(800,600);
     126  fMainWindow->resize(900,600);
    127127  fMainWindow->move(QPoint(50,100));
    128128#endif
     
    141141
    142142  fTextArea = new QTextEdit(topWidget);
    143 #ifdef GEANT4_QT_DEBUG
    144   printf("G4UIQt:: end\n");
    145 #endif
    146 #ifdef GEANT4_QT_DEBUG
    147   printf("G4UIQt::PushButton 1\n");
    148 #endif
    149143  QPushButton *clearButton = new QPushButton("clear",topWidget);
    150 #ifdef GEANT4_QT_DEBUG
    151   printf("G4UIQt::end1\n");
    152 #endif
    153144  connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback()));
    154145
     
    541532#endif
    542533    QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog);
    543     helpLine = new QLineEdit("Look for...",fHelpDialog);
     534    QWidget *helpWidget = new QWidget(fHelpDialog);
    544535    QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog);
    545536    QPushButton *exitButton = new QPushButton("Exit",fHelpDialog);
     537    exitButton->setAutoDefault(false);
    546538    connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
     539   
     540    QHBoxLayout *helpLayout = new QHBoxLayout(helpWidget);
     541#if QT_VERSION < 0x040000
     542    helpLayout->add(new QLabel("Search :",helpWidget));
     543#else
     544    helpLayout->addWidget(new QLabel("Search :",helpWidget));
     545#endif
     546    helpLine = new QLineEdit(fHelpDialog);
     547#if QT_VERSION < 0x040000
     548    helpLayout->add(helpLine);
     549#else
     550    helpLayout->addWidget(helpLine);
     551#endif
    547552    connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) );
    548553
    549 
    550554    // the help tree
    551     G4UImanager* UI = G4UImanager::GetUIpointer();
    552     if(UI==NULL) return;
    553     G4UIcommandTree * treeTop = UI->GetTree();
    554 
    555     // build widget
    556555#if QT_VERSION < 0x040000
    557556    fHelpTreeWidget = new QListView(splitter);
    558     fHelpTreeWidget->setSelectionMode(QListView::Single);
    559     fHelpTreeWidget->setRootIsDecorated(true);
    560     fHelpTreeWidget->addColumn("Command");
    561     fHelpTreeWidget->addColumn("Description",0);
    562     //    fHelpTreeWidget->setColumnWidth (1,0);
    563     fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
    564     //    QList<QListViewItem *> items;
    565557#else
    566558    fHelpTreeWidget = new QTreeWidget();
    567     fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
    568     fHelpTreeWidget->setColumnCount(2);
    569     fHelpTreeWidget->setColumnHidden(1,true);
    570     QStringList labels;
    571     labels << QString("Command") << QString("Description");
    572     fHelpTreeWidget->setHeaderLabels(labels);
    573     //    QList<QTreeWidgetItem *> items;
    574 #endif
     559#endif
     560    fHelpTreeWidget = CreateHelpTree();
    575561
    576562    fHelpArea = new QTextEdit(splitter);
    577563    fHelpArea->setReadOnly(true);
    578564
    579     G4int treeSize = treeTop->GetTreeEntry();
    580 #if QT_VERSION < 0x040000
    581     QListViewItem * newItem;
    582 #else
    583     QTreeWidgetItem * newItem;
    584 #endif
    585     for (int a=0;a<treeSize;a++) {
    586       // Creating new item
    587 
    588 #if QT_VERSION < 0x040000
    589       newItem = new QListViewItem(fHelpTreeWidget);
    590       newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
    591       newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace());
    592 #else
    593                                                                                                    //FIXME : Qt 4.2
    594                                                                                                    //      QStringList stringList;
    595                                                                                                    //      stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
    596                                                                                                    //      stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
    597                                                                                                    //      newItem = new QTreeWidgetItem(stringList);
    598                                                                                                    // FIXME : Qt 4.0
    599       newItem = new QTreeWidgetItem(fHelpTreeWidget);
    600       newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
    601       newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed());
    602 #endif
    603 
    604 
    605       // look for childs
    606       CreateChildTree(newItem,treeTop->GetTree(a+1));
    607       //      items.append(newItem);
    608     }
    609 
    610 
    611 #if QT_VERSION < 0x040000
    612     connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
    613     connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
    614 #else
    615     connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
    616     connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); 
    617 #endif
    618 
    619565    // Set layouts
    620566
    621567#if QT_VERSION >= 0x040000
    622     splitter->addWidget(fHelpTreeWidget);
     568    if (fHelpTreeWidget)
     569      splitter->addWidget(fHelpTreeWidget);
    623570    splitter->addWidget(fHelpArea);
    624571#endif
     
    626573
    627574#if QT_VERSION >= 0x040000
    628     vLayout->addWidget(splitter);
     575    vLayout->addWidget(helpWidget);
     576    vLayout->addWidget(splitter,1);
    629577    vLayout->addWidget(exitButton);
    630578#else
    631     vLayout->add(splitter);
     579    vLayout->addWidget(helpWidget);
     580    vLayout->add(splitter,1);
    632581    vLayout->addWidget(exitButton);
    633582#endif
     
    667616}
    668617
     618
    669619void G4UIQt::ActivateCommand(
    670620 G4String newCommand
    671621)
    672622{
     623  if (!fHelpTreeWidget) {
     624    return;
     625  }
    673626  // Look for the choosen command "newCommand"
    674627  size_t i = newCommand.index(" ");
     
    769722  }
    770723}
     724
     725
     726
     727/**
     728   Create the help tree widget
     729   @param parent : parent of tree widget
     730   @return the widget containing the tree or NULL if it could not have beeen created
     731 */
     732
     733#if QT_VERSION < 0x040000
     734QListView * G4UIQt::CreateHelpTree()
     735#else
     736QTreeWidget * G4UIQt::CreateHelpTree()
     737#endif
     738{
     739  G4UImanager* UI = G4UImanager::GetUIpointer();
     740  if(UI==NULL) return NULL;
     741  G4UIcommandTree * treeTop = UI->GetTree();
     742
     743
     744  // build widget
     745#if QT_VERSION < 0x040000
     746  fHelpTreeWidget->setSelectionMode(QListView::Single);
     747  fHelpTreeWidget->setRootIsDecorated(true);
     748  fHelpTreeWidget->addColumn("Command");
     749  fHelpTreeWidget->addColumn("Description",0);
     750  //    fHelpTreeWidget->setColumnWidth (1,0);
     751  fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
     752  //    QList<QListViewItem *> items;
     753#else
     754  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
     755  fHelpTreeWidget->setColumnCount(2);
     756  fHelpTreeWidget->setColumnHidden(1,true);
     757  QStringList labels;
     758  labels << QString("Command") << QString("Description");
     759  fHelpTreeWidget->setHeaderLabels(labels);
     760  //    QList<QTreeWidgetItem *> items;
     761#endif
     762
     763  G4int treeSize = treeTop->GetTreeEntry();
     764#if QT_VERSION < 0x040000
     765  QListViewItem * newItem;
     766#else
     767  QTreeWidgetItem * newItem;
     768#endif
     769  for (int a=0;a<treeSize;a++) {
     770    // Creating new item
     771
     772#if QT_VERSION < 0x040000
     773    newItem = new QListViewItem(fHelpTreeWidget);
     774    newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).simplifyWhiteSpace());
     775    newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).simplifyWhiteSpace());
     776#else
     777    newItem = new QTreeWidgetItem(fHelpTreeWidget);
     778    newItem->setText(0,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed());
     779    newItem->setText(1,QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed());
     780#endif
     781
     782
     783    // look for childs
     784    CreateChildTree(newItem,treeTop->GetTree(a+1));
     785    //      items.append(newItem);
     786  }
     787
     788
     789#if QT_VERSION < 0x040000
     790  connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
     791  connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));
     792#else
     793  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback())); 
     794  connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback())); 
     795#endif
     796
     797  return fHelpTreeWidget;
     798}
     799
     800
    771801
    772802/**   Fill the Help Tree Widget
     
    13101340}
    13111341
     1342
    13121343/**   Callback called when user give a new string to look for<br>
    1313    Display a list of matching commands descriptions.
     1344   Display a list of matching commands descriptions. If no string is set,
     1345   will display the complete help tree
    13141346*/
    13151347void G4UIQt::lookForHelpStringCallback(
    13161348)
    13171349{
    1318   QString found = "";
     1350  if (helpLine->text() =="") {
     1351    // clear old help tree
     1352    fHelpTreeWidget->clear();
     1353    CreateHelpTree();
     1354#if QT_VERSION < 0x040200
     1355    fHelpArea->clear();
     1356#else
     1357    fHelpArea->setText("");
     1358#endif
     1359    return;
     1360  }
     1361
    13191362  // the help tree
    13201363  G4UImanager* UI = G4UImanager::GetUIpointer();
    13211364  if(UI==NULL) return;
    13221365  G4UIcommandTree * treeTop = UI->GetTree();
    1323 #ifdef GEANT4_QT_DEBUG
    1324   printf("1111 %s\n",helpLine->text().toStdString().c_str());
    1325 #endif
    13261366 
    13271367  G4int treeSize = treeTop->GetTreeEntry();
     1368
     1369  // clear old help tree
     1370  fHelpTreeWidget->clear();
     1371
     1372  // look for new items
     1373
    13281374  int tmp = 0;
     1375  QMap<int,QString> commandResultMap;
     1376  QMap<int,QString> commandChildResultMap;
     1377
    13291378  for (int a=0;a<treeSize;a++) {
    13301379#ifdef GEANT4_QT_DEBUG
     
    13341383    tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive);
    13351384    if (tmp >0) {
     1385      commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
    13361386#ifdef GEANT4_QT_DEBUG
    13371387      printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp);
     
    13391389    }
    13401390    // look for childs
    1341     LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
    1342     tmp = 0;
    1343   }
    1344 }
    1345 
    1346 QHash<QString, int> G4UIQt::LookForHelpStringInChildTree(
     1391    commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),helpLine->text());
     1392    // insert new childs
     1393    if (!commandChildResultMap.empty()) {
     1394      QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
     1395      while (i != commandChildResultMap.constEnd()) {
     1396        commandResultMap.insertMulti(i.key(),i.value());
     1397        i++;
     1398      }
     1399      commandChildResultMap.clear();
     1400    }
     1401  }
     1402
     1403  // build new help tree
     1404#if QT_VERSION < 0x040000
     1405  fHelpTreeWidget->setSelectionMode(QListView::Single);
     1406  fHelpTreeWidget->setRootIsDecorated(true);
     1407  fHelpTreeWidget->addColumn("Command");
     1408  fHelpTreeWidget->addColumn("Description",0);
     1409  fHelpTreeWidget->addColumn("Match");
     1410  //  fHelpTreeWidget->header()->setResizeEnabled(FALSE,1);
     1411#else
     1412  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
     1413  fHelpTreeWidget->setColumnCount(3);
     1414  fHelpTreeWidget->setColumnHidden(1,true);
     1415  QStringList labels;
     1416  labels << QString("Command") << QString("Description") << QString("Match");
     1417  fHelpTreeWidget->setHeaderLabels(labels);
     1418#endif
     1419
     1420  if (commandResultMap.empty()) {
     1421#if QT_VERSION < 0x040200
     1422    fHelpArea->clear();
     1423    fHelpArea->append("No match found");
     1424#else
     1425    fHelpArea->setText("No match found");
     1426#endif
     1427    return;
     1428  }
     1429
     1430  QMap<int,QString>::const_iterator i = commandResultMap.constEnd();
     1431  i--;
     1432  // 10 maximum progress values
     1433  float multValue = 10.0/(float)(i.key());
     1434  QString progressChar = "|";
     1435  QString progressStr = "|";
     1436
     1437#if QT_VERSION < 0x040000
     1438  QListViewItem * newItem;
     1439#else
     1440  QTreeWidgetItem * newItem;
     1441#endif
     1442  bool end = false;
     1443  while (!end) {
     1444    if (i == commandResultMap.constBegin()) {
     1445      end = true;
     1446    }
     1447    for(int a=0;a<int(i.key()*multValue);a++) {
     1448      progressStr += progressChar;
     1449    }
     1450#if QT_VERSION < 0x040000
     1451    newItem = new QListViewItem(fHelpTreeWidget);
     1452    newItem->setText(0,i.value().simplifyWhiteSpace());
     1453    newItem->setText(1,i.value().simplifyWhiteSpace());
     1454   
     1455    newItem->setText(2,progressStr);
     1456#else
     1457    newItem = new QTreeWidgetItem(fHelpTreeWidget);
     1458    newItem->setText(0,i.value().trimmed());
     1459    newItem->setText(1,i.value().trimmed());
     1460    newItem->setText(2,progressStr);
     1461#endif
     1462   
     1463#if QT_VERSION >= 0x040200
     1464    newItem->setForeground ( 2, QBrush(Qt::blue) );
     1465#endif
     1466    progressStr = "|";
     1467    i--;
     1468  }
     1469  // FIXME :  to be checked on Qt3
     1470#if QT_VERSION < 0x040000
     1471  fHelpTreeWidget->setColumnWidthMode (0,QListView::Maximum);
     1472#else
     1473  fHelpTreeWidget->resizeColumnToContents (0);
     1474#endif
     1475}
     1476
     1477
     1478
     1479
     1480QMap<int,QString> G4UIQt::LookForHelpStringInChildTree(
    13471481 G4UIcommandTree *aCommandTree
    1348  ,const QString & text
    1349 )
    1350 {
    1351   QHash<QString, int> found;
    1352   if (aCommandTree == NULL) return found;
    1353 
     1482,const QString & text
     1483 )
     1484{
     1485  QMap<int,QString> commandResultMap;
     1486  if (aCommandTree == NULL) return commandResultMap;
     1487 
    13541488  // Get the Sub directories
    13551489  int tmp = 0;
     1490  QMap<int,QString> commandChildResultMap;
     1491 
    13561492  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
    13571493    const G4UIcommand* command = aCommandTree->GetGuidance();
    13581494#ifdef GEANT4_QT_DEBUG
     1495    printf("Command loop \n");
    13591496    //    printf("Command %s\n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data());
    13601497    //    printf("%s \n",GetCommandList (command).toStdString().c_str());
     
    13621499    tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
    13631500    if (tmp >0) {
    1364       found.insert(QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()),tmp);
     1501      commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
    13651502#ifdef GEANT4_QT_DEBUG
    13661503      printf("---Command %s match %d times \n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data(),tmp);
     
    13681505    }
    13691506    // look for childs
    1370     LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
    1371   }
    1372 
     1507    commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
     1508   
     1509    if (!commandChildResultMap.empty()) {
     1510      printf("Check -------------------in child %d\n",commandChildResultMap.count());
     1511      // insert new childs
     1512      QMap<int,QString>::const_iterator i = commandChildResultMap.constBegin();
     1513      while (i != commandChildResultMap.constEnd()) {
     1514        commandResultMap.insertMulti(i.key(),i.value());
     1515        i++;
     1516      }
     1517      commandChildResultMap.clear();
     1518    }
     1519  }
    13731520  // Get the Commands
    1374 
     1521 
    13751522  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
    13761523    const G4UIcommand* command = aCommandTree->GetCommand(a+1);
    13771524#ifdef GEANT4_QT_DEBUG
    1378     //    printf("Command Finale %s\n");
     1525    printf("Command Finale debut\n");
    13791526    //    printf("%s \n",GetCommandList (command).toStdString().c_str());
    13801527#endif
    13811528    tmp = GetCommandList (command).count(text,Qt::CaseInsensitive);
    13821529    if (tmp >0) {
    1383       found.insert(QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()),tmp);
     1530      commandResultMap.insertMulti(tmp,QString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
    13841531#ifdef GEANT4_QT_DEBUG
    13851532      printf("---Command Finale %s match %d times \n",(char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data(),tmp);
     
    13881535   
    13891536  }
    1390   return found;
    1391 }
    1392 #endif
     1537  printf("Command Finale retun \n");
     1538  return commandResultMap;
     1539}
     1540#endif
Note: See TracChangeset for help on using the changeset viewer.