Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update Project Properties dialog with vertical tabs and update ui
- Dialog now subclassed from new class QgsOptionsDialogBase
- Add collapsible group boxes where applicable
- Update Projection Selector ui to work in outlying cases
- Switch Opacity default for styles to Transparency
  • Loading branch information
dakcarto committed Mar 26, 2013
1 parent 4189f45 commit 5b7c895
Show file tree
Hide file tree
Showing 7 changed files with 2,443 additions and 1,481 deletions.
110 changes: 67 additions & 43 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -57,21 +57,31 @@ const char * QgsProjectProperties::GEO_NONE_DESC = QT_TRANSLATE_NOOP( "QgsOption
//stdc++ includes

QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl )
: QgsOptionsDialogBase( "ProjectProperties", parent, fl )
, mMapCanvas( mapCanvas )
, mEllipsoidList()
, mEllipsoidIndex( 0 )

{
setupUi( this );
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
// 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 );

connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( projectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( setMapUnitsToCurrentProjection() ) );

connect( cmbEllipsoid, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateEllipsoidUI( int ) ) );

connect( radMeters, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setDisabled( bool ) ) );
connect( radFeet, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setDisabled( bool ) ) );
connect( radDegrees, SIGNAL( toggled( bool ) ), btnGrpDegreeDisplay, SLOT( setEnabled( bool ) ) );

connect( radAutomatic, SIGNAL( toggled( bool ) ), mPrecisionFrame, SLOT( setDisabled( bool ) ) );
connect( radManual, SIGNAL( toggled( bool ) ), mPrecisionFrame, SLOT( setEnabled( bool ) ) );

///////////////////////////////////////////////////////////
// Properties stored in map canvas's QgsMapRenderer
// these ones are propagated to QgsProject by a signal
Expand All @@ -80,17 +90,14 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
QGis::UnitType myUnit = myRenderer->mapUnits();
setMapUnits( myUnit );

// we need to initialize it, since the on_cbxProjectionEnabled_stateChanged()
// callback triggered by setChecked() might use it.
// we need to initialize it, since the on_cbxProjectionEnabled_toggled()
// slot triggered by setChecked() might use it.
mProjectSrsId = myRenderer->destinationCrs().srsid();

//see if the user wants on the fly projection enabled
bool myProjectionEnabled = myRenderer->hasCrsTransformEnabled();
cbxProjectionEnabled->setChecked( myProjectionEnabled );

QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) );
projectionSelector->setSelectedCrsId( mProjectSrsId );
projectionSelector->setEnabled( myProjectionEnabled );

// see end of constructor for updating of projection selector

///////////////////////////////////////////////////////////
// Properties stored in QgsProject
Expand All @@ -99,16 +106,16 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

// get the manner in which the number of decimal places in the mouse
// position display is set (manual or automatic)
bool automaticPrecision = QgsProject::instance()->readBoolEntry( "PositionPrecision", "/Automatic" );
bool automaticPrecision = QgsProject::instance()->readBoolEntry( "PositionPrecision", "/Automatic", true );
if ( automaticPrecision )
{
radAutomatic->setChecked( true );
spinBoxDP->setDisabled( true );
labelDP->setDisabled( true );
mPrecisionFrame->setEnabled( false );
}
else
{
radManual->setChecked( true );
mPrecisionFrame->setEnabled( true );
}

cbxAbsolutePath->setCurrentIndex( QgsProject::instance()->readBoolEntry( "Paths", "/Absolute", true ) ? 0 : 1 );
Expand Down Expand Up @@ -434,6 +441,18 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
resetPythonMacros();
}

// Update projection selector (after mLayerSrsId is set)
bool myProjectionEnabled = myRenderer->hasCrsTransformEnabled();
bool onFlyChecked = cbxProjectionEnabled->isChecked();
cbxProjectionEnabled->setChecked( myProjectionEnabled );

if ( onFlyChecked == myProjectionEnabled )
{
// ensure selector is updated if cbxProjectionEnabled->toggled signal not sent
on_cbxProjectionEnabled_toggled( myProjectionEnabled );
}

restoreOptionsBaseUi();
restoreState();
}

Expand All @@ -442,15 +461,12 @@ QgsProjectProperties::~QgsProjectProperties()
saveState();
}



// return the map units
QGis::UnitType QgsProjectProperties::mapUnits() const
{
return mMapCanvas->mapRenderer()->mapUnits();
}


void QgsProjectProperties::setMapUnits( QGis::UnitType unit )
{
// select the button
Expand All @@ -466,21 +482,17 @@ void QgsProjectProperties::setMapUnits( QGis::UnitType unit )
mMapCanvas->mapRenderer()->setMapUnits( unit );
}


QString QgsProjectProperties::title() const
{
return titleEdit->text();
} // QgsProjectPropertires::title() const


void QgsProjectProperties::title( QString const & title )
{
titleEdit->setText( title );
QgsProject::instance()->title( title );
} // QgsProjectProperties::title( QString const & title )



//when user clicks apply button
void QgsProjectProperties::apply()
{
Expand Down Expand Up @@ -769,7 +781,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "DefaultStyles", "/Line", cboStyleLine->currentText() );
QgsProject::instance()->writeEntry( "DefaultStyles", "/Fill", cboStyleFill->currentText() );
QgsProject::instance()->writeEntry( "DefaultStyles", "/ColorRamp", cboStyleColorRamp->currentText() );
QgsProject::instance()->writeEntry( "DefaultStyles", "/AlphaInt", 255 - mTransparencySlider->value() );
QgsProject::instance()->writeEntry( "DefaultStyles", "/AlphaInt", ( int )( 255 - ( mTransparencySlider->value() * 2.55 ) ) );
QgsProject::instance()->writeEntry( "DefaultStyles", "/RandomColors", cbxStyleRandomColors->isChecked() );

// store project macros
Expand All @@ -792,25 +804,37 @@ bool QgsProjectProperties::isProjected()

void QgsProjectProperties::showProjectionsTab()
{
tabWidget->setCurrentIndex( 1 );
mOptionsListWidget->setCurrentRow( 1 );
}

void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged( int state )
void QgsProjectProperties::on_cbxProjectionEnabled_toggled( bool onFlyEnabled )
{
projectionSelector->setEnabled( state == Qt::Checked );

if ( state != Qt::Checked )
QString measureOnFlyState = tr( "Measure tool (CRS transformation: %1)" );
QString unitsOnFlyState = tr( "Canvas units (CRS transformation: %1)" );
if ( !onFlyEnabled )
{
mProjectSrsId = projectionSelector->selectedCrsId();
if ( !mProjectSrsId )
{
mProjectSrsId = projectionSelector->selectedCrsId();
}
projectionSelector->setSelectedCrsId( mLayerSrsId );

btnGrpMeasureEllipsoid->setTitle( measureOnFlyState.arg( tr( "OFF" ) ) );
btnGrpMapUnits->setTitle( unitsOnFlyState.arg( tr( "OFF" ) ) );
}
else
{
mLayerSrsId = projectionSelector->selectedCrsId();
if ( !mLayerSrsId )
{
mLayerSrsId = projectionSelector->selectedCrsId();
}
projectionSelector->setSelectedCrsId( mProjectSrsId );

btnGrpMeasureEllipsoid->setTitle( measureOnFlyState.arg( tr( "ON" ) ) );
btnGrpMapUnits->setTitle( unitsOnFlyState.arg( tr( "ON" ) ) );
}

// Enable/Disabel selector and update tool-tip
// Enable/Disable selector and update tool-tip
updateEllipsoidUI( mEllipsoidIndex );
}

Expand Down Expand Up @@ -873,7 +897,7 @@ void QgsProjectProperties::on_cbxWFSDelete_stateChanged( int aIdx )
void QgsProjectProperties::setMapUnitsToCurrentProjection()
{
long myCRSID = projectionSelector->selectedCrsId();
if ( myCRSID )
if ( isProjected() && myCRSID )
{
QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
//set radio button to crs map unit type
Expand All @@ -886,23 +910,17 @@ void QgsProjectProperties::setMapUnitsToCurrentProjection()
}

/*!
* Function to save dialog window state
* Function to save non-base dialog states
*/
void QgsProjectProperties::saveState()
{
QSettings settings;
settings.setValue( "/Windows/ProjectProperties/geometry", saveGeometry() );
settings.setValue( "/Windows/ProjectProperties/tab", tabWidget->currentIndex() );
}

/*!
* Function to restore dialog window state
* Function to restore non-base dialog states
*/
void QgsProjectProperties::restoreState()
{
QSettings settings;
restoreGeometry( settings.value( "/Windows/ProjectProperties/geometry" ).toByteArray() );
tabWidget->setCurrentIndex( settings.value( "/Windows/ProjectProperties/tab" ).toInt() );
}

/*!
Expand Down Expand Up @@ -1212,9 +1230,8 @@ void QgsProjectProperties::populateStyles()
cbxStyleRandomColors->setChecked( QgsProject::instance()->readBoolEntry( "DefaultStyles", "/RandomColors", true ) );

// alpha transparency
int transparencyInt = 255 - QgsProject::instance()->readNumEntry( "DefaultStyles", "/AlphaInt", 255 );
int transparencyInt = ( 255 - QgsProject::instance()->readNumEntry( "DefaultStyles", "/AlphaInt", 255 ) ) / 2.55;
mTransparencySlider->setValue( transparencyInt );
on_mTransparencySlider_valueChanged( transparencyInt );
}

void QgsProjectProperties::on_pbtnStyleManager_clicked()
Expand Down Expand Up @@ -1248,9 +1265,16 @@ void QgsProjectProperties::on_pbtnStyleColorRamp_clicked()

void QgsProjectProperties::on_mTransparencySlider_valueChanged( int value )
{
double alpha = 1 - ( value / 255.0 );
double transparencyPercent = ( 1 - alpha ) * 100;
mTransparencyLabel->setText( tr( "Transparency %1%" ).arg(( int ) transparencyPercent ) );
mTransparencySpinBox->blockSignals( true );
mTransparencySpinBox->setValue( value );
mTransparencySpinBox->blockSignals( false );
}

void QgsProjectProperties::on_mTransparencySpinBox_valueChanged( int value )
{
mTransparencySlider->blockSignals( true );
mTransparencySlider->setValue( value );
mTransparencySlider->blockSignals( false );
}

void QgsProjectProperties::editSymbol( QComboBox* cbo )
Expand Down
11 changes: 6 additions & 5 deletions src/app/qgsprojectproperties.h
Expand Up @@ -17,6 +17,7 @@
***************************************************************************/


#include "qgsoptionsdialogbase.h"
#include "ui_qgsprojectpropertiesbase.h"
#include "qgis.h"
#include "qgisgui.h"
Expand All @@ -30,7 +31,7 @@ class QgsStyleV2;
@note actual state is stored in QgsProject singleton instance
*/
class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBase
class QgsProjectProperties : public QgsOptionsDialogBase, private Ui::QgsProjectPropertiesBase
{
Q_OBJECT

Expand Down Expand Up @@ -122,13 +123,14 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
void on_pbtnStyleFill_clicked();
void on_pbtnStyleColorRamp_clicked();
void on_mTransparencySlider_valueChanged( int value );
void on_mTransparencySpinBox_valueChanged( int value );

/*!
* Slot to show the context help for this dialog
*/
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }

void on_cbxProjectionEnabled_stateChanged( int state );
void on_cbxProjectionEnabled_toggled( bool onFlyEnabled );

/*!
* Slot to link WFS checkboxes
Expand Down Expand Up @@ -159,7 +161,6 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
//! let listening canvases know to refresh
void refresh();


private:
QgsMapCanvas* mMapCanvas;
QgsStyleV2* mStyle;
Expand All @@ -168,12 +169,12 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
void editSymbol( QComboBox* cbo );

/*!
* Function to save dialog window state
* Function to save non-base dialog states
*/
void saveState();

/*!
* Function to restore dialog window state
* Function to restore non-base dialog states
*/
void restoreState();

Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -84,6 +84,7 @@ qgsmessagelogviewer.cpp
qgsnewhttpconnection.cpp
qgsnewvectorlayerdialog.cpp
qgsnumericsortlistviewitem.cpp
qgsoptionsdialogbase.cpp
qgscredentialdialog.cpp
qgsowssourceselect.cpp
qgsprojectbadlayerguihandler.cpp
Expand Down Expand Up @@ -183,6 +184,7 @@ qgsmessageviewer.h
qgsmessagelogviewer.h
qgsnewhttpconnection.h
qgsnewvectorlayerdialog.h
qgsoptionsdialogbase.h
qgscredentialdialog.h
qgsowssourceselect.h
qgsprojectionselector.h
Expand Down Expand Up @@ -227,6 +229,7 @@ qgsmaptoolpan.h
qgsmaptoolzoom.h
qgsmessagebar.h
qgsmessageviewer.h
qgsoptionsdialogbase.h
qgscredentialdialog.h
qgsowssourceselect.h
qgsprojectionselector.h
Expand Down

0 comments on commit 5b7c895

Please sign in to comment.