HYDROGUI_ShowHideOp.h
HYDROGUI_StreamDlg.h
HYDROGUI_StreamOp.h
+ HYDROGUI_LineEditDoubleValidator.h
HYDROGUI_StricklerTableDlg.h
HYDROGUI_StricklerTableOp.h
HYDROGUI_SubmersibleOp.h
HYDROGUI_ShowHideOp.cxx
HYDROGUI_StreamDlg.cxx
HYDROGUI_StreamOp.cxx
+ HYDROGUI_LineEditDoubleValidator.cxx
HYDROGUI_StricklerTableDlg.cxx
HYDROGUI_StricklerTableOp.cxx
HYDROGUI_SubmersibleOp.cxx
#include "HYDROGUI_GeoreferencementDlg.h"
#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_LineEditDoubleValidator.h"
#include <CurveCreator_Utils.hxx>
#include <AIS_InteractiveContext.hxx>
#include <QTableWidget>
-#include <QItemDelegate>
#include <QHeaderView>
#include <QRadioButton>
#include <QPushButton>
}
}
-//! Custom item delegate (line edit with double validator)
-class HYDROGUI_GeoreferencementDlg::Delegate : public QItemDelegate
-{
-public:
- Delegate( QObject* = 0 );
-
- QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
- const QModelIndex& ) const;
-
- void setEditorData( QWidget*, const QModelIndex& ) const;
- void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
-};
-
-HYDROGUI_GeoreferencementDlg::Delegate::Delegate( QObject* theParent )
- : QItemDelegate( theParent )
-{
-}
-
-QWidget* HYDROGUI_GeoreferencementDlg::Delegate::createEditor(
- QWidget* theParent, const QStyleOptionViewItem& theOption,
- const QModelIndex& theIndex ) const
-{
- QWidget* anEditor = 0;
-
- if ( theIndex.column() > 0 ) {
- QLineEdit* aLineEdit = new QLineEdit( theParent );
- QDoubleValidator* aDoubleValidator = new QDoubleValidator();
- aDoubleValidator->setNotation( QDoubleValidator::StandardNotation );
- aDoubleValidator->setDecimals( 2 );
- aLineEdit->setValidator( aDoubleValidator );
- anEditor = aLineEdit;
- } else {
- anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex );
- }
-
- return anEditor;
-}
-
-void HYDROGUI_GeoreferencementDlg::Delegate::setEditorData(
- QWidget* theEditor, const QModelIndex& theIndex ) const
-{
- if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
- aLineEdit->setText( theIndex.data( Qt::EditRole ).toString() );
- } else {
- QItemDelegate::setEditorData( theEditor, theIndex );
- }
-}
-
-void HYDROGUI_GeoreferencementDlg::Delegate::setModelData(
- QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const
-{
- if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
- theModel->setData( theIndex, aLineEdit->text() );
- } else {
- QItemDelegate::setModelData( theEditor, theModel, theIndex );
- }
-}
-
HYDROGUI_GeoreferencementDlg::HYDROGUI_GeoreferencementDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_InputPanel( theModule, theTitle ), myIsModified( false )
{
// Table
myTable = new QTableWidget( mainFrame() );
- myTable->setItemDelegate( new Delegate( this ) );
+ myTable->setItemDelegate( new HYDROGUI_LineEditDoubleValidator( this ) );
myTable->verticalHeader()->setVisible( false );
myTable->setSelectionBehavior( QAbstractItemView::SelectItems );
myTable->setSelectionMode( QAbstractItemView::SingleSelection );
{
Q_OBJECT
- class Delegate;
-
public:
enum ProfilesMode { AllProfiles, SelectedProfiles };
--- /dev/null
+// Copyright (C) 2014-2015 EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_LineEditDoubleValidator.h"
+
+#include <QLineEdit>
+
+HYDROGUI_LineEditDoubleValidator::HYDROGUI_LineEditDoubleValidator( QObject* theParent )
+ : QItemDelegate( theParent )
+{
+}
+
+QWidget* HYDROGUI_LineEditDoubleValidator::createEditor(
+ QWidget* theParent, const QStyleOptionViewItem& theOption,
+ const QModelIndex& theIndex ) const
+{
+ QWidget* anEditor = 0;
+
+ if ( theIndex.column() > 0 ) {
+ QLineEdit* aLineEdit = new QLineEdit( theParent );
+ QDoubleValidator* aDoubleValidator = new QDoubleValidator();
+ aDoubleValidator->setNotation( QDoubleValidator::StandardNotation );
+ aDoubleValidator->setDecimals( 2 );
+ aLineEdit->setValidator( aDoubleValidator );
+ anEditor = aLineEdit;
+ } else {
+ anEditor = QItemDelegate::createEditor( theParent, theOption, theIndex );
+ }
+
+ return anEditor;
+}
+
+void HYDROGUI_LineEditDoubleValidator::setEditorData(
+ QWidget* theEditor, const QModelIndex& theIndex ) const
+{
+ if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
+ aLineEdit->setText( theIndex.data( Qt::EditRole ).toString() );
+ } else {
+ QItemDelegate::setEditorData( theEditor, theIndex );
+ }
+}
+
+void HYDROGUI_LineEditDoubleValidator::setModelData(
+ QWidget* theEditor, QAbstractItemModel* theModel, const QModelIndex& theIndex) const
+{
+ if ( QLineEdit* aLineEdit = dynamic_cast<QLineEdit*>( theEditor ) ) {
+ theModel->setData( theIndex, aLineEdit->text() );
+ } else {
+ QItemDelegate::setModelData( theEditor, theModel, theIndex );
+ }
+}
--- /dev/null
+// Copyright (C) 2014-2015 EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef HYDROGUI_LINEEDITDOUBLEVALIDATOR_H
+#define HYDROGUI_LINEEDITDOUBLEVALIDATOR_H
+
+#include <QItemDelegate>
+
+//! Custom item delegate (line edit with double validator)
+class HYDROGUI_LineEditDoubleValidator : public QItemDelegate
+{
+public:
+ HYDROGUI_LineEditDoubleValidator( QObject* = 0 );
+
+ QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
+ const QModelIndex& ) const;
+
+ void setEditorData( QWidget*, const QModelIndex& ) const;
+ void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
+};
+
+#endif
//
#include "HYDROGUI_StricklerTableDlg.h"
+
#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_LineEditDoubleValidator.h"
#include <LightApp_Application.h>
#include <QToolButton>
#include <QLayout>
#include <QLabel>
+#include <QTableWidget>
+#include <QHeaderView>
HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
anImageNameLayout->addWidget( myName );
// Strickler table
- //...
+ myTableGroup = new QGroupBox( tr( "STRICKLER_TABLE_TABLE" ), this );
+
+ // Main layout
+ QVBoxLayout* aTableLayout = new QVBoxLayout( myTableGroup );
+ aTableLayout->setMargin( 5 );
+ aTableLayout->setSpacing( 5 );
+
+ // Buttons
+ myAddBtn = new QToolButton;
+ myAddBtn->setText( tr( "ADD" ) );
+ myRemoveBtn = new QToolButton;
+ myRemoveBtn->setText( tr( "REMOVE" ) );
+ myClearBtn = new QToolButton;
+ myClearBtn->setText( tr( "CLEAR_ALL" ) );
+
+ // Table
+ myTable = new QTableWidget( mainFrame() );
+ myTable->setItemDelegate( new HYDROGUI_LineEditDoubleValidator( this ) );
+ myTable->setEditTriggers( QAbstractItemView::DoubleClicked |
+ QAbstractItemView::SelectedClicked |
+ QAbstractItemView::EditKeyPressed );
+
+ myTable->setColumnCount( 2 );
+ QStringList aColumnNames;
+ aColumnNames << tr( "STRICKLER_TYPE" ) << tr( "STRICKLER_COEFFICIENT" );
+ myTable->setHorizontalHeaderLabels( aColumnNames );
+
+ myTable->horizontalHeader()->setStretchLastSection( false);
+ myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
+ myTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents );
+ myTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
+
+ // Layout
+ // buttons
+ QHBoxLayout* aButtonsLayout = new QHBoxLayout();
+ aButtonsLayout->addWidget( myAddBtn );
+ aButtonsLayout->addWidget( myRemoveBtn );
+ aButtonsLayout->addStretch( 1 );
+ aButtonsLayout->addWidget( myClearBtn );
+
+ // main
+ aTableLayout->addLayout( aButtonsLayout );
+ aTableLayout->addWidget( myTable );
+
// Common
addWidget( myFileNameGroup );
addWidget( myNameGroup );
- //addWidget( myTableGroup );
- addStretch();
+ addWidget( myTableGroup );
+
+ // Update controls
+ updateControls();
+ // Connections
connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+ connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( onAddCoefficient() ) );
+ connect( myRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemoveCoefficient() ) );
+ connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( onClearCoefficients() ) );
+ connect( myTable->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
+ this, SLOT( onSelectionChanged() ) );
setMinimumWidth( 350 );
}
{
myFileNameGroup->setVisible( !theIsEdit );
myNameGroup->setEnabled( theIsEdit );
- //myTableGroup->setEnabled( theIsEdit );
+ myTableGroup->setVisible( theIsEdit );
+ if ( !theIsEdit )
+ addStretch();
}
void HYDROGUI_StricklerTableDlg::reset()
myName->clear();
myNameGroup->setEnabled( false );
-
- //myTableGroup->setEnabled( false );
-
- //myIsInitialized = false;
}
QString HYDROGUI_StricklerTableDlg::getFileName() const
void HYDROGUI_StricklerTableDlg::setFileName( const QString& theName )
{
myFileName->setText( theName );
+
+ if ( !myNameGroup->isEnabled() )
+ myNameGroup->setEnabled( true );
}
void HYDROGUI_StricklerTableDlg::setStricklerTableName( const QString& theName )
return myName->text();
}
+void HYDROGUI_StricklerTableDlg::setData(const StricklerCoefficientList& theData)
+{
+ myTable->setRowCount( 0 );
+
+ foreach ( const StricklerCoefficient& aData, theData ) {
+ // Check the current Strickler type
+ if ( aData.myType.isEmpty() ) {
+ continue;
+ }
+
+ // Get Strickler coefficient value for the current Strickler type
+ QString aCoefficient = HYDROGUI_Tool::GetCoordinateString( aData.myCoefficient, false );
+
+ // Insert row with the data
+ int aRow = myTable->rowCount();
+ myTable->insertRow( aRow );
+
+ // "Type" column
+ QTableWidgetItem* aTypeItem = new QTableWidgetItem( aData.myType );
+ myTable->setItem( aRow, 0, aTypeItem );
+
+ // "Coefficient" column
+ myTable->setItem( aRow, 1, new QTableWidgetItem( aCoefficient ) );
+ }
+
+ myTable->resizeColumnToContents( 0 );
+ myTable->resizeRowsToContents();
+
+ updateControls();
+}
+
+void HYDROGUI_StricklerTableDlg::updateControls()
+{
+ bool isTableNotEmpty = myTable->rowCount() > 0;
+ myClearBtn->setEnabled( isTableNotEmpty );
+ onSelectionChanged();
+}
+
+void HYDROGUI_StricklerTableDlg::removeRows( const QList<int> theRows )
+{
+ QList<int> aSortedRows = theRows;
+ qSort( aSortedRows );
+
+ int aRowToRemove = -1;
+ int aNbRemoved = 0;
+ foreach ( int aRow, aSortedRows ) {
+ aRowToRemove = aRow - aNbRemoved;
+ if ( myTable->model()->removeRow( aRowToRemove ) ) {
+ aNbRemoved++;
+ }
+ }
+
+ if ( aNbRemoved > 0 )
+ updateControls();
+}
+
void HYDROGUI_StricklerTableDlg::onBrowse()
{
QString aFilter( tr( "STRICKLER_TABLE_FILTER" ) );
emit fileSelected( aFileName );
}
}
+
+/**
+ Add the new default constructed Strickler coefficient.
+ */
+void HYDROGUI_StricklerTableDlg::onAddCoefficient()
+{
+ int aRow = myTable->rowCount();
+ myTable->insertRow( aRow );
+
+ // Set default type (=> generate unique type name) and coefficient
+ //...
+
+ updateControls();
+}
+
+/**
+ Remove the selected Strickler coefficient.
+ */
+void HYDROGUI_StricklerTableDlg::onRemoveCoefficient()
+{
+ QList<int> aRows;
+ QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+ foreach ( const QModelIndex& anIndex, aSelectedIndexes ) {
+ aRows << anIndex.row();
+ }
+
+ removeRows( aRows );
+}
+
+/**
+ Clear all Strickler coefficients.
+ */
+void HYDROGUI_StricklerTableDlg::onClearCoefficients()
+{
+ QList<int> aRows;
+ for ( int i=0; i< myTable->rowCount(); i++ ) {
+ aRows << i;
+ }
+
+ removeRows( aRows );
+}
+
+/**
+ Slot called on table selection change.
+*/
+void HYDROGUI_StricklerTableDlg::onSelectionChanged()
+{
+ QModelIndexList aSelectedIndexes = myTable->selectionModel()->selectedRows();
+ myRemoveBtn->setEnabled( aSelectedIndexes.count() > 0 );
+}
#include "HYDROGUI_InputPanel.h"
+class HYDROData_StricklerTable;
+
class QGroupBox;
class QLineEdit;
class QToolButton;
+class QTableWidget;
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;
+
public:
HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle );
virtual ~HYDROGUI_StricklerTableDlg();
void setStricklerTableName( const QString& theName );
QString getStricklerTableName() const;
+ void setData(const StricklerCoefficientList& theData);
+
+protected:
+ void updateControls();
+ void removeRows( const QList<int> theRows );
+
protected slots:
void onBrowse();
+ void onAddCoefficient();
+ void onRemoveCoefficient();
+ void onClearCoefficients();
+
+ void onSelectionChanged();
+
signals:
void fileSelected( const QString& theFileName );
QGroupBox* myNameGroup; //!< The group for the Strickler table name input field
QLineEdit* myName; //!< The Strickler table name input field
+ QGroupBox* myTableGroup; //!< The group for the Strickler table table control and buttons
+ 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
};
#endif
#include <HYDROData_Document.h>
+#include <LightApp_UpdateFlags.h>
+
#include <QFileInfo>
HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool theIsEdit )
HYDROGUI_Operation::startOperation();
HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
- //aPanel->reset();
- //aPanel->setIsEdit( myIsEdit );
+ aPanel->reset();
+ aPanel->setIsEdit( myIsEdit );
if( myIsEdit )
{
if ( !myEditedObject.IsNull() )
{
// Edit selected Strickler table
+
+ aPanel->setStricklerTableName( myEditedObject->GetName() );
+
+ // Get Strickler table data from the data model
+ // ...
+
+ // The code below is a sample of data filling Strickler table
+ HYDROGUI_StricklerTableDlg::StricklerCoefficientList aData;
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef1( "Zones de champs, prairies, sans cultures", 20.0 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef2( "Zones de champs cultivé à végétation basse", 17.5 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef3( "Zones de champs cultivé à végétation haute", 12.5 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef4( "Zones d'arbustes, de sous-bois", 10.0 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef5( "Zones à faible urbanization (bourg)", 9.0 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef6( "Zones à forte urbanization (agglomération)", 9.0 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef7( "Canaux naturels", 35.0 );
+ HYDROGUI_StricklerTableDlg::StricklerCoefficient aStricklerCoef8( "Canaux artificiels en béton", 65.0 );
+ aData.append( aStricklerCoef1 );
+ aData.append( aStricklerCoef2 );
+ aData.append( aStricklerCoef3 );
+ aData.append( aStricklerCoef4 );
+ aData.append( aStricklerCoef5 );
+ aData.append( aStricklerCoef6 );
+ aData.append( aStricklerCoef7 );
+ aData.append( aStricklerCoef8 );
+ aPanel->setData(aData);
}
else
{
if( myIsEdit )
{
// Get data from input panel's table and save it into data model object
+
+ // Check, that type names are unique within the current
+ // Strickler table and show error message, if needed
+
+ //...
}
else
{
- // Import data from Strickler table file into data model model object
+ // Import data from Strickler table file into data model object
aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
}
theBrowseObjectsEntries.append( anEntry );
}
+ theUpdateFlags |= UF_ObjBrowser;
+
return true;
}
<context>
<name>HYDROGUI_StricklerTableDlg</name>
- <message>
- <source>STRICKLER_TABLE_NAME</source>
- <translation>Strickler table name</translation>
- </message>
<message>
<source>IMPORT_STRICKLER_TABLE_FROM_FILE</source>
<translation>Import Strickler table from file</translation>
<source>DEFAULT_STRICKLER_TABLE_NAME</source>
<translation>Strickler table</translation>
</message>
+ <message>
+ <source>STRICKLER_TABLE_TABLE</source>
+ <translation>Strickler table definition</translation>
+ </message>
+ <message>
+ <source>ADD</source>
+ <translation>Add</translation>
+ </message>
+ <message>
+ <source>REMOVE</source>
+ <translation>Remove</translation>
+ </message>
+ <message>
+ <source>CLEAR_ALL</source>
+ <translation>Clear all</translation>
+ </message>
+ <message>
+ <source>STRICKLER_TYPE</source>
+ <translation>Type</translation>
+ </message>
+ <message>
+ <source>STRICKLER_COEFFICIENT</source>
+ <translation>Coefficient</translation>
+ </message>
</context>
<context>