Skip to content

Commit 831e7cd

Browse files
committedApr 19, 2016
[FEATURE][styles] Add new style dock for interactive styling
1 parent b7a43f2 commit 831e7cd

18 files changed

+1362
-932
lines changed
 

‎python/gui/qgsfieldexpressionwidget.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class QgsFieldExpressionWidget : QWidget
8484
//! convenience slot to connect QgsMapLayerComboBox layer signal
8585
void setLayer( QgsMapLayer* layer );
8686

87+
//! sets the current row in the widget
88+
void setRow( int row );
89+
8790
//! sets the current field or expression in the widget
8891
void setField( const QString &fieldName );
8992

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ SET(QGIS_APP_SRCS
9494
nodetool/qgsvertexentry.cpp
9595
nodetool/qgsnodeeditor.cpp
9696

97+
qgsmapstylingwidget.cpp
9798
qgsmeasuredialog.cpp
9899
qgsmeasuretool.cpp
99100
qgsmergeattributesdialog.cpp
@@ -268,6 +269,7 @@ SET (QGIS_APP_MOC_HDRS
268269
nodetool/qgsselectedfeature.h
269270
nodetool/qgsnodeeditor.h
270271

272+
qgsmapstylingwidget.h
271273
qgsmeasuredialog.h
272274
qgsmeasuretool.h
273275
qgsmergeattributesdialog.h

‎src/app/qgisapp.cpp

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include <qgsnetworkaccessmanager.h>
7676
#include <qgsapplication.h>
7777
#include <qgscomposition.h>
78+
#include <qgsmapstylingwidget.h>
7879

7980
#include <QNetworkReply>
8081
#include <QNetworkProxy>
@@ -716,6 +717,16 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
716717
addDockWidget( Qt::LeftDockWidgetArea, mUndoWidget );
717718
mUndoWidget->hide();
718719

720+
mMapStylingDock = new QDockWidget( this );
721+
mMapStylingDock->setWindowTitle( tr( "Map Styling" ) );
722+
mMapStyleWidget = new QgsMapStylingWidget( mMapCanvas );
723+
mMapStylingDock->setWidget( mMapStyleWidget );
724+
725+
connect( mMapStyleWidget, SIGNAL( styleChanged( QgsMapLayer* ) ), this, SLOT( updateLabelToolButtons() ) );
726+
727+
addDockWidget( Qt::RightDockWidgetArea, mMapStylingDock );
728+
mMapStylingDock->hide();
729+
719730
mSnappingDialog = new QgsSnappingDialog( this, mMapCanvas );
720731
mSnappingDialog->setObjectName( "SnappingOption" );
721732

@@ -2399,6 +2410,9 @@ void QgisApp::setupConnections()
23992410
// connect legend signals
24002411
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
24012412
this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) );
2413+
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
2414+
this, SLOT( setMapStyleDockLayer( QgsMapLayer* ) ) );
2415+
24022416
connect( mLayerTreeView->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
24032417
this, SLOT( legendLayerSelectionChanged() ) );
24042418
connect( mLayerTreeView->layerTreeModel()->rootGroup(), SIGNAL( addedChildren( QgsLayerTreeNode*, int, int ) ),
@@ -2748,6 +2762,11 @@ void QgisApp::initLayerTreeView()
27482762
mLegendExpressionFilterButton->setToolTip( tr( "Filter legend by expression" ) );
27492763
connect( mLegendExpressionFilterButton, SIGNAL( toggled( bool ) ), this, SLOT( toggleFilterLegendByExpression( bool ) ) );
27502764

2765+
mActionStyleDock = new QAction( tr( "Map Styling" ), this );
2766+
mActionStyleDock->setToolTip( tr( "Open the map styling dock" ) );
2767+
mActionStyleDock->setIcon( QgsApplication::getThemeIcon( "propertyicons/symbology.png" ) );
2768+
connect( mActionStyleDock, SIGNAL( triggered() ), this, SLOT( mapStyleDock() ) );
2769+
27512770
// expand / collapse tool buttons
27522771
QAction* actionExpandAll = new QAction( tr( "Expand All" ), this );
27532772
actionExpandAll->setIcon( QgsApplication::getThemeIcon( "/mActionExpandTree.svg" ) );
@@ -2758,6 +2777,9 @@ void QgisApp::initLayerTreeView()
27582777
actionCollapseAll->setToolTip( tr( "Collapse All" ) );
27592778
connect( actionCollapseAll, SIGNAL( triggered( bool ) ), mLayerTreeView, SLOT( collapseAll() ) );
27602779

2780+
QWidget* spacer = new QWidget();
2781+
spacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
2782+
27612783
QToolBar* toolbar = new QToolBar();
27622784
toolbar->setIconSize( QSize( 16, 16 ) );
27632785
toolbar->addAction( actionAddGroup );
@@ -2767,6 +2789,8 @@ void QgisApp::initLayerTreeView()
27672789
toolbar->addAction( actionExpandAll );
27682790
toolbar->addAction( actionCollapseAll );
27692791
toolbar->addAction( mActionRemoveLayer );
2792+
toolbar->addWidget( spacer );
2793+
toolbar->addAction( mActionStyleDock );
27702794

27712795
QVBoxLayout* vboxLayout = new QVBoxLayout;
27722796
vboxLayout->setMargin( 0 );
@@ -5460,47 +5484,33 @@ void QgisApp::labeling()
54605484
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer*>( activeLayer() );
54615485
if ( !vlayer )
54625486
{
5463-
messageBar()->pushMessage( tr( "Labeling Options" ),
5464-
tr( "Please select a vector layer first" ),
5465-
QgsMessageBar::INFO,
5466-
messageTimeout() );
54675487
return;
54685488
}
54695489

5490+
mapStyleDock();
5491+
}
54705492

5471-
QDialog dlg;
5472-
dlg.setWindowTitle( tr( "Layer labeling settings" ) );
5473-
QgsLabelingWidget *labelingGui = new QgsLabelingWidget( vlayer, mMapCanvas, &dlg );
5474-
labelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
5475-
QVBoxLayout *layout = new QVBoxLayout( &dlg );
5476-
layout->addWidget( labelingGui );
5477-
5478-
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply, Qt::Horizontal, &dlg );
5479-
layout->addWidget( buttonBox );
5480-
5481-
dlg.setLayout( layout );
5482-
5483-
QSettings settings;
5484-
dlg.restoreGeometry( settings.value( "/Windows/Labeling/geometry" ).toByteArray() );
5485-
5486-
connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL( clicked() ), &dlg, SLOT( accept() ) );
5487-
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL( clicked() ), &dlg, SLOT( reject() ) );
5488-
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), labelingGui, SLOT( apply() ) );
5489-
5490-
if ( dlg.exec() )
5493+
void QgisApp::setMapStyleDockLayer( QgsMapLayer* layer )
5494+
{
5495+
if ( !layer )
54915496
{
5492-
labelingGui->writeSettingsToLayer();
5497+
mMapStylingDock->setEnabled( false );
5498+
return;
5499+
}
54935500

5494-
settings.setValue( "/Windows/Labeling/geometry", dlg.saveGeometry() );
5501+
mMapStylingDock->setEnabled( true );
5502+
// We don't set the layer if the dock isn't open mainly to save
5503+
// the extra work if it's not needed
5504+
if ( mMapStylingDock->isVisible() )
5505+
mMapStyleWidget->setLayer( layer );
54955506

5496-
// trigger refresh
5497-
if ( mMapCanvas )
5498-
{
5499-
mMapCanvas->refresh();
5500-
}
5501-
}
5507+
mMapStylingDock->setWindowTitle( tr( "Map Styling - %1" ).arg( layer->name() ) );
5508+
}
55025509

5503-
activateDeactivateLayerRelatedActions( vlayer );
5510+
void QgisApp::mapStyleDock()
5511+
{
5512+
mMapStylingDock->show();
5513+
setMapStyleDockLayer( activeLayer() );
55045514
}
55055515

55065516
void QgisApp::diagramProperties()
@@ -9848,7 +9858,7 @@ void QgisApp::layerEditStateChanged()
98489858
}
98499859
}
98509860

9851-
void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
9861+
void QgisApp::updateLabelToolButtons()
98529862
{
98539863
bool enableMove = false, enableRotate = false, enablePin = false, enableShowHide = false, enableChange = false;
98549864

@@ -9895,6 +9905,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
98959905
mActionMoveLabel->setEnabled( enableMove );
98969906
mActionRotateLabel->setEnabled( enableRotate );
98979907
mActionChangeLabelProperties->setEnabled( enableChange );
9908+
}
9909+
9910+
void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
9911+
{
9912+
updateLabelToolButtons();
98989913

98999914
mMenuPasteAs->setEnabled( clipboard() && !clipboard()->isEmpty() );
99009915
mActionPasteAsNewVector->setEnabled( clipboard() && !clipboard()->isEmpty() );

‎src/app/qgisapp.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
* it under the terms of the GNU General Public License as published by *
1313
* the Free Software Foundation; either version 2 of the License, or *
1414
* (at your option) any later version. *
15-
* *
16-
***************************************************************************/
15+
* * ***************************************************************************/
1716

1817
#ifndef QGISAPP_H
1918
#define QGISAPP_H
@@ -94,6 +93,8 @@ class QgsScaleComboBox;
9493
class QgsDataItem;
9594
class QgsTileScaleWidget;
9695

96+
class QgsLabelingWidget;
97+
class QgsMapStylingWidget;
9798
class QgsDiagramProperties;
9899

99100
#include <QMainWindow>
@@ -115,6 +116,7 @@ class QgsDiagramProperties;
115116
#include "qgsbookmarks.h"
116117
#include "qgswelcomepageitemsmodel.h"
117118

119+
118120
#include "ui_qgisapp.h"
119121

120122
#ifdef HAVE_TOUCH
@@ -1089,6 +1091,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
10891091
/** Called when some layer's editing mode was toggled on/off */
10901092
void layerEditStateChanged();
10911093

1094+
/** Update the label toolbar buttons */
1095+
void updateLabelToolButtons();
1096+
10921097
/** Activates or deactivates actions depending on the current maplayer type.
10931098
Is called from the legend when the current legend item has changed*/
10941099
void activateDeactivateLayerRelatedActions( QgsMapLayer *layer );
@@ -1164,6 +1169,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
11641169
//! shows label settings dialog (for labeling-ng)
11651170
void labeling();
11661171

1172+
//! shows the map styling dock
1173+
void mapStyleDock();
1174+
11671175
//! diagrams properties
11681176
void diagramProperties();
11691177

@@ -1285,6 +1293,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
12851293
/** Pushes a layer error to the message bar */
12861294
void onLayerError( const QString& msg );
12871295

1296+
/** Set the layer for the map style dock. Doesn't show the style dock */
1297+
void setMapStyleDockLayer( QgsMapLayer *layer );
1298+
12881299
signals:
12891300
/** Emitted when a key is pressed and we want non widget sublasses to be able
12901301
to pick up on this (e.g. maplayer) */
@@ -1682,6 +1693,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
16821693
QgsSnappingDialog *mSnappingDialog;
16831694

16841695
QgsPluginManager *mPluginManager;
1696+
QDockWidget *mMapStylingDock;
1697+
QgsMapStylingWidget* mMapStyleWidget;
16851698

16861699
QgsComposerManager *mComposerManager;
16871700

@@ -1720,6 +1733,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
17201733
QgsMapCanvasTracer* mTracer;
17211734

17221735
QAction* mActionFilterLegend;
1736+
QAction* mActionStyleDock;
17231737

17241738
QgsLegendFilterButton* mLegendExpressionFilterButton;
17251739

0 commit comments

Comments
 (0)
Failed to load comments.