Salome HOME
Merge branch 'BR_H2018_3' into BR_2018_V8_5
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StricklerTableDlg.cxx
index f98053b38aed65ea603c180000a784649b64e73d..b09540c4008b37c3e03578b09ca31dd06bb4a589 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include "HYDROGUI_StricklerTableDlg.h"
-
-#include "HYDROGUI_Module.h"
-#include "HYDROGUI_Tool.h"
-#include "HYDROGUI_LineEditDoubleValidator.h"
-#include "HYDROData_StricklerTable.h"
-
-#include <LightApp_Application.h>
-
-#include <SUIT_Session.h>
-#include <SUIT_ResourceMgr.h>
+#include <HYDROGUI_StricklerTableDlg.h>
+#include <HYDROGUI_LineEditDoubleValidator.h>
+#include <HYDROGUI_Tool.h>
+#include <HYDROData_StricklerTable.h>
 #include <SUIT_FileDlg.h>
-#include <SUIT_Desktop.h>
-#include <SUIT_MessageBox.h>
-
+#ifndef LIGHT_MODE
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#endif
+#include <QBoxLayout>
+#include <QColorDialog>
 #include <QGroupBox>
-#include <QLineEdit>
-#include <QToolButton>
-#include <QLayout>
+#include <QHeaderView>
 #include <QLabel>
+#include <QLineEdit>
+#include <QPainter>
 #include <QTableWidget>
-#include <QHeaderView>
-#include <QColorDialog>
+#include <QToolButton>
 
 HYDROGUI_ColorDelegate::HYDROGUI_ColorDelegate( QWidget* theParent )
 {
@@ -51,7 +46,7 @@ HYDROGUI_ColorDelegate::~HYDROGUI_ColorDelegate()
 void HYDROGUI_ColorDelegate::paint( QPainter* thePainter, const QStyleOptionViewItem& theOption,
                                     const QModelIndex& theIndex ) const
 {
-  QColor aColor = qVariantValue<QColor>( theIndex.data( Qt::BackgroundColorRole ) );
+  QColor aColor = theIndex.data( Qt::BackgroundColorRole ).value<QColor>();
   thePainter->fillRect( theOption.rect, aColor );
 }
 
@@ -59,7 +54,7 @@ QWidget* HYDROGUI_ColorDelegate::createEditor( QWidget* theParent,
                                                const QStyleOptionViewItem& theOption,
                                                const QModelIndex& theIndex ) const
 {
-  QColor aColor = qVariantValue<QColor>( theIndex.data( Qt::BackgroundColorRole ) );
+  QColor aColor = theIndex.data( Qt::BackgroundColorRole ).value<QColor>();
   QColor aNewColor = QColorDialog::getColor( aColor );
   if( aNewColor.isValid() )
   {
@@ -93,8 +88,6 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
 : HYDROGUI_InputPanel( theModule, theTitle ),
   myType( theType )
 {
-    SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-
     QString fileGroupTitle = theType == Export ? tr( "EXPORT_STRICKLER_TABLE_FILE" ) : tr( "IMPORT_STRICKLER_TABLE_FILE" );
 
     // Import Strickler table from file
@@ -107,7 +100,10 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
     myFileName->setReadOnly( true );
 
     QToolButton* aBrowseBtn = new QToolButton( aFileNameGroup );
+#ifndef LIGHT_MODE
+    SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
     aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
+#endif
 
     QBoxLayout* aFileNameLayout = new QHBoxLayout( aFileNameGroup );
     aFileNameLayout->setMargin( 5 );
@@ -123,6 +119,7 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
     myName = new QLineEdit( aNameGroup );
 
     QGroupBox* aAttrNameGroup = new QGroupBox( tr( "STRICKLER_TABLE_ATTR_NAME" ), this );
+    aAttrNameGroup->setVisible( theType == Edit );
     QLabel* aAttrNameLabel = new QLabel( tr( "ATTR_NAME" ), aAttrNameGroup );
     myAttrName = new QLineEdit( aAttrNameGroup );
 
@@ -164,17 +161,24 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
         QAbstractItemView::EditKeyPressed );
 
     myTable->setColumnCount( COLUMNS_COUNT );
+
     QStringList aColumnNames;
     aColumnNames << tr( "STRICKLER_TYPE" ) << tr( "STRICKLER_COEFFICIENT" ) << tr( "ATTR_VALUE" ) << tr( "COLOR" );
     myTable->setHorizontalHeaderLabels( aColumnNames );
 
     myTable->horizontalHeader()->setStretchLastSection( false );
-    myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::ResizeToContents );
-    myTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
-    myTable->horizontalHeader()->setResizeMode( 2, QHeaderView::ResizeToContents );
-    myTable->horizontalHeader()->setResizeMode( 3, QHeaderView::Stretch );
-
-    myTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
+    myTable->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Interactive );
+    myTable->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Interactive );
+    myTable->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::Interactive );
+    myTable->horizontalHeader()->setSectionResizeMode( 3, QHeaderView::Interactive );
+    myTable->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents );
+
+    const int default_size = 50;
+    myTable->horizontalHeader()->setMinimumSectionSize( default_size  );
+    myTable->horizontalHeader()->resizeSection( 0, 300 );
+    myTable->horizontalHeader()->resizeSection( 1, 75 );
+    myTable->horizontalHeader()->resizeSection( 2, 75 );
+    myTable->horizontalHeader()->resizeSection( 3, 75 );
 
     // Layout
     // buttons
@@ -252,7 +256,7 @@ void HYDROGUI_StricklerTableDlg::setTableNameReadOnly( bool on )
     myName->setReadOnly( on );
 }
 
-void HYDROGUI_StricklerTableDlg::getGuiData( Handle_HYDROData_StricklerTable& theTable ) const
+void HYDROGUI_StricklerTableDlg::getGuiData( Handle(HYDROData_StricklerTable)& theTable ) const
 {
   if( theTable.IsNull() )
     return;
@@ -280,7 +284,7 @@ void HYDROGUI_StricklerTableDlg::getGuiData( Handle_HYDROData_StricklerTable& th
   }
 }
 
-void HYDROGUI_StricklerTableDlg::setGuiData( const Handle_HYDROData_StricklerTable& theTable )
+void HYDROGUI_StricklerTableDlg::setGuiData( const Handle(HYDROData_StricklerTable)& theTable )
 {
   myAttrName->setText( theTable->GetAttrName() );
 
@@ -323,7 +327,7 @@ void HYDROGUI_StricklerTableDlg::setGuiData( const Handle_HYDROData_StricklerTab
     myTable->setItem( aRow, 3, anItem );
   }
 
-  myTable->resizeColumnToContents( 0 );
+  //myTable->resizeColumnToContents( 0 );
   myTable->resizeRowsToContents();
 
   updateControls();
@@ -390,9 +394,11 @@ Remove the selected Strickler coefficient.
 void HYDROGUI_StricklerTableDlg::onRemoveCoefficient()
 {
     QList<int> aRows;
-    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedIndexes();
     foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
-        aRows << anIndex.row();
+      int aRowIndex = anIndex.row();
+      if ( !aRows.contains( aRowIndex ) )
+        aRows << aRowIndex;
     }
 
     removeRows( aRows );
@@ -416,6 +422,6 @@ Slot called on table selection change.
 */
 void HYDROGUI_StricklerTableDlg::onSelectionChanged()
 {
-    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+    QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedIndexes();
     myRemoveBtn->setEnabled( aSelectedIndexes.count() > 0 );
 }