From 3030bd03de602f7b907e0bcc43e6aaf8c1c09fb4 Mon Sep 17 00:00:00 2001 From: san Date: Tue, 20 Mar 2007 17:35:10 +0000 Subject: [PATCH] STL collections used to simplify possible Qt 4 porting show()/hide() interface and update logic added --- src/QxGraph/QxGraph_Prs.cxx | 65 +++++++++++++++++++++++++++++-- src/QxGraph/QxGraph_Prs.h | 24 ++++++++---- src/QxGraph/QxGraph_ViewModel.cxx | 12 ------ src/QxGraph/QxGraph_ViewModel.h | 2 - 4 files changed, 79 insertions(+), 24 deletions(-) diff --git a/src/QxGraph/QxGraph_Prs.cxx b/src/QxGraph/QxGraph_Prs.cxx index 81ff0ebb7..ef453e4b0 100644 --- a/src/QxGraph/QxGraph_Prs.cxx +++ b/src/QxGraph/QxGraph_Prs.cxx @@ -32,7 +32,8 @@ */ QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas): myCanvas(theCanvas), - myDMode(0) + myDMode(0), + needUpdate(true) { myCanvas->addPrs(this); } @@ -51,9 +52,67 @@ QxGraph_Prs::~QxGraph_Prs() void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode) { if ( theDMode == -1 ) // add item for the current display mode - myDisplayMap[myDMode].append(theItem); + myDisplayMap[myDMode].push_back(theItem); else - myDisplayMap[theDMode].append(theItem); + myDisplayMap[theDMode].push_back(theItem); +} + +/*! Adds all the items of this presentation for the current display mode + * to the canvas. + */ +void QxGraph_Prs::show() +{ + if ( isToUpdate() ) + update(); + + for ( std::list::iterator it = myDisplayMap[myDMode].begin(); + it != myDisplayMap[myDMode].end(); + it++ ) + { + QCanvasItem* anItem = *it; + if ( anItem ) + { + anItem->setCanvas( myCanvas ); + anItem->show(); + } + } +} + +/*! Removes all the items belonging to this presentation from the canvas. + */ +void QxGraph_Prs::hide() +{ + for ( DMode2ItemList::iterator it1 = myDisplayMap.begin(); + it1 != myDisplayMap.end(); + it1++ ) + { + for ( std::list::iterator it2 = (*it1).second.begin(); + it2 != (*it1).second.end(); + it2++ ) + { + QCanvasItem* anItem = *it2; + if ( anItem ) + { + anItem->setCanvas( 0 ); + } + } + } +} + +/*! Prepare for full recomputation of the presentation + */ +void QxGraph_Prs::setToUpdate( const bool theFlag ) +{ + needUpdate = theFlag; +} + +/*! Re-fills the presentation with items. + * Base implementation just resets flag. + * It should be called at the end by re-implementations. + */ +void QxGraph_Prs::update() +{ + setToUpdate( false ); } /*! diff --git a/src/QxGraph/QxGraph_Prs.h b/src/QxGraph/QxGraph_Prs.h index 34bf24bcc..4b7a40fa9 100644 --- a/src/QxGraph/QxGraph_Prs.h +++ b/src/QxGraph/QxGraph_Prs.h @@ -19,11 +19,11 @@ #ifndef QXGRAPH_PRS_H #define QXGRAPH_PRS_H -#include "QxGraph.h" +#include #include -#include -#include +#include +#include class QxGraph_Canvas; @@ -33,6 +33,8 @@ class QXGRAPH_EXPORT QxGraph_Prs QxGraph_Prs(QxGraph_Canvas*); virtual ~QxGraph_Prs(); + QxGraph_Canvas* getCanvas() const { return myCanvas; } + void addItem(QCanvasItem* theItem, int theDMode = -1); /* add items for display mode theDMode @@ -43,20 +45,28 @@ class QXGRAPH_EXPORT QxGraph_Prs QCanvasItem* addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode = -1); QCanvasItem* addTextItem(QString theText, int theDMode = -1); - typedef QMap< int, QPtrList > DMode2ItemList; + typedef std::map< int, std::list > DMode2ItemList; const DMode2ItemList& getDisplayMap() const { return myDisplayMap; } - const QPtrList& getItems(int theDMode) { return myDisplayMap[theDMode]; } + const std::list& getItems(int theDMode) { return myDisplayMap[theDMode]; } void setDMode(int theDMode) { myDMode = theDMode; } int getDMode() const { return myDMode; } - private: + virtual void show(); + virtual void hide(); + virtual void setToUpdate( const bool ); + bool isToUpdate() { return needUpdate; } + +protected: + virtual void update(); + +private: QxGraph_Canvas* myCanvas; DMode2ItemList myDisplayMap; int myDMode; - + bool needUpdate; }; #endif diff --git a/src/QxGraph/QxGraph_ViewModel.cxx b/src/QxGraph/QxGraph_ViewModel.cxx index 8a85cf55d..166ceac33 100644 --- a/src/QxGraph/QxGraph_ViewModel.cxx +++ b/src/QxGraph/QxGraph_ViewModel.cxx @@ -65,10 +65,6 @@ void QxGraph_Viewer::initView( QxGraph_ViewWindow* view ) { view->initLayout(); - // for debug only (CreatePrs() must be called from YACSGui_Displayer) ---> - QxGraph_Prs* aPrs = CreatePrs(); - //aPrs->setDMode(YACSGui_Displayer::Full); from enumeration in Displayer - /* // test add items into the current canvas view QRect aRect(100,200,200,100); @@ -159,11 +155,3 @@ void QxGraph_Viewer::onShowToolbar() { if ( aView ) aView->getToolBar()->show(); } - -/*! - Create QxGraph_Prs object for the myCanvas -*/ -QxGraph_Prs* QxGraph_Viewer::CreatePrs() -{ - return new QxGraph_Prs(myCanvas); -} diff --git a/src/QxGraph/QxGraph_ViewModel.h b/src/QxGraph/QxGraph_ViewModel.h index fab15d582..e04fcb35e 100644 --- a/src/QxGraph/QxGraph_ViewModel.h +++ b/src/QxGraph/QxGraph_ViewModel.h @@ -63,8 +63,6 @@ class QXGRAPH_EXPORT QxGraph_Viewer: public SUIT_ViewModel void setCurrentView(QxGraph_CanvasView* theView) { myCurrentView = theView; } void setCurrentView(int theIndex); - QxGraph_Prs* CreatePrs(); - protected: void initView(QxGraph_ViewWindow* view); -- 2.39.2