Index: /usr/local/src/qgis/src/app/qgisapp.h =================================================================== --- /usr/local/src/qgis/src/app/qgisapp.h (revision 10763) +++ /usr/local/src/qgis/src/app/qgisapp.h (working copy) @@ -46,6 +46,7 @@ class QgsLegend; class QgsMapCanvas; +class QgsMapOverviewCanvas; class QgsMapLayer; class QgsMapTip; class QgsMapTool; @@ -138,7 +139,7 @@ //!Overloaded version of the private function with same name that takes the imagename as a parameter void saveMapAsImage( QString, QPixmap * ); /** Get the mapcanvas object from the app */ - QgsMapCanvas * mapCanvas() { return mMapCanvas; }; + QgsMapCanvas * mapCanvas() { return mMapCanvas; } QgsComposer* printComposer() {return mComposer;} @@ -337,6 +338,10 @@ void zoomToNext(); //! Zoom to selected features void zoomToSelected(); + //! Create new tab + void createTabifiedDock(); + //! do needed procedures when user switch the tab + void setCurrentDockCanvas(int); //! cuts selected features on the active layer to the clipboard /** @@ -597,6 +602,9 @@ //! Stops rendering of the main map void stopRendering(); + void slotDockVisibilityChanged(bool); + void slotDockTopLevelChanged(bool); + signals: /** emitted when a key is pressed and we want non widget sublasses to be able to pick up on this (e.g. maplayer) */ @@ -674,6 +682,9 @@ void createCanvas(); bool createDB(); void createMapTips(); + QgsMapCanvas * createMapCanvasWithTools(); + void resetupConnections(QgsMapCanvas *thePrevMapCanvas, QgsLegend *thePrevMapLegend, + QgsMapCanvas *theNewMapCanvas, QgsLegend *theNewMapLegend); // toolbars --------------------------------------- QToolBar *mFileToolBar; @@ -688,6 +699,8 @@ // actions for menus and toolbars ----------------- QAction *mActionNewProject; + QAction *mActionNewCanvas; + QAction *mActionCloseCanvas; QAction *mActionOpenProject; QAction *mActionFileSeparator1; QAction *mActionSaveProject; @@ -808,6 +821,7 @@ QMenu *mHelpMenu; // docks ------------------------------------------ + QDockWidget *mCanvasDock; QDockWidget *mLegendDock; QDockWidget *mOverviewDock; @@ -819,6 +833,7 @@ class Tools { public: + ~Tools(); QgsMapTool* mZoomIn; QgsMapTool* mZoomOut; QgsMapTool* mPan; @@ -839,7 +854,11 @@ QgsMapTool* mSimplifyFeature; QgsMapTool* mDeleteRing; QgsMapTool* mDeletePart; - } mMapTools; + QgsMapTool* mCurrentTool; + } *mMapTools; + + //! List of map tools + QList mMapToolsList; QgsMapTool *mNonEditMapTool; @@ -873,6 +892,16 @@ QMenu *toolPopupCapture; //! Map canvas QgsMapCanvas *mMapCanvas; + + //! Map overview canvas + QgsMapOverviewCanvas *mMapOverviewCanvas; + //! List of map canvases + QList mMapCanvasList; + //! List of overviewcanvases + QList mMapOverviewCanvasList; + //! List of legends + QList mMapLegendList; + //! Table of contents (legend) for the map QgsLegend *mMapLegend; //! Cursor for the overview map @@ -940,6 +969,9 @@ //!flag to indicate that the previous screen mode was 'maximised' bool mPrevScreenModeMaximized; + // mCountOfTabs counts all numbers of created tabs and put it in a name of a new tab + int mCountOfTabs; + QgsPythonDialog* mPythonConsole; QgsPythonUtils* mPythonUtils; Index: /usr/local/src/qgis/src/app/qgisapp.cpp =================================================================== --- /usr/local/src/qgis/src/app/qgisapp.cpp (revision 10763) +++ /usr/local/src/qgis/src/app/qgisapp.cpp (working copy) @@ -311,8 +311,15 @@ // constructor starts here QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl ) : QMainWindow( parent, fl ), + mCanvasDock( NULL ), + mLegendDock( NULL ), + mOverviewDock( NULL ), + mMapCanvas( NULL ), + mMapLegend( NULL ), + mOverviewMapCursor( NULL ), mSplash( splash ), mComposer( 0 ), + mCountOfTabs(0), mPythonConsole( NULL ), mPythonUtils( NULL ) { @@ -454,27 +461,18 @@ delete mInternalClipboard; delete mQgisInterface; - delete mMapTools.mZoomIn; - delete mMapTools.mZoomOut; - delete mMapTools.mPan; - delete mMapTools.mIdentify; - delete mMapTools.mMeasureDist; - delete mMapTools.mMeasureArea; - delete mMapTools.mCapturePoint; - delete mMapTools.mCaptureLine; - delete mMapTools.mCapturePolygon; - delete mMapTools.mMoveFeature; - delete mMapTools.mSplitFeatures; - delete mMapTools.mSelect; - delete mMapTools.mVertexAdd; - delete mMapTools.mVertexMove; - delete mMapTools.mVertexDelete; - delete mMapTools.mAddRing; - delete mMapTools.mSimplifyFeature; - delete mMapTools.mDeleteRing; - delete mMapTools.mDeletePart; - delete mMapTools.mAddIsland; + // call delete for all items from the lists + qDeleteAll(mMapCanvasList); + qDeleteAll(mMapOverviewCanvasList); + qDeleteAll(mMapLegendList); + qDeleteAll(mMapToolsList); + // remove all items from the lists + mMapCanvasList.clear(); + mMapOverviewCanvasList.clear(); + mMapLegendList.clear(); + mMapToolsList.clear(); + delete mPythonConsole; delete mPythonUtils; @@ -546,6 +544,18 @@ mActionNewProject->setStatusTip( tr( "New Project" ) ); connect( mActionNewProject, SIGNAL( triggered() ), this, SLOT( fileNew() ) ); + mActionNewCanvas = new QAction( getThemeIcon( "mActionNewCanvas.png" ), tr( "&New Canvas" ), this ); +// mActionNewCanvas->setShortcut( tr( "Ctrl+T", "New Canvas" ) ); + mActionNewCanvas->setShortcut( QKeySequence::AddTab ); + mActionNewCanvas->setStatusTip( tr( "New Canvas" ) ); + connect( mActionNewCanvas, SIGNAL( triggered() ), this, SLOT( createTabifiedDock() ) ); + + mActionCloseCanvas = new QAction( getThemeIcon( "mActionCloseCanvas.png" ), tr( "&Close Canvas" ), this ); +// mActionCloseCanvas->setShortcut( tr( "Ctrl+W", "Close Canvas" ) ); + mActionCloseCanvas->setShortcut( QKeySequence::Close ); + mActionCloseCanvas->setStatusTip( tr( "Close Canvas" ) ); +// connect( mActionCloseCanvas, SIGNAL( triggered() ), this, SLOT( twCloseTab() ) ); + mActionOpenProject = new QAction( getThemeIcon( "mActionFileOpen.png" ), tr( "&Open Project..." ), this ); shortcuts->registerAction( mActionOpenProject, tr( "Ctrl+O", "Open a Project" ) ); mActionOpenProject->setStatusTip( tr( "Open a Project" ) ); @@ -1086,6 +1096,7 @@ mFileMenu = menuBar()->addMenu( tr( "&File" ) ); mFileMenu->addAction( mActionNewProject ); + mFileMenu->addAction(mActionNewCanvas); mFileMenu->addAction( mActionOpenProject ); mRecentProjectsMenu = mFileMenu->addMenu( tr( "&Open Recent Projects" ) ); // Connect once for the entire submenu. @@ -1107,6 +1118,7 @@ mFileMenu->addAction( mActionPrintComposer ); mActionFileSeparator4 = mFileMenu->addSeparator(); + mFileMenu->addAction(mActionCloseCanvas); mFileMenu->addAction( mActionExit ); // Edit Menu @@ -1530,11 +1542,13 @@ QgsApplication::setThemeName( theThemeName ); //QgsDebugMsg("Setting theme to \n" + theThemeName); mActionNewProject->setIcon( getThemeIcon( "/mActionFileNew.png" ) ); + mActionNewCanvas->setIcon( getThemeIcon( "/mActionNewCanvas.png" ) ); mActionOpenProject->setIcon( getThemeIcon( "/mActionFileOpen.png" ) ); mActionSaveProject->setIcon( getThemeIcon( "/mActionFileSave.png" ) ); mActionSaveProjectAs->setIcon( getThemeIcon( "/mActionFileSaveAs.png" ) ); mActionPrintComposer->setIcon( getThemeIcon( "/mActionFilePrint.png" ) ); mActionSaveMapAsImage->setIcon( getThemeIcon( "/mActionSaveMapAsImage.png" ) ); + mActionCloseCanvas->setIcon( getThemeIcon( "/mActionCloseCanvas.png" ) ); mActionExit->setIcon( getThemeIcon( "/mActionFileExit.png" ) ); mActionAddOgrLayer->setIcon( getThemeIcon( "/mActionAddOgrLayer.png" ) ); mActionAddRasterLayer->setIcon( getThemeIcon( "/mActionAddRasterLayer.png" ) ); @@ -1601,36 +1615,70 @@ emit currentThemeChanged( theThemeName ); } +void QgisApp::resetupConnections(QgsMapCanvas *thePrevMapCanvas, QgsLegend *thePrevMapLegend, + QgsMapCanvas *theNewMapCanvas, QgsLegend *theNewMapLegend) +{ + if (thePrevMapCanvas && thePrevMapLegend) + { + // disconnect map layer registry signals to legend + disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), + thePrevMapLegend, SLOT( removeLayer( QString ) ) ); + disconnect( QgsMapLayerRegistry::instance(), SIGNAL( removedAll() ), + thePrevMapLegend, SLOT( removeAll() ) ); + disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), + thePrevMapLegend, SLOT( addLayer( QgsMapLayer * ) ) ); + disconnect( thePrevMapLegend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), + this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer* ) ) ); + + //signal when mouse moved over window (coords display in status bar) + disconnect( thePrevMapCanvas, SIGNAL( xyCoordinates( QgsPoint & ) ), this, SLOT( showMouseCoordinate( QgsPoint & ) ) ); + disconnect( thePrevMapCanvas->mapRenderer(), SIGNAL( drawingProgress( int, int ) ), this, SLOT( showProgress( int, int ) ) ); + disconnect( thePrevMapCanvas->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ), this, SLOT( hasCrsTransformEnabled( bool ) ) ); + disconnect( thePrevMapCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( destinationSrsChanged() ) ); + disconnect( thePrevMapCanvas, SIGNAL( extentsChanged() ), this, SLOT( showExtents() ) ); + disconnect( thePrevMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( showScale( double ) ) ); + disconnect( thePrevMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( updateMouseCoordinatePrecision() ) ); + disconnect( thePrevMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ), this, SLOT( mapToolChanged( QgsMapTool * ) ) ); + disconnect( thePrevMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ), + this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) ); + + disconnect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), thePrevMapCanvas, SLOT( setRenderFlag( bool ) ) ); + } + + if (theNewMapCanvas && theNewMapLegend) + { + // connect map layer registry signals to legend + connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), + theNewMapLegend, SLOT( removeLayer( QString ) ) ); + connect( QgsMapLayerRegistry::instance(), SIGNAL( removedAll() ), + theNewMapLegend, SLOT( removeAll() ) ); + connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), + theNewMapLegend, SLOT( addLayer( QgsMapLayer * ) ) ); + connect( theNewMapLegend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), + this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer* ) ) ); + + + //signal when mouse moved over window (coords display in status bar) + connect( theNewMapCanvas, SIGNAL( xyCoordinates( QgsPoint & ) ), this, SLOT( showMouseCoordinate( QgsPoint & ) ) ); + connect( theNewMapCanvas->mapRenderer(), SIGNAL( drawingProgress( int, int ) ), this, SLOT( showProgress( int, int ) ) ); + connect( theNewMapCanvas->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ), this, SLOT( hasCrsTransformEnabled( bool ) ) ); + connect( theNewMapCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( destinationSrsChanged() ) ); + connect( theNewMapCanvas, SIGNAL( extentsChanged() ), this, SLOT( showExtents() ) ); + connect( theNewMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( showScale( double ) ) ); + connect( theNewMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( updateMouseCoordinatePrecision() ) ); + connect( theNewMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ), this, SLOT( mapToolChanged( QgsMapTool * ) ) ); + connect( theNewMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ), + this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) ); + + connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), theNewMapCanvas, SLOT( setRenderFlag( bool ) ) ); + } +} + void QgisApp::setupConnections() { // connect the "cleanup" slot connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( saveWindowState() ) ); - //connect the legend, mapcanvas and overview canvas to the registry - // connect map layer registry signals to legend - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), - mMapLegend, SLOT( removeLayer( QString ) ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( removedAll() ), - mMapLegend, SLOT( removeAll() ) ); - connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), - mMapLegend, SLOT( addLayer( QgsMapLayer * ) ) ); - connect( mMapLegend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ), - this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer* ) ) ); - - - //signal when mouse moved over window (coords display in status bar) - connect( mMapCanvas, SIGNAL( xyCoordinates( QgsPoint & ) ), this, SLOT( showMouseCoordinate( QgsPoint & ) ) ); - connect( mMapCanvas->mapRenderer(), SIGNAL( drawingProgress( int, int ) ), this, SLOT( showProgress( int, int ) ) ); - connect( mMapCanvas->mapRenderer(), SIGNAL( hasCrsTransformEnabled( bool ) ), this, SLOT( hasCrsTransformEnabled( bool ) ) ); - connect( mMapCanvas->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( destinationSrsChanged() ) ); - connect( mMapCanvas, SIGNAL( extentsChanged() ), this, SLOT( showExtents() ) ); - connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( showScale( double ) ) ); - connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( updateMouseCoordinatePrecision() ) ); - connect( mMapCanvas, SIGNAL( mapToolSet( QgsMapTool * ) ), this, SLOT( mapToolChanged( QgsMapTool * ) ) ); - connect( mMapCanvas, SIGNAL( selectionChanged( QgsMapLayer * ) ), - this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) ); - - connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ), mMapCanvas, SLOT( setRenderFlag( bool ) ) ); // // Do we really need this ??? - its already connected to the esc key...TS // @@ -1642,87 +1690,229 @@ connect( QgsProject::instance(), SIGNAL( layerLoaded( int, int ) ), this, SLOT( showProgress( int, int ) ) ); + connect(this, SIGNAL(currentDockChanged(int)), this, SLOT(setCurrentDockCanvas(int))); } + void QgisApp::createCanvas() { + createTabifiedDock(); + mMapOverviewCanvas = mMapOverviewCanvasList.at(0); + mMapTools = mMapToolsList.at(0); +} + +void QgisApp::slotDockVisibilityChanged(bool visible) +{ + QObject *obj = sender(); + if (obj && visible) + { + QDockWidget *dockCanvas = qobject_cast(obj); + if (dockCanvas->property("newTab").toBool()) + { + setCurrentDockCanvas(mCanvasDock->property("ID").toInt()); + dockCanvas->setProperty("newTab", false); + } + else + { + setCurrentDockCanvas(dockCanvas->property("ID").toInt()); + mCanvasDock = dockCanvas; + } + } +} + +void QgisApp::slotDockTopLevelChanged(bool topLevel) +{ + QObject *obj = sender(); + if (obj && topLevel) + { + QDockWidget *dockCanvas = qobject_cast(obj); + if (dockCanvas->isFloating()) + { + setCurrentDockCanvas(dockCanvas->property("ID").toInt()); + } + } +} + +void QgisApp::createTabifiedDock() +{ + // create map canvas and add it to the tab widget + QgsMapCanvas *myMapCanvas = createMapCanvasWithTools(); + myMapCanvas->setObjectName( "theMapCanvas" ); + + QDockWidget *myCanvasDock = new QDockWidget(tr("Canvas %1").arg(mCountOfTabs + 1), this); + myCanvasDock->setObjectName(QString("Canvas %1").arg(mCountOfTabs + 1)); + myCanvasDock->setProperty("ID", mCountOfTabs); + myCanvasDock->setProperty("newTab", true); + myCanvasDock->setWidget(myMapCanvas); + myCanvasDock->setAllowedAreas(Qt::RightDockWidgetArea); + myCanvasDock->setTitleBarWidget(0/*new QLabel("sdfds")*/); + connect(myCanvasDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotDockVisibilityChanged(bool))); + connect(myCanvasDock, SIGNAL(topLevelChanged(bool)), this, SLOT(slotDockTopLevelChanged(bool))); + + if (mCountOfTabs == 0) + { + addDockWidget(Qt::RightDockWidgetArea, myCanvasDock); + mCanvasDock = myCanvasDock; + } + else + { + tabifyDockWidget(mCanvasDock, myCanvasDock); + } + mCountOfTabs++; + + // set canvas color in map canvas + int myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 ); + int myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 ); + int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 ); + QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt ); + myMapCanvas->setCanvasColor( myColor ); // this is fill colour before rendering onto canvas + + // create map legend for map canvas + QgsLegend *myMapLegend = new QgsLegend( NULL, "theMapLegend" ); + myMapLegend->setObjectName( "theMapLegend" ); + myMapLegend->setMapCanvas( myMapCanvas ); + + // add the toggle editing action also to legend such that right click menu and button show the same state + myMapLegend->setToggleEditingAction( mActionToggleEditing ); + myMapLegend->setWhatsThis( tr( "Map legend that displays all the layers currently on the map canvas." + "Click on the check box to turn a layer on or off. Double click on a layer" + "in the legend to customize its appearance and set other properties." ) ); + + // create overview canvas + QgsMapOverviewCanvas* myMapOverviewCanvas = new QgsMapOverviewCanvas( NULL, myMapCanvas ); + myMapOverviewCanvas->setWhatsThis( tr( "Map overview canvas. This canvas can be used to display a locator map" + "that shows the current extent of the map canvas. The current extent is shown as" + "a red rectangle. Any layer on the map can be added to the overview canvas." ) ); + + // set cursor in overview canvas + if (!mOverviewMapCursor) + { + QBitmap overviewPanBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits ); + QBitmap overviewPanBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits ); + + //set upper left corner as hot spot - this is better when extent marker is small; hand won't cover the marker + mOverviewMapCursor = new QCursor( overviewPanBmp, overviewPanBmpMask, 0, 0 ); + } + myMapOverviewCanvas->setCursor( *mOverviewMapCursor ); + + // append map canvas, overview canvas and legend to list + mMapCanvasList.append(myMapCanvas); + mMapOverviewCanvasList.append(myMapOverviewCanvas); + mMapLegendList.append(myMapLegend); +} + +void QgisApp::setCurrentDockCanvas(int index) +{ + // get new map canvas and legend from lists + QgsMapCanvas *pNewMapCanvas = mMapCanvasList.at(index); + QgsLegend *pNewMapLegend = mMapLegendList.at(index); + + // setup connections for new map canvas and legend selected in a tab + // and disconnect connections for previous map canvas and legend + if (pNewMapCanvas && pNewMapLegend) + { + resetupConnections(mMapCanvas, mMapLegend, pNewMapCanvas, pNewMapLegend); + } + + // set new map canvas, overview, legend and tools for a selected tab + mMapCanvas = pNewMapCanvas; + mMapLegend = pNewMapLegend; + mMapOverviewCanvas = mMapOverviewCanvasList.at(index); + mMapTools = mMapToolsList.at(index); + mMapTools->mCurrentTool = mMapToolsList.at(index)->mCurrentTool; + + // enable overview canvas for map canvas + mMapCanvas->enableOverviewMode( mMapOverviewCanvas ); + // set map tool for map canvas + mMapCanvas->setMapTool( mMapToolsList.at(index)->mCurrentTool ); + + // put new map legend in legend dock widget and new overview canvas to overview dock + if (mLegendDock && mOverviewDock) + { + mLegendDock->setWidget(mMapLegend); + mOverviewDock->setWidget(mMapOverviewCanvas); + } +} + +QgsMapCanvas *QgisApp::createMapCanvasWithTools() +{ // "theMapCanvas" used to find this canonical instance later mMapCanvas = new QgsMapCanvas( this, "theMapCanvas" ); mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector " "layers are displayed when added to the map" ) ); - setCentralWidget( mMapCanvas ); // set the focus to the map canvas mMapCanvas->setFocus(); // create tools - mMapTools.mZoomIn = new QgsMapToolZoom( mMapCanvas, FALSE /* zoomIn */ ); - mMapTools.mZoomIn->setAction( mActionZoomIn ); - mMapTools.mZoomOut = new QgsMapToolZoom( mMapCanvas, TRUE /* zoomOut */ ); - mMapTools.mZoomOut->setAction( mActionZoomOut ); - mMapTools.mPan = new QgsMapToolPan( mMapCanvas ); - mMapTools.mPan->setAction( mActionPan ); - mMapTools.mIdentify = new QgsMapToolIdentify( mMapCanvas ); - mMapTools.mIdentify->setAction( mActionIdentify ); - mMapTools.mMeasureDist = new QgsMeasureTool( mMapCanvas, FALSE /* area */ ); - mMapTools.mMeasureDist->setAction( mActionMeasure ); - mMapTools.mMeasureArea = new QgsMeasureTool( mMapCanvas, TRUE /* area */ ); - mMapTools.mMeasureArea->setAction( mActionMeasureArea ); - mMapTools.mCapturePoint = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CapturePoint ); - mMapTools.mCapturePoint->setAction( mActionCapturePoint ); + Tools *myMapTools = new Tools(); + + myMapTools->mZoomIn = new QgsMapToolZoom( mMapCanvas, FALSE /* zoomIn */ ); + myMapTools->mZoomIn->setAction( mActionZoomIn ); + myMapTools->mZoomOut = new QgsMapToolZoom( mMapCanvas, TRUE /* zoomOut */ ); + myMapTools->mZoomOut->setAction( mActionZoomOut ); + myMapTools->mPan = new QgsMapToolPan( mMapCanvas ); + myMapTools->mPan->setAction( mActionPan ); + myMapTools->mIdentify = new QgsMapToolIdentify( mMapCanvas ); + myMapTools->mIdentify->setAction( mActionIdentify ); + myMapTools->mMeasureDist = new QgsMeasureTool( mMapCanvas, FALSE /* area */ ); + myMapTools->mMeasureDist->setAction( mActionMeasure ); + myMapTools->mMeasureArea = new QgsMeasureTool( mMapCanvas, TRUE /* area */ ); + myMapTools->mMeasureArea->setAction( mActionMeasureArea ); + myMapTools->mCapturePoint = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CapturePoint ); + myMapTools->mCapturePoint->setAction( mActionCapturePoint ); mActionCapturePoint->setVisible( false ); - mMapTools.mCaptureLine = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CaptureLine ); - mMapTools.mCaptureLine->setAction( mActionCaptureLine ); + myMapTools->mCaptureLine = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CaptureLine ); + myMapTools->mCaptureLine->setAction( mActionCaptureLine ); mActionCaptureLine->setVisible( false ); - mMapTools.mCapturePolygon = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CapturePolygon ); - mMapTools.mCapturePolygon->setAction( mActionCapturePolygon ); + myMapTools->mCapturePolygon = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CapturePolygon ); + myMapTools->mCapturePolygon->setAction( mActionCapturePolygon ); mActionCapturePolygon->setVisible( false ); - mMapTools.mMoveFeature = new QgsMapToolMoveFeature( mMapCanvas ); - mMapTools.mMoveFeature->setAction( mActionMoveFeature ); - mMapTools.mSplitFeatures = new QgsMapToolSplitFeatures( mMapCanvas ); - mMapTools.mSplitFeatures->setAction( mActionSplitFeatures ); - mMapTools.mSelect = new QgsMapToolSelect( mMapCanvas ); - mMapTools.mSelect->setAction( mActionSelect ); - mMapTools.mVertexAdd = new QgsMapToolAddVertex( mMapCanvas ); - mMapTools.mVertexAdd->setAction( mActionAddVertex ); - mMapTools.mVertexMove = new QgsMapToolMoveVertex( mMapCanvas ); - mMapTools.mVertexMove->setAction( mActionMoveVertex ); - mMapTools.mVertexDelete = new QgsMapToolDeleteVertex( mMapCanvas ); - mMapTools.mVertexDelete->setAction( mActionDeleteVertex ); - mMapTools.mAddRing = new QgsMapToolAddRing( mMapCanvas ); - mMapTools.mAddRing->setAction( mActionAddRing ); - mMapTools.mAddIsland = new QgsMapToolAddIsland( mMapCanvas ); - mMapTools.mSimplifyFeature = new QgsMapToolSimplify( mMapCanvas ); - mMapTools.mSimplifyFeature->setAction( mActionSimplifyFeature ); - mMapTools.mDeleteRing = new QgsMapToolDeleteRing( mMapCanvas ); - mMapTools.mDeleteRing->setAction( mActionDeleteRing ); - mMapTools.mDeletePart = new QgsMapToolDeletePart( mMapCanvas ); - mMapTools.mDeletePart->setAction( mActionDeletePart ); + myMapTools->mMoveFeature = new QgsMapToolMoveFeature( mMapCanvas ); + myMapTools->mMoveFeature->setAction( mActionMoveFeature ); + myMapTools->mSplitFeatures = new QgsMapToolSplitFeatures( mMapCanvas ); + myMapTools->mSplitFeatures->setAction( mActionSplitFeatures ); + myMapTools->mSelect = new QgsMapToolSelect( mMapCanvas ); + myMapTools->mSelect->setAction( mActionSelect ); + myMapTools->mVertexAdd = new QgsMapToolAddVertex( mMapCanvas ); + myMapTools->mVertexAdd->setAction( mActionAddVertex ); + myMapTools->mVertexMove = new QgsMapToolMoveVertex( mMapCanvas ); + myMapTools->mVertexMove->setAction( mActionMoveVertex ); + myMapTools->mVertexDelete = new QgsMapToolDeleteVertex( mMapCanvas ); + myMapTools->mVertexDelete->setAction( mActionDeleteVertex ); + myMapTools->mAddRing = new QgsMapToolAddRing( mMapCanvas ); + myMapTools->mAddRing->setAction( mActionAddRing ); + myMapTools->mAddIsland = new QgsMapToolAddIsland( mMapCanvas ); + myMapTools->mSimplifyFeature = new QgsMapToolSimplify( mMapCanvas ); + myMapTools->mSimplifyFeature->setAction( mActionSimplifyFeature ); + myMapTools->mDeleteRing = new QgsMapToolDeleteRing( mMapCanvas ); + myMapTools->mDeleteRing->setAction( mActionDeleteRing ); + myMapTools->mDeletePart = new QgsMapToolDeletePart( mMapCanvas ); + myMapTools->mDeletePart->setAction( mActionDeletePart ); //ensure that non edit tool is initialised or we will get crashes in some situations - mNonEditMapTool = mMapTools.mPan; + mNonEditMapTool = myMapTools->mPan; + + myMapTools->mCurrentTool = myMapTools->mPan; + + mMapToolsList.append(myMapTools); + + return mMapCanvas; } void QgisApp::createOverview() { // overview canvas - QgsMapOverviewCanvas* overviewCanvas = new QgsMapOverviewCanvas( NULL, mMapCanvas ); - overviewCanvas->setWhatsThis( tr( "Map overview canvas. This canvas can be used to display a locator map that shows the current extent of the map canvas. The current extent is shown as a red rectangle. Any layer on the map can be added to the overview canvas." ) ); - - QBitmap overviewPanBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits ); - QBitmap overviewPanBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits ); - mOverviewMapCursor = new QCursor( overviewPanBmp, overviewPanBmpMask, 0, 0 ); //set upper left corner as hot spot - this is better when extent marker is small; hand won't cover the marker - overviewCanvas->setCursor( *mOverviewMapCursor ); // QVBoxLayout *myOverviewLayout = new QVBoxLayout; // myOverviewLayout->addWidget(overviewCanvas); // overviewFrame->setLayout(myOverviewLayout); mOverviewDock = new QDockWidget( tr( "Overview" ), this ); mOverviewDock->setObjectName( "Overview" ); mOverviewDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - mOverviewDock->setWidget( overviewCanvas ); + mOverviewDock->setWidget( mMapOverviewCanvas ); addDockWidget( Qt::LeftDockWidgetArea, mOverviewDock ); // add to the Panel submenu mPanelMenu->addAction( mOverviewDock->toggleViewAction() ); - mMapCanvas->enableOverviewMode( overviewCanvas ); + mMapCanvas->enableOverviewMode( mMapOverviewCanvas ); // moved here to set anti aliasing to both map canvas and overview QSettings mySettings; @@ -1762,15 +1952,6 @@ void QgisApp::createLegend() { - //legend - mMapLegend = new QgsLegend( NULL, "theMapLegend" ); - mMapLegend->setObjectName( "theMapLegend" ); - mMapLegend->setMapCanvas( mMapCanvas ); - - //add the toggle editing action also to legend such that right click menu and button show the same state - mMapLegend->setToggleEditingAction( mActionToggleEditing ); - - mMapLegend->setWhatsThis( tr( "Map legend that displays all the layers currently on the map canvas. Click on the check box to turn a layer on or off. Double click on a layer in the legend to customize its appearance and set other properties." ) ); mLegendDock = new QDockWidget( tr( "Layers" ), this ); mLegendDock->setObjectName( "Legend" ); mLegendDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); @@ -3053,8 +3234,8 @@ mMapCanvas->mapRenderer()->setProjectionsEnabled( FALSE ); // set the initial map tool - mMapCanvas->setMapTool( mMapTools.mPan ); - mNonEditMapTool = mMapTools.mPan; // signals are not yet setup to catch this + mMapCanvas->setMapTool( mMapTools->mPan ); + mNonEditMapTool = mMapTools->mPan; // signals are not yet setup to catch this } // QgisApp::fileNew(bool thePromptToSaveFlag) @@ -3799,11 +3980,11 @@ // showMaxmized() is a work-around. Turn off rendering for this as it // would otherwise cause two re-renders of the map, which can take a // long time. - bool renderFlag = mapCanvas()->renderFlag(); - mapCanvas()->setRenderFlag( false ); + bool renderFlag = mMapCanvas->renderFlag(); + mMapCanvas->setRenderFlag( false ); showNormal(); showMaximized(); - mapCanvas()->setRenderFlag( renderFlag ); + mMapCanvas->setRenderFlag( renderFlag ); mPrevScreenModeMaximized = false; } else @@ -3898,7 +4079,7 @@ { QgsDebugMsg( "hiding all layers!" ); - legend()->selectAll( false ); + mMapLegend->selectAll( false ); } @@ -3907,7 +4088,7 @@ { QgsDebugMsg( "Showing all layers!" ); - legend()->selectAll( true ); + mMapLegend->selectAll( true ); } @@ -3915,7 +4096,7 @@ { QgsDebugMsg( "Setting map tool to zoomIn" ); - mMapCanvas->setMapTool( mMapTools.mZoomIn ); + mMapCanvas->setMapTool( mMapTools->mZoomIn ); // notify the project we've made a change QgsProject::instance()->dirty( true ); @@ -3924,7 +4105,7 @@ void QgisApp::zoomOut() { - mMapCanvas->setMapTool( mMapTools.mZoomOut ); + mMapCanvas->setMapTool( mMapTools->mZoomOut ); // notify the project we've made a change QgsProject::instance()->dirty( true ); @@ -3940,7 +4121,7 @@ void QgisApp::pan() { - mMapCanvas->setMapTool( mMapTools.mPan ); + mMapCanvas->setMapTool( mMapTools->mPan ); } void QgisApp::zoomFull() @@ -3974,17 +4155,17 @@ void QgisApp::identify() { - mMapCanvas->setMapTool( mMapTools.mIdentify ); + mMapCanvas->setMapTool( mMapTools->mIdentify ); } void QgisApp::measure() { - mMapCanvas->setMapTool( mMapTools.mMeasureDist ); + mMapCanvas->setMapTool( mMapTools->mMeasureDist ); } void QgisApp::measureArea() { - mMapCanvas->setMapTool( mMapTools.mMeasureArea ); + mMapCanvas->setMapTool( mMapTools->mMeasureArea ); } void QgisApp::attributeTable() @@ -4067,27 +4248,27 @@ void QgisApp::moveFeature() { - mMapCanvas->setMapTool( mMapTools.mMoveFeature ); + mMapCanvas->setMapTool( mMapTools->mMoveFeature ); } void QgisApp::simplifyFeature() { - mMapCanvas->setMapTool( mMapTools.mSimplifyFeature ); + mMapCanvas->setMapTool( mMapTools->mSimplifyFeature ); } void QgisApp::deleteRing() { - mMapCanvas->setMapTool( mMapTools.mDeleteRing ); + mMapCanvas->setMapTool( mMapTools->mDeleteRing ); } void QgisApp::deletePart() { - mMapCanvas->setMapTool( mMapTools.mDeletePart ); + mMapCanvas->setMapTool( mMapTools->mDeletePart ); } void QgisApp::splitFeatures() { - mMapCanvas->setMapTool( mMapTools.mSplitFeatures ); + mMapCanvas->setMapTool( mMapTools->mSplitFeatures ); } void QgisApp::capturePoint() @@ -4098,7 +4279,7 @@ } // set current map tool to select - mMapCanvas->setMapTool( mMapTools.mCapturePoint ); + mMapCanvas->setMapTool( mMapTools->mCapturePoint ); } void QgisApp::captureLine() @@ -4108,7 +4289,7 @@ return; } - mMapCanvas->setMapTool( mMapTools.mCaptureLine ); + mMapCanvas->setMapTool( mMapTools->mCaptureLine ); } void QgisApp::capturePolygon() @@ -4117,12 +4298,12 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mCapturePolygon ); + mMapCanvas->setMapTool( mMapTools->mCapturePolygon ); } void QgisApp::select() { - mMapCanvas->setMapTool( mMapTools.mSelect ); + mMapCanvas->setMapTool( mMapTools->mSelect ); } @@ -4132,7 +4313,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mVertexAdd ); + mMapCanvas->setMapTool( mMapTools->mVertexAdd ); } @@ -4142,7 +4323,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mVertexMove ); + mMapCanvas->setMapTool( mMapTools->mVertexMove ); } void QgisApp::addRing() @@ -4151,7 +4332,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mAddRing ); + mMapCanvas->setMapTool( mMapTools->mAddRing ); } void QgisApp::addIsland() @@ -4160,7 +4341,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mAddIsland ); + mMapCanvas->setMapTool( mMapTools->mAddIsland ); } @@ -4170,7 +4351,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mVertexDelete ); + mMapCanvas->setMapTool( mMapTools->mVertexDelete ); } @@ -5057,9 +5238,13 @@ void QgisApp::mapToolChanged( QgsMapTool *tool ) { - if ( tool && !tool->isEditTool() ) + if ( tool ) { - mNonEditMapTool = tool; + if ( !tool->isEditTool() ) + { + mNonEditMapTool = tool; + } + mMapTools->mCurrentTool = tool; } } @@ -5114,8 +5299,8 @@ // coordinates with the aim of always having enough decimal places // to show the difference in position between adjacent pixels. // Also avoid taking the log of 0. - if ( mapCanvas()->mapUnitsPerPixel() != 0.0 ) - dp = static_cast( ceil( -1.0 * log10( mapCanvas()->mapUnitsPerPixel() ) ) ); + if ( mMapCanvas->mapUnitsPerPixel() != 0.0 ) + dp = static_cast( ceil( -1.0 * log10( mMapCanvas->mapUnitsPerPixel() ) ) ); } else dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" ); @@ -5958,3 +6143,27 @@ return QPixmap( myDefaultPath ); } } + +QgisApp::Tools::~Tools() +{ + delete mZoomIn; + delete mZoomOut; + delete mPan; + delete mIdentify; + delete mMeasureDist; + delete mMeasureArea; + delete mCapturePoint; + delete mCaptureLine; + delete mCapturePolygon; + delete mMoveFeature; + delete mSplitFeatures; + delete mSelect; + delete mVertexAdd; + delete mVertexMove; + delete mVertexDelete; + delete mAddRing; + delete mAddIsland; + delete mSimplifyFeature; + delete mDeleteRing; + delete mDeletePart; +}