Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update main options dialog with QgsOptionsDialogBase inheritance
- Moved current tab setting to /Windows/Options/tab, as used in QgsOptionsDialogBase
- Caveat: old setting /Windows/Options/row is not honored on first launch after update
  • Loading branch information
dakcarto committed Jun 4, 2013
1 parent 0f21022 commit 9843209
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 120 deletions.
74 changes: 11 additions & 63 deletions src/app/qgsoptions.cpp
Expand Up @@ -69,21 +69,26 @@
* Constructor
*/
QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
QDialog( parent, fl )
QgsOptionsDialogBase( "Options", parent, fl )
{
setupUi( this );

// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );

// stylesheet setup
mStyleSheetBuilder = QgisApp::instance()->styleSheetBuilder();
mStyleSheetNewOpts = mStyleSheetBuilder->defaultOptions();
mStyleSheetOldOpts = QMap<QString, QVariant>( mStyleSheetNewOpts );

connect( mOptionsSplitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( updateVerticalTabs() ) );

connect( cmbTheme, SIGNAL( activated( const QString& ) ), this, SLOT( themeChanged( const QString& ) ) );
connect( cmbTheme, SIGNAL( highlighted( const QString& ) ), this, SLOT( themeChanged( const QString& ) ) );
connect( cmbTheme, SIGNAL( textChanged( const QString& ) ), this, SLOT( themeChanged( const QString& ) ) );

connect( mFontFamilyRadioCustom, SIGNAL( toggled( bool ) ), mFontFamilyComboBox, SLOT( setEnabled( bool ) ) );

connect( cmbIconSize, SIGNAL( activated( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
connect( cmbIconSize, SIGNAL( highlighted( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
connect( cmbIconSize, SIGNAL( textChanged( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
Expand All @@ -107,10 +112,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

// read the current browser and set it
QSettings settings;
// mOptionsListWidget width is fixed to takes up less space in QtDesigner
// revert it now unless the splitter's state hasn't been saved yet
mOptionsListWidget->setMaximumWidth(
settings.value( "/Windows/Options/splitState" ).isNull() ? 150 : 16777215 );

int identifyMode = settings.value( "/Map/identifyMode", 0 ).toInt();
cmbIdentifyMode->setCurrentIndex( cmbIdentifyMode->findData( identifyMode ) );
Expand Down Expand Up @@ -740,69 +741,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
mOverlayAlgorithmComboBox->setCurrentIndex( 0 );
} //default is central point

// restore window and widget geometry/state
restoreGeometry( settings.value( "/Windows/Options/geometry" ).toByteArray() );
mOptionsSplitter->restoreState( settings.value( "/Windows/Options/splitState" ).toByteArray() );

int currentIndx = settings.value( "/Windows/Options/row" ).toInt();
mOptionsListWidget->setCurrentRow( currentIndx );
mOptionsStackedWidget->setCurrentIndex( currentIndx );

// load gdal driver list only when gdal tab is first opened
mLoadedGdalDriverList = false;

// restore window and widget geometry/state
restoreOptionsBaseUi();
}

//! Destructor
QgsOptions::~QgsOptions()
{
QSettings settings;
settings.setValue( "/Windows/Options/geometry", saveGeometry() );
settings.setValue( "/Windows/Options/splitState", mOptionsSplitter->saveState() );
settings.setValue( "/Windows/Options/row", mOptionsListWidget->currentRow() );
}

void QgsOptions::showEvent( QShowEvent * e )
{
Q_UNUSED( e );
on_mOptionsStackedWidget_currentChanged( -1 );
updateVerticalTabs();
}

void QgsOptions::paintEvent( QPaintEvent * e )
{
Q_UNUSED( e );
QTimer::singleShot( 0, this, SLOT( updateVerticalTabs() ) );
}

void QgsOptions::updateVerticalTabs()
{
if ( mOptionsListWidget->maximumWidth() != 16777215 )
mOptionsListWidget->setMaximumWidth( 16777215 );
// auto-resize splitter for vert scrollbar without covering icons in icon-only mode
// TODO: mOptionsListWidget has fixed 32px wide icons for now, allow user-defined
// Note: called on splitter resize and dialog paint event, so only update when necessary
int iconWidth = mOptionsListWidget->iconSize().width();
int snapToIconWidth = iconWidth + 32;

QList<int> splitSizes = mOptionsSplitter->sizes();
bool iconOnly = splitSizes.at( 0 ) <= snapToIconWidth;

int newWidth = mOptionsListWidget->verticalScrollBar()->isVisible() ? iconWidth + 26 : iconWidth + 12;
bool diffWidth = mOptionsListWidget->minimumWidth() != newWidth;

if ( diffWidth )
mOptionsListWidget->setMinimumWidth( newWidth );

if ( iconOnly && ( diffWidth || mOptionsListWidget->width() != newWidth ) )
{
splitSizes[1] = splitSizes.at( 1 ) - ( splitSizes.at( 0 ) - newWidth );
splitSizes[0] = newWidth;
mOptionsSplitter->setSizes( splitSizes );
}
if ( mOptionsListWidget->wordWrap() && iconOnly )
mOptionsListWidget->setWordWrap( false );
if ( !mOptionsListWidget->wordWrap() && !iconOnly )
mOptionsListWidget->setWordWrap( true );
}

void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )
Expand Down
11 changes: 2 additions & 9 deletions src/app/qgsoptions.h
Expand Up @@ -18,6 +18,7 @@
#ifndef QGSOPTIONS_H
#define QGSOPTIONS_H

#include "qgsoptionsdialogbase.h"
#include "ui_qgsoptionsbase.h"
#include "qgisgui.h"
#include "qgisapp.h"
Expand All @@ -32,7 +33,7 @@
* \class QgsOptions
* \brief Set user options and preferences
*/
class QgsOptions : public QDialog, private Ui::QgsOptionsBase
class QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOptionsBase
{
Q_OBJECT
public:
Expand Down Expand Up @@ -216,11 +217,6 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
*/
void on_mOptionsStackedWidget_currentChanged( int theIndx );

/** Slot to update widget of vertical tabs
* @note added in QGIS 1.9
*/
void updateVerticalTabs();

/* Load the list of drivers available in GDAL
* @note added in 2.0
*/
Expand All @@ -245,9 +241,6 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
void addCustomEnvVarRow( QString varName, QString varVal, QString varApply = QString() );

protected:
void showEvent( QShowEvent * e );
void paintEvent( QPaintEvent * e );

QgisAppStyleSheet* mStyleSheetBuilder;
QMap<QString, QVariant> mStyleSheetNewOpts;
QMap<QString, QVariant> mStyleSheetOldOpts;
Expand Down
48 changes: 0 additions & 48 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -4091,54 +4091,6 @@
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsOptionsBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>702</x>
<y>680</y>
</hint>
<hint type="destinationlabel">
<x>735</x>
<y>708</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsOptionsBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>670</x>
<y>685</y>
</hint>
<hint type="destinationlabel">
<x>684</x>
<y>707</y>
</hint>
</hints>
</connection>
<connection>
<sender>mFontFamilyRadioCustom</sender>
<signal>toggled(bool)</signal>
<receiver>mFontFamilyComboBox</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>548</x>
<y>503</y>
</hint>
<hint type="destinationlabel">
<x>572</x>
<y>509</y>
</hint>
</hints>
</connection>
<connection>
<sender>mOptionsListWidget</sender>
<signal>currentRowChanged(int)</signal>
Expand Down

0 comments on commit 9843209

Please sign in to comment.