Back to index

salome-gui  6.5.0
OB_Browser.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : OB_Browser.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 
00026 #include "OB_Browser.h"
00027 
00028 //#include "OB_Filter.h"
00029 //#include "OB_ListItem.h"
00030 //#include "OB_ListView.h"
00031 
00032 #include <QtxTreeView.h>
00033 #include <QtxSearchTool.h>
00034 //#include <SUIT_DataObjectIterator.h>
00035 
00036 #include <QAction>
00037 #include <QMenu>
00038 #include <QItemSelection>
00039 #include <QKeyEvent>
00040 #include <QVBoxLayout>
00041 #include <QAbstractItemModel>
00042 #include <QAbstractItemDelegate>
00043 #include <QHeaderView>
00044 
00045 #include <time.h>
00046 
00047 
00053 //TODO: ToolTip commented - to be removed or revised
00054 /*
00055 class OB_Browser::ToolTip : public QToolTip
00056 {
00057 public:
00058   ToolTip( OB_Browser* b, QWidget* p = 0 );
00059   virtual ~ToolTip();
00060 
00061   void        maybeTip( const QPoint& );
00062 
00063 private:
00064   OB_Browser* myBrowser;
00065 };
00066 */
00070 /*
00071 OB_Browser::ToolTip::ToolTip( OB_Browser* b, QWidget* p )
00072 : QToolTip( p ),
00073 myBrowser( b )
00074 {
00075 }
00076 */
00080 /*
00081 OB_Browser::ToolTip::~ToolTip()
00082 {
00083 }
00084 */
00091 /*
00092 void OB_Browser::ToolTip::maybeTip( const QPoint& pos )
00093 {
00094   if ( !parentWidget() || !myBrowser || !myBrowser->isShowToolTips() )
00095           return;
00096 
00097   QListView* lv = myBrowser->listView();
00098 
00099   QListViewItem* item = lv->itemAt( pos );
00100   SUIT_DataObject* obj = myBrowser->dataObject( item );
00101   if ( !obj )
00102     return;
00103 
00104   QString aText = obj->toolTip();
00105 
00106   if ( aText.isEmpty() )
00107     return;
00108 
00109   QRect aRect = lv->itemRect( item );
00110 
00111   tip( aRect, aText );
00112 }
00113 */
00114 
00115 
00136 OB_Browser::OB_Browser( QWidget* parent, QAbstractItemModel* model )
00137 : QWidget( parent ),
00138   myAutoOpenLevel( 0 )
00139 {
00140   // set-up tree view
00141   myView = new QtxTreeView( this );                                  // create tree view
00142   myView->setRootIsDecorated( true );                                // show root item
00143   myView->setSelectionMode( QAbstractItemView::ExtendedSelection );  // enable extended selection mode
00144   myView->setAllColumnsShowFocus( true );                            // focus is shown in all columns
00145 
00146   // enable drag-n-drop support
00147   myView->setDragDropMode( QAbstractItemView::DragDrop );            // enable both drag and drop operations
00148   myView->setDropIndicatorShown( true );                             // show drag indicator on dragging
00149 
00150   // set-up search tool
00151   mySearchTool = new QtxSearchTool( this, myView );                  // create search tool
00152   mySearchTool->setFrameStyle( QFrame::NoFrame | QFrame::Plain );    // do not show frame
00153   mySearchTool->setActivators( QtxSearchTool::StandardKey | QtxSearchTool::SlashKey ); // set activation mode
00154   mySearchTool->setSearcher( new QtxTreeViewSearcher( myView ) );    // assign searcher (for tree view)
00155   
00156   // layout widgets
00157   QVBoxLayout* main = new QVBoxLayout( this );
00158   main->addWidget( myView );
00159   main->addWidget( mySearchTool );
00160   main->setMargin( 0 );
00161   main->setSpacing( 3 );
00162 
00163   // TODO: decide what to do with tooltip
00164   //myShowToolTips = true;
00165   //myTooltip = new ToolTip( this, myView->viewport() );
00166 
00167   // TODO: drag-n-drop works differently - SUIT_TreeModel to be updated
00168   // and QTreeView needs some setup
00169   //connect( myView, SIGNAL( dropped( QPtrList<QListViewItem>, QListViewItem*, int ) ),
00170   //         this, SLOT( onDropped( QPtrList<QListViewItem>, QListViewItem*, int ) ) );
00171   setModel( model );
00172 
00173   connect( myView, SIGNAL( selectionChanged() ),
00174            this,   SIGNAL( selectionChanged() ) );
00175 }
00176 
00180 OB_Browser::~OB_Browser()
00181 {
00182   //delete myTooltip;
00183   //setUpdater( 0 );
00184 }
00185 
00191 QAbstractItemModel* OB_Browser::model() const
00192 {
00193   return myView->model();
00194 }
00195 
00201 void OB_Browser::setModel( QAbstractItemModel* model )
00202 {
00203   myView->setModel( model );
00204   myView->update();
00205   setModified();
00206 }
00207 
00213 QAbstractItemDelegate* OB_Browser::itemDelegate() const
00214 {
00215   return myView->itemDelegate();
00216 }
00217 
00223 void OB_Browser::setItemDelegate( QAbstractItemDelegate* d )
00224 {
00225   myView->setItemDelegate( d );
00226 }
00227 
00233 bool OB_Browser::rootIsDecorated() const
00234 {
00235   return myView->rootIsDecorated();
00236 }
00237 
00243 void OB_Browser::setRootIsDecorated( const bool decor )
00244 {
00245   if ( decor != rootIsDecorated() )
00246     myView->setRootIsDecorated( decor );
00247 }
00248 
00249 /*
00250   \brief Check if "Sorting" popup menu command for the header is enabled.
00251   \return \c true if "Sorting" menu command is enabled
00252   \sa setSortMenuEnabled()
00253 */
00254 bool OB_Browser::sortMenuEnabled() const
00255 {
00256   return myView->sortMenuEnabled();
00257 }
00258 
00259 /*
00260   \brief Enable/disable "Sorting" popup menu command for the header.
00261   \param enableSortMenu if \c true, enable "Sorting" menu command
00262   \sa sortMenuEnabled()
00263 */
00264 void OB_Browser::setSortMenuEnabled( const bool enabled )
00265 {
00266   if ( enabled != sortMenuEnabled() )
00267     myView->setSortMenuEnabled( enabled );
00268 }
00269 
00275 QtxSearchTool* OB_Browser::searchTool() const
00276 {
00277   return mySearchTool;
00278 }
00279 
00285 bool OB_Browser::isSearchToolEnabled() const
00286 {
00287   return mySearchTool->isEnabled();
00288 }
00289 
00295 void OB_Browser::setSearchToolEnabled( const bool enable )
00296 {
00297   if ( mySearchTool->isEnabled() == enable )
00298     return;
00299 
00300   mySearchTool->setEnabled( enable );
00301   if ( !mySearchTool->isEnabled() )
00302     mySearchTool->hide();
00303 }
00304 
00311 int OB_Browser::autoOpenLevel() const
00312 {
00313   return myAutoOpenLevel;
00314 }
00315 
00322 void OB_Browser::setAutoOpenLevel( const int levels )
00323 {
00324   if ( myAutoOpenLevel != levels )
00325     myAutoOpenLevel = levels;
00326 }
00327 
00336 void OB_Browser::openLevels( const int levels )
00337 {
00338   myView->expandLevels( levels < 0 ? autoOpenLevel() : levels );
00339 }
00340 
00344 /*
00345 bool OB_Browser::isShowToolTips()
00346 {
00347   return myShowToolTips;
00348 }
00349 */
00354 /*
00355 void OB_Browser::setShowToolTips( const bool theDisplay )
00356 {
00357   myShowToolTips = theDisplay;
00358 }
00359 */
00360 
00365 int OB_Browser::numberOfSelected() const
00366 {
00367   // we take selection by rows
00368   return myView->selectionModel() ? myView->selectionModel()->selectedRows().count() : 0;
00369 }
00370 
00375 QModelIndexList OB_Browser::selectedIndexes() const
00376 {
00377   // we take selection by rows
00378   return myView->selectionModel() ? myView->selectionModel()->selectedRows() : QModelIndexList();
00379 }
00380 
00385 const QItemSelection OB_Browser::selection() const
00386 {
00387   static QItemSelection emptySel;
00388   QItemSelection sel = emptySel;
00389   if ( myView->selectionModel() )
00390     sel = myView->selectionModel()->selection();
00391   return sel;
00392 }
00393 
00401 void OB_Browser::select( const QModelIndex& index, const bool on, const bool keepSelection )
00402 {
00403   if ( myView->selectionModel() ) {
00404     QItemSelectionModel::SelectionFlags f = on ? QItemSelectionModel::Select : QItemSelectionModel::Deselect;
00405     f = f | QItemSelectionModel::Rows;
00406     if ( !keepSelection )
00407       f = f | QItemSelectionModel::Clear;
00408 
00409     myView->selectionModel()->select( index, f );
00410   }
00411 }
00412 
00420 void OB_Browser::select( const QModelIndexList& indexes, const bool on, const bool keepSelection )
00421 {
00422   bool blocked = myView->signalsBlocked();
00423   myView->blockSignals( true );
00424 
00425   QModelIndex idx;
00426 
00427   if ( !indexes.isEmpty() ) {
00428     QItemSelection mysel;
00429     // select by range if indexes are contiguous
00430     QModelIndex first=indexes.at(0);
00431     QModelIndex last=first;
00432     if (indexes.size() > 1) {
00433       for (int i = 1; i < indexes.size(); ++i) 
00434       {
00435         idx=indexes.at(i);
00436         if(idx.parent().internalId()==last.parent().internalId() && idx.row()==last.row()+1 && idx.column()==last.column())
00437         {
00438           // index is contiguous to last: extend the range
00439           last=idx;
00440         }
00441         else
00442         {
00443           // index idx is not contiguous: create a new range
00444           mysel.select(first,last);
00445           first=idx;
00446           last=idx;
00447         }
00448       }
00449     }
00450     mysel.select(first,last);
00451 
00452     if ( myView->selectionModel() ) {
00453       QItemSelectionModel::SelectionFlags f = on ? QItemSelectionModel::Select : QItemSelectionModel::Deselect;
00454       f = f | QItemSelectionModel::Rows;
00455       if ( !keepSelection )
00456         f = f | QItemSelectionModel::Clear;
00457       myView->selectionModel()->select( mysel, f );
00458     }
00459   }
00460   else if ( !keepSelection )
00461   {
00462     myView->clearSelection();
00463   }
00464 
00465   myView->blockSignals( blocked );
00466   emit( selectionChanged() );
00467 }
00468 
00475 bool OB_Browser::isOpen( const QModelIndex& index ) const
00476 {
00477   return index.isValid() && model() && model()->hasChildren( index ) && myView->isExpanded( index );
00478 }
00479 
00486 void OB_Browser::setOpen( const QModelIndex& index, const bool open )
00487 {
00488   myView->setExpanded( index, open );  // hasChildren() ???
00489 }
00490 
00494 void OB_Browser::adjustWidth()
00495 {
00496   myView->resizeColumnToEncloseContents( 0 );
00497 }
00498 
00502 void OB_Browser::adjustFirstColumnWidth()
00503 {
00504   myView->resizeColumnToEncloseContents( 0 );
00505 }
00506 
00510 void OB_Browser::adjustColumnsWidth()
00511 {
00512   for ( int aCol = 1; aCol < myView->header()->count(); aCol++ ) {
00513     if ( myView->columnWidth( aCol ) > 0 )
00514       myView->resizeColumnToEncloseContents( aCol );
00515   }
00516 }
00517 
00522 /* TODO: removed - QTreeView::indexAt() should be used
00523 SUIT_DataObject* OB_Browser::dataObjectAt( const QPoint& pos ) const
00524 {
00525   SUIT_DataObject* obj = 0;
00526 
00527   QListView* lv = listView();
00528   if ( lv )
00529     obj = dataObject( lv->itemAt( pos ) );
00530 
00531   return obj;
00532 }
00533 */
00537 /* TODO: removed
00538 OB_Filter* OB_Browser::filter() const
00539 {
00540   return myView->filter();
00541 }
00542 */
00547 /* TODO: removed
00548 void OB_Browser::setFilter( OB_Filter* f )
00549 {
00550   myView->setFilter( f );
00551 }
00552 */
00557 /* TODO: removed
00558 void OB_Browser::setWidthMode( QListView::WidthMode mode )
00559 {
00560   for ( int i = 0, n = myView->columns(); i < n; i++ )
00561     if( mode!=QListView::Maximum || myView->columnWidth( i )>0 )
00562       myView->setColumnWidthMode( i, mode );
00563 }
00564 */
00571 /* TODO: removed
00572 void OB_Browser::updateTree( SUIT_DataObject* obj, const bool autoOpen )
00573 {
00574 //  QTime t1 = QTime::currentTime();
00575 
00576   if ( !obj && !(obj = getRootObject()) )
00577     return;
00578 
00579   DataObjectKey curKey;
00580   DataObjectMap selObjs, openObjs;
00581   DataObjectKeyMap selKeys, openKeys;
00582 
00583   int selNum = numberOfSelected();
00584 
00585   SUIT_DataObject* curObj = storeState( selObjs, openObjs, selKeys, openKeys, curKey );
00586 
00587   updateView( obj );
00588 
00589   restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey );
00590 
00591   if ( autoOpen )
00592     autoOpenBranches();
00593 
00594   setModified();
00595 
00596   if ( selNum != numberOfSelected() )
00597     emit selectionChanged();
00598 
00599 //  QTime t2 = QTime::currentTime();
00600 //  qDebug( QString( "update tree time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) );
00601 }
00602 */
00606 /* TODO: removed
00607 void OB_Browser::replaceTree( SUIT_DataObject* src, SUIT_DataObject* trg )
00608 {
00609   if ( !src || !trg || src == trg || src->root() != getRootObject() )
00610     return;
00611 
00612   DataObjectKey curKey;
00613   DataObjectMap selObjs, openObjs;
00614   DataObjectKeyMap selKeys, openKeys;
00615 
00616   int selNum = numberOfSelected();
00617 
00618   SUIT_DataObject* curObj = storeState( selObjs, openObjs, selKeys, openKeys, curKey );
00619 
00620   SUIT_DataObject* parent = src->parent();
00621   int pos = parent ? parent->childPos( src ) : -1;
00622 
00623   src->setParent( 0 );
00624 
00625   removeConnections( src );
00626   if ( isAutoDeleteObjects() )
00627     delete src;
00628 
00629   if ( parent && pos != -1 )
00630     parent->insertChild( trg, pos );
00631 
00632   trg->setParent( parent );
00633 
00634   updateView( trg );
00635   createConnections( trg );
00636 
00637   restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey );
00638 
00639   setModified();
00640 
00641   if ( selNum != numberOfSelected() )
00642     emit selectionChanged();
00643 }
00644 */
00649 /*
00650 void OB_Browser::adjustWidth( QListViewItem* item )
00651 {
00652   while ( item )
00653   {
00654     item->widthChanged( 0 );
00655     if ( item->isOpen() )
00656       adjustWidth( item->firstChild() );
00657     item = item->nextSibling();
00658   }
00659 }
00660 */
00661 
00665 /* TODO:
00666 void OB_Browser::removeReferences( QListViewItem* item )
00667 {
00668   if ( !item )
00669     return;
00670 
00671   SUIT_DataObject* obj = dataObject( item );
00672   obj->disconnect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
00673   myItems.remove( obj );
00674 
00675   QListViewItem* i = item->firstChild();
00676   while ( i )
00677   {
00678     removeReferences( i );
00679     i = i->nextSibling();
00680   }
00681 }
00682 */
00686 /* TODO: move to SUIT_TreeModel
00687 void OB_Browser::createConnections( SUIT_DataObject* obj )
00688 {
00689   if ( !obj )
00690     return;
00691 
00692   DataObjectList childList;
00693   obj->children( childList, true );
00694 
00695   childList.prepend( obj );
00696 
00697   for ( DataObjectListIterator it( childList ); it.current(); ++it )
00698     it.current()->connect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
00699 }
00700 */
00704 /* TODO: move to SUIT_TreeModel
00705 void OB_Browser::removeConnections( SUIT_DataObject* obj )
00706 {
00707   if ( !obj )
00708     return;
00709 
00710   DataObjectList childList;
00711   obj->children( childList, true );
00712 
00713   childList.prepend( obj );
00714 
00715   for ( DataObjectListIterator it( childList ); it.current(); ++it )
00716     it.current()->disconnect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
00717 }
00718 */
00726 /* TODO: to be revised
00727 SUIT_DataObject* OB_Browser::storeState( DataObjectMap& selObjs, DataObjectMap& openObjs,
00728                                          DataObjectKeyMap& selKeys, DataObjectKeyMap& openKeys,
00729                                          DataObjectKey& curKey ) const
00730 {
00731   QListView* lv = listView();
00732   if ( !lv )
00733     return 0;
00734 
00735   SUIT_DataObject* curObj = dataObject( lv->currentItem() );
00736 
00737   curKey = objectKey( curObj );
00738 
00739   for ( QListViewItemIterator it( lv ); it.current(); ++it )
00740   {
00741     SUIT_DataObject* obj = dataObject( it.current() );
00742     if ( !obj )
00743       continue;
00744 
00745     selObjs.insert( obj, lv->isSelected( it.current() ) );
00746     openObjs.insert( obj, lv->isOpen( it.current() ) );
00747     if ( lv->isSelected( it.current() ) )
00748       selKeys.insert( objectKey( obj ), 0 );
00749     if ( lv->isOpen( it.current() ) )
00750       openKeys.insert( objectKey( obj ), 0 );
00751   }
00752 
00753   return curObj;
00754 }
00755 */
00762 /* TODO: to be revised
00763 void OB_Browser::restoreState( const DataObjectMap& selObjs, const DataObjectMap& openObjs,
00764                                const SUIT_DataObject* curObj, const DataObjectKeyMap& selKeys,
00765                                const DataObjectKeyMap& openKeys, const DataObjectKey& curKey )
00766 {
00767   QListView* lv = listView();
00768   if ( !lv )
00769     return;
00770 
00771   bool block = lv->signalsBlocked();
00772   lv->blockSignals( true );
00773 
00774   QListViewItem* curItem = 0;
00775   for ( QListViewItemIterator it( lv ); it.current(); ++it )
00776   {
00777     QListViewItem* item = it.current();
00778     SUIT_DataObject* obj = dataObject( item );
00779 
00780     if ( !obj )
00781       continue;
00782 
00783     DataObjectKey key = objectKey( obj );
00784 
00785     if ( selObjs.contains( obj ) )
00786     {
00787       if ( selObjs[obj] && !lv->isSelected( item ) )
00788         lv->setSelected( item, true );
00789     }
00790     else if ( !key.isNull() && selKeys.contains( key ) && !lv->isSelected( item ) )
00791       lv->setSelected( item, true );
00792 
00793     if ( openObjs.contains( obj ) )
00794     {
00795       bool parentOpen = true;
00796       if( item && item->parent() )
00797         parentOpen = item->parent()->isOpen();
00798 
00799       if ( openObjs[obj] && parentOpen )
00800         lv->setOpen( item, true );
00801     }
00802     else if ( !key.isNull() && openKeys.contains( key ) )
00803     {
00804       bool parentOpen = true;
00805       if( item && item->parent() )
00806         parentOpen = item->parent()->isOpen();
00807 
00808       if( parentOpen )
00809         lv->setOpen( item, true );
00810     }
00811 
00812     if ( !curItem && ( curObj == obj || ( !curKey.isNull() && curKey == key )) )
00813       curItem = item;
00814   }
00815 
00816   if ( curItem )
00817     lv->setCurrentItem( curItem );
00818 
00819   lv->blockSignals( block );
00820 }
00821 */
00825 /* TODO: move to SUIT_TreeModel
00826 OB_Browser::DataObjectKey OB_Browser::objectKey( QListViewItem* i ) const
00827 {
00828   return objectKey( dataObject( i ) );
00829 }
00830 */
00834 /* TODO: move to SUIT_TreeModel
00835 OB_Browser::DataObjectKey OB_Browser::objectKey( SUIT_DataObject* obj ) const
00836 {
00837   if ( !obj )
00838     return 0;
00839 
00840   return DataObjectKey( obj->key() );
00841 }
00842 */
00843 
00848 QtxTreeView* OB_Browser::treeView() const
00849 {
00850   return myView;
00851 }
00852 
00857 void OB_Browser::contextMenuEvent( QContextMenuEvent* e )
00858 {
00859   QMenu* popup = new QMenu();
00860   
00861   createPopupMenu( popup );
00862 
00863   Qtx::simplifySeparators( popup );
00864 
00865   if ( !popup->actions().isEmpty() )
00866     popup->exec( e->globalPos() );
00867   delete popup;
00868 }
00869 
00874 unsigned long OB_Browser::getModifiedTime() const
00875 { 
00876   return myModifiedTime; 
00877 }
00878 
00882 void OB_Browser::setModified()
00883 {
00884   myModifiedTime = clock();
00885 }
00886 
00892 void OB_Browser::onExpandAll()
00893 {
00894   QModelIndexList indexes = selectedIndexes();
00895   QModelIndex index;
00896 
00897   foreach ( index, indexes ) {
00898     myView->expandAll( index );
00899   }
00900 }
00901 
00907 void OB_Browser::onCollapseAll()
00908 {
00909   QModelIndexList indexes = selectedIndexes();
00910   QModelIndex index;
00911 
00912   foreach ( index, indexes ) {
00913     myView->collapseAll( index );
00914   }
00915 }
00916 
00920 /* TODO: moved to SUIT_TreeModel
00921 void OB_Browser::onDestroyed( SUIT_DataObject* obj )
00922 {
00923   removeObject( obj );
00924 }
00925 */
00932   // TODO: drag-n-drop works differently - SUIT_TreeModel to be updated
00933   // and QTreeView needs some setup
00934 /*
00935 void OB_Browser::onDropped( QPtrList<QListViewItem> items, QListViewItem* item, int action )
00936 {
00937   SUIT_DataObject* obj = dataObject( item );
00938   if ( !obj )
00939     return;
00940 
00941   DataObjectList lst;
00942   for ( QPtrListIterator<QListViewItem> it( items ); it.current(); ++it )
00943   {
00944     SUIT_DataObject* o = dataObject( it.current() );
00945     if ( o )
00946       lst.append( o );
00947   }
00948 
00949   if ( !lst.isEmpty() )
00950     emit dropped( lst, obj, action );
00951 }
00952 */
00956 /* TODO: to be removed
00957 void OB_Browser::updateText()
00958 {
00959   if ( myColumnIds.isEmpty() )
00960     return;
00961 
00962   QListView* lv = listView();
00963   if ( !lv )
00964     return;
00965 
00966   for ( QListViewItemIterator it( lv ); it.current(); ++it )
00967   {
00968     SUIT_DataObject* obj = dataObject( it.current() );
00969     if ( !obj )
00970       continue;
00971 
00972     for( QMap<int, int>::iterator itr = myColumnIds.begin(); itr != myColumnIds.end(); ++itr )
00973       it.current()->setText( itr.data(), obj->text( itr.key() ) );
00974   }
00975 }
00976 */
00981 /* TODO: to be revised
00982 bool OB_Browser::needToUpdateTexts( QListViewItem* item ) const
00983 {
00984   SUIT_DataObject* obj = dataObject( item );
00985   if ( !obj )
00986     return false;
00987 
00988   for( QMap<int, int>::const_iterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
00989     if( item->text( it.data() ) != obj->text( it.key() ) )
00990       return true;
00991   return false;
00992 }
00993 */
00998 /* TODO: to be revised
00999 void OB_Browser::updateText( QListViewItem* item )
01000 {
01001   SUIT_DataObject* obj = dataObject( item );
01002   if ( !obj )
01003     return;
01004 
01005   for( QMap<int, int>::iterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
01006     item->setText( it.data(), obj->text( it.key() ) );
01007 }
01008 */
01009 
01014 void OB_Browser::createPopupMenu( QMenu* menu )
01015 {
01016   menu->addSeparator();
01017 
01018   QModelIndexList indexes = selectedIndexes();
01019 
01020   bool closed = false, opened = false;
01021   
01022   for ( QModelIndexList::Iterator it = indexes.begin(); 
01023         it != indexes.end() && !closed; ++it ) {
01024     closed = hasCollased( *it );
01025   }
01026 
01027   for ( QModelIndexList::Iterator it = indexes.begin(); 
01028         it != indexes.end() && !opened; ++it ) {
01029     opened = hasExpanded( *it );
01030   }
01031 
01032   if ( closed )
01033     menu->addAction( tr( "MEN_EXPAND_ALL" ), this, SLOT( onExpandAll() ) );
01034   if ( opened )
01035     menu->addAction( tr( "MEN_COLLAPSE_ALL" ), this, SLOT( onCollapseAll() ) );
01036 
01037   if ( isSearchToolEnabled() ) {
01038     menu->addSeparator();
01039     menu->addAction( tr( "MEN_FIND" ), searchTool(), SLOT( find() ), QKeySequence(Qt::CTRL + Qt::Key_F) );
01040     menu->addSeparator();
01041   }
01042 }
01043 
01047 /* TODO: to be revised
01048 void OB_Browser::expand( QListViewItem* item )
01049 {
01050   if ( !item )
01051     return;
01052 
01053   item->setOpen( true );
01054   for ( QListViewItem* child = item->firstChild(); child; child = child->nextSibling() )
01055     expand( child );
01056 }
01057 */
01062 bool OB_Browser::hasCollased( const QModelIndex& index ) const
01063 {
01064   bool result = false;
01065 
01066   if ( index.isValid() && model() ) {
01067     bool hasChildren = model()->hasChildren( index );
01068     result = hasChildren && !myView->isExpanded( index );
01069     if ( !result && hasChildren ) {
01070       int rows = model()->rowCount( index );
01071       for ( int i = 0; i < rows && !result; i ++ ) {
01072         QModelIndex child = model()->index( i, 0, index );
01073         result = hasCollased( child );
01074       }
01075     }
01076   }
01077   return result;
01078 }
01079 
01084 bool OB_Browser::hasExpanded( const QModelIndex& index ) const
01085 {
01086   bool result = false;
01087 
01088   if ( index.isValid() && model() ) {
01089     bool hasChildren = model()->hasChildren( index );
01090     result = hasChildren && myView->isExpanded( index );
01091     if ( !result && hasChildren ) {
01092       int rows = model()->rowCount( index );
01093       for ( int i = 0; i < rows && !result; i ++ ) {
01094         QModelIndex child = model()->index( i, 0, index );
01095         result = hasExpanded( child );
01096       }
01097     }
01098   }
01099   return result;
01100 }
01101 
01107 /* TODO: moved to SUIT_TreeModel
01108 void OB_Browser::removeObject( SUIT_DataObject* obj, const bool autoUpd )
01109 {
01110   if ( !obj )
01111     return;
01112 
01113   // Removing list view items from <myItems> recursively for all children.
01114   // Otherwise, "delete item" line will destroy all item's children,
01115   // and <myItems> will contain invalid pointers (see ~QListViewItem() description in Qt docs)
01116   DataObjectList childList;
01117   obj->children( childList, true );
01118   for ( DataObjectListIterator it( childList ); it.current(); ++it )
01119   {
01120     it.current()->disconnect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
01121     myItems.remove( it.current() );
01122   }
01123 
01124   QListViewItem* item = listViewItem( obj );
01125 
01126   obj->disconnect( this, SLOT( onDestroyed( SUIT_DataObject* ) ) );
01127   myItems.remove( obj );
01128 
01129   if ( obj == myRoot )
01130   {
01131     // remove all child list view items
01132     setRootObject( 0 );
01133     return;
01134   }
01135 
01136   if( !autoUpd )
01137     return;
01138 
01139   if ( isAutoUpdate() )
01140   {
01141     SUIT_DataObject* pObj = item && item->parent() ? dataObject( item->parent() ) : 0;
01142     updateTree( pObj, false );
01143   }
01144 
01145   delete item;
01146 }
01147 */
01152 /* TODO: to be revised
01153 void OB_Browser::autoOpenBranches()
01154 {
01155   openLevels();
01156 }
01157 */
01163 /* TODO: to be revised
01164 void OB_Browser::openBranch( QListViewItem* item, const int level )
01165 {
01166   if ( level < 1 )
01167     return;
01168 
01169   while ( item )
01170   {
01171     item->setOpen( true );
01172     openBranch( item->firstChild(), level - 1 );
01173     item = item->nextSibling();
01174   }
01175 }
01176 */
01180 /* TODO: to be revised
01181 void OB_Browser::onDoubleClicked( QListViewItem* item )
01182 {
01183   if ( item )
01184     emit doubleClicked( dataObject( item ) );
01185 }
01186 */
01187