From 5bc218e9c82ed4e0ec75a712a411c22e9b5f2aca Mon Sep 17 00:00:00 2001 From: mpa Date: Fri, 7 Nov 2014 10:33:47 +0300 Subject: [PATCH] 0022379: EDF 2276 GEOM: Dependency Tree - added resize event for view and new method of showing tree considering a size of scene --- src/DependencyTree/DependencyTree_View.cxx | 31 +++++++++++++++++++++- src/DependencyTree/DependencyTree_View.h | 6 +++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/DependencyTree/DependencyTree_View.cxx b/src/DependencyTree/DependencyTree_View.cxx index b1afd4085..1ccb309f1 100644 --- a/src/DependencyTree/DependencyTree_View.cxx +++ b/src/DependencyTree/DependencyTree_View.cxx @@ -351,6 +351,18 @@ void DependencyTree_View::onRebuildModel() updateModel( true, false ); } +//================================================================================= +// function : resizeEvent() +// purpose : reimplemented from QGraphicsView::resizeEvent() +//================================================================================= +void DependencyTree_View::resizeEvent(QResizeEvent *event) +{ + QPointF aCenter = mapToScene( event->oldSize().width()/2, + event->oldSize().height()/2 ); + QGraphicsView::resizeEvent( event ); + centerOn( aCenter.x(),aCenter.y() ); +} + //================================================================================= // function : onUpdateModel() // purpose : slot for updating tree model for main objects in viewer @@ -689,7 +701,7 @@ void DependencyTree_View::updateView() return; drawTree(); - fitAll(); + fitWindow(); } //================================================================================= @@ -734,6 +746,23 @@ void DependencyTree_View::clearView( bool isClearModel ) } } +//================================================================================= +// function : fitWindow() +// purpose : scale the window considering a size of scene +//================================================================================= +void DependencyTree_View::fitWindow() +{ + int sizeFactor = 4; + if( objectsBoundingRect(true).width() > sizeFactor*size().width() || + objectsBoundingRect(true).height() > sizeFactor*size().width() ) { + QRectF aRect = QRectF( -sizeFactor*size().width()/2, -sizeFactor*size().height()/2, + sizeFactor*size().width(), sizeFactor*size().height() ); + fitInView( aRect, Qt::KeepAspectRatio ); + } + else + fitAll(); +} + //================================================================================= // function : getNewTreeModel() // purpose : get dependency tree model from engine diff --git a/src/DependencyTree/DependencyTree_View.h b/src/DependencyTree/DependencyTree_View.h index 298933729..94e924749 100644 --- a/src/DependencyTree/DependencyTree_View.h +++ b/src/DependencyTree/DependencyTree_View.h @@ -68,6 +68,10 @@ public slots: void onRebuildModel(); +protected: + + void resizeEvent( QResizeEvent *event ); + private slots: void onUpdateModel(); @@ -93,6 +97,8 @@ private: void updateView(); void clearView( bool ); + void fitWindow(); + int checkMaxLevelsNumber(); void getNewTreeModel( bool = true, bool = true ); -- 2.39.2