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

ENH : Add ListWidget class

parent 21011b71
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 "otbWrapperListViewParameter.h"
namespace otb
{
namespace Wrapper
{
ListViewParameter::ListViewParameter()
: m_CurrentChoice(0)
{
}
ListViewParameter::~ListViewParameter()
{
}
void
ListViewParameter::AddChoice( std::string choicekey, std::string choiceName )
{
ListViewChoice choice;
choice.m_Key = choicekey;
choice.m_Name = choiceName;
m_ChoiceList.push_back(choice);
}
std::string
ListViewParameter::GetChoiceKey( int i )
{
return m_ChoiceList[i].m_Key;
}
std::vector<std::string>
ListViewParameter::GetChoiceKeys( )
{
std::vector<std::string> ret;
ChoiceList::iterator it = m_ChoiceList.begin();
for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
{
ret.push_back(it->m_Key);
}
return ret;
}
std::string
ListViewParameter::GetChoiceName( int i )
{
return m_ChoiceList[i].m_Name;
}
std::vector<std::string>
ListViewParameter::GetChoiceNames( )
{
std::vector<std::string> ret;
ChoiceList::iterator it = m_ChoiceList.begin();
for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
{
ret.push_back(it->m_Name);
}
return ret;
}
unsigned int
ListViewParameter::GetNbChoices( void )
{
return m_ChoiceList.size();
}
void
ListViewParameter::SetValue(unsigned int v)
{
m_CurrentChoice = v;
SetActive(true);
// Call Modified();
this->Modified();
}
void
ListViewParameter::SetValue(std::string choiceKey)
{
ChoiceList::iterator it = m_ChoiceList.begin();
unsigned int i = 0;
for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
{
if ( it->m_Key == choiceKey )
{
SetValue(i);
return;
}
++i;
}
itkExceptionMacro(<< "Cannot find " << choiceKey);
}
unsigned int
ListViewParameter::GetValue()
{
return m_CurrentChoice;
}
// TODO : not implemented yet
std::vector<std::string>
ListViewParameter::GetParametersKeys()
{
std::vector<std::string> parameters;
ChoiceList::iterator cit = m_ChoiceList.begin();
// for (cit = m_ChoiceList.begin(); cit != m_ChoiceList.end(); ++cit)
// {
// if (cit->m_AssociatedParameter)
// {
// std::vector<std::string> subparams = cit->m_AssociatedParameter->GetParametersKeys();
// for (std::vector<std::string>::const_iterator it = subparams.begin();
// it != subparams.end(); ++it)
// {
// parameters.push_back( cit->m_Key + "." + *it );
// }
// }
// }
return parameters;
}
/** Clear choices */
void
ListViewParameter::ClearChoices()
{
m_ChoiceList.clear();
}
}
}
/*=========================================================================
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 __otbWrapperListViewParameter_h
#define __otbWrapperListViewParameter_h
#include "otbWrapperParameter.h"
#include "otbWrapperParameterGroup.h"
namespace otb
{
namespace Wrapper
{
/** \class ListViewParameter
* \brief This class represent a ListWidget parameter for the wrapper framework
*
* The row selected in the ListWidget are stored in a std::vector. The
* method GetSelectedItems() allow the user to access to this method.
*
*/
class ListViewParameter
: public Parameter
{
public:
/** Standard class typedef */
typedef ListViewParameter Self;
typedef Parameter Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
itkNewMacro(Self);
/** RTTI support */
itkTypeMacro(ListViewParameter, Parameter);
/** Add a value to the choice */
void AddChoice( std::string choicekey, std::string choiceName );
/** Get the key of a specific choice value */
std::string GetChoiceKey( int i );
/** Get the list of the different choice keys */
std::vector<std::string> GetChoiceKeys();
/** Get the long name of a specific choice value */
std::string GetChoiceName( int i );
/** Get the list of the different choice keys */
std::vector<std::string> GetChoiceNames();
/** Get all parameters that are child of this choice parameter */
std::vector<std::string> GetParametersKeys();
/** Get the number of available choice */
unsigned int GetNbChoices( void );
/** Set choice value */
virtual void SetValue(unsigned int v);
/** Set choice value by its key */
virtual void SetValue(std::string choiceKey);
/** Return any value */
virtual unsigned int GetValue();
bool HasValue() const
{
// a choice parameter always has a value
return true;
}
void ClearValue()
{
// nothing to do : a choice parameter always has a value
}
void ClearChoices();
std::vector<int> GetSelectedItems()
{
return m_SelectedItems;
}
void SetSelectedItems(std::vector<int> selectedItems)
{
m_SelectedItems = selectedItems;
}
protected:
/** Constructor */
ListViewParameter();
/** Destructor */
virtual ~ListViewParameter();
struct ListViewChoice
{
ListViewChoice() {}
std::string m_Key;
std::string m_Name;
};
typedef std::vector<ListViewChoice> ChoiceList;
ChoiceList m_ChoiceList;
unsigned int m_CurrentChoice;
std::vector<int> m_SelectedItems;
private:
ListViewParameter(const ListViewParameter &); //purposely not implemented
void operator =(const ListViewParameter&); //purposely not implemented
}; // End class Parameter
} // End namespace Wrapper
} // End namespace otb
#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