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 ) ...@@ -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 ); QString stateValue;
selectCategory( categoryId );
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]; v = tokens.front().toInt( &ok );
if( tool.plugin->name( tool.id ) == toolName ) if( !ok )
{ return false;
m_ui->comboAvailableTools->setCurrentIndex( i ); tokens.pop_front();
selectTool( i );
return;
}
} }
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: ...@@ -68,6 +68,9 @@ public:
inline QList<ToolDescriptor> allTools() const { return m_ToolsByName.values(); } 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; } 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: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
...@@ -78,7 +81,6 @@ private slots: ...@@ -78,7 +81,6 @@ private slots:
void deleteProgressBars(); void deleteProgressBars();
public slots: public slots:
void selectTool( int categoryId, const QString& toolName );
void emitApplySignal(); void emitApplySignal();
void emitActionSignal(); void emitActionSignal();
void applyCurrentToolOn( const QList<GenericUIData*> &items, void applyCurrentToolOn( const QList<GenericUIData*> &items,
......
...@@ -72,8 +72,7 @@ bool UIMainWindow::saveUISettings() const ...@@ -72,8 +72,7 @@ bool UIMainWindow::saveUISettings() const
// Store the last category/tool used. // Store the last category/tool used.
settings->setValue( "lastCategory", ui->toolSelector->currentCategoryId() ); settings->setValue( "toolState", ui->toolSelector->state() );
settings->setValue( "lastTool", ui->toolSelector->currentToolName() );
return true; return true;
} }
...@@ -101,8 +100,8 @@ bool UIMainWindow::loadUISettings() ...@@ -101,8 +100,8 @@ bool UIMainWindow::loadUISettings()
// Load the last category/tool used. // Load the last category/tool used.
if( settings->contains("lastCategory") && settings->contains("lastTool") ) if( settings->contains("toolState") )
ui->toolSelector->selectTool( settings->value("lastCategory").toInt(), settings->value("lastTool").toString() ); ui->toolSelector->setState( settings->value("toolState").toString() );
return true; 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