<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <!--
<switch id="CreationMethod">
- <case id="PlaneByFaceAndDistance">
- -->
- <shape_selector id="planeFace"
- label="Plane face"
- tooltip="Select a planar face"
- shape_types="face">
- <selection_filter id="FaceFilter" parameters="plane"/>
- </shape_selector>
- <doublevalue id="distance"
- label="Distance"
- tooltip="Distance from selected face to plane"
+ <case id="PlaneByFaceAndDistance" title="On some distance from a face">
+ <shape_selector id="planeFace"
+ label="Plane face"
+ tooltip="Select a planar face"
+ shape_types="face">
+ <selection_filter id="FaceFilter" parameters="plane"/>
+ </shape_selector>
+ <doublevalue id="distance"
+ label="Distance"
+ tooltip="Distance from selected face to plane"
default="0" />
-<!--
</case>
- <case id="PlaneByGeneralEquation">
+ <case id="PlaneByGeneralEquation" title="By palne equation parameters">
<doublevalue id="A"
label="A:"
tooltip="The A parameter from general plane equation (Ax+By+Cz+D=0)"
default="0" />
</case>
</switch>
- -->
</source>
ModuleBase_WidgetDoubleValue.h
ModuleBase_WidgetEditor.h
ModuleBase_WidgetFactory.h
- ModuleBase_WidgetSwitch.h
ModuleBase_WidgetShapeSelector.h
ModuleBase_IWorkshop.h
ModuleBase_Definitions.h
ModuleBase_IPrefMgr.h
ModuleBase_Preferences.h
ModuleBase_ActionInfo.h
- ModuleBase_WidgetToolbox.h
ModuleBase_PageBase.h
ModuleBase_PageWidget.h
ModuleBase_PageGroupBox.h
+ ModuleBase_PagedContainer.h
+ ModuleBase_WidgetSwitch.h
+ ModuleBase_WidgetToolbox.h
ModuleBase_WidgetValidated.h
)
ModuleBase_WidgetDoubleValue.cpp
ModuleBase_WidgetEditor.cpp
ModuleBase_WidgetFactory.cpp
- ModuleBase_WidgetSwitch.cpp
ModuleBase_WidgetShapeSelector.cpp
ModuleBase_WidgetChoice.cpp
ModuleBase_WidgetFileSelector.cpp
ModuleBase_WidgetLabel.cpp
ModuleBase_Preferences.cpp
ModuleBase_ActionInfo.cpp
- ModuleBase_WidgetToolbox.cpp
ModuleBase_PageBase.cpp
ModuleBase_PageWidget.cpp
ModuleBase_PageGroupBox.cpp
+ ModuleBase_PagedContainer.cpp
+ ModuleBase_WidgetSwitch.cpp
+ ModuleBase_WidgetToolbox.cpp
ModuleBase_WidgetValidated.cpp
)
--- /dev/null
+/*
+ * ModuleBase_PagedContainer.cpp
+ *
+ * Created on: Mar 13, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_PagedContainer.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+
+#include <QWidget>
+#include <Qlist>
+#include <QVBoxLayout>
+
+
+ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId),
+ myIsFocusOnCurrentPage(false)
+{
+}
+
+ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
+{
+}
+
+int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
+ const QString& theName, const QString& theCaseId)
+{
+ myCaseIds << theCaseId;
+ myPages << thePage;
+ return myPages.count();
+}
+
+QList<QWidget*> ModuleBase_PagedContainer::getControls() const
+{
+ QList<QWidget*> aResult;
+ int anIndex = currentPageIndex();
+ QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
+ foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
+ aResult << eachModelWidget->getControls();
+ }
+ return aResult;
+}
+
+bool ModuleBase_PagedContainer::focusTo()
+{
+ int anIndex = currentPageIndex();
+ if (anIndex > myPages.count())
+ return false;
+ return myPages[anIndex]->takeFocus();
+}
+
+void ModuleBase_PagedContainer::setHighlighted(bool)
+{
+ //page containers should not be highlighted, do nothing
+}
+
+void ModuleBase_PagedContainer::enableFocusProcessing()
+{
+ myIsFocusOnCurrentPage = true;
+}
+
+bool ModuleBase_PagedContainer::restoreValue()
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeStringPtr aStringAttr = aData->string(attributeID());
+ QString aCaseId = QString::fromStdString(aStringAttr->value());
+ int idx = myCaseIds.indexOf(aCaseId);
+ if (idx == -1)
+ return false;
+ setCurrentPageIndex(idx);
+ return true;
+}
+
+void ModuleBase_PagedContainer::activateCustom()
+{
+ // activate current page
+ focusTo();
+}
+
+bool ModuleBase_PagedContainer::storeValueCustom() const
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeStringPtr aStringAttr = aData->string(attributeID());
+ QString aWidgetValue = myCaseIds.at(currentPageIndex());
+ aStringAttr->setValue(aWidgetValue.toStdString());
+ return true;
+}
+
+
+void ModuleBase_PagedContainer::onPageChanged()
+{
+ storeValue();
+ if (myIsFocusOnCurrentPage) focusTo();
+}
+
+
--- /dev/null
+/*
+ * ModuleBase_PagedContainer.h
+ *
+ * Created on: Mar 13, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEDCONTAINER_H_
+#define MODULEBASE_PAGEDCONTAINER_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+class ModuleBase_PageBase;
+
+class MODULEBASE_EXPORT ModuleBase_PagedContainer : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+ public:
+ ModuleBase_PagedContainer(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+ virtual ~ModuleBase_PagedContainer();
+
+ virtual int addPage(ModuleBase_PageBase* theWidget,
+ const QString& theName, const QString& theCaseId);
+ // ModuleBase_ModelWidget
+ virtual QList<QWidget*> getControls() const;
+ virtual bool focusTo();
+ virtual void setHighlighted(bool isHighlighted);
+ virtual void enableFocusProcessing();
+ virtual bool restoreValue();
+
+ protected:
+ virtual int currentPageIndex() const = 0;
+ virtual void setCurrentPageIndex(int ) = 0;
+ // ModuleBase_ModelWidget
+ virtual void activateCustom();
+ virtual bool storeValueCustom() const;
+
+ protected slots:
+ void onPageChanged();
+
+ private:
+ bool myIsFocusOnCurrentPage;
+ QStringList myCaseIds;
+ QList<ModuleBase_PageBase*> myPages;
+
+};
+
+#endif /* MODULEBASE_PAGEDCONTAINER_H_ */
QString aCaseId = qs(myWidgetApi->getProperty(_ID));
ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
createWidget(aPage);
- QWidget* aCasePageWidget = dynamic_cast<QWidget*>(aPage);
- if (aWdgType == WDG_SWITCH) {
- ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
- aSwitch->addPage(aCasePageWidget, aPageName);
- } else if (aWdgType == WDG_TOOLBOX) {
- ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
- aToolbox->addPage(aPage, aPageName, aCaseId);
+ if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) {
+ ModuleBase_PagedContainer* aContainer = qobject_cast<ModuleBase_PagedContainer*>(aWidget);
+ aContainer->addPage(aPage, aPageName, aCaseId);
}
} while (myWidgetApi->toNextWidget());
}
#include <ModuleBase_WidgetSwitch.h>
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_PageBase.h>
+#include <ModuleBase_Tools.h>
#include <QComboBox>
-#include <QVBoxLayout>
+#include <QFrame>
#include <QSpacerItem>
-
+#include <QStackedLayout>
+#include <QVBoxLayout>
ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId)
-: ModuleBase_ModelWidget(theParent, theData, theParentId)
+: ModuleBase_PagedContainer(theParent, theData, theParentId)
{
- myMainLay = new QVBoxLayout(this);
- myMainLay->setContentsMargins(2, 4, 2, 2);
+ QVBoxLayout* aMainLay = new QVBoxLayout(this);
+ //aMainLay->setContentsMargins(2, 4, 2, 2);
+ ModuleBase_Tools::adjustMargins(aMainLay);
myCombo = new QComboBox(this);
myCombo->hide();
- myMainLay->addWidget(myCombo);
- //this->setFrameShape(QFrame::StyledPanel);
- connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
- connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
+ myPagesLayout = new QStackedLayout(this);
+ aMainLay->addWidget(myCombo);
+ aMainLay->addLayout(myPagesLayout, 1);
+ setLayout(aMainLay);
+ connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
+ connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
}
ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
{
}
-QList<QWidget*> ModuleBase_WidgetSwitch::getControls() const
-{
- QList<QWidget*> aList;
- aList << myCombo;
- return aList;
-}
-
-int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
-{
- return insertPage(count(), theWidget, theName);
-}
-
-int ModuleBase_WidgetSwitch::count() const
-{
- return myCombo->count();
-}
-
-int ModuleBase_WidgetSwitch::currentIndex() const
-{
- return myCombo->currentIndex();
-}
-
-QWidget* ModuleBase_WidgetSwitch::currentWidget() const
-{
- int idx = currentIndex();
- return myCases[idx];
-}
-
-int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
-{
- return myCases.indexOf(theWidget);
-}
-int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
+int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
+ const QString& theCaseId)
{
- int index = theIndex < count() ? theIndex : count();
- if (count() == 0)
+ int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId);
+ myCombo->addItem(theName);
+ int aResultCount = myCombo->count();
+ if (aResultCount == 1)
myCombo->show();
- myCombo->insertItem(index, theName);
- myCases.insert(index, theWidget);
- myMainLay->addWidget(theWidget);
- setCurrentIndex(theIndex);
- return index;
+ QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
+ aFrame->setFrameShape(QFrame::Box);
+ aFrame->setFrameStyle(QFrame::Sunken);
+ myPagesLayout->addWidget(aFrame);
+ return aResultCount;
}
-bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
+int ModuleBase_WidgetSwitch::currentPageIndex() const
{
- return myCases[index]->isEnabled();
+ int aComboIndex = myCombo->currentIndex();
+ return aComboIndex;
}
-QString ModuleBase_WidgetSwitch::pageText(int index) const
-{
- return myCombo->itemText(index);
-}
-
-QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
-{
- return myCases[index]->toolTip();
-}
-
-void ModuleBase_WidgetSwitch::removePage(int index)
-{
- myCombo->removeItem(index);
- myCases.removeAt(index);
- if (count() == 0) {
- myCombo->hide();
- }
-}
-
-void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
-{
- myCases[index]->setEnabled(enabled);
-}
-
-void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
-{
- myCombo->setItemText(index, theName);
-}
-
-void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
-{
- myCases[index]->setToolTip(toolTip);
-}
-
-void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
-{
- myCombo->setCurrentIndex(index);
- refresh();
-}
-void ModuleBase_WidgetSwitch::refresh()
+void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
{
- foreach(QWidget* eachWidget, myCases)
- {
- eachWidget->setVisible(false);
- }
- if (currentIndex() >= myCases.count())
- return;
- myCases[currentIndex()]->setVisible(true);
+ bool isComboSignalsBlocked = myCombo->blockSignals(true);
+ bool isPagesLayoutSignalsBlocked = myPagesLayout->blockSignals(true);
+ myCombo->setCurrentIndex(theIndex);
+ myPagesLayout->setCurrentIndex(theIndex);
+ myCombo->blockSignals(isComboSignalsBlocked);
+ myPagesLayout->blockSignals(isPagesLayoutSignalsBlocked);
}
* Author: sbh
*/
-#ifndef ModuleBase_WidgetSwitch_H_
-#define ModuleBase_WidgetSwitch_H_
+#ifndef MODULEBASE_WIDGETSWITCH_H_
+#define MODULEBASE_WIDGETSWITCH_H_
#include <ModuleBase.h>
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_PagedContainer.h>
class QComboBox;
-class QVBoxLayout;
+class QStackedLayout;
/**
* \ingroup GUI
* Implements a model widget for swithch as a container widget. It can be defined in XML with "switch" keyword
*/
-class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_ModelWidget
+class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_PagedContainer
{
Q_OBJECT
public:
const std::string& theParentId);
virtual ~ModuleBase_WidgetSwitch();
- virtual bool restoreValue() {
- return false;
- }
-
- virtual QList<QWidget*> getControls() const;
-
- virtual bool focusTo() {
- return false;
- }
-
/// Add a page to the widget
/// \param theWidget a page widget
/// \param theName a name of page
- int addPage(QWidget* theWidget, const QString & theName);
-
- /// Returns count of pages
- int count() const;
-
- /// Returns index of current page
- int currentIndex() const;
-
- /// Returns current widget (page)
- QWidget * currentWidget() const;
-
- /// Returns index of widget (page)
- /// \param theWidget a widget page
- int indexOf(QWidget * theWidget) const;
-
- /// Insert page
- /// \param index an index (position) to insert
- /// \param theWidget a page widget
- /// \param theName a name of the page
- int insertPage(int index, QWidget * theWidget, const QString & theName);
-
- /// Returns True if a page by given index is enabled
- /// \param index index of the page
- bool isPageEnabled(int index) const;
-
- /// Returns text of the page by its id
- /// \param index index of the page
- QString pageText(int index) const;
-
- /// Returns tooltip of the page by its id
- /// \param index index of the page
- QString pageToolTip(int index) const;
+ virtual int addPage(ModuleBase_PageBase* theWidget,
+ const QString& theName, const QString& theCaseId);
- /// Remove page by its id
- /// \param index index of the page
- void removePage(int index);
-
- /// Enale/disable a page by its Id
- /// \param index index of the page
- /// \param enabled an enable flag
- void setPageEnabled(int index, bool enabled);
-
- /// Set page name
- /// \param index index of the page
- /// \param text a name of the page
- void setPageName(int index, const QString & text);
-
- /// Set page tooltip
- /// \param index index of the page
- /// \param toolTip a tooltip of the page
- void setPageToolTip(int index, const QString & toolTip);
-
- public slots:
+ protected:
+ virtual int currentPageIndex() const;
/// Set current page by index
/// \param index index of the page
- void setCurrentIndex(int index);
-
-signals:
- /// Emitted on current page change
- void currentPageChanged(int);
-
- protected:
- virtual bool storeValueCustom() const {
- return false;
- }
- /// Update widget
- void refresh();
+ virtual void setCurrentPageIndex(int index);
private:
- /// Layout
- QVBoxLayout* myMainLay;
-
/// Combo box
QComboBox* myCombo;
-
- /// List of pages
- QWidgetList myCases;
+ QStackedLayout* myPagesLayout;
};
#endif /* ModuleBase_WidgetSwitch_H_ */
#include <ModelAPI_AttributeString.h>
#include <QWidget>
-#include <Qlist>
+#include <QList>
#include <QVBoxLayout>
ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId)
-: ModuleBase_ModelWidget(theParent, theData, theParentId),
- myIsPassFocusToCurrentPage(false)
+: ModuleBase_PagedContainer(theParent, theData, theParentId)
{
QVBoxLayout* aMainLayout = new QVBoxLayout(this);
ModuleBase_Tools::zeroMargins(aMainLayout);
int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
const QString& theName, const QString& theCaseId)
{
- myCaseIds << theCaseId;
- myPages << thePage;
+ ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId);
QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
aFrame->setFrameShape(QFrame::Box);
aFrame->setFrameStyle(QFrame::Sunken);
- return myToolBox->addItem(aFrame, theName);
+ myToolBox->addItem(aFrame, theName);
+ return myToolBox->count();
}
-bool ModuleBase_WidgetToolbox::restoreValue()
+int ModuleBase_WidgetToolbox::currentPageIndex() const
{
- // A rare case when plugin was not loaded.
- if(!myFeature)
- return false;
- DataPtr aData = myFeature->data();
- AttributeStringPtr aStringAttr = aData->string(attributeID());
- QString aCaseId = QString::fromStdString(aStringAttr->value());
- int idx = myCaseIds.indexOf(aCaseId);
- if (idx == -1)
- return false;
- bool isSignalsBlocked = myToolBox->blockSignals(true);
- myToolBox->setCurrentIndex(idx);
- myToolBox->blockSignals(isSignalsBlocked);
- return true;
-}
-
-QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
-{
- QList<QWidget*> aResult;
- int idx = myToolBox->currentIndex();
- QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[idx]->modelWidgets();
- foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
- aResult << eachModelWidget->getControls();
- }
- return aResult;
-}
-
-bool ModuleBase_WidgetToolbox::focusTo()
-{
- int idx = myToolBox->currentIndex();
- if (idx > myPages.count())
- return false;
- return myPages[idx]->takeFocus();
-}
-
-void ModuleBase_WidgetToolbox::setHighlighted(bool)
-{
- //page containers sould not be highlighted, do nothing
+ return myToolBox->currentIndex();
}
-void ModuleBase_WidgetToolbox::enableFocusProcessing()
+void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
{
- myIsPassFocusToCurrentPage = true;
-}
-
-
-void ModuleBase_WidgetToolbox::activateCustom()
-{
- // activate current page
- focusTo();
+ bool isSignalsBlocked = myToolBox->blockSignals(true);
+ myToolBox->setCurrentIndex(theIndex);
+ myToolBox->blockSignals(isSignalsBlocked);
}
-bool ModuleBase_WidgetToolbox::storeValueCustom() const
-{
- // A rare case when plugin was not loaded.
- if(!myFeature)
- return false;
- DataPtr aData = myFeature->data();
- AttributeStringPtr aStringAttr = aData->string(attributeID());
- QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
- aStringAttr->setValue(aWidgetValue.toStdString());
- return true;
-}
-void ModuleBase_WidgetToolbox::onPageChanged()
-{
- storeValue();
- if (myIsPassFocusToCurrentPage) focusTo();
-}
#ifndef MODULEBASE_WIDGETTOOLBOX_H_
#define MODULEBASE_WIDGETTOOLBOX_H_
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase.h>
+#include <ModuleBase_PagedContainer.h>
#include <QToolBox>
class ModuleBase_PageBase;
-class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
+class MODULEBASE_EXPORT ModuleBase_WidgetToolbox : public ModuleBase_PagedContainer
{
Q_OBJECT
public:
ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
const std::string& theParentId);
virtual ~ModuleBase_WidgetToolbox();
-
- virtual bool restoreValue();
- virtual QList<QWidget*> getControls() const;
- virtual bool focusTo();
- virtual void setHighlighted(bool isHighlighted);
- virtual void enableFocusProcessing();
-
+ /// Overrides ModuleBase_PagedContainer
int addPage(ModuleBase_PageBase* theWidget,
const QString& theName, const QString& theCaseId);
protected:
- virtual void activateCustom();
- virtual bool storeValueCustom() const;
-
- protected slots:
- void onPageChanged();
+ /// Implements ModuleBase_PagedContainer
+ virtual int currentPageIndex() const;
+ /// Implements ModuleBase_PagedContainer
+ virtual void setCurrentPageIndex(int);
private:
- bool myIsPassFocusToCurrentPage;
QToolBox* myToolBox;
- QStringList myCaseIds;
- QList<ModuleBase_PageBase*> myPages;
};
#endif /* MODULEBASE_WIDGETTOOLBOX_H_ */