Commit 37e1c053 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[FIX #169] keep track of previously selected tabs

parent 1fa09401
......@@ -70,7 +70,8 @@
WQtControlPanel::WQtControlPanel( WMainWindow* parent )
: QDockWidget( "Control Panel", parent ),
m_ignoreSelectionChange( false ),
m_activeModule( WModule::SPtr() )
m_activeModule( WModule::SPtr() ),
m_previousTab()
{
setObjectName( "Control Panel Dock" );
......@@ -874,6 +875,45 @@ void WQtControlPanel::setActiveModule( WModule::SPtr module, bool forceUpdate )
buildPropTab( module->getProperties(), module->getInformationProperties() );
}
// re-select the previous tab
bool foundTab = false;
std::map< QString, int > priorityList;
if( m_previousTab != "" )
{
// search the tab with the previous title
for( size_t idx = 0; idx < m_tabWidget->count(); ++idx )
{
if( m_tabWidget->tabText( idx ) == m_previousTab )
{
m_tabWidget->setCurrentIndex( idx );
foundTab = true;
break;
}
// keep track of the indices in the tab. we use this map later as priority list. Please not that we add 1 to the index. This ensures
// that the invalid index is 0, even if it is -1 in Qt.
priorityList[ m_tabWidget->tabText( idx ) ] = idx + 1;
}
if( !foundTab )
{
// the tab does not exist anymore. We need to use our priority list
if( priorityList[ "Settings" ] != 0 )
{
m_tabWidget->setCurrentIndex( priorityList[ "Settings" ] - 1 );
}
else if( priorityList[ "Information" ] != 0 )
{
m_tabWidget->setCurrentIndex( priorityList[ "Settings" ] - 1 );
}
else
{
// there is no info and no settings tab. Set the first tab.
m_tabWidget->setCurrentIndex( 0 );
}
}
}
// update compatibles toolbar
createCompatibleButtons( module );
......@@ -943,6 +983,8 @@ void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boos
int propIdx = addTabWidgetContent( tab );
// select the property widget preferably
if( m_previousTab == "" )
{
if( propIdx != -1 )
{
m_tabWidget->setCurrentIndex( propIdx );
......@@ -951,6 +993,7 @@ void WQtControlPanel::buildPropTab( boost::shared_ptr< WProperties > props, boos
{
m_tabWidget->setCurrentIndex( infoIdx );
}
}
}
/**
......@@ -1240,6 +1283,11 @@ QAction* WQtControlPanel::getMissingModuleAction() const
void WQtControlPanel::clearAndDeleteTabs()
{
if( m_tabWidget->currentIndex() != -1 )
{
m_previousTab = m_tabWidget->tabText( m_tabWidget->currentIndex() );
}
m_tabWidget->setDisabled( true );
QWidget *widget;
while( ( widget = m_tabWidget->widget( 0 ) ))
......
......@@ -379,6 +379,12 @@ private:
* The module currently active
*/
WModule::SPtr m_activeModule;
/**
* The title of the last selected tab in the control panel. This needs to be done using the tab name as the tab index is not consistent(
* depending on the number of tabs. Sometimes, some tabs are not visible).
*/
QString m_previousTab;
private slots:
/**
* function that gets called when a tree item is selected, on a new select that tab widget
......
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