1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetSwitch.cpp
6 * Created on: Apr 16, 2014
10 #include <ModuleBase_WidgetSwitch.h>
11 #include <ModuleBase_ModelWidget.h>
12 #include <ModuleBase_PageBase.h>
15 #include <QVBoxLayout>
16 #include <QSpacerItem>
19 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
20 const std::string& theParentId)
21 : ModuleBase_ModelWidget(theParent, theData, theParentId)
23 myMainLay = new QVBoxLayout(this);
24 myMainLay->setContentsMargins(2, 4, 2, 2);
25 myCombo = new QComboBox(this);
27 myMainLay->addWidget(myCombo);
28 //this->setFrameShape(QFrame::StyledPanel);
29 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
30 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
34 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
38 QList<QWidget*> ModuleBase_WidgetSwitch::getControls() const
40 QList<QWidget*> aList;
45 int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
47 return insertPage(count(), theWidget, theName);
50 int ModuleBase_WidgetSwitch::count() const
52 return myCombo->count();
55 int ModuleBase_WidgetSwitch::currentIndex() const
57 return myCombo->currentIndex();
60 QWidget* ModuleBase_WidgetSwitch::currentWidget() const
62 int idx = currentIndex();
66 int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
68 return myCases.indexOf(theWidget);
71 int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
73 int index = theIndex < count() ? theIndex : count();
76 myCombo->insertItem(index, theName);
77 myCases.insert(index, theWidget);
78 myMainLay->addWidget(theWidget);
79 setCurrentIndex(theIndex);
83 bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
85 return myCases[index]->isEnabled();
88 QString ModuleBase_WidgetSwitch::pageText(int index) const
90 return myCombo->itemText(index);
93 QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
95 return myCases[index]->toolTip();
98 void ModuleBase_WidgetSwitch::removePage(int index)
100 myCombo->removeItem(index);
101 myCases.removeAt(index);
107 void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
109 myCases[index]->setEnabled(enabled);
112 void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
114 myCombo->setItemText(index, theName);
117 void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
119 myCases[index]->setToolTip(toolTip);
122 void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
124 myCombo->setCurrentIndex(index);
128 void ModuleBase_WidgetSwitch::refresh()
130 foreach(QWidget* eachWidget, myCases)
132 eachWidget->setVisible(false);
134 if (currentIndex() >= myCases.count())
136 myCases[currentIndex()]->setVisible(true);