SHAPER  9.12.0
ModuleBase_ListView.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef ModuleBase_ListView_H_
21 #define ModuleBase_ListView_H_
22 
23 #include "ModuleBase.h"
24 
25 #include <QModelIndex>
26 #include <QObject>
27 #include <QListWidget>
28 #include <QTimer>
29 
30 #include <set>
31 
32 class QAction;
33 class QListWidget;
34 class QWidget;
35 
36 
41 {
42  Q_OBJECT
43 public:
47  : QListWidget(theParent)
48  {
49  }
50 
52  virtual QSize sizeHint() const
53  {
54  int aHeight = 2 * QFontMetrics(font()).height();
55  QSize aSize = QListWidget::sizeHint();
56  return QSize(aSize.width(), aHeight);
57  }
58 
60  virtual QSize minimumSizeHint() const
61  {
62  int aHeight = 4/*2*/ * QFontMetrics(font()).height();
63  QSize aSize = QListWidget::minimumSizeHint();
64  return QSize(aSize.width(), aHeight);
65  }
66 
67 signals:
68  void activated();
69 
70 protected:
71  virtual void mouseReleaseEvent(QMouseEvent* e) {
72  QListWidget::mouseReleaseEvent(e);
73  emit activated();
74  }
75 
76 #ifndef WIN32
77  // The code is necessary only for Linux because
78  //it can not update viewport on widget resize
79 protected:
80  void resizeEvent(QResizeEvent* theEvent)
81  {
82  QListWidget::resizeEvent(theEvent);
83  QTimer::singleShot(5, viewport(), SLOT(repaint()));
84  }
85 #endif
86 };
87 
88 
93 class MODULEBASE_EXPORT ModuleBase_ListView : public QObject
94 {
95 Q_OBJECT
96 
97 public:
99  ModuleBase_ListView(QWidget* theParent = 0, const QString& theObjectName = QString(),
100  const QString& theToolTip = QString());
102  virtual ~ModuleBase_ListView() {}
103 
106  QListWidget* getControl() const { return myListControl; }
107 
111  void addItem(const QString& theTextValue, const int theIndex);
112 
115  bool hasItem(const QString& theTextValue) const;
116 
119  void getSelectedIndices(std::set<int>& theIndices);
120 
123  void selectIndices(const std::set<int>& theIndices);
124 
126  void removeSelectedItems();
127 
130  void removeItems(std::set<int>& theIndices);
131 
134  void restoreSelection(const QModelIndexList& theIndices);
135 
138 
139 protected slots:
141  void onCopyItem();
142 
144  void onListSelection();
145 
146 
147 signals:
150 
151  void listActivated();
152 
153 protected:
155 
156  QAction* myCopyAction;
157  QAction* myDeleteAction;
158 };
159 
160 #endif
Customization of a List Widget to make it to be placed on full width of container.
Definition: ModuleBase_ListView.h:41
CustomListWidget(QWidget *theParent)
Constructor.
Definition: ModuleBase_ListView.h:46
virtual QSize sizeHint() const
Redefinition of virtual method.
Definition: ModuleBase_ListView.h:52
virtual QSize minimumSizeHint() const
Redefinition of virtual method.
Definition: ModuleBase_ListView.h:60
An extension of QListWidget to provide Undo/Redo functionality.
Definition: ModuleBase_ListView.h:94
void deleteActionClicked()
Signal about delete action click.
QListWidget * myListControl
List control.
Definition: ModuleBase_ListView.h:154
virtual ~ModuleBase_ListView()
Destructor.
Definition: ModuleBase_ListView.h:102
QListWidget * getControl() const
Returns current control.
Definition: ModuleBase_ListView.h:106
QAction * myDeleteAction
A delete action for pop-up menu in a list control.
Definition: ModuleBase_ListView.h:157
void updateActionsStatus()
Update enable/disable state of context menu actions.
QAction * myCopyAction
A copy action for pop-up menu in a list control.
Definition: ModuleBase_ListView.h:156