Salome HOME
#2309 Possibility to hide faces
[modules/shaper.git] / src / ModuleBase / ModuleBase_ListView.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModuleBase_ListView_H_
22 #define ModuleBase_ListView_H_
23
24 #include "ModuleBase.h"
25
26 #include <QModelIndex>
27 #include <QObject>
28
29 #include <set>
30
31 class QAction;
32 class QListWidget;
33 class QWidget;
34
35 /**
36 * \ingroup GUI
37 * An extension of QListWidget to provide Undo/Redo functionality
38 */
39 class MODULEBASE_EXPORT ModuleBase_ListView : public QObject
40 {
41 Q_OBJECT
42
43 public:
44   /// Constructor
45   ModuleBase_ListView(QWidget* theParent = 0, const QString& theObjectName = QString(),
46     const QString& theToolTip = QString());
47   /// Destructor
48   virtual ~ModuleBase_ListView() {}
49
50   /// Returns current control
51   /// \return list view instance
52   QListWidget* getControl() const { return myListControl; }
53
54   /// Adds a new list widget item to the end of the list and connect it to the given index
55   /// \param theTextValue value visualized in the view
56   /// \param theIndex an item internal index
57   void addItem(const QString& theTextValue, const int theIndex);
58
59   /// Returns list of internal list view item indices
60   /// \param theIndices an output container for indices
61   void getSelectedIndices(std::set<int>& theIndices);
62
63   /// Removes selected items from the list widget
64   void removeSelectedItems();
65
66   /// Remove items contain parameter indices
67   /// \param theIndices an indices
68   void removeItems(std::set<int>& theIndices);
69
70   /// Set selected items if possible
71   /// \param theIndices container of indices to be selected
72   void restoreSelection(const QModelIndexList& theIndices);
73
74   /// Update enable/disable state of context menu actions
75   void updateActionsStatus();
76
77 protected slots:
78   /// Slot for copy command in a list pop-up menu
79   void onCopyItem();
80
81   /// Slot is called on selection of list of selected items
82   void onListSelection();
83
84 signals:
85   /// Signal about delete action click
86   void deleteActionClicked();
87
88 protected:
89   QListWidget* myListControl; ///< List control
90
91   QAction* myCopyAction; ///< A copy action for pop-up menu in a list control
92   QAction* myDeleteAction; ///< A delete action for pop-up menu in a list control
93 };
94
95 #endif