Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / QxGraph / QxGraph_Canvas.cxx
1 //  SALOME QxGraph : build Supervisor viewer into desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "QxGraph_Canvas.h"
24 #include "QxGraph_Def.h"
25 #include "QxGraph_Prs.h"
26
27 #include <SUIT_ResourceMgr.h>
28
29 #include <qobjectlist.h>
30 #include <QxGraph_CanvasView.h>
31
32 /*!
33   Constructor
34 */
35 QxGraph_Canvas::QxGraph_Canvas(SUIT_ResourceMgr* theMgr) :
36   QCanvas()
37 {
38   printf("Construct QxGraph_Canvas\n");
39
40   resize(GRAPH_WIDTH, GRAPH_HEIGHT);
41   setDoubleBuffering(true);
42
43   QColor aColor = theMgr->colorValue( "QxGraph", "Background", DEF_BACK_COLOR );
44   setBackgroundColor(aColor);
45 }
46
47 /*!
48   Destructor
49 */
50 QxGraph_Canvas::~QxGraph_Canvas()
51 {
52   /*QObjectList* aNodeList = queryList("QObject");
53   QObjectListIt aIt(*aNodeList);
54   QObject* anObj;
55   while ( (anObj = aIt.current()) != 0 ) {
56     ++aIt;
57     aNodeList->removeRef(anObj);
58     delete anObj;
59   }
60   delete aNodeList;*/
61
62   myPrsList.setAutoDelete(true);
63   myPrsList.clear();
64 }
65
66 /*!
67   Add view
68 */
69 void QxGraph_Canvas::addView(QCanvasView* theView)
70 {
71   myViews.append( theView );
72   QCanvas::addView(theView);
73   theView->setPaletteBackgroundColor(backgroundColor().light(120)); 
74 }
75
76 /*!
77   Remove view
78 */
79 void QxGraph_Canvas::removeView( QCanvasView* theView )
80 {
81   myViews.remove( theView );
82 }
83
84 /*!
85   Remove item
86 */
87 void QxGraph_Canvas::removeItem( QCanvasItem* theItem )
88 {
89   QValueList< QCanvasView* >::iterator anIter;
90   for ( anIter = myViews.begin(); anIter != myViews.end(); ++anIter )
91   {
92     QxGraph_CanvasView* aView = dynamic_cast<QxGraph_CanvasView*>( *anIter );
93     if ( aView )
94       aView->itemRemoved( theItem );
95   }
96
97   QCanvas::removeItem( theItem );
98 }
99
100 /*!
101   Get Prs object with index theIndex
102 */
103 QxGraph_Prs* QxGraph_Canvas::getPrs(int theIndex)
104 {
105   QxGraph_Prs* aRetPrs = 0;
106   if ( theIndex >= 0 && theIndex < myPrsList.count() )
107     aRetPrs = myPrsList.at(theIndex);
108   return aRetPrs;
109 }