Orfeo Toolbox  3.16
otbWrapperQtWidgetInputImageParameter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
19 #include <stdexcept>
20 
21 namespace otb
22 {
23 namespace Wrapper
24 {
25 
27 : QtWidgetParameterBase(param, m),
28  m_InputImageParam(param)
29 {
30 }
31 
33 {
34 }
35 
37 {
38 
39 }
40 
42 {
43  // Set up input text edit
44  m_HLayout = new QHBoxLayout;
45  m_HLayout->setSpacing(0);
46  m_HLayout->setContentsMargins(0, 0, 0, 0);
47  m_Input = new QLineEdit;
48  m_Input->setToolTip( m_InputImageParam->GetDescription() );
49  connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) );
50  connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) );
51 
52  m_HLayout->addWidget(m_Input);
53 
54  // Set up input text edit
55  m_Button = new QPushButton;
56  m_Button->setText("...");
57  m_Button->setToolTip("Select file...");
58  m_Button->setMaximumWidth(m_Button->width());
59  connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) );
60  m_HLayout->addWidget(m_Button);
61 
62  this->setLayout(m_HLayout);
63 }
64 
66 {
67  QFileDialog fileDialog;
68  fileDialog.setConfirmOverwrite(true);
69  fileDialog.setFileMode(QFileDialog::ExistingFile);
70  fileDialog.setNameFilter("Raster files (*)");
71 
72  if (fileDialog.exec())
73  {
74  if ( this->SetFileName(fileDialog.selectedFiles().at(0)) == true )
75  m_Input->setText(fileDialog.selectedFiles().at(0));
76  else
77  {
78  std::ostringstream oss;
79  oss << "The given file "
80  << fileDialog.selectedFiles().at(0).toAscii().constData()
81  << " is not valid.";
82  this->GetModel()->SendLogWARNING( oss.str() );
83  }
84  }
85 }
86 
87 bool QtWidgetInputImageParameter::SetFileName(const QString& value)
88 {
89  bool res = true;
90  // save value
91  if(m_InputImageParam->SetFromFileName(value.toAscii().constData()) == true)
92  {
93  // notify of value change
94  QString key( m_InputImageParam->GetKey() );
95 
96  emit ParameterChanged(key);
97  }
98  else
99  res = false;
100 
101  return res;
102 }
103 
104 }
105 }

Generated at Sun May 19 2013 01:01:50 for Orfeo Toolbox with doxygen 1.8.3.1