1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_ListView_H_
22 #define ModuleBase_ListView_H_
24 #include "ModuleBase.h"
26 #include <QModelIndex>
28 #include <QListWidget>
39 * Customization of a List Widget to make it to be placed on full width of container
41 class CustomListWidget : public QListWidget
46 /// \param theParent a parent widget
47 CustomListWidget(QWidget* theParent)
48 : QListWidget(theParent)
52 /// Redefinition of virtual method
53 virtual QSize sizeHint() const
55 int aHeight = 2 * QFontMetrics(font()).height();
56 QSize aSize = QListWidget::sizeHint();
57 return QSize(aSize.width(), aHeight);
60 /// Redefinition of virtual method
61 virtual QSize minimumSizeHint() const
63 int aHeight = 4/*2*/ * QFontMetrics(font()).height();
64 QSize aSize = QListWidget::minimumSizeHint();
65 return QSize(aSize.width(), aHeight);
72 virtual void mouseReleaseEvent(QMouseEvent* e) {
73 QListWidget::mouseReleaseEvent(e);
78 // The code is necessary only for Linux because
79 //it can not update viewport on widget resize
81 void resizeEvent(QResizeEvent* theEvent)
83 QListWidget::resizeEvent(theEvent);
84 QTimer::singleShot(5, viewport(), SLOT(repaint()));
92 * An extension of QListWidget to provide Undo/Redo functionality
94 class MODULEBASE_EXPORT ModuleBase_ListView : public QObject
100 ModuleBase_ListView(QWidget* theParent = 0, const QString& theObjectName = QString(),
101 const QString& theToolTip = QString());
103 virtual ~ModuleBase_ListView() {}
105 /// Returns current control
106 /// \return list view instance
107 QListWidget* getControl() const { return myListControl; }
109 /// Adds a new list widget item to the end of the list and connect it to the given index
110 /// \param theTextValue value visualized in the view
111 /// \param theIndex an item internal index
112 void addItem(const QString& theTextValue, const int theIndex);
114 /// Returns True if the control already contains an item with the given text
115 /// \param theTextValue tex of item to find
116 bool hasItem(const QString& theTextValue) const;
118 /// Returns list of internal list view item indices
119 /// \param theIndices an output container for indices
120 void getSelectedIndices(std::set<int>& theIndices);
122 /// Removes selected items from the list widget
123 void removeSelectedItems();
125 /// Remove items contain parameter indices
126 /// \param theIndices an indices
127 void removeItems(std::set<int>& theIndices);
129 /// Set selected items if possible
130 /// \param theIndices container of indices to be selected
131 void restoreSelection(const QModelIndexList& theIndices);
133 /// Update enable/disable state of context menu actions
134 void updateActionsStatus();
137 /// Slot for copy command in a list pop-up menu
140 /// Slot is called on selection of list of selected items
141 void onListSelection();
145 /// Signal about delete action click
146 void deleteActionClicked();
148 void listActivated();
151 QListWidget* myListControl; ///< List control
153 QAction* myCopyAction; ///< A copy action for pop-up menu in a list control
154 QAction* myDeleteAction; ///< A delete action for pop-up menu in a list control