Skip to content
Permalink
Browse files

Allow renaming map views

  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent dbe54c0 commit 560e9c25b3d73ca692d78939f2512414148b5d16
@@ -267,6 +267,7 @@
#include "qgsvectorlayerutils.h"
#include "qgshelp.h"
#include "qgsvectorfilewritertask.h"
#include "qgsnewnamedialog.h"

#include "qgssublayersdialog.h"
#include "ogr/qgsopenvectorlayerdialog.h"
@@ -3163,6 +3164,7 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name, bool isFloating,
mapCanvas->freeze( false );
markDirty();
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::closed, this, &QgisApp::markDirty );
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::renameTriggered, this, &QgisApp::renameView );
return mapCanvas;
}

@@ -11173,6 +11175,37 @@ void QgisApp::refreshActionFeatureAction()
mActionFeatureAction->setEnabled( layerHasActions );
}

void QgisApp::renameView()
{
QgsMapCanvasDockWidget *view = qobject_cast< QgsMapCanvasDockWidget * >( sender() );
if ( !view )
return;

// calculate existing names
QStringList names;
Q_FOREACH ( QgsMapCanvas *c, mapCanvases() )
{
if ( c == view->mapCanvas() )
continue;

names << c->objectName();
}

QString currentName = view->mapCanvas()->objectName();

QgsNewNameDialog renameDlg( currentName, currentName, QStringList(), names, QRegExp(), Qt::CaseSensitive, this );
renameDlg.setWindowTitle( tr( "Map Views" ) );
//renameDlg.setHintString( tr( "Name of the new view" ) );
renameDlg.setOverwriteEnabled( false );
renameDlg.setConflictingNameWarning( tr( "A view with this name already exists" ) );
if ( renameDlg.exec() || renameDlg.name().isEmpty() )
{
QString newName = renameDlg.name();
view->setWindowTitle( newName );
view->mapCanvas()->setObjectName( newName );
}
}

/////////////////////////////////////////////////////////////////
//
//
@@ -759,6 +759,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QMenu *panelMenu() { return mPanelMenu; }

void renameView();

protected:

//! Handle state changes (WindowTitleChange)
@@ -59,10 +59,15 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
connect( mActionSetCrs, &QAction::triggered, this, &QgsMapCanvasDockWidget::setMapCrs );
connect( mMapCanvas, &QgsMapCanvas::destinationCrsChanged, this, &QgsMapCanvasDockWidget::mapCrsChanged );
mapCrsChanged();
menu->addAction( mActionSetCrs );

QgsMapSettingsAction *settingsAction = new QgsMapSettingsAction( menu );
menu->addAction( settingsAction );

menu->addSeparator();
menu->addAction( mActionSetCrs );
menu->addAction( mActionRename );
connect( mActionRename, &QAction::triggered, this, &QgsMapCanvasDockWidget::renameTriggered );

mScaleCombo = settingsAction->scaleCombo();
mRotationEdit = settingsAction->rotationSpinBox();
mMagnificationEdit = settingsAction->magnifierSpinBox();
@@ -54,6 +54,10 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
*/
void closeWithoutWarning();

signals:

void renameTriggered();

protected:

virtual void closeEvent( QCloseEvent *event ) override;
@@ -73,7 +73,7 @@
<normaloff>:/images/themes/default/propertyicons/CRS.svg</normaloff>:/images/themes/default/propertyicons/CRS.svg</iconset>
</property>
<property name="text">
<string>Set Map CRS</string>
<string>Set Map CRS...</string>
</property>
<property name="toolTip">
<string>Set Map CRS</string>
@@ -94,6 +94,14 @@
<string>Synchronize View with Main Map</string>
</property>
</action>
<action name="mActionRename">
<property name="text">
<string>Rename view...</string>
</property>
<property name="toolTip">
<string>Rename View</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

0 comments on commit 560e9c2

Please sign in to comment.
You can’t perform that action at this time.