Commit ed711189 authored by Frédéric Larue's avatar Frédéric Larue

Prevent AlgorithmSelector to select a category or a tool that does not exist anymore.

parent 1fe21501
......@@ -30,9 +30,9 @@ AlgorithmSelector::AlgorithmSelector(QWidget *parent) :
m_CategoryButtonGroup = new QButtonGroup( this );
connect( m_CategoryButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(selectCategory(int)) );
m_ToolsByCategory.resize( ToolCategory::categoriesCount() );
m_LastUsedInCategory.resize( ToolCategory::categoriesCount() );
for( int i=0; i<ToolCategory::categoriesCount(); ++i )
m_ToolsByCategory.resize( ToolCategory::categoryCount() );
m_LastUsedInCategory.resize( ToolCategory::categoryCount() );
for( int i=0; i<ToolCategory::categoryCount(); ++i )
m_LastUsedInCategory[i] = 0;
}
......@@ -124,7 +124,7 @@ void AlgorithmSelector::finalizeTools()
QPushButton *firstCategoryButton = NULL;
int firstCategoryId = -1;
for( int categoryId : ToolCategory::categoriesId() )
for( int categoryId : ToolCategory::categoryIds() )
if( !m_ToolsByCategory[categoryId].empty() )
{
QVBoxLayout *l = new QVBoxLayout();
......@@ -174,8 +174,11 @@ void AlgorithmSelector::finalizeTools()
}
void AlgorithmSelector::selectCategory( int categoryId )
bool AlgorithmSelector::selectCategory( int categoryId )
{
if( !ToolCategory::isCategoryDeclared(categoryId) )
return false;
disconnect( m_ui->comboAvailableTools, SIGNAL(currentIndexChanged(int)), this, SLOT(selectTool(int)) );
m_SelectedCategory = categoryId;
......@@ -190,10 +193,12 @@ void AlgorithmSelector::selectCategory( int categoryId )
selectTool( lastUsedId );
connect( m_ui->comboAvailableTools, SIGNAL(currentIndexChanged(int)), this, SLOT(selectTool(int)) );
return true;
}
void AlgorithmSelector::selectTool( int n )
bool AlgorithmSelector::selectTool( int n )
{
if( m_SelectedToolParam )
{
......@@ -201,6 +206,9 @@ void AlgorithmSelector::selectTool( int n )
m_SelectedToolParam = NULL;
}
if( n >= m_ToolsByCategory[m_SelectedCategory].size() )
return false;
if( n >= 0 )
{
m_SelectedTool = &m_ToolsByCategory[m_SelectedCategory][n];
......@@ -240,6 +248,8 @@ void AlgorithmSelector::selectTool( int n )
m_ui->groupToolDescription->hide();
m_SelectedTool = NULL;
}
return true;
}
......
......@@ -75,8 +75,8 @@ protected:
void changeEvent(QEvent *e);
private slots:
void selectCategory( int categoryId );
void selectTool( int n );
bool selectCategory( int categoryId );
bool selectTool( int n );
void createProgressBars( int n );
void deleteProgressBars();
......
......@@ -29,8 +29,8 @@ public:
static inline bool isCategoryDeclared( int id ) { return s_CategoryById.contains( id ); }
static void declareCategory( int id, const QString& name, const QString &iconName );
static inline int categoriesCount() { return s_CategoryById.size(); }
static inline QList<int> categoriesId()
static inline int categoryCount() { return s_CategoryById.size(); }
static inline QList<int> categoryIds()
{
QList<int> ids;
for( auto i=s_CategoryById.begin(); i!=s_CategoryById.end(); ++i )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment