1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_ListView_H_
21 #define ModuleBase_ListView_H_
23 #include "ModuleBase.h"
25 #include <QModelIndex>
27 #include <QListWidget>
38 * Customization of a List Widget to make it to be placed on full width of container
40 class CustomListWidget : public QListWidget
45 /// \param theParent a parent widget
46 CustomListWidget(QWidget* theParent)
47 : QListWidget(theParent)
51 /// Redefinition of virtual method
52 virtual QSize sizeHint() const
54 int aHeight = 2 * QFontMetrics(font()).height();
55 QSize aSize = QListWidget::sizeHint();
56 return QSize(aSize.width(), aHeight);
59 /// Redefinition of virtual method
60 virtual QSize minimumSizeHint() const
62 int aHeight = 4/*2*/ * QFontMetrics(font()).height();
63 QSize aSize = QListWidget::minimumSizeHint();
64 return QSize(aSize.width(), aHeight);
71 virtual void mouseReleaseEvent(QMouseEvent* e) {
72 QListWidget::mouseReleaseEvent(e);
77 // The code is necessary only for Linux because
78 //it can not update viewport on widget resize
80 void resizeEvent(QResizeEvent* theEvent)
82 QListWidget::resizeEvent(theEvent);
83 QTimer::singleShot(5, viewport(), SLOT(repaint()));
91 * An extension of QListWidget to provide Undo/Redo functionality
93 class MODULEBASE_EXPORT ModuleBase_ListView : public QObject
99 ModuleBase_ListView(QWidget* theParent = 0, const QString& theObjectName = QString(),
100 const QString& theToolTip = QString());
102 virtual ~ModuleBase_ListView() {}
104 /// Returns current control
105 /// \return list view instance
106 QListWidget* getControl() const { return myListControl; }
108 /// Adds a new list widget item to the end of the list and connect it to the given index
109 /// \param theTextValue value visualized in the view
110 /// \param theIndex an item internal index
111 void addItem(const QString& theTextValue, const int theIndex);
113 /// Returns True if the control already contains an item with the given text
114 /// \param theTextValue tex of item to find
115 bool hasItem(const QString& theTextValue) const;
117 /// Returns list of internal list view item indices
118 /// \param theIndices an output container for indices
119 void getSelectedIndices(std::set<int>& theIndices);
121 /// Removes selected items from the list widget
122 void removeSelectedItems();
124 /// Remove items contain parameter indices
125 /// \param theIndices an indices
126 void removeItems(std::set<int>& theIndices);
128 /// Set selected items if possible
129 /// \param theIndices container of indices to be selected
130 void restoreSelection(const QModelIndexList& theIndices);
132 /// Update enable/disable state of context menu actions
133 void updateActionsStatus();
136 /// Slot for copy command in a list pop-up menu
139 /// Slot is called on selection of list of selected items
140 void onListSelection();
144 /// Signal about delete action click
145 void deleteActionClicked();
147 void listActivated();
150 QListWidget* myListControl; ///< List control
152 QAction* myCopyAction; ///< A copy action for pop-up menu in a list control
153 QAction* myDeleteAction; ///< A delete action for pop-up menu in a list control