X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetMultiSelector.cpp;h=5ee8ac64a38bd0bab91c132eb4b3a475fdebfac9;hb=a2982d2108f929cf9e7f996cfd590c4ce59dc21c;hp=87c62ba3909e0eae55b51f2e95a294a36b0e733b;hpb=35f0e7a2748c1ae77e4dae1a156d10ddadc10afe;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 87c62ba39..5ee8ac64a 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + /* * ModuleBase_WidgetMultiSelector.cpp * @@ -13,7 +15,6 @@ #include #include -#include #include @@ -24,8 +25,11 @@ #include #include #include +#include +#include +#include -#include +#include #include ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent, @@ -33,7 +37,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_ModelWidget(theParent, theData, theParentId), - myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false) + myWorkshop(theWorkshop), myIsActive(false) { myMainWidget = new QWidget(theParent); QGridLayout* aMainLay = new QGridLayout(myMainWidget); @@ -54,14 +58,20 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myListControl = new QListWidget(myMainWidget); aMainLay->addWidget(myListControl, 2, 0, 2, -1); - aMainLay->setColumnStretch(1, 1); + aMainLay->setRowStretch(2, 1); + aMainLay->addWidget(new QLabel(myMainWidget)); + aMainLay->setRowMinimumHeight(3, 20); myMainWidget->setLayout(aMainLay); - - //TODO: Move into the base class - myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); - //TODO_END connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged())); + myCopyAction = new QAction(QIcon(":pictures/copy.png"), tr("Copy"), this); + myCopyAction->setShortcut(QKeySequence::Copy); + myCopyAction->setEnabled(false); + connect(myCopyAction, SIGNAL(triggered(bool)), SLOT(onCopyItem())); + myListControl->addAction(myCopyAction); + myListControl->setContextMenuPolicy(Qt::ActionsContextMenu); + connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection())); + activateSelection(true); } @@ -78,7 +88,7 @@ bool ModuleBase_WidgetMultiSelector::storeValue() const return false; DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); + std::dynamic_pointer_cast(aData->attribute(attributeID())); if (aSelectionListAttr) { aSelectionListAttr->clear(); @@ -90,6 +100,7 @@ bool ModuleBase_WidgetMultiSelector::storeValue() const foreach (GeomSelection aSelec, mySelection) { aSelectionListAttr->append(aSelec.first, aSelec.second); } + //updateSelectionList(aSelectionListAttr); updateObject(myFeature); return true; } @@ -104,7 +115,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() return false; DataPtr aData = myFeature->data(); AttributeSelectionListPtr aSelectionListAttr = - boost::dynamic_pointer_cast(aData->attribute(attributeID())); + std::dynamic_pointer_cast(aData->attribute(attributeID())); if (aSelectionListAttr) { mySelection.clear(); @@ -116,7 +127,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value())); } - updateSelectionList(); + updateSelectionList(aSelectionListAttr); return true; } return false; @@ -163,7 +174,7 @@ void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate) void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { activateShapeSelection(); - QList anEmptyList; + QObjectPtrList anEmptyList; myWorkshop->setSelected(anEmptyList); // Clear mySelection, myListControl and storeValue() onSelectionChanged(); @@ -182,7 +193,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionChanged() NCollection_List::Iterator aShpIt(aSelectedShapes); GeomShapePtr aShape; for (aIt = aOwnersList.cbegin(); aIt != aOwnersList.cend(); aShpIt.Next(), aIt++) { - ResultPtr aResult = boost::dynamic_pointer_cast(*aIt); + ResultPtr aResult = std::dynamic_pointer_cast(*aIt); if (myFeature) { // We can not select a result of our feature const std::list& aResList = myFeature->results(); @@ -197,11 +208,11 @@ void ModuleBase_WidgetMultiSelector::onSelectionChanged() if(isSkipSelf) continue; } - aShape = boost::shared_ptr(new GeomAPI_Shape()); + aShape = std::shared_ptr(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aShpIt.Value())); mySelection.append(GeomSelection(aResult, aShape)); } - updateSelectionList(); + //updateSelectionList(); emit valuesChanged(); } @@ -250,25 +261,35 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection() } //******************************************************************** -void ModuleBase_WidgetMultiSelector::updateSelectionList() +void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList) { - QString aType; - if (myTypeCombo->currentText().toLower() == "vertices") - aType = "vertex"; - else if (myTypeCombo->currentText().toLower() == "edges") - aType = "edge"; - else if (myTypeCombo->currentText().toLower() == "faces") - aType = "face"; - else if (myTypeCombo->currentText().toLower() == "solids") - aType = "solid"; - myListControl->clear(); - int i = 1; - foreach (GeomSelection aSel, mySelection) { - QString aName(aSel.first->data()->name().c_str()); - aName += ":" + aType + QString("_%1").arg(i); - myListControl->addItem(aName); - i++; + for (int i = 0; i < theList->size(); i++) { + AttributeSelectionPtr aAttr = theList->value(i); + myListControl->addItem(aAttr->namingName().c_str()); + } +} + +//******************************************************************** +void ModuleBase_WidgetMultiSelector::onCopyItem() +{ + QList aItems = myListControl->selectedItems(); + QString aRes; + foreach(QListWidgetItem* aItem, aItems) { + if (!aRes.isEmpty()) + aRes += "\n"; + aRes += aItem->text(); + } + if (!aRes.isEmpty()) { + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(aRes); } - myListControl->repaint(); } + +//******************************************************************** +void ModuleBase_WidgetMultiSelector::onListSelection() +{ + QList aItems = myListControl->selectedItems(); + myCopyAction->setEnabled(!aItems.isEmpty()); +} +