const static char* NODE_SELFILTER = "selection_filter";
const static char* NODE_XMLPARENT = "libxml_parent";
+// Property panels
+const static char* PROPERTY_PANEL_ID = "property_panel_id";
+
// Widgets
const static char* WDG_INFO = "label";
const static char* WDG_ERRORINFO = "error_label";
ModuleBase_IWidgetCreator::ModuleBase_IWidgetCreator()
{
-
}
ModuleBase_IWidgetCreator::~ModuleBase_IWidgetCreator()
{
+}
+
+const std::set<std::string>& ModuleBase_IWidgetCreator::panelTypes()
+{
+ return std::set<std::string>();
+}
+const std::set<std::string>& ModuleBase_IWidgetCreator::pageTypes()
+{
+ return std::set<std::string>();
+}
+
+const std::set<std::string>& ModuleBase_IWidgetCreator::widgetTypes()
+{
+ return std::set<std::string>();
}
~ModuleBase_IWidgetCreator();
/// Returns a container of possible page types, which this creator can process
- /// \returns types
- virtual const std::set<std::string>& pageTypes() = 0;
+ /// \returns list of type names
+ virtual const std::set<std::string>& panelTypes();
+
+ /// Returns a container of possible page types, which this creator can process
+ /// \returns list of type names
+ virtual const std::set<std::string>& pageTypes();
/// Returns a container of possible widget types, which this creator can process
- /// \returns types
- virtual const std::set<std::string>& widgetTypes() = 0;
+ /// \returns list of type names
+ virtual const std::set<std::string>& widgetTypes();
+
+ /// Create panel control by its type.
+ /// \param theType a panel type
+ /// \param theParent a parent widget
+ /// \return created widget or null
+ virtual QWidget* createPanelByType(const std::string& theType,
+ QWidget* theParent) {};
/// Create page by its type
/// \param theType a type
/// \param theData a low-level API for reading xml definitions of widgets
virtual ModuleBase_PageBase* createPageByType(const std::string& theType,
QWidget* theParent,
- Config_WidgetAPI* theWidgetApi) = 0;
+ Config_WidgetAPI* theWidgetApi) {};
/// Create widget by its type
/// \param theType a type
virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
QWidget* theParent,
Config_WidgetAPI* theWidgetApi,
- ModuleBase_IWorkshop* theWorkshop) = 0;
+ ModuleBase_IWorkshop* theWorkshop) {};
};
typedef std::shared_ptr<ModuleBase_IWidgetCreator> WidgetCreatorPtr;
placePageWidget(thePage);
}
+void ModuleBase_PageBase::addWidget(QWidget* theWidget)
+{
+ placeWidget(theWidget);
+}
+
void ModuleBase_PageBase::clearPage()
{
myWidgetList.clear();
addPageStretch();
}
}
+
+void ModuleBase_PageBase::placePageWidget(ModuleBase_PageBase* theWidget)
+{
+ QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
+ placeWidget(aWidget);
+}
void addModelWidget(ModuleBase_ModelWidget* theWidget);
/// Adds the given ModuleBase_PageBase to the page
void addPageWidget(ModuleBase_PageBase* theWidget);
+ /// Adds the given widget to the page
+ void addWidget(QWidget* theWidget);
/// Removes all items from page's layout
void clearPage();
/// Passes focus from page to the first ModuleBase_ModelWidget contained on the page
/// Pure Virtual. Allows to derived class to lay out the widget properly;
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0;
/// Pure Virtual. Allows to derived class to lay out the page properly;
- virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0;
+ virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+ /// Pure Virtual. Allows to derived class to lay out the page properly;
+ virtual void placeWidget(QWidget* theWidget) = 0;
/// Pure Virtual. Returns layout of the page.
virtual QLayout* pageLayout() = 0;
/// Pure Virtual. Allows to derived class to insert page stretch properly.
}
-void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
+void ModuleBase_PageGroupBox::placeWidget(QWidget* theWidget)
{
- QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
- if (!aWidget) {
+ if (!theWidget) {
#ifdef _DEBUG
std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
#endif
}
const int kCol = 0;
const int kRow = myMainLayout->count();
- myMainLayout->addWidget(aWidget, kRow, kCol);
+ myMainLayout->addWidget(theWidget, kRow, kCol);
myMainLayout->setRowStretch(kRow, 0);
}
/// Adds the given widget to page's layout
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
/// Adds the given page to page's layout
- virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+ virtual void placeWidget(QWidget* theWidget);
/// Returns page's layout (QGridLayout)
virtual QLayout* pageLayout();
/// Adds a stretch to page's layout
myMainLayout->setRowStretch(kRow, 0);
}
-void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget)
+void ModuleBase_PageWidget::placeWidget(QWidget* theWidget)
{
- QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
- if (!aWidget) {
+ if (!theWidget) {
#ifdef _DEBUG
std::cout << "ModuleBase_PageWidget::placePageWidget: can not cast page" << std::endl;
#endif
}
const int kCol = 0;
const int kRow = myMainLayout->count();
- myMainLayout->addWidget(aWidget, kRow, kCol);
+ myMainLayout->addWidget(theWidget, kRow, kCol);
myMainLayout->setRowStretch(kRow, 0);
}
/// Adds the given widget to page's layout
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
/// Adds the given page to page's layout
- virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+ virtual void placeWidget(QWidget* theWidget);
/// Returns page's layout (QGridLayout)
virtual QLayout* pageLayout();
/// Adds a stretch to page's layout
}
-void ModuleBase_WidgetCheckGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
+void ModuleBase_WidgetCheckGroupBox::placeWidget(QWidget* theWidget)
{
- QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
- if (!aWidget) {
+ if (!theWidget) {
#ifdef _DEBUG
std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
#endif
}
const int kCol = 0;
const int kRow = myMainLayout->count();
- myMainLayout->addWidget(aWidget, kRow, kCol);
+ myMainLayout->addWidget(theWidget, kRow, kCol);
myMainLayout->setRowStretch(kRow, 0);
}
/// Adds the given widget to page's layout
virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
/// Adds the given page to page's layout
- virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+ virtual void placeWidget(QWidget* theWidget);
/// Returns page's layout (QGridLayout)
virtual QLayout* pageLayout();
/// Adds a stretch to page's layout
void ModuleBase_WidgetCreatorFactory::registerCreator(const WidgetCreatorPtr& theCreator)
{
+ std::set<std::string>::const_iterator anIt, aLast;
+ /// fill map of panels
+ const std::set<std::string>& aPanelTypes = theCreator->panelTypes();
+ for (anIt = aPanelTypes.begin(), aLast = aPanelTypes.end(); anIt != aLast; anIt++) {
+ std::string aKey = *anIt;
+ if (!myPanelToCreator.contains(aKey))
+ myPanelToCreator[aKey] = theCreator;
+ else {
+ Events_Error::send("The" + aKey + " panel XML definition has been already \
+used by another widget creator");
+ }
+ }
+
+ /// fill map of widgets
const std::set<std::string>& aTypes = theCreator->widgetTypes();
- std::set<std::string>::const_iterator anIt = aTypes.begin(), aLast = aTypes.end();
- for (; anIt != aLast; anIt++) {
+ for (anIt = aTypes.begin(), aLast = aTypes.end(); anIt != aLast; anIt++) {
std::string aKey = *anIt;
if (!myCreators.contains(aKey))
myCreators[aKey] = theCreator;
}
}
+ /// fill map of pages
const std::set<std::string>& aPTypes = theCreator->pageTypes();
for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
std::string aKey = *anIt;
}
}
+bool ModuleBase_WidgetCreatorFactory::hasPanelWidget(const std::string& theType)
+{
+ return myPanelToCreator.contains(theType);
+}
+
+QWidget* ModuleBase_WidgetCreatorFactory::createPanel(const std::string& theType, QWidget* theParent)
+{
+ QWidget* aPanel = 0;
+ if (myPanelToCreator.contains(theType)) {
+ WidgetCreatorPtr aCreator = myPanelToCreator[theType];
+ aPanel = aCreator->createPanelByType(theType, theParent);
+ }
+ return aPanel;
+}
+
bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
{
return myPageToCreator.contains(theType);
/// \param theCreator a new widget creator
void registerCreator(const WidgetCreatorPtr& theCreator);
+ /// Returns true if there is a creator, which can make a panel by the type
+ /// \param theType a type
+ /// \return a boolean value
+ bool hasPanelWidget(const std::string& theType);
+
+ /// Create panel by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
+ /// \return a created panel or null
+ QWidget* createPanel(const std::string& theType, QWidget* theParent);
+
/// Returns true if there is a creator, which can make a page by the type
/// \param theType a type
+ /// \return a boolean value
bool hasPageWidget(const std::string& theType);
/// Create page by its type
/// \param theType a type
/// \param theParent a parent widget
+ /// \return a created page or null
ModuleBase_PageBase* createPageByType(const std::string& theType,
QWidget* theParent,
Config_WidgetAPI* theWidgetApi);
/// Create widget by its type
/// \param theType a type
/// \param theParent a parent widget
+ /// \return a created widget or null
ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
QWidget* theParent,
Config_WidgetAPI* theWidgetApi,
/// Constructor is hidden
ModuleBase_WidgetCreatorFactory();
- /// Map of widget type in XML to creator
- QMap<std::string, WidgetCreatorPtr> myCreators;
+ /// Map of widget panel in XML to creator
+ QMap<std::string, WidgetCreatorPtr> myPanelToCreator;
/// Map of widget page in XML to creator
QMap<std::string, WidgetCreatorPtr> myPageToCreator;
+
+ /// Map of widget type in XML to creator
+ QMap<std::string, WidgetCreatorPtr> myCreators;
};
typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
{
+ std::string aWType = myWidgetApi->widgetType();
+ if (aWType == NODE_FEATURE) {
+ QWidget* aPanel = createPanel(thePage->pageWidget());
+ thePage->addWidget(aPanel);
+ return;
+ }
+
if (!myWidgetApi->toChildWidget())
return;
} while (!theFound && myWidgetApi->toNextWidget());
}
+QWidget* ModuleBase_WidgetFactory::createPanel(QWidget* theParent)
+{
+ QWidget* aPanel = 0;
+ std::string aPanelName = myWidgetApi->getProperty(PROPERTY_PANEL_ID);
+ if (!aPanelName.empty() && ModuleBase_WidgetCreatorFactory::get()->hasPanelWidget(aPanelName))
+ aPanel = ModuleBase_WidgetCreatorFactory::get()->createPanel(aPanelName, theParent);
+ return aPanel;
+}
+
ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType,
QWidget* theParent)
{
/// check if ModuleBase_Widget has expandable widgets in getControls
bool hasExpandingControls(QWidget* theParent);
+ /// creates panel control, if the corresponded parameter is provided by feature
+ /// \param theParent a parent widget
+ /// \return true if the panel is created
+ QWidget* createPanel(QWidget* theParent);
+
/// Create page by its type
/// \param theType a type
/// \param theParent a parent widget