Salome HOME
portage V8_5_0
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ExportLandCoverMapDlg.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_ExportLandCoverMapDlg.h"
20
21 #include <SUIT_MessageBox.h>
22
23 #include <QCheckBox>
24 #include <QVBoxLayout>
25 #include <QComboBox>
26 #include <QLabel>
27 #include <QDoubleSpinBox>
28 #include <QVBoxLayout>
29
30 HYDROGUI_ExportLandCoverMapDlg::HYDROGUI_ExportLandCoverMapDlg( QWidget* theParent, bool IsLinear, const QStringList& theAttrItems )
31   : QtxDialog( theParent, false, true, QtxDialog::OKCancel )
32 {
33   setWindowTitle( tr( "EXPORT_LANDCOVERMAP" ) );
34   setButtonPosition( Left, OK );
35   setButtonPosition( Right, Cancel );
36
37   myAttrCheckBox = new QCheckBox( tr( "WRITE_ST_AS_ATTRS_TO_DBF" ), mainFrame() );
38   myAttrCheckBox->setChecked(false);
39   myAvFields = new QComboBox( mainFrame() );
40   myAvFields->setEnabled(false);
41   myAvFields->addItems( theAttrItems );
42
43   QVBoxLayout* aSketchLayout = new QVBoxLayout( mainFrame() );
44   aSketchLayout->setMargin( 0 );
45   aSketchLayout->setSpacing( 5 );
46
47   QGridLayout* aLayout = new QGridLayout();
48   aLayout->setMargin( 5 );
49   aLayout->setSpacing( 5 );
50   aLayout->addWidget( myAttrCheckBox, 0, 0 );
51   aLayout->addWidget( myAvFields, 1, 0, 1, 2 );
52
53   if(!IsLinear)
54   {
55     myDiscrLabel = new QLabel( tr( "LCM_DISCR_LABEL" ), mainFrame() );
56     myDeflSpinBox = new QDoubleSpinBox( mainFrame() );
57     myDeflSpinBox->setRange(0.001, 2); 
58     myDeflSpinBox->setDecimals(3);
59     myDeflSpinBox->setSingleStep(0.001);
60     myDeflLabel = new QLabel ( tr( "LCM_DEFL_LABEL" ), mainFrame() );
61     aLayout->addWidget( myDiscrLabel, 2, 0 );
62     aLayout->addWidget( myDeflLabel, 3, 0, 1, 1 );
63     aLayout->addWidget( myDeflSpinBox, 3, 1, 2, 2 );
64   }
65   else
66   {
67     myDeflSpinBox = NULL;
68     myDeflLabel = NULL;
69     myDiscrLabel = NULL;
70   }
71
72   myWarningLabel = new QLabel( tr( "ATTRS_NOT_WRITTEN_TO_DBF" ), mainFrame() );
73   myWarningLabel->setStyleSheet("QLabel { font: italic; color : blue; }");
74   
75   aSketchLayout->addLayout( aLayout );
76   aSketchLayout->addWidget( myWarningLabel, 1, Qt::AlignHCenter );
77   aSketchLayout->addStretch(1);
78
79   setMinimumSize( 300, 100 );
80
81   connect( myAttrCheckBox, SIGNAL(clicked(bool)), this, SLOT(onAttrCBChecked(bool)));
82   connect( myAvFields, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onAvFieldsChanged(const QString&)));
83
84 }
85
86 HYDROGUI_ExportLandCoverMapDlg::~HYDROGUI_ExportLandCoverMapDlg()
87 {
88 }
89
90 void HYDROGUI_ExportLandCoverMapDlg::onAttrCBChecked( bool theState )
91 {
92   if (theState)
93     myAvFields->setEnabled(true);
94   else
95     myAvFields->setEnabled(false);
96
97   myWarningLabel->setVisible( !theState || getCurrentItem().isEmpty() );
98 }
99
100 void HYDROGUI_ExportLandCoverMapDlg::onAvFieldsChanged(const QString& theText)
101 {
102   myWarningLabel->setVisible( theText.isEmpty() );
103 }
104
105 QString HYDROGUI_ExportLandCoverMapDlg::getCurrentItem() const
106 {
107   return myAvFields->currentText();
108 }
109
110 bool HYDROGUI_ExportLandCoverMapDlg::getAttrCheckBoxState()
111 {
112   return myAttrCheckBox->isChecked();
113 }
114
115 double HYDROGUI_ExportLandCoverMapDlg::getDeflValue() const
116 {
117   if (myDeflSpinBox)
118     return myDeflSpinBox->value();
119   else 
120     return -1; //value is not needed
121 }