Salome HOME
refs #562: basic logic for Strickler table operation and dialog.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StricklerTableDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_StricklerTableDlg.h"
20 #include "HYDROGUI_Module.h"
21
22 #include <LightApp_Application.h>
23
24 #include <SUIT_Session.h>
25 #include <SUIT_ResourceMgr.h>
26 #include <SUIT_FileDlg.h>
27 #include <SUIT_Desktop.h>
28 #include <SUIT_MessageBox.h>
29
30 #include <QGroupBox>
31 #include <QLineEdit>
32 #include <QToolButton>
33 #include <QLayout>
34 #include <QLabel>
35
36 HYDROGUI_StricklerTableDlg::HYDROGUI_StricklerTableDlg( HYDROGUI_Module* theModule, const QString& theTitle )
37 : HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
38 {
39   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
40
41   // Import Strickler table from file
42   myFileNameGroup = new QGroupBox( tr( "IMPORT_STRICKLER_TABLE_FROM_FILE" ), this );
43
44   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
45
46   myFileName = new QLineEdit( myFileNameGroup );
47   myFileName->setReadOnly( true );
48
49   myBrowseBtn = new QToolButton( myFileNameGroup );
50   myBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
51
52   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
53   aFileNameLayout->setMargin( 5 );
54   aFileNameLayout->setSpacing( 5 );
55   aFileNameLayout->addWidget( aFileNameLabel );
56   aFileNameLayout->addWidget( myFileName );
57   aFileNameLayout->addWidget( myBrowseBtn );
58
59   // Strickler table name
60   myNameGroup = new QGroupBox( tr( "STRICKLER_TABLE_NAME" ), this );
61
62   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myNameGroup );
63   myName = new QLineEdit( myNameGroup );
64
65   QBoxLayout* anImageNameLayout = new QHBoxLayout( myNameGroup );
66   anImageNameLayout->setMargin( 5 );
67   anImageNameLayout->setSpacing( 5 );
68   anImageNameLayout->addWidget( anImageNameLabel );
69   anImageNameLayout->addWidget( myName );
70
71   // Strickler table
72   //...
73
74   // Common
75   addWidget( myFileNameGroup );
76   addWidget( myNameGroup );
77   //addWidget( myTableGroup );
78   addStretch();
79
80   connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
81
82   setMinimumWidth( 350 );
83 }
84
85 HYDROGUI_StricklerTableDlg::~HYDROGUI_StricklerTableDlg()
86 {
87 }
88
89 void HYDROGUI_StricklerTableDlg::setIsEdit( const bool theIsEdit )
90 {
91   myFileNameGroup->setVisible( !theIsEdit );
92   myNameGroup->setEnabled( theIsEdit );
93   //myTableGroup->setEnabled( theIsEdit );
94 }
95
96 void HYDROGUI_StricklerTableDlg::reset()
97 {
98   myFileName->clear();
99
100   myName->clear();
101   myNameGroup->setEnabled( false );
102    
103   //myTableGroup->setEnabled( false );
104
105   //myIsInitialized = false;
106 }
107
108 QString HYDROGUI_StricklerTableDlg::getFileName() const
109 {
110   return myFileName->text();
111 }
112
113 void HYDROGUI_StricklerTableDlg::setFileName( const QString& theName )
114 {
115   myFileName->setText( theName );
116 }
117
118 void HYDROGUI_StricklerTableDlg::setStricklerTableName( const QString& theName )
119 {
120   myName->setText(theName);
121 }
122
123 QString HYDROGUI_StricklerTableDlg::getStricklerTableName() const
124 {
125   return myName->text();
126 }
127
128 void HYDROGUI_StricklerTableDlg::onBrowse()
129 {
130   QString aFilter( tr( "STRICKLER_TABLE_FILTER" ) );
131   QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_STRICKLER_TABLE_FROM_FILE" ), true );
132   if( !aFileName.isEmpty() )
133   {
134     setFileName( aFileName );
135     emit fileSelected( aFileName );
136   }
137 }