Skip to content

Commit

Permalink
Merge pull request #1091 from 3nids/uioptionbase2
Browse files Browse the repository at this point in the history
dialog base: separator and dialog title as argument to init/restore
  • Loading branch information
dakcarto committed Jan 23, 2014
2 parents db7cddf + f9c5ee0 commit 94027df
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 34 deletions.
21 changes: 13 additions & 8 deletions src/app/pluginmanager/qgspluginmanager.cpp
Expand Up @@ -1346,18 +1346,23 @@ bool QgsPluginManager::hasInvalidPlugins( )

void QgsPluginManager::updateWindowTitle( )
{
QString newTitle = QString( "%1 - %2" ).arg( tr( "Plugins" ) ).arg( mOptionsListWidget->currentItem()->text() );
if ( mOptionsListWidget->currentRow() < mOptionsListWidget->count() - 1 )
QListWidgetItem *curitem = mOptListWidget->currentItem();
if ( curitem )
{
// if it's not the Settings tab, add the plugin count
newTitle += QString( " (%3)" ).arg( mModelProxy->countWithCurrentStatus() );
QString title = QString( "%1 | %2" ).arg( tr( "Plugins" ) ).arg( curitem->text() );
if ( mOptionsListWidget->currentRow() < mOptionsListWidget->count() - 1 )
{
// if it's not the Settings tab, add the plugin count
title += QString( " (%3)" ).arg( mModelProxy->countWithCurrentStatus() );
setWindowTitle( title );
}
}
else
{
setWindowTitle( mDialogTitle );
}
setWindowTitle( newTitle );
return;
}



void QgsPluginManager::showEvent( QShowEvent* e )
{
if ( mInit )
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsabout.cpp
Expand Up @@ -38,7 +38,8 @@ QgsAbout::QgsAbout( QWidget *parent )
#endif
{
setupUi( this );
initOptionsBase();
QString title = QString( "%1 - %2 Bit" ).arg( windowTitle() ).arg( QSysInfo::WordSize );
initOptionsBase( true, title );
init();
}

Expand All @@ -50,8 +51,6 @@ void QgsAbout::init()
{
setPluginInfo();

setWindowTitle( QString( "%1 - %2 Bit" ).arg( windowTitle() ).arg( QSysInfo::WordSize ) );

// set the 60x60 icon pixmap
QPixmap icon( QgsApplication::iconsPath() + "qgis-icon-60x60.png" );
qgisIcon->setPixmap( icon );
Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -225,8 +225,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
.arg( pyramidSentence2 ).arg( pyramidSentence3 )
.arg( pyramidSentence4 ).arg( pyramidSentence5 ) );

setWindowTitle( tr( "Layer Properties - %1" ).arg( lyr->name() ) );

tableTransparency->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
tableTransparency->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );

Expand Down Expand Up @@ -402,7 +400,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv

mResetColorRenderingBtn->setIcon( QgsApplication::getThemeIcon( "/mActionUndo.png" ) );

restoreOptionsBaseUi();
QString title = QString( tr( "Layer Properties - %1" ) ).arg( lyr->name() );
restoreOptionsBaseUi( title );
} // QgsRasterLayerProperties ctor


Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -250,8 +250,6 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
);
}

setWindowTitle( tr( "Layer Properties - %1" ).arg( layer->name() ) );

QSettings settings;
// if dialog hasn't been opened/closed yet, default to Styles tab, which is used most often
// this will be read by restoreOptionsBaseUi()
Expand All @@ -261,7 +259,8 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mOptStackedWidget->indexOf( mOptsPage_Style ) );
}

restoreOptionsBaseUi();
QString title = QString( tr( "Layer Properties - %1" ) ).arg( layer->name() );
restoreOptionsBaseUi( title );
} // QgsVectorLayerProperties ctor


Expand Down
42 changes: 28 additions & 14 deletions src/gui/qgsoptionsdialogbase.cpp
Expand Up @@ -47,11 +47,14 @@ QgsOptionsDialogBase::~QgsOptionsDialogBase()
}
}

void QgsOptionsDialogBase::initOptionsBase( bool restoreUi )
void QgsOptionsDialogBase::initOptionsBase( bool restoreUi, QString title )
{
// save original dialog title so it can be used to be concatenated
// save dialog title so it can be used to be concatenated
// with category title in icon-only mode
mDialogTitle = windowTitle();
if ( title.isEmpty() )
mDialogTitle = windowTitle();
else
mDialogTitle = title;

// don't add to dialog margins
// redefine now, or those in inherited .ui file will be added
Expand Down Expand Up @@ -109,16 +112,22 @@ void QgsOptionsDialogBase::initOptionsBase( bool restoreUi )
mInit = true;

if ( restoreUi )
restoreOptionsBaseUi();
restoreOptionsBaseUi( mDialogTitle );
}

void QgsOptionsDialogBase::restoreOptionsBaseUi()
void QgsOptionsDialogBase::restoreOptionsBaseUi( QString title )
{
if ( !mInit )
{
return;
}

if ( !title.isEmpty() )
{
mDialogTitle = title;
updateWindowTitle();
}

// re-save original dialog title in case it was changed after dialog initialization
mDialogTitle = windowTitle();

Expand Down Expand Up @@ -179,6 +188,19 @@ void QgsOptionsDialogBase::paintEvent( QPaintEvent* e )
QDialog::paintEvent( e );
}

void QgsOptionsDialogBase::updateWindowTitle()
{
QListWidgetItem *curitem = mOptListWidget->currentItem();
if ( curitem )
{
setWindowTitle( QString( "%1 | %2" ).arg( mDialogTitle ).arg( curitem->text() ) );
}
else
{
setWindowTitle( mDialogTitle );
}
}

void QgsOptionsDialogBase::updateOptionsListVerticalTabs()
{
if ( !mInit )
Expand Down Expand Up @@ -221,15 +243,7 @@ void QgsOptionsDialogBase::optionsStackedWidget_CurrentChanged( int indx )
mOptListWidget->setCurrentRow( indx );
mOptListWidget->blockSignals( false );

QListWidgetItem *curitem = mOptListWidget->currentItem();
if ( curitem )
{
setWindowTitle( QString( "%1 - %2" ).arg( mDialogTitle ).arg( curitem->text() ) );
}
else
{
setWindowTitle( mDialogTitle );
}
updateWindowTitle();
}

void QgsOptionsDialogBase::optionsStackedWidget_WidgetRemoved( int indx )
Expand Down
9 changes: 6 additions & 3 deletions src/gui/qgsoptionsdialogbase.h
Expand Up @@ -59,14 +59,15 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog

/** Set up the base ui connections for vertical tabs.
* @param restoreUi Whether to restore the base ui at this time.
* @param title the window title
*/
void initOptionsBase( bool restoreUi = true );
void initOptionsBase( bool restoreUi = true, QString title = QString() );

/** Restore the base ui.
* Sometimes useful to do at end of subclass's constructor.
* e.g. if setWindowTitle is used after initOptionsBase.
* @param title the window title (it does not need to be defined if previously given to initOptionsBase();
*/
void restoreOptionsBaseUi();
void restoreOptionsBaseUi( QString title = QString() );

/** determine if the options list is in icon only mode
*/
Expand All @@ -82,6 +83,8 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog
void showEvent( QShowEvent* e );
void paintEvent( QPaintEvent* e );

virtual void updateWindowTitle();

QString mOptsKey;
bool mInit;
QListWidget* mOptListWidget;
Expand Down

0 comments on commit 94027df

Please sign in to comment.