Salome HOME
Issue #901 - It is possible to define empty name for parameter
[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   QLayoutItem *aChild;
44   while ((aChild = pageLayout()->takeAt(0)) != 0) {
45     if(aChild->widget()) {
46       aChild->widget()->deleteLater();
47     } else {
48       delete aChild;
49     }
50   }
51
52   // Issue #460: this patch is necessary since the row stretch information
53   // is stored independently on the items: when the items are removed
54   // from the layout the stretch information is kept, so in the next 
55   // filling of the layout some "additional" (old) rows may be stretched
56   // without necessity. 
57   // In this patch we clear the stretch information specifying the default value: 0.
58   QGridLayout* aLayout = dynamic_cast<QGridLayout*>( pageLayout() );
59   if( aLayout )
60   {
61     int r = aLayout->rowCount();
62     for( int i=0; i<r; i++ )
63       aLayout->setRowStretch( i, 0 );
64   }
65   myWidgetList.clear();
66 }
67
68
69 bool ModuleBase_PageBase::takeFocus()
70 {
71   if(myWidgetList.isEmpty())
72     return false;
73
74   return myWidgetList.first()->focusTo();
75 }
76
77 QList<ModuleBase_ModelWidget*> ModuleBase_PageBase::modelWidgets()
78 {
79   return myWidgetList;
80 }
81
82 void ModuleBase_PageBase::alignToTop()
83 {
84   bool hasExpanding = false;
85   QList<QWidget *> aListToCheck;
86   ModuleBase_ModelWidget* aModelWidget;
87   foreach(aModelWidget, myWidgetList) {
88     aListToCheck << aModelWidget->getControls();
89   }
90   foreach(QWidget* eachWidget, aListToCheck) {
91     QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
92     if(aVPolicy & QSizePolicy::ExpandFlag) {
93       hasExpanding = true;
94       break;
95     }
96   }
97   if(!hasExpanding) {
98     addPageStretch();
99   }
100 }