Salome HOME
It removes SketchShapePlugin from plugins
[modules/shaper.git] / src / ModuleBase / ModuleBase_PageBase.cpp
1 /*
2  * ModuleBase_PageBase.cpp
3  *
4  *  Created on: Mar 4, 2015
5  *      Author: sbh
6  */
7
8 #include <ModuleBase_PageBase.h>
9 #include <ModuleBase_ModelWidget.h>
10
11 #include <QLayout>
12
13 class QWidget;
14
15 ModuleBase_PageBase::ModuleBase_PageBase()
16 {
17
18 }
19
20 ModuleBase_PageBase::~ModuleBase_PageBase()
21 {
22
23 }
24
25 QWidget* ModuleBase_PageBase::pageWidget()
26 {
27   return dynamic_cast<QWidget*>(this);
28 }
29
30 void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget)
31 {
32   placeModelWidget(theWidget);
33   myWidgetList.append(theWidget);
34 }
35
36 void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage)
37 {
38   placePageWidget(thePage);
39 }
40
41 void ModuleBase_PageBase::clearPage()
42 {
43   myWidgetList.clear();
44
45   QLayoutItem *aChild;
46   while ((aChild = pageLayout()->takeAt(0)) != 0) {
47     if(aChild->widget()) {
48       delete aChild->widget();
49     } else {
50       delete aChild;
51     }
52   }
53
54   // Issue #460: this patch is necessary since the row stretch information
55   // is stored independently on the items: when the items are removed
56   // from the layout the stretch information is kept, so in the next 
57   // filling of the layout some "additional" (old) rows may be stretched
58   // without necessity. 
59   // In this patch we clear the stretch information specifying the default value: 0.
60   QGridLayout* aLayout = dynamic_cast<QGridLayout*>( pageLayout() );
61   if( aLayout )
62   {
63     int r = aLayout->rowCount();
64     for( int i=0; i<r; i++ )
65       aLayout->setRowStretch( i, 0 );
66   }
67 }
68
69
70 bool ModuleBase_PageBase::takeFocus()
71 {
72   if(myWidgetList.isEmpty())
73     return false;
74
75   return myWidgetList.first()->focusTo();
76 }
77
78 QList<ModuleBase_ModelWidget*> ModuleBase_PageBase::modelWidgets()
79 {
80   return myWidgetList;
81 }
82
83 void ModuleBase_PageBase::alignToTop()
84 {
85   bool hasExpanding = false;
86   QList<QWidget *> aListToCheck;
87   ModuleBase_ModelWidget* aModelWidget;
88   foreach(aModelWidget, myWidgetList) {
89     aListToCheck << aModelWidget->getControls();
90   }
91   foreach(QWidget* eachWidget, aListToCheck) {
92     QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
93     if(aVPolicy & QSizePolicy::ExpandFlag) {
94       hasExpanding = true;
95       break;
96     }
97   }
98   if(!hasExpanding) {
99     addPageStretch();
100   }
101 }