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

States of all tool category saved and restored on application launching / exiting.

parent 4bfdf610
......@@ -244,21 +244,54 @@ void AlgorithmSelector::selectTool( int n )
}
void AlgorithmSelector::selectTool( int categoryId, const QString& toolName )
QString AlgorithmSelector::state() const
{
m_CategoryButtonGroup->button( categoryId )->setChecked( true );
selectCategory( categoryId );
QString stateValue;
stateValue += QString::number(m_SelectedCategory) + ";";
stateValue += QString::number(m_ui->comboAvailableTools->currentIndex());
for( auto v : m_LastUsedInCategory )
stateValue += ";" + QString::number(v);
return stateValue;
}
for( int i=0; i<m_ToolsByCategory[m_SelectedCategory].size(); ++i )
bool AlgorithmSelector::setState( const QString &stateValue )
{
QStringList tokens = stateValue.split( ';' );
if( tokens.size() != m_LastUsedInCategory.size()+2 )
return false;
bool ok;
int selectedCategory = tokens.front().toInt( &ok );
if( !ok )
return false;
tokens.pop_front();
int selectedTool = tokens.front().toInt( &ok );
if( !ok )
return false;
tokens.pop_front();
QVector<int> lastUsedInCategory( m_LastUsedInCategory.size() );
for( auto &v : lastUsedInCategory )
{
auto &tool = m_ToolsByCategory[m_SelectedCategory][i];
if( tool.plugin->name( tool.id ) == toolName )
{
m_ui->comboAvailableTools->setCurrentIndex( i );
selectTool( i );
return;
}
v = tokens.front().toInt( &ok );
if( !ok )
return false;
tokens.pop_front();
}
m_CategoryButtonGroup->button( selectedCategory )->setChecked( true );
selectCategory( selectedCategory );
m_ui->comboAvailableTools->setCurrentIndex( selectedTool );
selectTool( selectedTool );
m_LastUsedInCategory = lastUsedInCategory;
return true;
}
......
......@@ -68,6 +68,9 @@ public:
inline QList<ToolDescriptor> allTools() const { return m_ToolsByName.values(); }
inline const ToolDescriptor* getToolByName( const QString& name ) const { auto found = m_ToolsByName.find(name); return (found==m_ToolsByName.end())? NULL : &*found; }
QString state() const;
bool setState( const QString &stateValue );
protected:
void changeEvent(QEvent *e);
......@@ -78,7 +81,6 @@ private slots:
void deleteProgressBars();
public slots:
void selectTool( int categoryId, const QString& toolName );
void emitApplySignal();
void emitActionSignal();
void applyCurrentToolOn( const QList<GenericUIData*> &items,
......
......@@ -72,8 +72,7 @@ bool UIMainWindow::saveUISettings() const
// Store the last category/tool used.
settings->setValue( "lastCategory", ui->toolSelector->currentCategoryId() );
settings->setValue( "lastTool", ui->toolSelector->currentToolName() );
settings->setValue( "toolState", ui->toolSelector->state() );
return true;
}
......@@ -101,8 +100,8 @@ bool UIMainWindow::loadUISettings()
// Load the last category/tool used.
if( settings->contains("lastCategory") && settings->contains("lastTool") )
ui->toolSelector->selectTool( settings->value("lastCategory").toInt(), settings->value("lastTool").toString() );
if( settings->contains("toolState") )
ui->toolSelector->setState( settings->value("toolState").toString() );
return true;
}
......
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