Skip to content
Snippets Groups Projects
Commit d112baae authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ADD: Qtwidget for a directory parameter

parent 2e29abff
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
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);
}
}
}
/*=========================================================================
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment