Salome HOME
refs #550: fix crash when myObject is NULL
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PriorityWidget.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROGUI_PRIORITYWIDGET_H
20 #define HYDROGUI_PRIORITYWIDGET_H
21
22 #include <HYDROGUI.h>
23
24 #include <HYDROData_Object.h>
25 #include <HYDROData_PriorityQueue.h>
26
27 #include <QStyledItemDelegate>
28 #include <QWidget>
29
30 class QTableView;
31 class QToolButton;
32
33 /** 
34  * \class HYDROGUI_PriorityWidget
35  * \brief The class representing widget for tuning of the objects priorities and bathymetry conflicts
36  *
37  * The widget represents a table and a set of buttons (add and remove)
38  * providing the possibility to define priority rules.
39  */
40 class HYDRO_EXPORT HYDROGUI_PriorityWidget : public QWidget
41 {
42   Q_OBJECT
43
44   class Delegate;
45
46 public:
47   HYDROGUI_PriorityWidget( QWidget* theParent );
48   virtual ~HYDROGUI_PriorityWidget();
49
50   void setObjects( const QList<Handle(HYDROData_Object)>& theObjects );
51
52   HYDROData_ListOfRules getRules() const;
53   void setRules( const HYDROData_ListOfRules& theRules );
54
55 protected:
56   void updateControls();
57
58 protected slots:
59   void onAddRule();
60   void onRemoveRule();
61   void onClearRules();
62
63   void onSelectionChanged();
64
65   void onShowError( const QString& theMsg );
66
67 private:
68   QTableView*  myTable;  ///< the table view
69   QToolButton* myAdd;    ///< the add rule button
70   QToolButton* myRemove; ///< the remove rule button
71   QToolButton* myClear;  ///< the clear all rules button
72 };
73
74 /** 
75  * \class HYDROGUI_PriorityWidget::Delegate
76  * \brief The class representing custom item delegate (combobox)
77  */
78 class HYDROGUI_PriorityWidget::Delegate : public QStyledItemDelegate
79 {
80   Q_OBJECT
81
82 public:
83   Delegate( QObject* theParent = 0 );
84   
85   QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
86                          const QModelIndex& ) const;
87   
88   void setEditorData( QWidget*, const QModelIndex& ) const;
89   void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
90
91 protected slots:
92   void finishEditing();
93 };
94
95 #endif