]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #659: support of attributes in the Strickler table
authorasl <asl@opencascade.com>
Mon, 9 Nov 2015 06:00:48 +0000 (09:00 +0300)
committerasl <asl@opencascade.com>
Mon, 9 Nov 2015 06:00:48 +0000 (09:00 +0300)
src/HYDROGUI/HYDROGUI_StricklerTableDlg.cxx
src/HYDROGUI/HYDROGUI_StricklerTableDlg.h
src/HYDROGUI/HYDROGUI_StricklerTableOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 40269457f68c683b12a6aa1259fd74c758cc1e9c..85897ffeea60ec70554f3043e3d47c603061ce26 100644 (file)
@@ -21,6 +21,7 @@
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_LineEditDoubleValidator.h"
+#include "HYDROData_StricklerTable.h"
 
 #include <LightApp_Application.h>
 
 #include <QLabel>
 #include <QTableWidget>
 #include <QHeaderView>
+#include <QColorDialog>
+
+HYDROGUI_ColorDelegate::HYDROGUI_ColorDelegate( QWidget* theParent )
+{
+}
+
+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 ) );
+  thePainter->fillRect( theOption.rect, aColor );
+}
+
+QWidget* HYDROGUI_ColorDelegate::createEditor( QWidget* theParent,
+                                               const QStyleOptionViewItem& theOption,
+                                               const QModelIndex& theIndex ) const
+{
+  QColor aColor = qVariantValue<QColor>( theIndex.data( Qt::BackgroundColorRole ) );
+  QColor aNewColor = QColorDialog::getColor( aColor );
+  if( aNewColor.isValid() )
+  {
+    QAbstractItemModel* aModel = const_cast<QAbstractItemModel*>( theIndex.model() );
+    QVariant aValue = qVariantFromValue( aNewColor );
+    aModel->setData( theIndex, aValue, Qt::BackgroundColorRole );
+  }
+  return 0;
+}
+
+void HYDROGUI_ColorDelegate::setEditorData( QWidget* theEditor, const QModelIndex& theIndex ) const
+{
+}
+
+void HYDROGUI_ColorDelegate::setModelData( QWidget* theEditor, QAbstractItemModel* theModel,
+                                           const QModelIndex& theIndex ) const
+{
+}
+
+QSize  HYDROGUI_ColorDelegate::sizeHint( const QStyleOptionViewItem& theOption, const QModelIndex& theIndex ) const
+{
+  return theOption.rect.size();
+}
+
+
+
 
 HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle, int theType )
 : HYDROGUI_InputPanel( theModule, theTitle ),
@@ -71,12 +120,22 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
     QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), aNameGroup );
     myName = new QLineEdit( aNameGroup );
 
+    QGroupBox* aAttrNameGroup = new QGroupBox( tr( "STRICKLER_TABLE_ATTR_NAME" ), this );
+    QLabel* aAttrNameLabel = new QLabel( tr( "ATTR_NAME" ), aAttrNameGroup );
+    myAttrName = new QLineEdit( aAttrNameGroup );
+
     QBoxLayout* anImageNameLayout = new QHBoxLayout( aNameGroup );
     anImageNameLayout->setMargin( 5 );
     anImageNameLayout->setSpacing( 5 );
     anImageNameLayout->addWidget( anImageNameLabel );
     anImageNameLayout->addWidget( myName );
 
+    QBoxLayout* anAttrNameLayout = new QHBoxLayout( aAttrNameGroup );
+    anAttrNameLayout->setMargin( 5 );
+    anAttrNameLayout->setSpacing( 5 );
+    anAttrNameLayout->addWidget( aAttrNameLabel );
+    anAttrNameLayout->addWidget( myAttrName );
+
     // Strickler table
     QGroupBox* aTableGroup = new QGroupBox( tr( "STRICKLER_TABLE_TABLE" ), this );
     aTableGroup->setVisible( theType == Edit );
@@ -96,19 +155,22 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
 
     // Table
     myTable = new QTableWidget( mainFrame() );
-    myTable->setItemDelegate( new HYDROGUI_LineEditDoubleValidator( this ) );
+    myTable->setItemDelegateForColumn( 1, new HYDROGUI_LineEditDoubleValidator( this ) );
+    myTable->setItemDelegateForColumn( 3, new HYDROGUI_ColorDelegate( this ) );
     myTable->setEditTriggers( QAbstractItemView::DoubleClicked |
         QAbstractItemView::SelectedClicked |
         QAbstractItemView::EditKeyPressed );
 
-    myTable->setColumnCount( 2 );
+    myTable->setColumnCount( 4 );
     QStringList aColumnNames;
-    aColumnNames << tr( "STRICKLER_TYPE" ) << tr( "STRICKLER_COEFFICIENT" );
+    aColumnNames << tr( "STRICKLER_TYPE" ) << tr( "STRICKLER_COEFFICIENT" ) << tr( "ATTR_VALUE" ) << tr( "COLOR" );
     myTable->setHorizontalHeaderLabels( aColumnNames );
 
-    myTable->horizontalHeader()->setStretchLastSection( false);
-    myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
+    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 );
 
@@ -127,6 +189,7 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
     // Common
     addWidget( aFileNameGroup );
     addWidget( aNameGroup );
+    addWidget( aAttrNameGroup );
     addWidget( aTableGroup );
 
     // Update controls
@@ -140,7 +203,7 @@ HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModu
     connect( myTable->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), 
         this, SLOT( onSelectionChanged() ) );  
 
-    setMinimumWidth( 350 );
+    setMinimumWidth( 450 );
 
     if ( theType != Edit )
         addStretch();
@@ -187,47 +250,81 @@ void HYDROGUI_StricklerTableDlg::setTableNameReadOnly( bool on )
     myName->setReadOnly( on );
 }
 
-HYDROGUI_StricklerTableDlg::StricklerCoefficientList HYDROGUI_StricklerTableDlg::getData() const
+void HYDROGUI_StricklerTableDlg::getGuiData( Handle_HYDROData_StricklerTable& theTable ) const
 {
-    StricklerCoefficientList aRes;
-    for ( int i = 0; i < myTable->rowCount(); i++ )
-    {
-        QTableWidgetItem* typeItem = myTable->item( i, 0 );
-        QTableWidgetItem* coeffItem = myTable->item( i, 1 );
-        aRes.append( StricklerCoefficient( typeItem->text(), coeffItem->text().toDouble() ) );
-    }
-    return aRes;
+  if( theTable.IsNull() )
+    return;
+
+  theTable->SetAttrName( myAttrName->text() );
+  theTable->Clear();
+  for ( int i = 0; i < myTable->rowCount(); i++ )
+  {
+    QTableWidgetItem* typeItem = myTable->item( i, 0 );
+    QString aType = typeItem->data( Qt::DisplayRole ).toString();
+
+    QTableWidgetItem* coeffItem = myTable->item( i, 1 );
+    QString aCoeffStr = coeffItem->data( Qt::DisplayRole ).toString();
+    double aCoeff = aCoeffStr.toDouble();
+
+    QTableWidgetItem* attrValueItem = myTable->item( i, 2 );
+    QString anAttrValue = attrValueItem->data( Qt::DisplayRole ).toString();
+
+    QTableWidgetItem* colorItem = myTable->item( i, 3 );
+    QColor aColor = colorItem->backgroundColor();
+
+    theTable->Set( aType, aCoeff );
+    theTable->SetAttrValue( aType, anAttrValue );
+    theTable->SetColor( aType, aColor );
+  }
 }
 
-void HYDROGUI_StricklerTableDlg::setData(const StricklerCoefficientList& theData)
+void HYDROGUI_StricklerTableDlg::setGuiData( const Handle_HYDROData_StricklerTable& theTable )
 {
-    myTable->setRowCount( 0 );
+  myAttrName->setText( theTable->GetAttrName() );
 
-    foreach ( const StricklerCoefficient& aData, theData ) {
-        // Check the current Strickler type
-        if ( aData.myType.isEmpty() ) {
-            continue;
-        }
+  if( theTable.IsNull() )
+  {
+    myTable->setRowCount( 0 );
+    return;
+  }
+
+  QStringList aTypes = theTable->GetTypes();
+  myTable->setRowCount( 0 );
+  foreach( QString aType, aTypes )
+  {
+    // Check the current Strickler type
+    if( aType.isEmpty() )
+      continue;
+
+    // Get Strickler data for the current Strickler type
+    QString aCoefficient = HYDROGUI_Tool::GetCoordinateString( theTable->Get( aType, 0.0 ), false );
+    QString anAttrValue = theTable->GetAttrValue( aType );
+    QColor aColor = theTable->GetColor( aType );
+
+    // Insert row with the data
+    int aRow = myTable->rowCount();
+    myTable->insertRow( aRow );
 
-        // Get Strickler coefficient value for the current Strickler type
-        QString aCoefficient = HYDROGUI_Tool::GetCoordinateString( aData.myCoefficient, false );
+    // "Type" column
+    QTableWidgetItem* aTypeItem = new QTableWidgetItem( aType );    
+    myTable->setItem( aRow, 0, aTypeItem );
 
-        // Insert row with the data
-        int aRow = myTable->rowCount();
-        myTable->insertRow( aRow );
+    // "Coefficient" column
+    myTable->setItem( aRow, 1, new QTableWidgetItem( aCoefficient ) );
 
-        // "Type" column
-        QTableWidgetItem* aTypeItem = new QTableWidgetItem( aData.myType );    
-        myTable->setItem( aRow, 0, aTypeItem );
+    // "Attribute value" column
+    myTable->setItem( aRow, 2, new QTableWidgetItem( anAttrValue ) );
 
-        // "Coefficient" column
-        myTable->setItem( aRow, 1, new QTableWidgetItem( aCoefficient ) );
-    }
+    // "Color" column
+    QTableWidgetItem* anItem = new QTableWidgetItem();
+    anItem->setBackgroundColor( aColor );
+    myTable->setItem( aRow, 3, anItem );
+  }
 
-    myTable->resizeColumnToContents( 0 );
-    myTable->resizeRowsToContents();
+  myTable->resizeColumnToContents( 0 );
+  myTable->resizeRowsToContents();
 
-    updateControls();
+  updateControls();
 }
 
 void HYDROGUI_StricklerTableDlg::updateControls()
index 0fa872b2d18fd1e27e35e48b70b5af70031a28bd..70eb3505e9030d6368d43cfa0657f28b7747ce22 100644 (file)
@@ -20,8 +20,9 @@
 #define HYDROGUI_STRICKLERTABLEDLG_H
 
 #include "HYDROGUI_InputPanel.h"
+#include <QAbstractItemDelegate>
 
-class HYDROData_StricklerTable;
+class Handle_HYDROData_StricklerTable;
 
 class QGroupBox;
 class QLineEdit;
@@ -34,17 +35,6 @@ class HYDROGUI_StricklerTableDlg : public HYDROGUI_InputPanel
     Q_OBJECT
 
 public:
-    struct StricklerCoefficient
-    {
-        QString myType;
-        double  myCoefficient;
-
-        StricklerCoefficient(  const QString& theType,
-            double theCoefficient )
-            : myType( theType ), myCoefficient( theCoefficient ) {}
-    };
-    typedef QList<StricklerCoefficient> StricklerCoefficientList;
-
     enum { Edit, Import, Export };
 
 public:
@@ -62,8 +52,8 @@ public:
     bool                       isTableNameReadOnly() const;
     void                       setTableNameReadOnly( bool );
 
-    StricklerCoefficientList   getData() const;
-    void                       setData(const StricklerCoefficientList& theData);
+    void                       getGuiData( Handle_HYDROData_StricklerTable& theTable ) const;
+    void                       setGuiData( const Handle_HYDROData_StricklerTable& theTable );
 
 protected:
     void                       updateControls();
@@ -85,10 +75,32 @@ private:
     int                        myType;
     QLineEdit*                 myFileName;   //!< Source Strickler table file name input field
     QLineEdit*                 myName;       //!< The Strickler table name input field
+    QLineEdit*                 myAttrName;   //!< The Strickler table attribute's name input field
     QTableWidget*              myTable;      //!< The table of Strickler coefficients
     QToolButton*               myAddBtn;     //!< The add Strickler coefficient button
     QToolButton*               myRemoveBtn;  //!< The remove Strickler coefficient button
     QToolButton*               myClearBtn;   //!< The clear all Strickler coefficients button
 };
 
+class HYDROGUI_ColorDelegate : public QAbstractItemDelegate
+{
+public:
+  HYDROGUI_ColorDelegate( QWidget* theParent );
+  virtual ~HYDROGUI_ColorDelegate();
+
+  virtual void paint( QPainter* thePainter, const QStyleOptionViewItem& theOption,
+                      const QModelIndex& theIndex ) const;
+
+  virtual QWidget* createEditor( QWidget* theParent,
+                                 const QStyleOptionViewItem& theOption,
+                                 const QModelIndex& theIndex ) const;
+
+  virtual void setEditorData( QWidget* theEditor, const QModelIndex& theIndex ) const;
+
+  virtual void setModelData( QWidget* theEditor, QAbstractItemModel* theModel,
+                             const QModelIndex& theIndex ) const;
+
+  virtual QSize        sizeHint( const QStyleOptionViewItem& theOption, const QModelIndex& theIndex ) const;
+};
+
 #endif
index 31435e65069e112797f6704a74dc2ba5e2b6907b..2433bca6e6ef285602b853c2162c5b3172464cb8 100644 (file)
@@ -60,14 +60,7 @@ void HYDROGUI_StricklerTableOp::startOperation()
         {
             // Edit selected Strickler table
             aPanel->setTableName( myObject->GetName() );
-
-            // Get Strickler table data from the data model
-            HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData;
-            QStringList aTypes = myObject->GetTypes();
-            for ( QStringList::iterator it = aTypes.begin(); it != aTypes.end(); ++it )
-                aData.append( HYDROGUI_StricklerTableDlg::StricklerCoefficient( *it, myObject->Get( *it, 0 ) ) );
-
-            aPanel->setData( aData );
+            aPanel->setGuiData( myObject );
         }
     }
     else if ( isExport() )
@@ -161,13 +154,7 @@ bool HYDROGUI_StricklerTableOp::processApply( int& theUpdateFlags, QString& theE
     if( isEdit() )
     {
         // Get data from input panel's table and save it into data model object
-        aStricklerTableObj->Clear();
-        HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData = aPanel->getData();
-        for ( HYDROGUI_StricklerTableDlg::StricklerCoefficientList::iterator it = aData.begin(); it != aData.end(); ++it )
-        {
-            const HYDROGUI_StricklerTableDlg::StricklerCoefficient& anInfo = *it;
-            aStricklerTableObj->Set( anInfo.myType, anInfo.myCoefficient );
-        }
+      aPanel->getGuiData( aStricklerTableObj );
     }
     else
     {
index 95c6c91ef5ba1a80521fe18bd1abc0f03bbee046..6837f82c4b6139122372c8f5fb42419115219e70 100644 (file)
@@ -2715,6 +2715,22 @@ Polyline should consist from one not closed curve.</translation>
       <source>STRICKLER_COEFFICIENT</source>
       <translation>Coefficient</translation>
     </message>
+    <message>
+      <source>STRICKLER_TABLE_ATTR_NAME</source>
+      <translation>QGIS attribute name</translation>
+    </message>
+    <message>
+      <source>ATTR_NAME</source>
+      <translation>Attribute name</translation>
+    </message>
+    <message>
+      <source>ATTR_VALUE</source>
+      <translation>Attr.value</translation>
+    </message>
+    <message>
+      <source>COLOR</source>
+      <translation>Color</translation>
+    </message>
   </context>
 
   <context>