Index: /usr/local/src/qgis/python/gui/qgstabwidget.sip =================================================================== --- /usr/local/src/qgis/python/gui/qgstabwidget.sip (revision 0) +++ /usr/local/src/qgis/python/gui/qgstabwidget.sip (revision 0) @@ -0,0 +1,18 @@ +/** \class QgsMapCanvasLayer + * Class provides a stack of tabbed widgets +*/ +class QgsTabWidget: QTabWidget +{ +%TypeHeaderCode +#include +%End + +public: + QgsTabWidget(QWidget *parent); + void addTab(QWidget *widget, const QIcon &icon, const QString &label); + void addTab(QWidget *widget, const QString &label); + void insertTab(int index, QWidget *widget, const QIcon &icon, const QString &label); + void insertTab(int index, QWidget *widget, const QString &label); + void removeTab(int index); +}; + Index: /usr/local/src/qgis/python/gui/qgisinterface.sip =================================================================== --- /usr/local/src/qgis/python/gui/qgisinterface.sip (revision 10666) +++ /usr/local/src/qgis/python/gui/qgisinterface.sip (working copy) @@ -72,6 +72,9 @@ /** Return a pointer to the map canvas */ virtual QgsMapCanvas * mapCanvas()=0; + /** Return a pointer to the main tab widget */ + virtual QgsTabWidget * tabWidget()=0; + /** Return a pointer to the main window (instance of QgisApp in case of QGIS) */ virtual QWidget * mainWindow()=0; @@ -92,6 +95,21 @@ /** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */ virtual void removeDockWidget ( QDockWidget * dockwidget )=0; + /** Add a tab widget to the main window */ + virtual void addTabWidget( QWidget *page, const QString &label )=0; + + /** Add a tab widget to the main window with icon */ + virtual void addTabWidget( QWidget *page, const QIcon &icon, const QString &label )=0; + + /** Insert a tab widget to the main window with label */ + virtual void insertTabWidget( int index, QWidget *page, const QString &label )=0; + + /** Insert a tab widget to the main window with icon and label */ + virtual void insertTabWidget( int index, QWidget *page, const QIcon &icon, const QString &label )=0; + + /** Remove specified tab widget from main window (doesn't delete it) */ + virtual void removeTabWidget( int index )=0; + /** refresh legend of a layer */ virtual void refreshLegend( QgsMapLayer * layer )=0; Index: /usr/local/src/qgis/python/gui/gui.sip =================================================================== --- /usr/local/src/qgis/python/gui/gui.sip (revision 10666) +++ /usr/local/src/qgis/python/gui/gui.sip (working copy) @@ -25,5 +25,6 @@ %Include qgsprojectionselector.sip %Include qgsquickprint.sip %Include qgsrubberband.sip +%Include qgstabwidget.sip %Include qgsvertexmarker.sip Index: /usr/local/src/qgis/src/app/qgisappinterface.h =================================================================== --- /usr/local/src/qgis/src/app/qgisappinterface.h (revision 10666) +++ /usr/local/src/qgis/src/app/qgisappinterface.h (working copy) @@ -87,6 +87,9 @@ /** Return a pointer to the map canvas used by qgisapp */ QgsMapCanvas * mapCanvas(); + /** Return a pointer to the main tab widget that containing map canvas */ + QgsTabWidget * tabWidget(); + /** Gives access to main QgisApp object Plugins don't need to know about QgisApp, as we pass it as QWidget, @@ -107,6 +110,21 @@ /** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */ void removeDockWidget( QDockWidget * dockwidget ); + /** Add a tab widget to the main window */ + void addTabWidget( QWidget *page, const QString &label ); + + /** Add a tab widget to the main window with icon */ + void addTabWidget( QWidget *page, const QIcon &icon, const QString &label ); + + /** Insert a tab widget to the main window with label */ + void insertTabWidget( int index, QWidget *page, const QString &label ); + + /** Insert a tab widget to the main window with icon and label */ + void insertTabWidget( int index, QWidget *page, const QIcon &icon, const QString &label ); + + /** Remove specified tab widget from main window (doesn't delete it). */ + void removeTabWidget( int index ); + virtual void refreshLegend( QgsMapLayer *l ); /** Add window to Window menu. The action title is the window title Index: /usr/local/src/qgis/src/app/qgisapp.h =================================================================== --- /usr/local/src/qgis/src/app/qgisapp.h (revision 10666) +++ /usr/local/src/qgis/src/app/qgisapp.h (working copy) @@ -44,6 +44,7 @@ class QgsHelpViewer; class QgsLegend; class QgsMapCanvas; +class QgsMapOverviewCanvas; class QgsMapLayer; class QgsMapTip; class QgsMapTool; @@ -54,6 +55,7 @@ class QgsRasterLayer; class QgsRectangle; class QgsVectorLayer; +class QgsTabWidget; #include #include @@ -137,8 +139,11 @@ //!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; } + /** Get the tabwidget object from the app */ + QgsTabWidget *tabWidget() { return mTabWidget; } + QgsComposer* printComposer() {return mComposer;} //! Set theme (icons) @@ -180,6 +185,22 @@ * After adding the dock widget to the ui (by delegating to the QMainWindow * parent class, it will also add it to the View menu list of docks.*/ void addDockWidget( Qt::DockWidgetArea area, QDockWidget * dockwidget ); + + /** Add a tab to the tab widget with label */ + void addTabWidget( QWidget *page, const QString &label ); + + /** Add a tab to the tab widget with icon and label */ + void addTabWidget( QWidget *page, const QIcon &icon, const QString &label ); + + /** Insert a tab to the tab widget with label */ + void insertTabWidget( int index, QWidget *page, const QString &label ); + + /** Insert a tab to the tab widget with icon and label */ + void insertTabWidget( int index, QWidget *page, const QIcon &icon, const QString &label ); + + /** Remove specified tab from tab widget (doesn't delete it) */ + void removeTabWidget( int index ); + /** Add a toolbar to the main window. Overloaded from QMainWindow. * After adding the toolbar to the ui (by delegating to the QMainWindow * parent class, it will also add it to the View menu list of toolbars.*/ @@ -331,6 +352,14 @@ void zoomToNext(); //! Zoom to selected features void zoomToSelected(); + /** do needed procedures when user switch the tab */ + void twCurrentTabChanged(int index); + /** do needed procedures when user move the tab */ + void twCurrentTabMoved(int from, int to); + /** close a tab at index index */ + void twCloseTab(int index); + /** overloaded slot of methods above that closes the current tab */ + void twCloseTab(); //! cuts selected features on the active layer to the clipboard /** @@ -352,6 +381,7 @@ void editPaste( QgsMapLayer * destinationLayer = 0 ); void loadOGRSublayers( QString layertype, QString uri, QStringList list ); + void twCreateNewTab(); protected: @@ -650,16 +680,20 @@ void readSettings(); void writeSettings(); void createActions(); + void createActionsExt(); void createActionGroups(); void createMenus(); void createToolBars(); void createStatusBar(); void setupConnections(); void createLegend(); + void createTabWidget(); void createOverview(); - void createCanvas(); bool createDB(); void createMapTips(); + QgsMapCanvas * createMapCanvasWithTools(); + void resetupConnections(QgsMapCanvas *thePrevMapCanvas, QgsLegend *thePrevMapLegend, + QgsMapCanvas *theNewMapCanvas, QgsLegend *theNewMapLegend); // toolbars --------------------------------------- QToolBar *mFileToolBar; @@ -673,6 +707,8 @@ // actions for menus and toolbars ----------------- QAction *mActionNewProject; + QAction *mActionNewTab; + QAction *mActionCloseTab; QAction *mActionOpenProject; QAction *mActionFileSeparator1; QAction *mActionSaveProject; @@ -798,26 +834,33 @@ class Tools { - public: - QgsMapTool* mZoomIn; - QgsMapTool* mZoomOut; - QgsMapTool* mPan; - QgsMapTool* mIdentify; - QgsMapTool* mMeasureDist; - QgsMapTool* mMeasureArea; - QgsMapTool* mCapturePoint; - QgsMapTool* mCaptureLine; - QgsMapTool* mCapturePolygon; - QgsMapTool* mMoveFeature; - QgsMapTool* mSplitFeatures; - QgsMapTool* mSelect; - QgsMapTool* mVertexAdd; - QgsMapTool* mVertexMove; - QgsMapTool* mVertexDelete; - QgsMapTool* mAddRing; - QgsMapTool* mAddIsland; - } mMapTools; + public: + ~Tools(); + QgsMapTool* mZoomIn; + QgsMapTool* mZoomOut; + QgsMapTool* mPan; + QgsMapTool* mIdentify; + QgsMapTool* mMeasureDist; + QgsMapTool* mMeasureArea; + QgsMapTool* mCapturePoint; + QgsMapTool* mCaptureLine; + QgsMapTool* mCapturePolygon; + QgsMapTool* mMoveFeature; + QgsMapTool* mSplitFeatures; + QgsMapTool* mSelect; + QgsMapTool* mVertexAdd; + QgsMapTool* mVertexMove; + QgsMapTool* mVertexDelete; + QgsMapTool* mAddRing; + QgsMapTool* mAddIsland; + QgsMapTool* currentTool; + } *mMapTools; + Tools *mapTools() { return mMapTools; } + + //! List of map tools + QList mMapToolsList; + QgsMapTool *mNonEditMapTool; //! Widget that will live on the statusbar to display "scale 1:" @@ -850,6 +893,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; + //! Tab widget + QgsTabWidget *mTabWidget; //! Table of contents (legend) for the map QgsLegend *mMapLegend; //! Cursor for the overview map Index: /usr/local/src/qgis/src/app/qgisapp.cpp =================================================================== --- /usr/local/src/qgis/src/app/qgisapp.cpp (revision 10666) +++ /usr/local/src/qgis/src/app/qgisapp.cpp (working copy) @@ -129,6 +129,7 @@ #include "qgsrectangle.h" #include "qgsrenderer.h" #include "qgsserversourceselect.h" +#include "qgstabwidget.h" #include "qgsvectordataprovider.h" #include "qgsvectorlayer.h" #include "ogr/qgsopenvectorlayerdialog.h" @@ -306,6 +307,11 @@ // constructor starts here QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl ) : QMainWindow( parent, fl ), + mLegendDock( NULL ), + mOverviewDock( NULL ), + mMapCanvas( NULL ), + mMapLegend( NULL ), + mOverviewMapCursor( NULL ), mSplash( splash ), mComposer( 0 ), mPythonConsole( NULL ), @@ -344,11 +350,13 @@ createMenus(); createToolBars(); createStatusBar(); - createCanvas(); + createTabWidget(); + twCreateNewTab(); mMapCanvas->freeze(); createLegend(); createOverview(); createMapTips(); + createActionsExt(); readSettings(); updateRecentProjectPaths(); @@ -449,24 +457,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.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; @@ -536,6 +538,18 @@ mActionNewProject->setStatusTip( tr( "New Project" ) ); connect( mActionNewProject, SIGNAL( triggered() ), this, SLOT( fileNew() ) ); + mActionNewTab = new QAction( getThemeIcon( "mActionNewTab.png" ), tr( "&New Tab" ), this ); +// mActionNewTab->setShortcut( tr( "Ctrl+T", "New Tab" ) ); + mActionNewTab->setShortcut( QKeySequence::AddTab ); + mActionNewTab->setStatusTip( tr( "New Tab" ) ); + connect( mActionNewTab, SIGNAL( triggered() ), this, SLOT( twCreateNewTab() ) ); + + mActionCloseTab = new QAction( getThemeIcon( "mActionCloseTab.png" ), tr( "&Close Tab" ), this ); +// mActionCloseTab->setShortcut( tr( "Ctrl+W", "Close Tab" ) ); + mActionCloseTab->setShortcut( QKeySequence::Close ); + mActionCloseTab->setStatusTip( tr( "Close Tab" ) ); + connect( mActionCloseTab, SIGNAL( triggered() ), this, SLOT( twCloseTab() ) ); + mActionOpenProject = new QAction( getThemeIcon( "mActionFileOpen.png" ), tr( "&Open Project..." ), this ); mActionOpenProject->setShortcut( tr( "Ctrl+O", "Open a Project" ) ); mActionOpenProject->setStatusTip( tr( "Open a Project" ) ); @@ -937,6 +951,22 @@ connect( mActionAbout, SIGNAL( triggered() ), this, SLOT( about() ) ); } +void QgisApp::createActionsExt() +{ + // create actions that helps user to navigate in tabs + QAction *myActionNextTab = new QAction(this); +// myActionNextTab->setShortcut(tr("Ctrl+PgDown", "Goto next tab")); + myActionNextTab->setShortcut(QKeySequence::NextChild); + connect(myActionNextTab, SIGNAL(triggered()), mTabWidget, SLOT(nextTab())); + addAction(myActionNextTab); + + QAction *myActionPreviousTab = new QAction(this); +// myActionPrevTab->setShortcut(tr("Ctrl+PgUp", "Goto previous tab")); + myActionPreviousTab->setShortcut(QKeySequence::PreviousChild); + connect(myActionPreviousTab, SIGNAL(triggered()), mTabWidget, SLOT(previousTab())); + addAction(myActionPreviousTab); +} + void QgisApp::showPythonDialog() { if ( !mPythonUtils || !mPythonUtils->isEnabled() ) @@ -1023,6 +1053,7 @@ mFileMenu = menuBar()->addMenu( tr( "&File" ) ); mFileMenu->addAction( mActionNewProject ); + mFileMenu->addAction(mActionNewTab); mFileMenu->addAction( mActionOpenProject ); mRecentProjectsMenu = mFileMenu->addMenu( tr( "&Open Recent Projects" ) ); // Connect once for the entire submenu. @@ -1044,6 +1075,7 @@ mFileMenu->addAction( mActionPrintComposer ); mActionFileSeparator4 = mFileMenu->addSeparator(); + mFileMenu->addAction(mActionCloseTab); mFileMenu->addAction( mActionExit ); // Edit Menu @@ -1449,11 +1481,13 @@ QgsApplication::setThemeName( theThemeName ); //QgsDebugMsg("Setting theme to \n" + theThemeName); mActionNewProject->setIcon( getThemeIcon( "/mActionFileNew.png" ) ); + mActionNewTab->setIcon( getThemeIcon( "/mActionNewTab.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" ) ); + mActionCloseTab->setIcon( getThemeIcon( "/mActionCloseTab.png" ) ); mActionExit->setIcon( getThemeIcon( "/mActionFileExit.png" ) ); mActionAddOgrLayer->setIcon( getThemeIcon( "/mActionAddOgrLayer.png" ) ); mActionAddRasterLayer->setIcon( getThemeIcon( "/mActionAddRasterLayer.png" ) ); @@ -1516,36 +1550,71 @@ 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 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 // @@ -1555,82 +1624,239 @@ connect( QgsProject::instance(), SIGNAL( oldProjectVersionWarning( QString ) ), this, SLOT( oldProjectVersionWarning( QString ) ) ); + // do something when current tab in tab widget was switched or moved + connect( mTabWidget, SIGNAL(currentChanged(int)), this, SLOT(twCurrentTabChanged(int))); + connect( mTabWidget, SIGNAL(tabMoved(int,int)), this, SLOT(twCurrentTabMoved(int, int))); + + // close a current tab when the close button on a tab is clicked + connect( mTabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(twCloseTab(int))); } -void QgisApp::createCanvas() + +void QgisApp::twCurrentTabChanged(int index) { + // get new map canvas and legend from lists + QgsMapCanvas *pNewMapCanvas = mMapCanvasList.at(index); + QgsLegend *pNewMapLegend = mMapLegendList.at(index); + + // do nothing if new map canvas and legend is current + if (pNewMapCanvas == mMapCanvas && pNewMapLegend == mMapLegend) return; + + // 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); + + // enable overview canvas for map canvas + mMapCanvas->enableOverviewMode( mMapOverviewCanvas ); + // set map tool for map canvas + mMapCanvas->setMapTool( mMapToolsList.at(index)->currentTool ); + + // put new map legend in legend dock widget and new overview canvas to overview dock + if (mLegendDock && mOverviewDock) + { + mLegendDock->setWidget(mMapLegend); + mOverviewDock->setWidget(mMapOverviewCanvas); + } +} + +void QgisApp::twCurrentTabMoved(int from, int to) +{ + // do appropriated procedures to change an index of the current tab to new one + twCurrentTabChanged(to); + + // do the swap in lists + mMapCanvasList.swap(from, to); + mMapOverviewCanvasList.swap(from,to); + mMapLegendList.swap(from, to); + mMapToolsList.swap(from, to); +} + +void QgisApp::twCreateNewTab() +{ + // countOfTabs counts all numbers of created tabs and put it in a name of a new tab + static int countOfTabs = 1; + + // create map canvas and add it to the tab widget + QgsMapCanvas *myMapCanvas = createMapCanvasWithTools(); + myMapCanvas->setObjectName( "theMapCanvas" ); + mTabWidget->addTab(myMapCanvas, tr("Canvas %1").arg(countOfTabs++)); + + // 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); + + // set map canvas and map tools for new tab + twCurrentTabChanged(mTabWidget->currentIndex()); +} + +void QgisApp::twCloseTab() +{ + // close the current tab + twCloseTab(mTabWidget->currentIndex()); +} + +void QgisApp::twCloseTab(int index) +{ + // do nothing when we have an one tab + if (mTabWidget->count() == 1) return; + + // remove current tab + mTabWidget->removeTab(index); + + QgsMapCanvas *ptmpMapCanvas = mMapCanvasList[index]; + QgsLegend *ptmpMapLegend = mMapLegendList[index]; + + // disconnect the connetions relative to the map canvas and legend at index *index* + resetupConnections(ptmpMapCanvas, ptmpMapLegend, NULL, NULL); + + // free memory allocated by tems corresponding to the current tab + delete mMapToolsList[index]; + delete mMapOverviewCanvasList[index]; + delete ptmpMapLegend; + delete ptmpMapCanvas; + + // set the pointers to NULL + mMapCanvas = NULL; + mMapOverviewCanvas = NULL; + mMapLegend = NULL; + mMapTools = NULL; + + // remove corresponding to current tab map canvas, overview canvas, map legend and map tools + mMapCanvasList.removeAt(index); + mMapOverviewCanvasList.removeAt(index); + mMapLegendList.removeAt(index); + mMapToolsList.removeAt(index); + + // *update* the current tab + twCurrentTabChanged(mTabWidget->currentIndex()); +} + +void QgisApp::createTabWidget() +{ + // create the main tab widget + mTabWidget = new QgsTabWidget(this); + mTabWidget->setTabPosition(QTabWidget::East); + mTabWidget->setTabsClosable(true); + mTabWidget->setMovable(true); + setCentralWidget( mTabWidget ); +} + +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 " + QgsMapCanvas *myMapCanvas = new QgsMapCanvas( this, "theMapCanvas" ); + myMapCanvas->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(); + myMapCanvas->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 ); + mMapTools = new Tools(); + + mMapTools->mZoomIn = new QgsMapToolZoom( myMapCanvas, FALSE /* zoomIn */ ); + mMapTools->mZoomIn->setAction( mActionZoomIn ); + mMapTools->mZoomOut = new QgsMapToolZoom( myMapCanvas, TRUE /* zoomOut */ ); + mMapTools->mZoomOut->setAction( mActionZoomOut ); + mMapTools->mPan = new QgsMapToolPan( myMapCanvas ); + mMapTools->mPan->setAction( mActionPan ); + mMapTools->mIdentify = new QgsMapToolIdentify( myMapCanvas ); + mMapTools->mIdentify->setAction( mActionIdentify ); + mMapTools->mMeasureDist = new QgsMeasureTool( myMapCanvas, FALSE /* area */ ); + mMapTools->mMeasureDist->setAction( mActionMeasure ); + mMapTools->mMeasureArea = new QgsMeasureTool( myMapCanvas, TRUE /* area */ ); + mMapTools->mMeasureArea->setAction( mActionMeasureArea ); + mMapTools->mCapturePoint = new QgsMapToolAddFeature( myMapCanvas, QgsMapToolCapture::CapturePoint ); + mMapTools->mCapturePoint->setAction( mActionCapturePoint ); mActionCapturePoint->setVisible( false ); - mMapTools.mCaptureLine = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CaptureLine ); - mMapTools.mCaptureLine->setAction( mActionCaptureLine ); + mMapTools->mCaptureLine = new QgsMapToolAddFeature( myMapCanvas, QgsMapToolCapture::CaptureLine ); + mMapTools->mCaptureLine->setAction( mActionCaptureLine ); mActionCaptureLine->setVisible( false ); - mMapTools.mCapturePolygon = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CapturePolygon ); - mMapTools.mCapturePolygon->setAction( mActionCapturePolygon ); + mMapTools->mCapturePolygon = new QgsMapToolAddFeature( myMapCanvas, QgsMapToolCapture::CapturePolygon ); + mMapTools->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->mMoveFeature = new QgsMapToolMoveFeature( myMapCanvas ); + mMapTools->mMoveFeature->setAction( mActionMoveFeature ); + mMapTools->mSplitFeatures = new QgsMapToolSplitFeatures( myMapCanvas ); + mMapTools->mSplitFeatures->setAction( mActionSplitFeatures ); + mMapTools->mSelect = new QgsMapToolSelect( myMapCanvas ); + mMapTools->mSelect->setAction( mActionSelect ); + mMapTools->mVertexAdd = new QgsMapToolAddVertex( myMapCanvas ); + mMapTools->mVertexAdd->setAction( mActionAddVertex ); + mMapTools->mVertexMove = new QgsMapToolMoveVertex( myMapCanvas ); + mMapTools->mVertexMove->setAction( mActionMoveVertex ); + mMapTools->mVertexDelete = new QgsMapToolDeleteVertex( myMapCanvas ); + mMapTools->mVertexDelete->setAction( mActionDeleteVertex ); + mMapTools->mAddRing = new QgsMapToolAddRing( myMapCanvas ); + mMapTools->mAddRing->setAction( mActionAddRing ); + mMapTools->mAddIsland = new QgsMapToolAddIsland( myMapCanvas ); + + // set a current map tool + mMapTools->currentTool = mMapTools->mPan; + //ensure that non edit tool is initialised or we will get crashes in some situations - mNonEditMapTool = mMapTools.mPan; + mNonEditMapTool = mMapTools->mPan; + + // append map tools to list + mMapToolsList.append(mMapTools); + + return myMapCanvas; } 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 ); - // moved here to set anti aliasing to both map canvas and overview QSettings mySettings; mMapCanvas->enableAntiAliasing( mySettings.value( "/qgis/enable_anti_aliasing", false ).toBool() ); @@ -1659,6 +1885,31 @@ mMapCanvas->refresh(); } +void QgisApp::addTabWidget( QWidget *page, const QString &label ) +{ + mTabWidget->addTab( page, label ); +} + +void QgisApp::addTabWidget( QWidget *page, const QIcon &icon, const QString &label ) +{ + mTabWidget->addTab( page, icon, label ); +} + +void QgisApp::insertTabWidget( int index, QWidget *page, const QString &label ) +{ + mTabWidget->insertTab( index, page, label ); +} + +void QgisApp::insertTabWidget( int index, QWidget *page, const QIcon &icon, const QString &label ) +{ + mTabWidget->insertTab( index, page, icon, label ); +} + +void QgisApp::removeTabWidget( int index ) +{ + mTabWidget->removeTab( index ); +} + QToolBar *QgisApp::addToolBar( QString name ) { QToolBar *toolBar = QMainWindow::addToolBar( name ); @@ -1669,15 +1920,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 ); @@ -2960,8 +3202,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) @@ -3703,11 +3945,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 @@ -3802,7 +4044,7 @@ { QgsDebugMsg( "hiding all layers!" ); - legend()->selectAll( false ); + mMapLegend->selectAll( false ); } @@ -3811,7 +4053,7 @@ { QgsDebugMsg( "Showing all layers!" ); - legend()->selectAll( true ); + mMapLegend->selectAll( true ); } @@ -3819,7 +4061,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 ); @@ -3828,7 +4070,7 @@ void QgisApp::zoomOut() { - mMapCanvas->setMapTool( mMapTools.mZoomOut ); + mMapCanvas->setMapTool( mMapTools->mZoomOut ); // notify the project we've made a change QgsProject::instance()->dirty( true ); @@ -3844,7 +4086,7 @@ void QgisApp::pan() { - mMapCanvas->setMapTool( mMapTools.mPan ); + mMapCanvas->setMapTool( mMapTools->mPan ); } void QgisApp::zoomFull() @@ -3878,17 +4120,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() @@ -3971,12 +4213,12 @@ void QgisApp::moveFeature() { - mMapCanvas->setMapTool( mMapTools.mMoveFeature ); + mMapCanvas->setMapTool( mMapTools->mMoveFeature ); } void QgisApp::splitFeatures() { - mMapCanvas->setMapTool( mMapTools.mSplitFeatures ); + mMapCanvas->setMapTool( mMapTools->mSplitFeatures ); } void QgisApp::capturePoint() @@ -3987,7 +4229,7 @@ } // set current map tool to select - mMapCanvas->setMapTool( mMapTools.mCapturePoint ); + mMapCanvas->setMapTool( mMapTools->mCapturePoint ); } void QgisApp::captureLine() @@ -3997,7 +4239,7 @@ return; } - mMapCanvas->setMapTool( mMapTools.mCaptureLine ); + mMapCanvas->setMapTool( mMapTools->mCaptureLine ); } void QgisApp::capturePolygon() @@ -4006,12 +4248,12 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mCapturePolygon ); + mMapCanvas->setMapTool( mMapTools->mCapturePolygon ); } void QgisApp::select() { - mMapCanvas->setMapTool( mMapTools.mSelect ); + mMapCanvas->setMapTool( mMapTools->mSelect ); } @@ -4021,7 +4263,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mVertexAdd ); + mMapCanvas->setMapTool( mMapTools->mVertexAdd ); } @@ -4031,7 +4273,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mVertexMove ); + mMapCanvas->setMapTool( mMapTools->mVertexMove ); } void QgisApp::addRing() @@ -4040,7 +4282,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mAddRing ); + mMapCanvas->setMapTool( mMapTools->mAddRing ); } void QgisApp::addIsland() @@ -4049,7 +4291,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mAddIsland ); + mMapCanvas->setMapTool( mMapTools->mAddIsland ); } @@ -4059,7 +4301,7 @@ { return; } - mMapCanvas->setMapTool( mMapTools.mVertexDelete ); + mMapCanvas->setMapTool( mMapTools->mVertexDelete ); } @@ -4937,9 +5179,13 @@ void QgisApp::mapToolChanged( QgsMapTool *tool ) { - if ( tool && !tool->isEditTool() ) + if ( tool ) { - mNonEditMapTool = tool; + if ( !tool->isEditTool() ) + { + mNonEditMapTool = tool; + } + mMapTools->currentTool = tool; } } @@ -4994,8 +5240,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" ); @@ -5822,3 +6068,24 @@ 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; +} Index: /usr/local/src/qgis/src/app/qgisappinterface.cpp =================================================================== --- /usr/local/src/qgis/src/app/qgisappinterface.cpp (revision 10666) +++ /usr/local/src/qgis/src/app/qgisappinterface.cpp (working copy) @@ -29,6 +29,7 @@ #include "qgsmaplayerregistry.h" #include "qgsmapcanvas.h" #include "qgslegend.h" +#include "qgstabwidget.h" QgisAppInterface::QgisAppInterface( QgisApp * _qgis ) : qgis( _qgis ) @@ -141,6 +142,11 @@ return qgis->mapCanvas(); } +QgsTabWidget * QgisAppInterface::tabWidget() +{ + return qgis->tabWidget(); +} + QWidget * QgisAppInterface::mainWindow() { return qgis; @@ -174,6 +180,31 @@ qgis->removeDockWidget( dockwidget ); } +void QgisAppInterface::addTabWidget( QWidget *page, const QString &label ) +{ + qgis->addTabWidget( page, label ); +} + +void QgisAppInterface::addTabWidget( QWidget *page, const QIcon &icon, const QString &label ) +{ + qgis->addTabWidget( page, icon, label ); +} + +void QgisAppInterface::insertTabWidget( int index, QWidget *page, const QString &label ) +{ + qgis->insertTabWidget( index, page, label ); +} + +void QgisAppInterface::insertTabWidget( int index, QWidget *page, const QIcon &icon, const QString &label ) +{ + qgis->insertTabWidget( index, page, icon, label ); +} + +void QgisAppInterface::removeTabWidget( int index ) +{ + qgis->removeTabWidget( index ); +} + void QgisAppInterface::refreshLegend( QgsMapLayer *l ) { if ( l && qgis && qgis->legend() ) Index: /usr/local/src/qgis/src/gui/qgstabwidget.cpp =================================================================== --- /usr/local/src/qgis/src/gui/qgstabwidget.cpp (revision 0) +++ /usr/local/src/qgis/src/gui/qgstabwidget.cpp (revision 0) @@ -0,0 +1,64 @@ +#include +#include + +#include "qgstabwidget.h" + +QgsTabWidget::QgsTabWidget(QWidget *parent) + : QTabWidget(parent) +{ + tabBar()->hide(); + connect(tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(tabMove(int, int))); +} + +QgsTabWidget::~QgsTabWidget() +{ +} + +void QgsTabWidget::addTab(QWidget *widget, const QIcon &icon, const QString &label) +{ + QTabWidget::addTab(widget, icon, label); + if (count() > 1) tabBar()->show(); +} + +void QgsTabWidget::addTab(QWidget *widget, const QString &label) +{ + QTabWidget::addTab(widget, label); + if (count() > 1) tabBar()->show(); +} + +void QgsTabWidget::insertTab(int index, QWidget *widget, const QIcon &icon, const QString &label) +{ + QTabWidget::insertTab(index, widget, icon, label); + if (count() > 1) tabBar()->show(); +} + +void QgsTabWidget::insertTab(int index, QWidget *widget, const QString &label) +{ + QTabWidget::insertTab(index, widget, label); + if (count() > 1) tabBar()->show(); +} + +void QgsTabWidget::removeTab(int index) +{ + if (count() != 1) { + QTabWidget::removeTab(index); + if (count() == 1) tabBar()->hide(); + } +} + +void QgsTabWidget::mouseDoubleClickEvent(QMouseEvent *event) +{ + bool ok; + QString myTabText = QInputDialog::getText(this, tr("Tab text"), tr("Enter new tab text:"), + QLineEdit::Normal, tr("Canvas %1").arg(currentIndex() + 1), &ok); + + if (ok && !myTabText.isEmpty()) + setTabText(currentIndex(), myTabText); + + event->accept(); +} + +void QgsTabWidget::tabMove(int from, int to) +{ + emit tabMoved(from, to); +} Index: /usr/local/src/qgis/src/gui/CMakeLists.txt =================================================================== --- /usr/local/src/qgis/src/gui/CMakeLists.txt (revision 10666) +++ /usr/local/src/qgis/src/gui/CMakeLists.txt (working copy) @@ -12,6 +12,7 @@ qgsfiledropedit.cpp qgsgenericprojectionselector.cpp qgsmapcanvas.cpp +qgstabwidget.cpp qgsmapcanvasitem.cpp qgsmapcanvasmap.cpp qgsmapcanvassnapper.cpp @@ -41,6 +42,7 @@ qgsmessageviewer.h qgsprojectionselector.h qgsquickprint.h +qgstabwidget.h ) QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS}) @@ -121,6 +123,7 @@ qgsrubberband.h qgsvertexmarker.h qgsmaptip.h +qgstabwidget.h ${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h ${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsgenericprojectionselectorbase.h Index: /usr/local/src/qgis/src/gui/qgisinterface.h =================================================================== --- /usr/local/src/qgis/src/gui/qgisinterface.h (revision 10666) +++ /usr/local/src/qgis/src/gui/qgisinterface.h (working copy) @@ -21,6 +21,7 @@ class QAction; class QMenu; +class QIcon; class QToolBar; class QDockWidget; class QMainWindow; @@ -36,6 +37,7 @@ class QgsMapLayer; class QgsMapCanvas; class QgsRasterLayer; +class QgsTabWidget; class QgsVectorLayer; /** \ingroup gui @@ -107,6 +109,9 @@ /** Return a pointer to the map canvas */ virtual QgsMapCanvas * mapCanvas() = 0; + /** Return a pointer to the main tab widget that containing map canvas */ + virtual QgsTabWidget * tabWidget() = 0; + /** Return a pointer to the main window (instance of QgisApp in case of QGIS) */ virtual QWidget * mainWindow() = 0; @@ -124,6 +129,21 @@ /** Remove specified dock widget from main window (doesn't delete it). Added in QGIS 1.1. */ virtual void removeDockWidget( QDockWidget * dockwidget ) = 0; + /** Add a tab to the tab widget with label */ + virtual void addTabWidget( QWidget *page, const QString &label ) = 0; + + /** Add a tab to the tab widget with icon and label */ + virtual void addTabWidget( QWidget *page, const QIcon &icon, const QString &label ) = 0; + + /** Insert a tab to the tab widget with label */ + virtual void insertTabWidget( int index, QWidget *page, const QString &label ) = 0; + + /** Insert a tab to the tab widget with icon and label */ + virtual void insertTabWidget( int index, QWidget *page, const QIcon &icon, const QString &label ) = 0; + + /** Remove specified tab from tab widget (doesn't delete it) */ + virtual void removeTabWidget( int index ) = 0; + /** refresh the legend of a layer */ virtual void refreshLegend( QgsMapLayer *l ) = 0; Index: /usr/local/src/qgis/src/gui/qgstabwidget.h =================================================================== --- /usr/local/src/qgis/src/gui/qgstabwidget.h (revision 0) +++ /usr/local/src/qgis/src/gui/qgstabwidget.h (revision 0) @@ -0,0 +1,37 @@ +#ifndef QGSTABWIDGET_H +#define QGSTABWIDGET_H + +#include +#include + +class QLineEdit; + +class GUI_EXPORT QgsTabWidget : public QTabWidget +{ + Q_OBJECT + +public: + QgsTabWidget(QWidget *parent = 0); + ~QgsTabWidget(); + + void addTab(QWidget *widget, const QIcon &icon, const QString &label); + void addTab(QWidget *widget, const QString &label); + void insertTab(int index, QWidget *widget, const QIcon &icon, const QString &label); + void insertTab(int index, QWidget *widget, const QString &label); + void removeTab(int index); + +signals: + void tabMoved(int from, int to); + +public slots: + void nextTab() { currentIndex() == count() - 1 ? setCurrentIndex(0) : setCurrentIndex(currentIndex() + 1); } + void previousTab() { currentIndex() == 0 ? setCurrentIndex(count() - 1) : setCurrentIndex(currentIndex() - 1); } + +private slots: + void tabMove(int from, int to); + +private: + void mouseDoubleClickEvent(QMouseEvent *event); +}; + +#endif // QGSTABWIDGET_H