X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetMultiSelector.cpp;h=40149e343af3eaa76486ab8e32c62541712a22ed;hb=8cd56d486b6e96b8814002f9f0f4acadd6cea11b;hp=a7025605a33498387f021540810e65fd46cfad20;hpb=8f09d362a50ccbc085841c24af2e755121e458ba;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index a7025605a..40149e343 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -15,8 +15,6 @@ #include #include -#include - #include #include #include @@ -34,18 +32,25 @@ #include #include #include +#include #include #include +/** +* Customization of a List Widget to make it to be placed on full width of container +*/ class CustomListWidget : public QListWidget { public: + /// Constructor + /// \param theParent a parent widget CustomListWidget( QWidget* theParent ) : QListWidget( theParent ) { } + /// Redefinition of virtual method virtual QSize sizeHint() const { int aHeight = 2*QFontMetrics( font() ).height(); @@ -53,12 +58,24 @@ public: return QSize( aSize.width(), aHeight ); } + /// Redefinition of virtual method virtual QSize minimumSizeHint() const { - int aHeight = 2*QFontMetrics( font() ).height(); + int aHeight = 4/*2*/*QFontMetrics( font() ).height(); QSize aSize = QListWidget::minimumSizeHint(); return QSize( aSize.width(), aHeight ); } + +#ifndef WIN32 +// The code is necessary only for Linux because +//it can not update viewport on widget resize +protected: + void resizeEvent(QResizeEvent* theEvent) + { + QListWidget::resizeEvent(theEvent); + QTimer::singleShot(5, viewport(), SLOT(repaint())); + } +#endif }; ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent, @@ -79,14 +96,15 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen std::string aPropertyTypes = theData->getProperty("type_choice"); QString aTypesStr = aPropertyTypes.c_str(); - QStringList aShapeTypes = aTypesStr.split(' '); + QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts); myIsUseChoice = theData->getBooleanAttribute("use_choice", true); - myTypeCombo->addItems(aShapeTypes); + if (!aShapeTypes.empty()) + myTypeCombo->addItems(aShapeTypes); aMainLay->addWidget(myTypeCombo, 0, 1); // if the xml definition contains one type, the controls to select a type should not be shown - if (aShapeTypes.size() == 1 || !myIsUseChoice) { + if (aShapeTypes.size() <= 1 || !myIsUseChoice) { aTypeLabel->setVisible(false); myTypeCombo->setVisible(false); } @@ -96,7 +114,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen : tr("Selected objects:"), this); aMainLay->addWidget(aListLabel, 1, 0); // if the xml definition contains one type, an information label should be shown near to the latest - if (aShapeTypes.size() == 1) { + if (aShapeTypes.size() <= 1) { QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); if (!aLabelIcon.isEmpty()) { QLabel* aSelectedLabel = new QLabel("", this); @@ -107,6 +125,9 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen } myListControl = new CustomListWidget(this); + QString anObjName = QString::fromStdString(attributeID()); + myListControl->setObjectName(anObjName); + aMainLay->addWidget(myListControl, 2, 0, 1, -1); aMainLay->setRowStretch(2, 1); //aMainLay->addWidget(new QLabel(this)); //FIXME(sbh)??? @@ -193,11 +214,9 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid) else { AttributeRefListPtr aRefListAttr = myFeature->data()->reflist(attributeID()); // restore objects in the attribute. Indeed there is only one stored object -#ifdef DEBUG_REFLIST int aCountAppened = aRefListAttr->size() - mySelectionCount; for (int i = 0; i < aCountAppened; i++) aRefListAttr->removeLast(); -#endif } } @@ -300,8 +319,7 @@ QList ModuleBase_WidgetMultiSelector::getControls() const //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { - activateSelection(true); - activateFilters(true); + activateSelectionAndFilters(true); QList anEmptyList; // This method will call Selection changed event which will call onSelectionChanged // To clear mySelection, myListControl and storeValue() @@ -314,7 +332,8 @@ void ModuleBase_WidgetMultiSelector::updateFocus() // Set focus to List control in order to make possible // to use Tab key for transfer the focus to next widgets myListControl->setCurrentRow(myListControl->model()->rowCount() - 1); - myListControl->setFocus(); + ModuleBase_Tools::setFocus(myListControl, + "ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()"); } //******************************************************************** @@ -332,7 +351,10 @@ QIntList ModuleBase_WidgetMultiSelector::getShapeTypes() const } else { for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) { - aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i))); + TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)); + aShapeTypes.append(aType); + if (aType == TopAbs_SOLID) + aShapeTypes.append(TopAbs_COMPSOLID); } } return aShapeTypes; @@ -347,14 +369,12 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum aShapeTypeName = myTypeCombo->itemText(idx); TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName); if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) { - activateSelection(false); - activateFilters(false); + activateSelectionAndFilters(false); bool isBlocked = myTypeCombo->blockSignals(true); myTypeCombo->setCurrentIndex(idx); myTypeCombo->blockSignals(isBlocked); - activateSelection(true); - activateFilters(true); + activateSelectionAndFilters(true); break; } }