+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+
+ if (aModel) {
+ QList<int> aRows;
+
+ QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedIndexes();
+ foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
+ int aRowIndex = anIndex.row();
+ if ( !aRows.contains( aRowIndex ) )
+ aRows << aRowIndex;
+ }
+
+ if ( aModel->removeRows( aRows ) ) {
+ updateControls();
+ emit ruleChanged();
+ }
+ }
+}
+
+/**
+ Clear all rules.
+ */
+void HYDROGUI_PriorityWidget::onClearRules()
+{
+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+ if ( aModel && aModel->removeAll() ) {
+ updateControls();
+ emit ruleChanged();
+ }
+}
+
+/**
+ Set objects which could be used for rules definition.
+ @param theObjects the ordered list of objects
+ */
+void HYDROGUI_PriorityWidget::setObjects( const QList<Handle(HYDROData_Entity)>& theObjects )
+{
+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+ if( aModel ) {
+ aModel->setObjects( theObjects );
+ updateControls();
+ }
+}
+
+/**
+ Get rules.
+ @return the list of rules
+ */
+HYDROData_ListOfRules HYDROGUI_PriorityWidget::getRules() const
+{
+ HYDROData_ListOfRules aRules;
+
+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+ if( aModel ) {
+ aRules = aModel->getRules();
+ }
+
+ return aRules;
+}
+
+/**
+ Set rules.
+ @param theRules the list of rules
+*/
+void HYDROGUI_PriorityWidget::setRules( const HYDROData_ListOfRules& theRules )
+{
+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+ if( aModel ) {
+ aModel->setRules( theRules );
+ updateControls();
+ }
+}
+
+/**
+ Get table view.
+ @return the table view
+ */
+QTableView* HYDROGUI_PriorityWidget::getTable() const
+{
+ return myTable;
+}
+
+/**
+ Slot called on table selection change.
+*/
+void HYDROGUI_PriorityWidget::onSelectionChanged()
+{
+ QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedIndexes();
+ myRemove->setEnabled( aSelectedIndexes.count() > 0 );
+}
+
+/**
+ Update GUI controls state.
+ */
+void HYDROGUI_PriorityWidget::updateControls()
+{
+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+ if( aModel ) {
+ myAdd->setEnabled( aModel->canCreateNewRule() );
+ bool isTableNotEmpty = aModel->rowCount() > 0;
+ myClear->setEnabled( isTableNotEmpty );
+ }
+ onSelectionChanged();
+}
+
+/**
+ Show error message.
+ */
+void HYDROGUI_PriorityWidget::onShowError( const QString& theMsg ) {
+ SUIT_MessageBox::warning( this, tr( "INCORRECT_INPUT" ), theMsg );
+}
+
+/**
+ Undo last change in priority rules table.
+ */
+void HYDROGUI_PriorityWidget::undoLastChange()
+{
+ HYDROGUI_PriorityTableModel* aModel =
+ dynamic_cast<HYDROGUI_PriorityTableModel*>( myTable->model() );
+ if ( aModel )
+ aModel->undoLastChange();
+}