Skip to content

Commit

Permalink
keep rotation support state in canvas (followup 204e710)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 16, 2015
1 parent 204e710 commit d11cc82
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
19 changes: 15 additions & 4 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -161,7 +161,7 @@ class QgsMapCanvas : QGraphicsView
void clearExtentHistory();

/** Zoom to the extent of the selected features of current (vector) layer.
Added in version 1.2: optionally specify different than current layer */
@param layer optionally specify different than current layer */
void zoomToSelected( QgsVectorLayer* layer = NULL );

/** Pan to the selected features of current (vector) layer keeping same extent. */
Expand Down Expand Up @@ -203,7 +203,7 @@ class QgsMapCanvas : QGraphicsView
//! return number of layers on the map
int layerCount() const;

//! return list of layers within map canvas. Added in v1.5
//! return list of layers within map canvas.
QList<QgsMapLayer*> layers() const;

/*! Freeze/thaw the map canvas. This is used to prevent the canvas from
Expand Down Expand Up @@ -350,6 +350,14 @@ class QgsMapCanvas : QGraphicsView
//! ask user about datum transformation
void getDatumTransformInfo( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );

//! return if canvas rotation is enabled
//! @note added in 2.8
static bool rotationEnabled();

//! change canvas rotation support
//! @note added in 2.8
static void enableRotation( bool enabled );

signals:
/** Let the owner know how far we are with render operations */
//! @deprecated since 2.4 - already unused in 2.0 anyway
Expand All @@ -365,6 +373,10 @@ class QgsMapCanvas : QGraphicsView
//! Emitted when the extents of the map change
void extentsChanged();

//! Emitted when the rotation of the map changes
//! @note added in 2.8
void rotationChanged( double );

/** Emitted when the canvas has rendered.

Passes a pointer to the painter on which the map was drawn. This is
Expand All @@ -383,8 +395,7 @@ class QgsMapCanvas : QGraphicsView
void mapCanvasRefreshed();

// ### QGIS 3: rename to mapRefreshStarted()
/** Emitted when the canvas is about to be rendered.
\note Added in 1.5 */
/** Emitted when the canvas is about to be rendered. */
void renderStarting();

//! Emitted when a new set of layers has been received
Expand Down
10 changes: 2 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -1684,7 +1684,6 @@ void QgisApp::createStatusBar()
mCoordsEdit->setMaximumHeight( 20 );
mCoordsEdit->setContentsMargins( 0, 0, 0, 0 );
mCoordsEdit->setAlignment( Qt::AlignCenter );
mCoordsEdit->setAlignment( Qt::AlignCenter );
QRegExp coordValidator( "[+-]?\\d+\\.?\\d*\\s*,\\s*[+-]?\\d+\\.?\\d*" );
mCoordsEditValidator = new QRegExpValidator( coordValidator, mCoordsEdit );
mCoordsEdit->setWhatsThis( tr( "Shows the map coordinates at the "
Expand Down Expand Up @@ -1726,7 +1725,7 @@ void QgisApp::createStatusBar()
statusBar()->addPermanentWidget( mScaleEdit, 0 );
connect( mScaleEdit, SIGNAL( scaleChanged() ), this, SLOT( userScale() ) );

if ( QSettings().value( "/qgis/canvasRotation", true ).toBool() )
if ( QgsMapCanvas::rotationEnabled() )
{
// add a widget to show/set current rotation
mRotationLabel = new QLabel( QString(), statusBar() );
Expand All @@ -1747,7 +1746,6 @@ void QgisApp::createStatusBar()
mRotationEdit->setKeyboardTracking( false );
mRotationEdit->setMaximumWidth( 120 );
mRotationEdit->setDecimals( 1 );
mRotationEdit->setMaximumHeight( 20 );
mRotationEdit->setRange( -180.0, 180.0 );
mRotationEdit->setWrapping( true );
mRotationEdit->setSingleStep( 5.0 );
Expand Down Expand Up @@ -2098,10 +2096,6 @@ void QgisApp::setupConnections()
connect( this, SIGNAL( projectRead() ),
this, SLOT( checkForDeprecatedLabelsInProject() ) );

// reset rotation on new project
connect( this, SIGNAL( newProject() ),
this, SLOT( resetMapSettings() ) );

// setup undo/redo actions
connect( mUndoWidget, SIGNAL( undoStackChanged() ), this, SLOT( updateUndoActions() ) );
}
Expand Down Expand Up @@ -3530,7 +3524,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )

//QgsDebugMsg("emiting new project signal");

//emit signal so QgsComposer knows we have a new project
// emit signal so listeners know we have a new project
emit newProject();

mMapCanvas->freeze( false );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Expand Up @@ -151,7 +151,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsRasterLayer *addRasterLayer( const QString &rasterFile, const QString &baseName, bool guiWarning = true );

/** Returns and adjusted uri for the layer based on current and available CRS as well as the last selected image format
* @note added in 2.4
* @note added in 2.8
*/
QString crsAndFormatAdjustedLayerUri( const QString& uri, const QStringList& supportedCrs, const QStringList& supportedFormats ) const;

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsoptions.cpp
Expand Up @@ -583,7 +583,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
cbxCopyWKTGeomFromTable->setChecked( settings.value( "/qgis/copyGeometryAsWKT", true ).toBool() );
leNullValue->setText( settings.value( "qgis/nullValue", "NULL" ).toString() );
cbxIgnoreShapeEncoding->setChecked( settings.value( "/qgis/ignoreShapeEncoding", true ).toBool() );
cbxCanvasRotation->setChecked( settings.value( "/qgis/canvasRotation", true ).toBool() );
cbxCanvasRotation->setChecked( QgsMapCanvas::rotationEnabled() );

cmbLegendDoubleClickAction->setCurrentIndex( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() );

Expand Down Expand Up @@ -1111,7 +1111,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/legendDoubleClickAction", cmbLegendDoubleClickAction->currentIndex() );
bool legendLayersCapitalise = settings.value( "/qgis/capitaliseLayerName", false ).toBool();
settings.setValue( "/qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
settings.setValue( "/qgis/canvasRotation", cbxCanvasRotation->isChecked() );
QgsMapCanvas::enableRotation( cbxCanvasRotation->isChecked() );

// Default simplify drawing configuration
QgsVectorSimplifyMethod::SimplifyHints simplifyHints = QgsVectorSimplifyMethod::NoSimplification;
Expand Down
12 changes: 11 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Expand Up @@ -904,7 +904,7 @@ double QgsMapCanvas::rotation() const

void QgsMapCanvas::setRotation( double degrees )
{
if ( !QSettings().value( "/qgis/canvasRotation", true ).toBool() )
if ( !rotationEnabled() )
return;

double current = rotation();
Expand Down Expand Up @@ -1905,3 +1905,13 @@ bool QgsMapCanvas::event( QEvent * e )
return done;
}
#endif

bool QgsMapCanvas::rotationEnabled()
{
return QSettings().value( "/qgis/canvasRotation", true ).toBool();
}

void QgsMapCanvas::enableRotation( bool enable )
{
QSettings().setValue( "/qgis/canvasRotation", enable );
}
9 changes: 8 additions & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -419,6 +419,14 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! ask user about datum transformation
void getDatumTransformInfo( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );

//! return if canvas rotation is enabled
//! @note added in 2.8
static bool rotationEnabled();

//! change canvas rotation support
//! @note added in 2.8
static void enableRotation( bool enabled );

private slots:
//! called when current maptool is destroyed
void mapToolDestroyed();
Expand Down Expand Up @@ -644,7 +652,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
QgsPreviewEffect* mPreviewEffect;

QgsRectangle imageRect( const QImage& img );

}; // class QgsMapCanvas


Expand Down

0 comments on commit d11cc82

Please sign in to comment.