Commit 35c6838f authored by Otmane Lahlou's avatar Otmane Lahlou

ENH: fork WrapperQtWidget{ InputImageListParameter, FileSelection}

parent 30af2492
......@@ -9,7 +9,9 @@ set( Common_ApplicationsWrapper_SOURCES
mvdWrapperQtWidgetParameterFactory.cxx
mvdWrapperQtWidgetView.cxx
mvdWrapperQtWidgetParameterGroup.cxx
mvdWrapperQtWidgetChoiceParameter.cxx
mvdWrapperQtWidgetChoiceParameter.cxx
mvdWrapperQtWidgetInputImageListParameter.cxx
mvdWrapperQtWidgetFileSelection.cxx
)
#############################################################################
......@@ -24,6 +26,8 @@ set( Common_ApplicationsWrapper_HEADERS_MOC
mvdWrapperQtWidgetView.h
mvdWrapperQtWidgetParameterGroup.h
mvdWrapperQtWidgetChoiceParameter.h
mvdWrapperQtWidgetInputImageListParameter.h
mvdWrapperQtWidgetFileSelection.h
)
#############################################################################
......
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more 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 "mvdWrapperQtWidgetFileSelection.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
#include "Core/mvdAlgorithm.h"
namespace mvd
{
namespace Wrapper
{
/*
TRANSLATOR mvd::ApplicationLauncher
Necessary for lupdate to be aware of C++ namespaces.
Context comment for translator.
*/
/*****************************************************************************/
/* CONSTANTS */
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
QtWidgetFileSelection::QtWidgetFileSelection()
: QWidget()
{
this->DoCreateWidget();
//
// set accept drops in the widget
setAcceptDrops( true );
}
/*******************************************************************************/
QtWidgetFileSelection::~QtWidgetFileSelection()
{
}
/*******************************************************************************/
void QtWidgetFileSelection::DoUpdateGUI()
{
}
/*******************************************************************************/
void QtWidgetFileSelection::DoCreateWidget()
{
unsigned int sp = 2;
// Set up input text edit
m_HLayout = new QHBoxLayout;
m_HLayout->setSpacing(sp);
m_HLayout->setContentsMargins(sp, sp, sp, sp);
m_Checkbox = new QCheckBox();
m_HLayout->addWidget(m_Checkbox);
m_Input = new QLabel;
m_HLayout->addWidget(m_Input);
// Set up input text edit
m_Button = new QPushButton;
m_Button->setText("...");
m_Button->setToolTip("Select file...");
m_Button->setFixedWidth(30);
connect( m_Button, SIGNAL(clicked()), this, SLOT(SelectFile()) );
m_HLayout->addWidget(m_Button);
this->setLayout(m_HLayout);
}
/*******************************************************************************/
void
QtWidgetFileSelection::dragEnterEvent( QDragEnterEvent * event )
{
//
// accepts all the proposed actions : checking will be done
// dragMoveEvent method
event->acceptProposedAction();
}
/*******************************************************************************/
void
QtWidgetFileSelection::dragMoveEvent(QDragMoveEvent *event)
{
// if (event->mimeData()->hasFormat("text/plain")
//
// if the mouse is within the QLabel geometry : allow drops
if ( event->answerRect().intersects( m_Input->geometry() ) )
{
event->acceptProposedAction();
}
else
{
event->ignore();
}
}
/*******************************************************************************/
void
QtWidgetFileSelection::dropEvent(QDropEvent *event)
{
//
// TODO : need to define the mimeData format
// TODO : the data to drop will be defined in the DataSet TreeWidget
//
// get the text form the mimeData stored in the event : path
// to the image in the dataset
if ( event->mimeData()->hasText () )
{
//
// text stored in mimeData represents the filename to use
// extract valid filename by removing %20 and file:// form the
// string if any
std::string ofname = ExtractValidFilename( ToStdString(event->mimeData()->text()) );
//
// set the filename
m_Input->setText( QString( ofname.c_str() ) );
// since QLabel does not emit signal when textChanged, raise a signal
// in the code
emit textChanged( QString( ofname.data() ) );
}
}
/*******************************************************************************/
std::string
QtWidgetFileSelection::ExtractValidFilename(std::string payload)
{
// Parse the payload stream to extract all the filename
std::stringstream s (payload);
std::string token;
std::string ofname;
while ( s >> token )
{
// filename may contain whitespace coded as %20. Detect
// it and replace the 3 characters by a whitespace to be able to
// open the file.
while( size_t pos = token.find("%") != std::string::npos )
{
token.replace( pos, 3," ");
}
#ifdef WIN32
// In Win32 the files name are stored with no file://
ofname = token;
#else
// Remove the "file://" form the string : subst(7, end)
ofname = token.substr(7, token.size() );
#endif
}
return ofname;
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
void QtWidgetFileSelection::SelectFile()
{
QFileDialog fileDialog;
fileDialog.setConfirmOverwrite(true);
fileDialog.setFileMode(QFileDialog::ExistingFile);
fileDialog.setNameFilter("Raster files (*)");
if (fileDialog.exec())
{
QString filemane( fileDialog.selectedFiles().at(0) );
m_Input->setText(filemane);
// since QLabel does not emit signal when textChanged, raise a signal
// in the code
emit textChanged( fileDialog.selectedFiles().at(0) );
}
}
}
}
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more 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 __mvdWrapperQtWidgetFileSelection_h
#define __mvdWrapperQtWidgetFileSelection_h
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QtGui>
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
{
}
namespace mvd
{
namespace Wrapper
{
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class QtWidgetFileSelection
*
* \brief WIP.
*/
class QtWidgetFileSelection : public QWidget
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
/** \brief Constructor. */
QtWidgetFileSelection();
/** \brief destructor. */
virtual ~QtWidgetFileSelection();
/** \brief convenient methods */
bool IsChecked()
{
return m_Checkbox->isChecked();
}
void SetChecked( bool val )
{
return m_Checkbox->setChecked( val );
}
std::string GetFilename()
{
return static_cast<const char*>( m_Input->text().toAscii() );
}
void ClearFilename()
{
m_Input->clear();
}
QLabel* GetInput()
{
return m_Input;
}
signals:
void textChanged(const QString &);
protected slots:
void SelectFile();
protected:
/** \brief drag and drop events reimplementation */
void dragEnterEvent( QDragEnterEvent * event );
void dropEvent( QDropEvent *event );
void dragMoveEvent(QDragMoveEvent *event);
private:
QtWidgetFileSelection(const QtWidgetFileSelection&); //purposely not implemented
void operator=(const QtWidgetFileSelection&); //purposely not implemented
virtual void DoCreateWidget();
virtual void DoUpdateGUI();
std::string ExtractValidFilename(std::string payload);
QHBoxLayout * m_HLayout;
QLabel* m_Input;
QPushButton * m_Button;
QCheckBox * m_Checkbox;
};
}
}
#endif
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more 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 "mvdWrapperQtWidgetInputImageListParameter.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdWrapperQtWidgetFileSelection.h"
namespace mvd
{
namespace Wrapper
{
/*
TRANSLATOR mvd::ApplicationLauncher
Necessary for lupdate to be aware of C++ namespaces.
Context comment for translator.
*/
/*****************************************************************************/
/* CONSTANTS */
/*****************************************************************************/
/* STATIC IMPLEMENTATION SECTION */
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
QtWidgetInputImageListParameter::
QtWidgetInputImageListParameter(otb::Wrapper::InputImageListParameter* param,
otb::Wrapper::QtWidgetModel* m)
: otb::Wrapper::QtWidgetParameterBase(param, m),
m_InputImageListParam(param)
{
QObject::connect( this, SIGNAL(Change()), GetModel(), SLOT(NotifyUpdate()) );
}
/*******************************************************************************/
QtWidgetInputImageListParameter::~QtWidgetInputImageListParameter()
{
}
/*******************************************************************************/
void QtWidgetInputImageListParameter::DoUpdateGUI()
{
}
/*******************************************************************************/
void QtWidgetInputImageListParameter::DoCreateWidget()
{
m_FileSelectionList.clear();
const unsigned int sp(2);
const unsigned int buttonSize(30);
// Global layout
QHBoxLayout * hLayout = new QHBoxLayout;
hLayout->setSpacing(sp);
hLayout->setContentsMargins(sp, sp, sp, sp);
// Button layout
QVBoxLayout * buttonLayout = new QVBoxLayout;
buttonLayout->setSpacing(sp);
buttonLayout->setContentsMargins(sp, sp, sp, sp);
QHBoxLayout * addSupLayout = new QHBoxLayout;
addSupLayout->setSpacing(sp);
addSupLayout->setContentsMargins(sp, sp, sp, sp);
QHBoxLayout * upDownLayout = new QHBoxLayout;
upDownLayout->setSpacing(sp);
upDownLayout->setContentsMargins(sp, sp, sp, sp);
// Add file button
QPushButton * addButton = new QPushButton;
addButton->setText("+");
addButton->setFixedWidth(buttonSize);
addButton->setToolTip("Add a file selector...");
connect( addButton, SIGNAL(clicked()), this, SLOT(AddFile()) );
addSupLayout->addWidget(addButton);
// Supress file button
QPushButton * supButton = new QPushButton;
supButton->setText("-");
supButton->setFixedWidth(buttonSize);
supButton->setToolTip("Supress the selected file...");
connect( supButton, SIGNAL(clicked()), this, SLOT(SupressFile()) );
addSupLayout->addWidget(supButton);
buttonLayout->addLayout(addSupLayout);
// Up file edit
QPushButton * upButton = new QPushButton;
upButton->setText("Up");
upButton->setFixedWidth(buttonSize);
upButton->setToolTip("Up the selected file in the list...");
connect( upButton, SIGNAL(clicked()), this, SLOT(UpFile()) );
upDownLayout->addWidget(upButton);
// Down file edit
QPushButton * downButton = new QPushButton;
downButton->setText("Down");
downButton->setFixedWidth(buttonSize);
downButton->setToolTip("Down the selected file in the list...");
connect( downButton, SIGNAL(clicked()), this, SLOT(DownFile()) );
upDownLayout->addWidget(downButton);
buttonLayout->addLayout(upDownLayout);
// Erase file edit
QPushButton * eraseButton = new QPushButton;
eraseButton->setText("Erase");
eraseButton->setFixedWidth(2*(buttonSize+sp));
eraseButton->setToolTip("Erase the selected file of the list...");
connect( eraseButton, SIGNAL(clicked()), this, SLOT(EraseFile()) );
buttonLayout->addWidget(eraseButton);
QVBoxLayout * fileLayout = new QVBoxLayout();
fileLayout->setSpacing(0);
QtWidgetFileSelection * fileSelection = new QtWidgetFileSelection();
fileSelection->setFixedHeight(30);
fileLayout->addWidget( fileSelection );
m_InputImageListParam->AddNullElement();
connect( fileSelection, SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) );
m_FileSelectionList.push_back(fileSelection);
QGroupBox *mainGroup = new QGroupBox();
mainGroup->setLayout(fileLayout);
QScrollArea * scroll = new QScrollArea();
scroll->setWidget(mainGroup);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scroll->setWidgetResizable(true);
hLayout->addWidget(scroll);
hLayout->addLayout(buttonLayout);
this->setLayout(hLayout);
m_FileLayout = fileLayout;
m_HLayout = hLayout;
m_Scroll = scroll;
}
/*******************************************************************************/
void QtWidgetInputImageListParameter::RecreateImageList()
{
// save value
m_InputImageListParam->ClearValue();
if( m_FileSelectionList.size() == 0)
{
this->AddFile();
}
else
{
for(unsigned int j=0; j<m_FileSelectionList.size(); j++ )
{
m_InputImageListParam->AddFromFileName(m_FileSelectionList[j]->GetFilename());
connect( m_FileSelectionList[j]->GetInput(), SIGNAL(textChanged(const QString&)), this, SLOT(UpdateImageList()) );
}
emit Change();
// notify of value change
QString key( m_InputImageListParam->GetKey() );
emit ParameterChanged(key);
}
}
/*******************************************************************************/
void
QtWidgetInputImageListParameter::UpdateFileList( std::map<unsigned int, unsigned int> idMap )
{
std::vector<QtWidgetFileSelection *> tmpList;
// Keys become values and inverse
std::map<unsigned int, unsigned int> idMapBis;
for(unsigned int i=0; i<idMap.size(); i++ )
{
idMapBis[ idMap[i] ] = i;
}
// Create the new item list
for(unsigned int i=0; i<m_FileSelectionList.size(); i++ )
{
m_FileLayout->addWidget( m_FileSelectionList[ idMapBis[i] ] );
tmpList.push_back(m_FileSelectionList[ idMapBis[i] ]);
}
m_FileSelectionList = tmpList;
QGroupBox *mainGroup = new QGroupBox();