case EditDigueId:
anOp = new HYDROGUI_DigueOp( aModule, theId == EditDigueId );
break;
+ case ImportStricklerTableFromFileId:
case EditStricklerTableId:
anOp = new HYDROGUI_StricklerTableOp( aModule, theId == EditStricklerTableId );
break;
//
#include "HYDROGUI_StricklerTableDlg.h"
+#include "HYDROGUI_Module.h"
+#include <LightApp_Application.h>
+
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_FileDlg.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+
+#include <QGroupBox>
#include <QLineEdit>
+#include <QToolButton>
+#include <QLayout>
+#include <QLabel>
HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle )
: HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
{
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+
+ // Import Strickler table from file
+ myFileNameGroup = new QGroupBox( tr( "IMPORT_STRICKLER_TABLE_FROM_FILE" ), this );
+
+ QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
+
+ myFileName = new QLineEdit( myFileNameGroup );
+ myFileName->setReadOnly( true );
+
+ myBrowseBtn = new QToolButton( myFileNameGroup );
+ myBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
+
+ QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
+ aFileNameLayout->setMargin( 5 );
+ aFileNameLayout->setSpacing( 5 );
+ aFileNameLayout->addWidget( aFileNameLabel );
+ aFileNameLayout->addWidget( myFileName );
+ aFileNameLayout->addWidget( myBrowseBtn );
+
+ // Strickler table name
+ myNameGroup = new QGroupBox( tr( "STRICKLER_TABLE_NAME" ), this );
+
+ QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myNameGroup );
+ myName = new QLineEdit( myNameGroup );
+
+ QBoxLayout* anImageNameLayout = new QHBoxLayout( myNameGroup );
+ anImageNameLayout->setMargin( 5 );
+ anImageNameLayout->setSpacing( 5 );
+ anImageNameLayout->addWidget( anImageNameLabel );
+ anImageNameLayout->addWidget( myName );
+
+ // Strickler table
+ //...
+
+ // Common
+ addWidget( myFileNameGroup );
+ addWidget( myNameGroup );
+ //addWidget( myTableGroup );
+ addStretch();
+
+ connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+
+ setMinimumWidth( 350 );
}
HYDROGUI_StricklerTableDlg::~HYDROGUI_StricklerTableDlg()
{
}
+void HYDROGUI_StricklerTableDlg::setIsEdit( const bool theIsEdit )
+{
+ myFileNameGroup->setVisible( !theIsEdit );
+ myNameGroup->setEnabled( theIsEdit );
+ //myTableGroup->setEnabled( theIsEdit );
+}
+
+void HYDROGUI_StricklerTableDlg::reset()
+{
+ myFileName->clear();
+
+ myName->clear();
+ myNameGroup->setEnabled( false );
+
+ //myTableGroup->setEnabled( false );
+
+ //myIsInitialized = false;
+}
+
+QString HYDROGUI_StricklerTableDlg::getFileName() const
+{
+ return myFileName->text();
+}
+
+void HYDROGUI_StricklerTableDlg::setFileName( const QString& theName )
+{
+ myFileName->setText( theName );
+}
+
void HYDROGUI_StricklerTableDlg::setStricklerTableName( const QString& theName )
{
myName->setText(theName);
{
return myName->text();
}
+
+void HYDROGUI_StricklerTableDlg::onBrowse()
+{
+ QString aFilter( tr( "STRICKLER_TABLE_FILTER" ) );
+ QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_STRICKLER_TABLE_FROM_FILE" ), true );
+ if( !aFileName.isEmpty() )
+ {
+ setFileName( aFileName );
+ emit fileSelected( aFileName );
+ }
+}
#include "HYDROGUI_InputPanel.h"
+class QGroupBox;
class QLineEdit;
+class QToolButton;
class HYDROGUI_StricklerTableDlg : public HYDROGUI_InputPanel
{
HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle );
virtual ~HYDROGUI_StricklerTableDlg();
- void setStricklerTableName( const QString& theName );
- QString getStricklerTableName() const;
+ void setIsEdit( const bool theIsEdit );
+ void reset();
+
+ QString getFileName() const;
+ void setFileName( const QString& theName );
+
+ void setStricklerTableName( const QString& theName );
+ QString getStricklerTableName() const;
+
+protected slots:
+ void onBrowse();
+
+signals:
+ void fileSelected( const QString& theFileName );
private:
- QLineEdit* myName;
+ QGroupBox* myFileNameGroup; //!< The group for the source Strickler table file selection
+ QLineEdit* myFileName; //!< Source Strickler table file name input field
+ QToolButton* myBrowseBtn;
+
+ QGroupBox* myNameGroup; //!< The group for the Strickler table name input field
+ QLineEdit* myName; //!< The Strickler table name input field
+
};
#endif
#include "HYDROGUI_StricklerTableOp.h"
#include "HYDROGUI_StricklerTableDlg.h"
+#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_DataObject.h"
+
+#include <HYDROData_Document.h>
+
+#include <QFileInfo>
HYDROGUI_StricklerTableOp::HYDROGUI_StricklerTableOp( HYDROGUI_Module* theModule, bool theIsEdit )
: HYDROGUI_Operation( theModule ),
}
void HYDROGUI_StricklerTableOp::startOperation()
-{
+{
+ HYDROGUI_Operation::startOperation();
+
+ HYDROGUI_StricklerTableDlg* aPanel = (HYDROGUI_StricklerTableDlg*)inputPanel();
+ //aPanel->reset();
+ //aPanel->setIsEdit( myIsEdit );
+
+ if( myIsEdit )
+ {
+ if ( isApplyAndClose() )
+ myEditedObject = Handle(HYDROData_StricklerTable)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ if ( !myEditedObject.IsNull() )
+ {
+ // Edit selected Strickler table
+ }
+ else
+ {
+ // Import Strickler table from file
+ }
+ }
}
void HYDROGUI_StricklerTableOp::abortOperation()
{
+ //...
+
+ HYDROGUI_Operation::abortOperation();
}
void HYDROGUI_StricklerTableOp::commitOperation()
{
+ //...
+
+ HYDROGUI_Operation::commitOperation();
}
HYDROGUI_InputPanel* HYDROGUI_StricklerTableOp::createInputPanel() const
{
- HYDROGUI_StricklerTableDlg* aDlg = new HYDROGUI_StricklerTableDlg( module(), getName() );
- return aDlg;
+ HYDROGUI_StricklerTableDlg* aPanel = new HYDROGUI_StricklerTableDlg( module(), getName() );
+ connect( aPanel, SIGNAL( fileSelected( const QString& ) ), SLOT( onFileSelected() ) );
+ return aPanel;
}
bool HYDROGUI_StricklerTableOp::processApply( int& theUpdateFlags, QString& theErrorMsg,
QStringList& theBrowseObjectsEntries )
{
+ HYDROGUI_StricklerTableDlg* aPanel = ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
+ if ( !aPanel )
+ return false;
+
+ QString aFilePath;
+ if( !myIsEdit )
+ {
+ aFilePath = aPanel->getFileName();
+ if ( aFilePath.isEmpty() )
+ {
+ theErrorMsg = tr( "SELECT_STRICKLER_TABLE_FILE" ).arg( aFilePath );
+ return false;
+ }
+ }
+
+ QString aStricklerTableName = aPanel->getStricklerTableName().simplified();
+ if ( aStricklerTableName.isEmpty() )
+ {
+ theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+ return false;
+ }
+
+ if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aStricklerTableName ) )
+ {
+ // check that there are no other objects with the same name in the document
+ Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aStricklerTableName );
+ if( !anObject.IsNull() )
+ {
+ theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aStricklerTableName );
+ return false;
+ }
+ }
+
+ Handle(HYDROData_StricklerTable) aStricklerTableObj;
+ if( myIsEdit )
+ aStricklerTableObj = myEditedObject;
+ else
+ {
+ aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( doc()->CreateObject( KIND_STRICKLER_TABLE ) );
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
+ theBrowseObjectsEntries.append( anEntry );
+ }
+
+ if( aStricklerTableObj.IsNull() )
+ return false;
+
+ aStricklerTableObj->SetName( aStricklerTableName );
+
+ if( myIsEdit )
+ {
+ // Get data from input panel's table and save it into data model object
+ }
+ else
+ {
+ // Import data from Strickler table file into data model model object
+ aStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( aFilePath ) );
+ }
+
+ aStricklerTableObj->Update();
+
+ if( !myIsEdit )
+ {
+ QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj );
+ theBrowseObjectsEntries.append( anEntry );
+ }
+
return true;
}
+
+void HYDROGUI_StricklerTableOp::onFileSelected()
+{
+ HYDROGUI_StricklerTableDlg* aPanel =
+ ::qobject_cast<HYDROGUI_StricklerTableDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
+
+ QString anStricklerTableName = aPanel->getStricklerTableName().simplified();
+ if ( anStricklerTableName.isEmpty() )
+ {
+ anStricklerTableName = aPanel->getFileName();
+ if ( !anStricklerTableName.isEmpty() ) {
+ anStricklerTableName = QFileInfo( anStricklerTableName ).baseName();
+ }
+
+ if ( anStricklerTableName.isEmpty() ) {
+ anStricklerTableName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
+ }
+ aPanel->setStricklerTableName( anStricklerTableName );
+ }
+}
virtual ~HYDROGUI_StricklerTableOp();
protected:
- virtual void startOperation();
- virtual void abortOperation();
- virtual void commitOperation();
+ virtual void startOperation();
+ virtual void abortOperation();
+ virtual void commitOperation();
virtual HYDROGUI_InputPanel* createInputPanel() const;
- virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg,
- QStringList& theBrowseObjectsEntries );
+ virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg,
+ QStringList& theBrowseObjectsEntries );
+
+protected slots:
+ void onFileSelected();
private:
bool myIsEdit;
<source>PREF_VIEWER_AUTO_FITALL</source>
<translation>Make automatic fit all after show object operation</translation>
</message>
+ <message>
+ <source>STRICKLER_TABLE_FILTER</source>
+ <translation>Strickler table files (*.txt);;All files (*.* *)</translation>
+ </message>
</context>
<context>
<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>
+ </message>
+ <message>
+ <source>FILE_NAME</source>
+ <translation>File name</translation>
+ </message>
+ <message>
+ <source>STRICKLER_TABLE_NAME</source>
+ <translation>Strickler table name</translation>
+ </message>
+ <message>
+ <source>NAME</source>
+ <translation>Name</translation>
+ </message>
+ <message>
+ <source>DEFAULT_STRICKLER_TABLE_NAME</source>
+ <translation>Strickler table</translation>
+ </message>
</context>
<context>
<source>EDIT_STRICKLER_TABLE</source>
<translation>Edit Strickler table</translation>
</message>
+ <message>
+ <source>SELECT_STRICKLER_TABLE_FILE</source>
+ <translation>The Strickler table file is not chosen</translation>
+ </message>
</context>
<context>