diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetDirectoryParameter.cxx b/Code/Wrappers/QtWidget/otbWrapperQtWidgetDirectoryParameter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..cfeb93778d9dc16bce6016270903e474ea2be6d0 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetDirectoryParameter.cxx @@ -0,0 +1,89 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbWrapperQtWidgetDirectoryParameter.h" + +namespace otb +{ +namespace Wrapper +{ + +QtWidgetDirectoryParameter::QtWidgetDirectoryParameter(DirectoryParameter* param, QtWidgetModel* m) +: QtWidgetParameterBase(param, m), + m_DirectoryParam(param) +{ +} + +QtWidgetDirectoryParameter::~QtWidgetDirectoryParameter() +{ +} + +void QtWidgetDirectoryParameter::DoUpdateGUI() +{ + +} + +void QtWidgetDirectoryParameter::DoCreateWidget() +{ + // Set up input text edit + m_HLayout = new QHBoxLayout; + m_HLayout->setSpacing(0); + m_HLayout->setContentsMargins(0, 0, 0, 0); + m_Input = new QLineEdit; + m_Input->setToolTip( m_DirectoryParam->GetDescription() ); + connect( m_Input, SIGNAL(textChanged(const QString&)), this, SLOT(SetFileName(const QString&)) ); + connect( m_Input, SIGNAL(textChanged(const QString&)), GetModel(), SLOT(NotifyUpdate()) ); + + m_HLayout->addWidget(m_Input); + + // Set up input text edit + m_Button = new QPushButton; + m_Button->setText("..."); + m_Button->setToolTip("Select d Directory..."); + m_Button->setMaximumWidth(m_Button->width()); + connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) ); + m_HLayout->addWidget(m_Button); + + this->setLayout(m_HLayout); +} + +void QtWidgetDirectoryParameter::SelectFile() +{ + QFileDialog fileDialog; + fileDialog.setConfirmOverwrite(true); + fileDialog.setFileMode(QFileDialog::Directory); + fileDialog.setNameFilter("Select a Directory"); + + if (fileDialog.exec()) + { + this->SetFileName(fileDialog.selectedFiles().at(0)); + m_Input->setText(fileDialog.selectedFiles().at(0)); + } +} + +void QtWidgetDirectoryParameter::SetFileName(const QString& value) +{ + // save value + m_DirectoryParam->SetValue(value.toStdString()); + + // notify of value change + QString key( QString::fromStdString(m_DirectoryParam->GetKey()) ); + emit ParameterChanged(key); +} + +} +} diff --git a/Code/Wrappers/QtWidget/otbWrapperQtWidgetDirectoryParameter.h b/Code/Wrappers/QtWidget/otbWrapperQtWidgetDirectoryParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..ec7b0af45c6df26afd290983bb38dda013a2c149 --- /dev/null +++ b/Code/Wrappers/QtWidget/otbWrapperQtWidgetDirectoryParameter.h @@ -0,0 +1,65 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbWrapperQtWidgetDirectoryParameter_h +#define __otbWrapperQtWidgetDirectoryParameter_h + +#include <QtGui> +#include "otbWrapperDirectoryParameter.h" +#include "otbWrapperQtWidgetParameterBase.h" + + +namespace otb +{ +namespace Wrapper +{ + +/** \class + * \brief + */ +class QtWidgetDirectoryParameter : public QtWidgetParameterBase +{ + Q_OBJECT +public: + QtWidgetDirectoryParameter(DirectoryParameter*, QtWidgetModel*); + virtual ~QtWidgetDirectoryParameter(); + +protected slots: + void SetFileName( const QString& value ); + void SelectFile(); + +private: + QtWidgetDirectoryParameter(const QtWidgetDirectoryParameter&); //purposely not implemented + void operator=(const QtWidgetDirectoryParameter&); //purposely not implemented + + virtual void DoCreateWidget(); + + virtual void DoUpdateGUI(); + + + DirectoryParameter::Pointer m_DirectoryParam; + + QHBoxLayout * m_HLayout; + QLineEdit* m_Input; + QPushButton * m_Button; +}; + + +} +} + +#endif