Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ModuleBase / ModuleBase_ListView.cpp
index c7ce0e2d5a4042552a11632e8b74c72b96564828..b0ca3c8e82bec2897387ec90dcbed2ff28b491b1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModuleBase_ListView.h"
 #include <QAction>
 #include <QApplication>
 #include <QClipboard>
-#include <QListWidget>
 #include <QWidget>
-#include <QTimer>
-
-const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
-
-/**
-* 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();
-    QSize aSize = QListWidget::sizeHint();
-    return QSize(aSize.width(), aHeight);
-  }
-
-  /// Redefinition of virtual method
-  virtual QSize        minimumSizeHint() const
-  {
-    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()));
-  }
+#include <QResizeEvent>
+#include <QTimer>
 #endif
-};
+
+const int ATTRIBUTE_SELECTION_INDEX_ROLE = Qt::UserRole + 1;
 
 //********************************************************************
 ModuleBase_ListView::ModuleBase_ListView(QWidget* theParent, const QString& theObjectName,
@@ -94,6 +55,7 @@ ModuleBase_ListView::ModuleBase_ListView(QWidget* theParent, const QString& theO
 
   myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
   connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
+  connect(myListControl, SIGNAL(activated()), this, SIGNAL(listActivated()));
 }
 
 //********************************************************************
@@ -115,6 +77,19 @@ void ModuleBase_ListView::getSelectedIndices(std::set<int>& theIndices)
   }
 }
 
+//********************************************************************
+void  ModuleBase_ListView::selectIndices(const std::set<int>& theIndices)
+{
+  myListControl->clearSelection();
+  for (int i = 0; i < myListControl->count(); i++) {
+    QListWidgetItem* anItem = myListControl->item(i);
+    int aId = anItem->data(ATTRIBUTE_SELECTION_INDEX_ROLE).toInt();
+    if (theIndices.find(aId) != theIndices.end()) {
+      anItem->setSelected(true);
+    }
+  }
+}
+
 //********************************************************************
 void ModuleBase_ListView::removeSelectedItems()
 {
@@ -175,4 +150,10 @@ void ModuleBase_ListView::onListSelection()
   QList<QListWidgetItem*> aItems = myListControl->selectedItems();
   myCopyAction->setEnabled(!aItems.isEmpty());
   myDeleteAction->setEnabled(!aItems.isEmpty());
-}
\ No newline at end of file
+}
+
+//********************************************************************
+bool ModuleBase_ListView::hasItem(const QString& theTextValue) const
+{
+  return myListControl->findItems(theTextValue, Qt::MatchExactly).length() > 0;
+}