From 8d54f199bd9ead3c2f0c704322975198e65264d6 Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 15 Aug 2014 14:23:59 +0400 Subject: [PATCH] refs #416: to store the open state of object browser items in the binary array --- src/ObjBrowser/OB_Browser.cxx | 60 +++++++++++++++++++++++++++++++++++ src/ObjBrowser/OB_Browser.h | 6 ++++ 2 files changed, 66 insertions(+) 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* ); -- 2.39.2