Changeset 697 for trunk/geant4
- Timestamp:
- Jan 25, 2008, 4:49:41 PM (17 years ago)
- Location:
- trunk/geant4/interfaces/basic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/interfaces/basic/include/G4UIQt.hh
r695 r697 39 39 40 40 #include <qobject.h> 41 #include <q hash.h>41 #include <qmap.h> 42 42 43 43 class QMainWindow; … … 109 109 void TerminalHelp(G4String); 110 110 #if QT_VERSION < 0x040000 111 QListView * CreateHelpTree(); 112 #else 113 QTreeWidget * CreateHelpTree(); 114 #endif 115 116 #if QT_VERSION < 0x040000 111 117 void CreateChildTree(QListViewItem*,G4UIcommandTree*); 112 118 QListViewItem* FindTreeItem(QListViewItem *,const QString&); … … 122 128 bool eventFilter(QObject*,QEvent*); 123 129 void ActivateCommand(G4String); 124 Q Hash<QString, int> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&);130 QMap<int,QString> LookForHelpStringInChildTree(G4UIcommandTree *,const QString&); 125 131 126 132 -
trunk/geant4/interfaces/basic/src/G4UIQt.cc
r695 r697 120 120 #if QT_VERSION < 0x040000 121 121 fMainWindow->setCaption( tr( "G4UI Session" )); 122 fMainWindow->resize( 800,600);122 fMainWindow->resize(900,600); 123 123 fMainWindow->move(50,100); 124 124 #else 125 125 fMainWindow->setWindowTitle( tr("G4UI Session") ); 126 fMainWindow->resize( 800,600);126 fMainWindow->resize(900,600); 127 127 fMainWindow->move(QPoint(50,100)); 128 128 #endif … … 141 141 142 142 fTextArea = new QTextEdit(topWidget); 143 #ifdef GEANT4_QT_DEBUG144 printf("G4UIQt:: end\n");145 #endif146 #ifdef GEANT4_QT_DEBUG147 printf("G4UIQt::PushButton 1\n");148 #endif149 143 QPushButton *clearButton = new QPushButton("clear",topWidget); 150 #ifdef GEANT4_QT_DEBUG151 printf("G4UIQt::end1\n");152 #endif153 144 connect(clearButton, SIGNAL(clicked()), SLOT(ClearButtonCallback())); 154 145 … … 541 532 #endif 542 533 QVBoxLayout *vLayout = new QVBoxLayout(fHelpDialog); 543 helpLine = new QLineEdit("Look for...",fHelpDialog);534 QWidget *helpWidget = new QWidget(fHelpDialog); 544 535 QSplitter *splitter = new QSplitter(Qt::Horizontal,fHelpDialog); 545 536 QPushButton *exitButton = new QPushButton("Exit",fHelpDialog); 537 exitButton->setAutoDefault(false); 546 538 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 547 552 connect( helpLine, SIGNAL( editingFinished () ), this, SLOT( lookForHelpStringCallback() ) ); 548 553 549 550 554 // the help tree 551 G4UImanager* UI = G4UImanager::GetUIpointer();552 if(UI==NULL) return;553 G4UIcommandTree * treeTop = UI->GetTree();554 555 // build widget556 555 #if QT_VERSION < 0x040000 557 556 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;565 557 #else 566 558 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(); 575 561 576 562 fHelpArea = new QTextEdit(splitter); 577 563 fHelpArea->setReadOnly(true); 578 564 579 G4int treeSize = treeTop->GetTreeEntry();580 #if QT_VERSION < 0x040000581 QListViewItem * newItem;582 #else583 QTreeWidgetItem * newItem;584 #endif585 for (int a=0;a<treeSize;a++) {586 // Creating new item587 588 #if QT_VERSION < 0x040000589 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 #else593 //FIXME : Qt 4.2594 // 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.0599 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 #endif603 604 605 // look for childs606 CreateChildTree(newItem,treeTop->GetTree(a+1));607 // items.append(newItem);608 }609 610 611 #if QT_VERSION < 0x040000612 connect(fHelpTreeWidget, SIGNAL(selectionChanged ()),this, SLOT(HelpTreeClicCallback()));613 connect(fHelpTreeWidget, SIGNAL(doubleClicked (QListViewItem*)),this, SLOT(HelpTreeDoubleClicCallback()));614 #else615 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(HelpTreeClicCallback()));616 connect(fHelpTreeWidget, SIGNAL(itemDoubleClicked (QTreeWidgetItem*,int)),this, SLOT(HelpTreeDoubleClicCallback()));617 #endif618 619 565 // Set layouts 620 566 621 567 #if QT_VERSION >= 0x040000 622 splitter->addWidget(fHelpTreeWidget); 568 if (fHelpTreeWidget) 569 splitter->addWidget(fHelpTreeWidget); 623 570 splitter->addWidget(fHelpArea); 624 571 #endif … … 626 573 627 574 #if QT_VERSION >= 0x040000 628 vLayout->addWidget(splitter); 575 vLayout->addWidget(helpWidget); 576 vLayout->addWidget(splitter,1); 629 577 vLayout->addWidget(exitButton); 630 578 #else 631 vLayout->add(splitter); 579 vLayout->addWidget(helpWidget); 580 vLayout->add(splitter,1); 632 581 vLayout->addWidget(exitButton); 633 582 #endif … … 667 616 } 668 617 618 669 619 void G4UIQt::ActivateCommand( 670 620 G4String newCommand 671 621 ) 672 622 { 623 if (!fHelpTreeWidget) { 624 return; 625 } 673 626 // Look for the choosen command "newCommand" 674 627 size_t i = newCommand.index(" "); … … 769 722 } 770 723 } 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 734 QListView * G4UIQt::CreateHelpTree() 735 #else 736 QTreeWidget * 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 771 801 772 802 /** Fill the Help Tree Widget … … 1310 1340 } 1311 1341 1342 1312 1343 /** 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 1314 1346 */ 1315 1347 void G4UIQt::lookForHelpStringCallback( 1316 1348 ) 1317 1349 { 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 1319 1362 // the help tree 1320 1363 G4UImanager* UI = G4UImanager::GetUIpointer(); 1321 1364 if(UI==NULL) return; 1322 1365 G4UIcommandTree * treeTop = UI->GetTree(); 1323 #ifdef GEANT4_QT_DEBUG1324 printf("1111 %s\n",helpLine->text().toStdString().c_str());1325 #endif1326 1366 1327 1367 G4int treeSize = treeTop->GetTreeEntry(); 1368 1369 // clear old help tree 1370 fHelpTreeWidget->clear(); 1371 1372 // look for new items 1373 1328 1374 int tmp = 0; 1375 QMap<int,QString> commandResultMap; 1376 QMap<int,QString> commandChildResultMap; 1377 1329 1378 for (int a=0;a<treeSize;a++) { 1330 1379 #ifdef GEANT4_QT_DEBUG … … 1334 1383 tmp = GetCommandList (command).count(helpLine->text(),Qt::CaseInsensitive); 1335 1384 if (tmp >0) { 1385 commandResultMap.insertMulti(tmp,QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data())); 1336 1386 #ifdef GEANT4_QT_DEBUG 1337 1387 printf("Command %s match %d times \n",(char*)(treeTop->GetTree(a+1)->GetPathName()).data(),tmp); … … 1339 1389 } 1340 1390 // 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 1480 QMap<int,QString> G4UIQt::LookForHelpStringInChildTree( 1347 1481 G4UIcommandTree *aCommandTree 1348 1349 )1350 { 1351 Q Hash<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 1354 1488 // Get the Sub directories 1355 1489 int tmp = 0; 1490 QMap<int,QString> commandChildResultMap; 1491 1356 1492 for (int a=0;a<aCommandTree->GetTreeEntry();a++) { 1357 1493 const G4UIcommand* command = aCommandTree->GetGuidance(); 1358 1494 #ifdef GEANT4_QT_DEBUG 1495 printf("Command loop \n"); 1359 1496 // printf("Command %s\n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()); 1360 1497 // printf("%s \n",GetCommandList (command).toStdString().c_str()); … … 1362 1499 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); 1363 1500 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())); 1365 1502 #ifdef GEANT4_QT_DEBUG 1366 1503 printf("---Command %s match %d times \n",(char*)(aCommandTree->GetTree(a+1)->GetPathName()).data(),tmp); … … 1368 1505 } 1369 1506 // 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 } 1373 1520 // Get the Commands 1374 1521 1375 1522 for (int a=0;a<aCommandTree->GetCommandEntry();a++) { 1376 1523 const G4UIcommand* command = aCommandTree->GetCommand(a+1); 1377 1524 #ifdef GEANT4_QT_DEBUG 1378 // printf("Command Finale %s\n");1525 printf("Command Finale debut\n"); 1379 1526 // printf("%s \n",GetCommandList (command).toStdString().c_str()); 1380 1527 #endif 1381 1528 tmp = GetCommandList (command).count(text,Qt::CaseInsensitive); 1382 1529 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())); 1384 1531 #ifdef GEANT4_QT_DEBUG 1385 1532 printf("---Command Finale %s match %d times \n",(char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data(),tmp); … … 1388 1535 1389 1536 } 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.