*/
QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas):
myCanvas(theCanvas),
- myDMode(0)
+ myDMode(0),
+ needUpdate(true)
{
myCanvas->addPrs(this);
}
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<QCanvasItem*>::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<QCanvasItem*>::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 <needUpdate> flag.
+ * It should be called at the end by re-implementations.
+ */
+void QxGraph_Prs::update()
+{
+ setToUpdate( false );
}
/*!
#ifndef QXGRAPH_PRS_H
#define QXGRAPH_PRS_H
-#include "QxGraph.h"
+#include <QxGraph.h>
#include <qcanvas.h>
-#include <qmap.h>
-#include <qptrlist.h>
+#include <map>
+#include <list>
class QxGraph_Canvas;
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
QCanvasItem* addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode = -1);
QCanvasItem* addTextItem(QString theText, int theDMode = -1);
- typedef QMap< int, QPtrList<QCanvasItem> > DMode2ItemList;
+ typedef std::map< int, std::list<QCanvasItem*> > DMode2ItemList;
const DMode2ItemList& getDisplayMap() const { return myDisplayMap; }
- const QPtrList<QCanvasItem>& getItems(int theDMode) { return myDisplayMap[theDMode]; }
+ const std::list<QCanvasItem*>& 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
{
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);
if ( aView )
aView->getToolBar()->show();
}
-
-/*!
- Create QxGraph_Prs object for the myCanvas
-*/
-QxGraph_Prs* QxGraph_Viewer::CreatePrs()
-{
- return new QxGraph_Prs(myCanvas);
-}
void setCurrentView(QxGraph_CanvasView* theView) { myCurrentView = theView; }
void setCurrentView(int theIndex);
- QxGraph_Prs* CreatePrs();
-
protected:
void initView(QxGraph_ViewWindow* view);