Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More integration of layer tree view in QGIS app
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent 21b2a9a commit 72b3ef7
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 38 deletions.
30 changes: 15 additions & 15 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -15,25 +15,27 @@
* *
***************************************************************************/
#include "qgsgpsinformationwidget.h"
#include "qgsnmeaconnection.h"
#include "qgsgpsconnectionregistry.h"
#include "qgsgpsdetector.h"

#include "info.h"

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgscoordinatetransform.h"
#include "qgsfeatureaction.h"
#include "qgsgeometry.h"
#include "qgsgpsconnectionregistry.h"
#include "qgsgpsdetector.h"
#include "qgslayertreeview.h"
#include "qgslogger.h"
#include "qgsmaprenderer.h"
#include "qgsmaptooladdfeature.h"
#include "qgsnmeaconnection.h"
#include "qgspoint.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsmaprenderer.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsfeatureaction.h"
#include "qgsgeometry.h"
#include "qgisapp.h"

//for avoid intersections static method
#include "qgsmaptooladdfeature.h"

// QWT Charting widget
#include <qwt_global.h>
Expand Down Expand Up @@ -66,8 +68,6 @@ QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWi
{
setupUi( this );

// to connect signals that layers have changed (which layer, edit state)
mpLegend = QgisApp::instance()->legend();
mpLastLayer = 0;

mLastGpsPosition = QgsPoint( 0.0, 0.0 );
Expand Down Expand Up @@ -232,7 +232,7 @@ QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWi
//SLM - added functionality
mLogFile = 0;

connect( mpLegend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
this, SLOT( updateCloseFeatureButton( QgsMapLayer* ) ) );

mStackedWidget->setCurrentIndex( 3 ); // force to Options
Expand Down
1 change: 0 additions & 1 deletion src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -96,7 +96,6 @@ class QgsGPSInformationWidget: public QWidget, private Ui::QgsGPSInformationWidg
QList<QgsPoint> mCaptureList;
FixStatus mLastFixStatus;
QString mDateTimeFormat; // user specified format string in registry (no UI presented)
QgsLegend * mpLegend;
QgsVectorLayer * mpLastLayer;
QFile * mLogFile;
QTextStream mLogFileTextStream;
Expand Down
12 changes: 6 additions & 6 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -18,13 +18,13 @@
#include "nodetool/qgsselectedfeature.h"
#include "nodetool/qgsvertexentry.h"

#include "qgsproject.h"
#include "qgisapp.h"
#include "qgslayertreeview.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"
#include "qgisapp.h"
#include "qgslegend.h"

#include <QMouseEvent>
#include <QRubberBand>
Expand Down Expand Up @@ -370,7 +370,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
emit messageDiscarded();

mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
mIsPoint = vlayer->geometryType() == QGis::Point;
Expand Down Expand Up @@ -657,7 +657,7 @@ void QgsMapToolNodeTool::cleanTool( bool deleteSelectedFeature )
QgsVectorLayer *vlayer = mSelectedFeature->vlayer();
Q_ASSERT( vlayer );

disconnect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
disconnect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
disconnect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
disconnect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );

Expand Down
4 changes: 2 additions & 2 deletions src/app/nodetool/qgsselectedfeature.cpp
Expand Up @@ -23,7 +23,7 @@
#include <qgsrubberband.h>
#include <qgisapp.h>
#include <qgsmaprenderer.h>
#include <qgslegend.h>
#include <qgslayertreeview.h>
#include <qgsproject.h>

QgsSelectedFeature::QgsSelectedFeature( QgsFeatureId featureId,
Expand Down Expand Up @@ -107,7 +107,7 @@ void QgsSelectedFeature::setSelectedFeature( QgsFeatureId featureId, QgsVectorLa
mGeometry = 0;

// signal changing of current layer
connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );

// feature was deleted
connect( mVlayer, SIGNAL( featureDeleted( QgsFeatureId ) ), this, SLOT( featureDeleted( QgsFeatureId ) ) );
Expand Down
15 changes: 12 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -550,6 +550,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
//set the focus to the map canvas
mMapCanvas->setFocus();

mLayerTreeView = new QgsLayerTreeView( this );

// "theMapLegend" used to find this canonical instance later
mMapLegend = new QgsLegend( mMapCanvas, this, "theMapLegend" );

Expand Down Expand Up @@ -2181,6 +2183,12 @@ QgsLegend *QgisApp::legend()
return mMapLegend;
}

QgsLayerTreeView* QgisApp::layerTreeView()
{
Q_ASSERT( mLayerTreeView );
return mLayerTreeView;
}

QgsPluginManager *QgisApp::pluginManager()
{
Q_ASSERT( mPluginManager );
Expand Down Expand Up @@ -2380,7 +2388,6 @@ void QgisApp::initLayerTreeView()
QgsLayerTreeModel* model = new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
model->setFlag(QgsLayerTreeModel::AllowVisibilityManagement);

mLayerTreeView = new QgsLayerTreeView( this );
mLayerTreeView->setModel( model );
mLayerTreeView->setMenuProvider( new QgsAppLayerTreeViewMenuProvider(mLayerTreeView, mMapCanvas) );

Expand Down Expand Up @@ -4340,7 +4347,8 @@ void QgisApp::hideAllLayers()
{
QgsDebugMsg( "hiding all layers!" );

legend()->setLayersVisible( false );
foreach ( QgsLayerTreeLayer* nodeLayer, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
nodeLayer->setVisible( false );
}


Expand All @@ -4349,7 +4357,8 @@ void QgisApp::showAllLayers()
{
QgsDebugMsg( "Showing all layers!" );

legend()->setLayersVisible( true );
foreach ( QgsLayerTreeLayer* nodeLayer, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
nodeLayer->setVisible( true );
}


Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -433,6 +433,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! returns pointer to map legend
QgsLegend *legend();

QgsLayerTreeView* layerTreeView();

//! returns pointer to plugin manager
QgsPluginManager *pluginManager();

Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisappinterface.cpp
Expand Up @@ -34,6 +34,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgslayertreeview.h"
#include "qgslegend.h"
#include "qgsshortcutsmanager.h"
#include "qgsattributedialog.h"
Expand All @@ -50,7 +51,7 @@ QgisAppInterface::QgisAppInterface( QgisApp * _qgis )
pluginManagerIface( _qgis->pluginManager() )
{
// connect signals
connect( qgis->legend(), SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
connect( qgis->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SIGNAL( currentLayerChanged( QgsMapLayer * ) ) );
connect( qgis, SIGNAL( currentThemeChanged( QString ) ),
this, SIGNAL( currentThemeChanged( QString ) ) );
Expand Down
11 changes: 6 additions & 5 deletions src/app/qgsmaptoolcapture.cpp
Expand Up @@ -16,14 +16,15 @@
#include "qgsmaptoolcapture.h"

#include "qgisapp.h"
#include "qgsvertexmarker.h"
#include "qgscursors.h"
#include "qgsrubberband.h"
#include "qgsgeometryvalidator.h"
#include "qgslayertreeview.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
#include "qgsrubberband.h"
#include "qgsvectorlayer.h"
#include "qgslogger.h"
#include "qgsgeometryvalidator.h"
#include "qgsvertexmarker.h"

#include <QCursor>
#include <QPixmap>
Expand All @@ -46,7 +47,7 @@ QgsMapToolCapture::QgsMapToolCapture( QgsMapCanvas* canvas, enum CaptureMode too
QPixmap mySelectQPixmap = QPixmap(( const char ** ) capture_point_cursor );
mCursor = QCursor( mySelectQPixmap, 8, 8 );

connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SLOT( currentLayerChanged( QgsMapLayer * ) ) );
}

Expand Down
1 change: 0 additions & 1 deletion src/app/qgsmaptoolcapture.h
Expand Up @@ -20,7 +20,6 @@
#include "qgsmaptooledit.h"
#include "qgspoint.h"
#include "qgsgeometry.h"
#include "qgslegend.h"

#include <QPoint>
#include <QList>
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsundowidget.cpp
Expand Up @@ -14,12 +14,12 @@
***************************************************************************/
#include "qgsundowidget.h"

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgslayertreeview.h"
#include "qgsmaplayer.h"
#include "qgsmapcanvas.h"
#include "qgslegend.h"

#include "qgisapp.h"
#include "qgsapplication.h"

QgsUndoWidget::QgsUndoWidget( QWidget * parent, QgsMapCanvas * mapCanvas )
: QDockWidget( parent )
Expand All @@ -29,7 +29,7 @@ QgsUndoWidget::QgsUndoWidget( QWidget * parent, QgsMapCanvas * mapCanvas )

connect( undoButton, SIGNAL( clicked() ), this, SLOT( undo( ) ) );
connect( redoButton, SIGNAL( clicked() ), this, SLOT( redo( ) ) );
connect( QgisApp::instance()->legend(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
this, SLOT( layerChanged( QgsMapLayer* ) ) );

undoButton->setDisabled( true );
Expand Down

0 comments on commit 72b3ef7

Please sign in to comment.