Salome HOME
Provide Copy command for items in Group operation
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 29 Dec 2014 13:50:03 +0000 (16:50 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 29 Dec 2014 13:50:03 +0000 (16:50 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/copy.png [new file with mode: 0644]

index 4204870979762d92365ea481ea3a52fefba947d7..114a76748d716bd951d53f499582f9875ac3bd2e 100644 (file)
@@ -25,6 +25,9 @@
 #include <QString>
 #include <QComboBox>
 #include <QEvent>
+#include <QAction>
+#include <QApplication>
+#include <QClipboard>
 
 #include <memory>
 #include <string>
@@ -64,6 +67,14 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   //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);
 }
 
@@ -261,3 +272,27 @@ void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListP
     myListControl->addItem(aAttr->namingName().c_str());
   }
 }
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onCopyItem()
+{
+  QList<QListWidgetItem*> 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);
+  }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onListSelection()
+{
+  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+  myCopyAction->setEnabled(!aItems.isEmpty());
+}
+
index 47f08a5e683efd1f4696894f6df17029ab6e171e..111b27f0d8a5e487e043b1e1e50c2d3de09033e0 100644 (file)
@@ -29,6 +29,7 @@ class QWidget;
 class QListWidget;
 class QComboBox;
 class ModuleBase_IWorkshop;
+class QAction;
 
 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
 {
@@ -61,6 +62,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
   void onSelectionTypeChanged();
   void onSelectionChanged();
 
+protected slots:
+  void onCopyItem();
+  void onListSelection();
+
  protected:
   void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
                     NCollection_List<TopoDS_Shape>& theResult);
@@ -83,6 +88,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
 
   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
   QList<GeomSelection> mySelection;
+
+  QAction* myCopyAction;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index b7c79dd9bb6456e486649959355613b1dbc57bb7..3176442f64049a911497746232d405bbe7f120aa 100644 (file)
@@ -8,6 +8,7 @@
      <file>pictures/undo.png</file>
      <file>pictures/rebuild.png</file>
      <file>pictures/preferences.png</file>
+     <file>pictures/copy.png</file>
      
      <file>pictures/params_folder.png</file>
      <file>pictures/constr_folder.png</file>
diff --git a/src/XGUI/pictures/copy.png b/src/XGUI/pictures/copy.png
new file mode 100644 (file)
index 0000000..12968bf
Binary files /dev/null and b/src/XGUI/pictures/copy.png differ