From: asl Date: Fri, 15 Aug 2014 10:23:59 +0000 (+0400) Subject: refs #416: to store the open state of object browser items in the binary array X-Git-Tag: V7_5_0a1~18^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e62f4a6e7757ba72bd52587564ea6a111129ea2e;p=modules%2Fgui.git refs #416: to store the open state of object browser items in the binary array --- diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 8211d2ed9..20634584a 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -1194,3 +1194,63 @@ void OB_Browser::onDoubleClicked( QListViewItem* item ) \fn void OB_Browser::selectionChanged(); \brief Emitted when selection is changed in the Object Browser. */ + +QByteArray OB_Browser::getOpenStates( int theColumn ) const +{ + QByteArray aData; + QDataStream aStream( &aData, QIODevice::WriteOnly ); + MapOfOpenStates aMap; + const_cast( this )->openStates( true, aMap, QModelIndex(), theColumn ); + MapOfOpenStates::const_iterator anIt = aMap.begin(), aLast = aMap.end(); + for( ; anIt!=aLast; anIt++ ) + { + QString anEntry = anIt.key(); + qint32 anOpenAttr = anIt.value() ? 1 : 0; + aStream << anEntry << anOpenAttr; + } + return aData; +} + +void OB_Browser::setOpenStates( const QByteArray& theData, int theColumn ) +{ + QByteArray* aData = const_cast( &theData ); + QDataStream aStream( aData, QIODevice::ReadOnly ); + MapOfOpenStates aMap; + while( !aStream.atEnd() ) + { + QString anEntry; + qint32 anOpenAttr; + aStream >> anEntry >> anOpenAttr; + bool isOpen = anOpenAttr!=0; + aMap[anEntry] = isOpen; + } + openStates( false, aMap, QModelIndex(), theColumn ); +} + +void OB_Browser::openStates( bool isGet, MapOfOpenStates& theMap, const QModelIndex& theIndex, int theColumn ) +{ + if( theIndex.isValid() ) + { + QString anEntry = theIndex.sibling( theIndex.row(), theColumn ).data().toString(); + bool isOpen; + if( isGet ) + { + isOpen = treeView()->isExpanded( theIndex ); + theMap[anEntry] = isOpen; + } + else + { + isOpen = theMap.contains( anEntry ) ? theMap[anEntry] : false; + treeView()->setExpanded( theIndex, isOpen ); + } + } + + const QAbstractItemModel* aModel = model(); + + int n = aModel->rowCount( theIndex ); + for( int i=0; iindex( i, 0, theIndex ); + openStates( isGet, theMap, aChild, theColumn ); + } +} diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index 2df9ff23f..442d9b81b 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -112,6 +112,12 @@ public: QtxTreeView* treeView() const; + QByteArray getOpenStates( int theColumn ) const; + void setOpenStates( const QByteArray&, int theColumn ); + + typedef QMap MapOfOpenStates; + void openStates( bool isGet, MapOfOpenStates&, const QModelIndex& theIndex, int theColumn ); + signals: void selectionChanged(); //void doubleClicked( SUIT_DataObject* );