Salome HOME
Qt4 porting: the filter is editable, but should not be (MESH-026 GUI test scenario)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.cxx
index caa1fb900208b3c3a24b0becbd7139715ff417eb..d0b2c15dd80166144b4b61b6932081536e3c568f 100755 (executable)
@@ -379,6 +379,7 @@ SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
   Qt::ItemFlags f = flags();
   f = f | Qt::ItemIsUserCheckable;
   f = f & ~Qt::ItemIsTristate;
+  f = f & ~Qt::ItemIsEditable;
   setFlags( f );
   setChecked(value);
 }
@@ -389,6 +390,7 @@ SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
   Qt::ItemFlags f = flags();
   f = f | Qt::ItemIsUserCheckable;
   f = f & ~Qt::ItemIsTristate;
+  f = f & ~Qt::ItemIsEditable;
   setFlags( f );
   setChecked( value );
   setText( text );
@@ -459,7 +461,7 @@ void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
                                                         const QModelIndex& index ) const
 {
   QString value = index.model()->data( index, Qt::DisplayRole ).toString();
-  QComboBox* cb = static_cast<QComboBox*>( editor );
+  QComboBox* cb = dynamic_cast<QComboBox*>( editor );
   bool bOk = false;
   if ( cb ) {
     int i = cb->findText( value );
@@ -475,7 +477,7 @@ void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
                                                        QAbstractItemModel* model,
                                                        const QModelIndex& index) const
 {
-  QComboBox* cb = static_cast<QComboBox*>( editor );
+  QComboBox* cb = dynamic_cast<QComboBox*>( editor );
   if ( cb ) model->setData( index, cb->currentText(), Qt::DisplayRole );
   else QItemDelegate::setModelData( editor, model, index );
 }
@@ -499,6 +501,8 @@ public:
   Table( int, int, QWidget* = 0 );
   virtual ~Table();
 
+  QSize                   minimumSizeHint() const;
+
   void                    setEditable( bool, int, int );
   bool                    isEditable( int, int ) const;
 
@@ -524,6 +528,10 @@ SMESHGUI_FilterTable::Table::Table (QWidget* parent)
   setReadOnly( false );
 }
 
+//=======================================================================
+// name    : SMESHGUI_FilterTable::Table::Table
+// Purpose : Constructor
+//=======================================================================
 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
 : QTableWidget(numRows, numCols, parent)
 {
@@ -533,10 +541,27 @@ SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
   setReadOnly( false );
 }
 
+//=======================================================================
+// name    : SMESHGUI_FilterTable::Table::~Table
+// Purpose : Destructor
+//=======================================================================
 SMESHGUI_FilterTable::Table::~Table()
 {
 }
 
+//=======================================================================
+// name    : SMESHGUI_FilterTable::Table::minimumSizeHint
+// Purpose : Get minimum size for the table
+//=======================================================================
+QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
+{
+  QSize s = QTableWidget::minimumSizeHint();
+  QHeaderView* hv = horizontalHeader();
+  if ( hv )
+    s.setWidth( qMax( s.width(), hv->length() ) );
+  return s;
+}
+
 //=======================================================================
 // name    : SMESHGUI_FilterTable::Table::setEditable
 // Purpose : Set editable of specified cell
@@ -546,10 +571,15 @@ void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
 {
   QTableWidgetItem* anItem = item( row, col );
   if ( anItem ) {
+    bool isSignalsBlocked = signalsBlocked();
+    blockSignals( true );
+
     Qt::ItemFlags f = anItem->flags();
     if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
     else f = f | Qt::ItemIsEditable;
     anItem->setFlags( f );
+    
+    blockSignals( isSignalsBlocked );
   }
 }
 
@@ -566,16 +596,13 @@ bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
 {
   setEditTriggers( on ? 
-                  QAbstractItemView::DoubleClicked   |
-                  QAbstractItemView::SelectedClicked |
-                  QAbstractItemView::EditKeyPressed  |
-                  QAbstractItemView::AnyKeyPressed   :
-                  QAbstractItemView::NoEditTriggers );
+                  QAbstractItemView::NoEditTriggers  :
+                  QAbstractItemView::AllEditTriggers );
 }
 
 bool SMESHGUI_FilterTable::Table::isReadOnly() const
 {
-  return editTriggers() != QAbstractItemView::NoEditTriggers;
+  return editTriggers() == QAbstractItemView::NoEditTriggers;
 }
 
 //=======================================================================
@@ -726,7 +753,7 @@ void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
 
     // layout widgets
     QGridLayout* aLay = new QGridLayout(myTableGrp);
-    aLay->setMargin(0);
+    aLay->setMargin(MARGIN);
     aLay->setSpacing(SPACING);
 
     aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
@@ -887,9 +914,10 @@ bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType)
       }
     } else {
       bool aRes = false;
+      bool isSignalsBlocked = aTable->signalsBlocked();
       aTable->blockSignals(true);
       double  aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
-      aTable->blockSignals(false);
+      aTable->blockSignals(isSignalsBlocked);
 
       if (!aRes && aTable->isEditable(i, 2)) {
         if (theMess)
@@ -996,9 +1024,9 @@ void SMESHGUI_FilterTable::GetCriterion (const int                 theRow,
   }
   else
   {
-    theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().data();
+    theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
     if ( aCriterionType != SMESH::FT_RangeOfIds )
-      theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().data();
+      theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
   }
 
   QTableWidgetItem* anItem = aTable->item(theRow, 0);
@@ -1275,9 +1303,14 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
        aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges ||
        aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume)
   {
+    bool isSignalsBlocked = aTable->signalsBlocked();
+    aTable->blockSignals( true );
+
     if (aCompareItem->count() > 0)
       aCompareItem->clear();
     aTable->setEditable(false, row, 2);
+
+    aTable->blockSignals( isSignalsBlocked );
   }
   else if (aCriterionType == SMESH::FT_RangeOfIds ||
            aCriterionType == SMESH::FT_BelongToGeom ||
@@ -1359,6 +1392,10 @@ void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const boo
   }
   myIsLocked = false;
 
+  // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
+  bool isSignalsBlocked = theTable->signalsBlocked();
+  theTable->blockSignals( true );
+
   // Criteria
   theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
 
@@ -1366,11 +1403,18 @@ void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const boo
   theTable->setItem(aCurrRow, 1, getCompareItem());
 
   // Threshold
-  //theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
+  theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
 
-  //Logical operation NOT
+  // Logical operation NOT
   theTable->setItem(aCurrRow, 3, getUnaryItem());
 
+  // Logical operation AND / OR
+  theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
+
+  theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
+    
+  theTable->blockSignals( isSignalsBlocked );
+
   // Logical binary operation for previous value
   int anAddBinOpStr = -1;
   if (aCurrRow == theTable->rowCount() - 1)
@@ -1390,7 +1434,7 @@ void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const boo
   }
 
   theTable->setEditable(false, theTable->rowCount() - 1, 4);
-
+  
   if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
        aCurrCol >=0 && aCurrCol < theTable->rowCount())
   theTable->setCurrentCell(aCurrRow, aCurrCol);
@@ -1595,13 +1639,15 @@ SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget*  thePar
   QString aCoStr;
   aCoStr.fill(' ', 10);
 
-  aTable->horizontalHeaderItem(0)->setText(tr("CRITERION") + aCrStr);
-  aTable->horizontalHeaderItem(1)->setText(tr("COMPARE")   + aCoStr);
-  aTable->horizontalHeaderItem(2)->setText(tr("THRESHOLD_VALUE"));
-  aTable->horizontalHeaderItem(3)->setText(tr("UNARY"));
-  aTable->horizontalHeaderItem(4)->setText(tr("BINARY") + "  ");
-  aTable->horizontalHeaderItem(5)->setText(tr("ID"));
-
+  QStringList aHeaderLabels;
+  aHeaderLabels.append( tr("CRITERION") + aCrStr );
+  aHeaderLabels.append( tr("COMPARE")   + aCoStr );
+  aHeaderLabels.append( tr("THRESHOLD_VALUE") );
+  aHeaderLabels.append( tr("UNARY") );
+  aHeaderLabels.append( tr("BINARY") + "  " );
+  aHeaderLabels.append( tr("ID") );
+  aTable->setHorizontalHeaderLabels( aHeaderLabels );
+  
   // set geometry of the table
   for (int i = 0; i <= 4; i++)
     aTable->resizeColumnToContents(i);
@@ -1645,6 +1691,21 @@ void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
   {
     anIter.value()->setReadOnly(!isEditable);
 
+    // Set Flags for CheckItems directly IPAL 19974
+    Table* aTable = anIter.value();
+    for (int i = 0, n = aTable->rowCount(); i < n; i++)
+      for (int j = 0, m = aTable->columnCount(); j < m; j++)
+       {
+         QTableWidgetItem* anItem = aTable->item(i, j);
+         if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
+           Qt::ItemFlags f = anItem->flags();
+           if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
+           else f = f | Qt::ItemIsUserCheckable;
+           anItem->setFlags( f );
+         }
+       }
+    //end of IPAL19974
+
     if (isEditable)
     {
       myAddBtn->show();
@@ -2016,11 +2077,11 @@ QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
   aLay->setMargin(MARGIN);
   aLay->setSpacing(SPACING);
 
-  myButtons[ BTN_OK     ] = new QPushButton(tr("SMESH_BUT_OK"   ),  aGrp);
-  myButtons[ BTN_Apply  ] = new QPushButton(tr("SMESH_BUT_APPLY"),  aGrp);
-  myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
-  myButtons[ BTN_Close  ] = new QPushButton(tr("SMESH_BUT_CLOSE"),  aGrp);
-  myButtons[ BTN_Help   ] = new QPushButton(tr("SMESH_BUT_HELP"),   aGrp);
+  myButtons[ BTN_OK     ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
+  myButtons[ BTN_Apply  ] = new QPushButton(tr("SMESH_BUT_APPLY"),           aGrp);
+  myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"),          aGrp);
+  myButtons[ BTN_Close  ] = new QPushButton(tr("SMESH_BUT_CLOSE"),           aGrp);
+  myButtons[ BTN_Help   ] = new QPushButton(tr("SMESH_BUT_HELP"),            aGrp);
 
   aLay->addWidget(myButtons[ BTN_OK     ]);
   aLay->addSpacing(10);
@@ -2351,7 +2412,7 @@ bool SMESHGUI_FilterDlg::isValid() const
       myTable->GetThreshold(i, aName);
 
       std::vector<_PTR(SObject)> aList =
-        SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().data(), "GEOM");
+        SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
       if (aList.size() == 0) {
         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
                                     tr("BAD_SHAPE_NAME").arg(aName));
@@ -2414,9 +2475,13 @@ void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg)
 // name    : SMESHGUI_FilterDlg::SetGroupIds
 // Purpose : Set mesh
 //=======================================================================
-void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_ptr theMesh)
+void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
 {
   myMesh = theMesh;
+  if ( myMesh->_is_nil() ) {
+    myButtons[BTN_OK]->setEnabled(false);
+    myButtons[BTN_Apply]->setEnabled(false);
+  }
 }
 
 //=======================================================================
@@ -2751,6 +2816,14 @@ void SMESHGUI_FilterDlg::onSelectionDone()
   int aRow, aCol;
   const SALOME_ListIO& aList = mySelector->StoredIObjects();
 
+  if ( myMesh->_is_nil() && aList.Extent()>0 ) {
+    myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
+    if ( !(myMesh->_is_nil()) ) {
+      myButtons[BTN_OK]->setEnabled(true);
+      myButtons[BTN_Apply]->setEnabled(true);
+    }
+  }
+
   if (aList.Extent() != 1 ||
       !myTable->CurrentCell(aRow, aCol) ||
       myTable->GetCriterionType(aRow) != SMESH::FT_BelongToGeom &&
@@ -2770,6 +2843,7 @@ void SMESHGUI_FilterDlg::onSelectionDone()
     }
 }
 
+
 //=======================================================================
 // name    : SMESHGUI_FilterDlg::onCriterionChanged
 // Purpose : SLOT called when cretarion of current row changed. Update selection