Skip to content

Commit

Permalink
Remove the legend from the application completely.
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent d26bdf7 commit 55c4ae5
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 85 deletions.
1 change: 0 additions & 1 deletion src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -31,7 +31,6 @@ class QgsGPSConnection;
class QgsGPSTrackerThread;
struct QgsGPSInformation;

class QgsLegend;
class QFile;
class QColor;

Expand Down
4 changes: 2 additions & 2 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -284,8 +284,8 @@ void QgsAppLegendInterface::onAddedChildren(QgsLayerTreeNode* node, int indexFro
emit itemAdded( mLayerTreeView->layerTreeModel()->node2index(child) );

// also notify about all children
if (QgsLayerTree::isGroup(child))
onAddedChildren(child, 0, child->children().count());
if (QgsLayerTree::isGroup(child) && child->children().count())
onAddedChildren(child, 0, child->children().count()-1);
}
}

Expand Down
90 changes: 29 additions & 61 deletions src/app/qgisapp.cpp
Expand Up @@ -113,6 +113,7 @@
#include "qgscredentialdialog.h"
#include "qgscursors.h"
#include "qgscustomization.h"
#include "qgscustomlayerorderwidget.h"
#include "qgscustomprojectiondialog.h"
#include "qgsdatasourceuri.h"
#include "qgsdatumtransformdialog.h"
Expand Down Expand Up @@ -142,10 +143,6 @@
#include "qgslayertreeutils.h"
#include "qgslayertreeview.h"
#include "qgslayertreeviewdefaultactions.h"
#include "qgslegend.h"
#include "qgslegendgroup.h"
#include "qgslayerorder.h"
#include "qgslegendlayer.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
Expand Down Expand Up @@ -556,11 +553,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mMapCanvas->setFocus();

mLayerTreeView = new QgsLayerTreeView( this );

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

mMapLayerOrder = new QgsLayerOrder( mMapLegend, this, "theMapLayerOrder" );
mLayerTreeView->setObjectName("theLayerTreeView"); // "theLayerTreeView" used to find this canonical instance later

// create undo widget
mUndoWidget = new QgsUndoWidget( NULL, mMapCanvas );
Expand All @@ -574,7 +567,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
createCanvasTools();
mMapCanvas->freeze();
initLayerTreeView();
initLegend();
createOverview();
createMapTips();
createDecorations();
Expand Down Expand Up @@ -822,7 +814,6 @@ QgisApp::QgisApp( )
mMapCanvas = new QgsMapCanvas();
mMapCanvas->freeze();
mLayerTreeView = new QgsLayerTreeView( this );
mMapLegend = new QgsLegend( mMapCanvas );
mUndoWidget = new QgsUndoWidget( NULL, mMapCanvas );
mInfoBar = new QgsMessageBar( centralWidget() );
// More tests may need more members to be initialized
Expand Down Expand Up @@ -2216,8 +2207,10 @@ QgsMessageBar* QgisApp::messageBar()

void QgisApp::initLayerTreeView()
{
mLayerTreeDock = new QDockWidget( tr( "Layers NEW" ), this );
mLayerTreeDock->setObjectName( "LayersNEW" );
mLayerTreeView->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." ) );

mLayerTreeDock = new QDockWidget( tr( "Layers" ), this );
mLayerTreeDock->setObjectName( "Layers" );
mLayerTreeDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );

QgsLayerTreeModel* model = new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), this );
Expand All @@ -2233,8 +2226,28 @@ void QgisApp::initLayerTreeView()
mLayerTreeDock->setWidget( mLayerTreeView );
addDockWidget( Qt::LeftDockWidgetArea, mLayerTreeDock );

mLayerTreeCanvasBridge = new QgsLayerTreeMapCanvasBridge( QgsProject::instance()->layerTreeRoot(), mMapCanvas );
mLayerTreeCanvasBridge->setParent(this);
mLayerTreeCanvasBridge = new QgsLayerTreeMapCanvasBridge( QgsProject::instance()->layerTreeRoot(), mMapCanvas, this );

mMapLayerOrder = new QgsCustomLayerOrderWidget(mLayerTreeCanvasBridge, this);
mMapLayerOrder->setObjectName("theMapLayerOrder");

QCheckBox *orderCb = new QCheckBox( tr( "Control rendering order" ) );
orderCb->setChecked( false );

mMapLayerOrder->setWhatsThis( tr( "Map layer list that displays all layers in drawing order." ) );
mLayerOrderDock = new QDockWidget( tr( "Layer order" ), this );
mLayerOrderDock->setObjectName( "LayerOrder" );
mLayerOrderDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );

QWidget* w = new QWidget( this );
QVBoxLayout* l = new QVBoxLayout;
l->setMargin( 0 );
l->addWidget( mMapLayerOrder );
l->addWidget( orderCb );
w->setLayout( l );
mLayerOrderDock->setWidget( w );
addDockWidget( Qt::LeftDockWidgetArea, mLayerOrderDock );
mLayerOrderDock->hide();
}


Expand Down Expand Up @@ -2262,51 +2275,6 @@ void QgisApp::layerTreeViewCurrentChanged(const QModelIndex& current, const QMod
}


void QgisApp::initLegend()
{
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 );

QCheckBox *orderCb = new QCheckBox( tr( "Control rendering order" ) );
orderCb->setChecked( false );

connect( orderCb, SIGNAL( toggled( bool ) ), mMapLegend, SLOT( unsetUpdateDrawingOrder( bool ) ) );
connect( mMapLegend, SIGNAL( updateDrawingOrderUnchecked( bool ) ), orderCb, SLOT( setChecked( bool ) ) );

QWidget *w = new QWidget( this );
QLayout *l = new QVBoxLayout;
l->setMargin( 0 );
l->addWidget( mMapLegend );
w->setLayout( l );
mLegendDock->setWidget( w );
addDockWidget( Qt::LeftDockWidgetArea, mLegendDock );

// add to the Panel submenu
mPanelMenu->addAction( mLegendDock->toggleViewAction() );

mMapLayerOrder->setWhatsThis( tr( "Map layer list that displays all layers in drawing order." ) );
mLayerOrderDock = new QDockWidget( tr( "Layer order" ), this );
mLayerOrderDock->setObjectName( "LayerOrder" );
mLayerOrderDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );

w = new QWidget( this );
l = new QVBoxLayout;
l->setMargin( 0 );
l->addWidget( mMapLayerOrder );
l->addWidget( orderCb );
w->setLayout( l );
mLayerOrderDock->setWidget( w );
addDockWidget( Qt::LeftDockWidgetArea, mLayerOrderDock );
mLayerOrderDock->hide();

// add to the Panel submenu
mPanelMenu->addAction( mLayerOrderDock->toggleViewAction() );

return;
}

void QgisApp::createMapTips()
{
// Set up the timer for maptips. The timer is reset everytime the mouse is moved
Expand Down Expand Up @@ -9504,7 +9472,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
else
{
vlp = new QgsVectorLayerProperties( vlayer, this );
connect( vlp, SIGNAL( refreshLegend( QString, QgsLegendItem::Expansion ) ), mLayerTreeView, SLOT( refreshLayerSymbology( QString ) ) );
connect( vlp, SIGNAL( refreshLegend( QString ) ), mLayerTreeView, SLOT( refreshLayerSymbology( QString ) ) );
}

if ( vlp->exec() )
Expand Down
9 changes: 2 additions & 7 deletions src/app/qgisapp.h
Expand Up @@ -44,12 +44,11 @@ class QgsComposer;
class QgsComposerView;
class QgsComposerManager;
class QgsContrastEnhancement;
class QgsCustomLayerOrderWidget;
class QgsGeometry;
class QgsFeature;
class QgsLayerTreeMapCanvasBridge;
class QgsLayerTreeView;
class QgsLegend;
class QgsLayerOrder;
class QgsMapCanvas;
class QgsMapLayer;
class QgsMapTip;
Expand Down Expand Up @@ -1327,7 +1326,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void createStatusBar();
void setupConnections();
void initLayerTreeView();
void initLegend();
void createOverview();
void createCanvasTools();
void createMapTips();
Expand Down Expand Up @@ -1371,7 +1369,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

// docks ------------------------------------------
QDockWidget *mLayerTreeDock;
QDockWidget *mLegendDock;
QDockWidget *mLayerOrderDock;
QDockWidget *mOverviewDock;
QDockWidget *mpGpsDock;
Expand Down Expand Up @@ -1473,10 +1470,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsLayerTreeView* mLayerTreeView;
//! Helper class that connects layer tree with map canvas
QgsLayerTreeMapCanvasBridge* mLayerTreeCanvasBridge;
//! Table of contents (legend) for the map
QgsLegend *mMapLegend;
//! Table of contents (legend) to order layers of the map
QgsLayerOrder *mMapLayerOrder;
QgsCustomLayerOrderWidget* mMapLayerOrder;
//! Cursor for the overview map
QCursor *mOverviewMapCursor;
//! scale factor
Expand Down
1 change: 0 additions & 1 deletion src/app/qgisappinterface.cpp
Expand Up @@ -35,7 +35,6 @@
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgslayertreeview.h"
#include "qgslegend.h"
#include "qgsshortcutsmanager.h"
#include "qgsattributedialog.h"
#include "qgsfield.h"
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsmaptoolpinlabels.cpp
Expand Up @@ -21,7 +21,6 @@
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgslegend.h"
#include "qgsvectorlayer.h"

#include "qgsmaptoolselectutils.h"
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsmaptoolpinlabels.h
Expand Up @@ -20,7 +20,6 @@

#include "qgsmaptoollabel.h"
#include "qgsrectangle.h"
#include "qgslegend.h"
#include "qgscoordinatetransform.h"

class QgsRubberBand;
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -22,7 +22,6 @@
#include "qgisapp.h"
#include "qgisappstylesheet.h"
#include "qgshighlight.h"
#include "qgslegend.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
#include "qgsgenericprojectionselector.h"
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -33,7 +33,6 @@
#include "qgslabeldialog.h"
#include "qgslabelinggui.h"
#include "qgslabel.h"
#include "qgslegenditem.h"
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
Expand Down Expand Up @@ -573,7 +572,7 @@ void QgsVectorLayerProperties::apply()
layer->setSimplifyMethod( simplifyMethod );

// update symbology
emit refreshLegend( layer->id(), QgsLegendItem::DontChange );
emit refreshLegend( layer->id() );

layer->triggerRepaint();
// notify the project we've made a change
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -27,7 +27,6 @@
#include "qgsdelattrdialog.h"
#include "qgsattributetypedialog.h"
#include "qgsfield.h"
#include "qgslegenditem.h"
#include "qgsmapcanvas.h"
#include "qgscontexthelp.h"
#include "qgsexpressionbuilderdialog.h"
Expand Down Expand Up @@ -123,7 +122,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

/** emitted when changes to layer were saved to update legend */
void refreshLegend( QString layerID, bool expandItem );
void refreshLegend( QString layerID, QgsLegendItem::Expansion expandItem );
void refreshLegend( QString layerID );

void toggleEditing( QgsMapLayer * );

Expand Down
5 changes: 3 additions & 2 deletions src/gui/layertree/qgslayertreemapcanvasbridge.cpp
Expand Up @@ -4,8 +4,9 @@

#include "qgsmapcanvas.h"

QgsLayerTreeMapCanvasBridge::QgsLayerTreeMapCanvasBridge(QgsLayerTreeGroup *root, QgsMapCanvas *canvas)
: mRoot(root)
QgsLayerTreeMapCanvasBridge::QgsLayerTreeMapCanvasBridge(QgsLayerTreeGroup *root, QgsMapCanvas *canvas, QObject* parent)
: QObject(parent)
, mRoot(root)
, mCanvas(canvas)
, mPendingCanvasUpdate(false)
, mHasCustomLayerOrder(false)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layertree/qgslayertreemapcanvasbridge.h
Expand Up @@ -15,7 +15,7 @@ class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject
{
Q_OBJECT
public:
QgsLayerTreeMapCanvasBridge(QgsLayerTreeGroup* root, QgsMapCanvas* canvas);
QgsLayerTreeMapCanvasBridge(QgsLayerTreeGroup* root, QgsMapCanvas* canvas, QObject* parent = 0);

bool hasCustomLayerOrder() const { return mHasCustomLayerOrder; }
QStringList customLayerOrder() const { return mCustomLayerOrder; }
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -380,6 +380,8 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
// Add check if vector layer when disconnecting from selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
if ( !currentLayer )
continue;
disconnect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
Expand Down
2 changes: 0 additions & 2 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -53,8 +53,6 @@ class QGraphicsScene;

class QgsMapToPixel;
class QgsMapLayer;
class QgsLegend;
class QgsLegendView;
class QgsHighlight;
class QgsVectorLayer;

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgstilescalewidget.cpp
Expand Up @@ -127,7 +127,7 @@ void QgsTileScaleWidget::showTileScale( QMainWindow *mainWindow )
QgsTileScaleWidget *tws = new QgsTileScaleWidget( canvas );
tws->setObjectName( "theTileScaleWidget" );

QObject *legend = mainWindow->findChild<QObject*>( "theMapLegend" );
QObject *legend = mainWindow->findChild<QObject*>( "theLayerTreeView" );
if ( legend )
{
connect( legend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
Expand Down

0 comments on commit 55c4ae5

Please sign in to comment.