Skip to content
Permalink
Browse files

[FEATURE][styles] Add new style dock for interactive styling

  • Loading branch information
NathanW2 committed Apr 19, 2016
1 parent b7a43f2 commit 831e7cd23633bf16a54b8175b35c76154ac1284f
@@ -84,6 +84,9 @@ class QgsFieldExpressionWidget : QWidget
//! convenience slot to connect QgsMapLayerComboBox layer signal
void setLayer( QgsMapLayer* layer );

//! sets the current row in the widget
void setRow( int row );

//! sets the current field or expression in the widget
void setField( const QString &fieldName );

@@ -94,6 +94,7 @@ SET(QGIS_APP_SRCS
nodetool/qgsvertexentry.cpp
nodetool/qgsnodeeditor.cpp

qgsmapstylingwidget.cpp
qgsmeasuredialog.cpp
qgsmeasuretool.cpp
qgsmergeattributesdialog.cpp
@@ -268,6 +269,7 @@ SET (QGIS_APP_MOC_HDRS
nodetool/qgsselectedfeature.h
nodetool/qgsnodeeditor.h

qgsmapstylingwidget.h
qgsmeasuredialog.h
qgsmeasuretool.h
qgsmergeattributesdialog.h
@@ -75,6 +75,7 @@
#include <qgsnetworkaccessmanager.h>
#include <qgsapplication.h>
#include <qgscomposition.h>
#include <qgsmapstylingwidget.h>

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

mMapStylingDock = new QDockWidget( this );
mMapStylingDock->setWindowTitle( tr( "Map Styling" ) );
mMapStyleWidget = new QgsMapStylingWidget( mMapCanvas );
mMapStylingDock->setWidget( mMapStyleWidget );

connect( mMapStyleWidget, SIGNAL( styleChanged( QgsMapLayer* ) ), this, SLOT( updateLabelToolButtons() ) );

addDockWidget( Qt::RightDockWidgetArea, mMapStylingDock );
mMapStylingDock->hide();

mSnappingDialog = new QgsSnappingDialog( this, mMapCanvas );
mSnappingDialog->setObjectName( "SnappingOption" );

@@ -2399,6 +2410,9 @@ void QgisApp::setupConnections()
// connect legend signals
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SLOT( activateDeactivateLayerRelatedActions( QgsMapLayer * ) ) );
connect( mLayerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer * ) ),
this, SLOT( setMapStyleDockLayer( QgsMapLayer* ) ) );

connect( mLayerTreeView->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
this, SLOT( legendLayerSelectionChanged() ) );
connect( mLayerTreeView->layerTreeModel()->rootGroup(), SIGNAL( addedChildren( QgsLayerTreeNode*, int, int ) ),
@@ -2748,6 +2762,11 @@ void QgisApp::initLayerTreeView()
mLegendExpressionFilterButton->setToolTip( tr( "Filter legend by expression" ) );
connect( mLegendExpressionFilterButton, SIGNAL( toggled( bool ) ), this, SLOT( toggleFilterLegendByExpression( bool ) ) );

mActionStyleDock = new QAction( tr( "Map Styling" ), this );
mActionStyleDock->setToolTip( tr( "Open the map styling dock" ) );
mActionStyleDock->setIcon( QgsApplication::getThemeIcon( "propertyicons/symbology.png" ) );
connect( mActionStyleDock, SIGNAL( triggered() ), this, SLOT( mapStyleDock() ) );

// expand / collapse tool buttons
QAction* actionExpandAll = new QAction( tr( "Expand All" ), this );
actionExpandAll->setIcon( QgsApplication::getThemeIcon( "/mActionExpandTree.svg" ) );
@@ -2758,6 +2777,9 @@ void QgisApp::initLayerTreeView()
actionCollapseAll->setToolTip( tr( "Collapse All" ) );
connect( actionCollapseAll, SIGNAL( triggered( bool ) ), mLayerTreeView, SLOT( collapseAll() ) );

QWidget* spacer = new QWidget();
spacer->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );

QToolBar* toolbar = new QToolBar();
toolbar->setIconSize( QSize( 16, 16 ) );
toolbar->addAction( actionAddGroup );
@@ -2767,6 +2789,8 @@ void QgisApp::initLayerTreeView()
toolbar->addAction( actionExpandAll );
toolbar->addAction( actionCollapseAll );
toolbar->addAction( mActionRemoveLayer );
toolbar->addWidget( spacer );
toolbar->addAction( mActionStyleDock );

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

mapStyleDock();
}

QDialog dlg;
dlg.setWindowTitle( tr( "Layer labeling settings" ) );
QgsLabelingWidget *labelingGui = new QgsLabelingWidget( vlayer, mMapCanvas, &dlg );
labelingGui->layout()->setContentsMargins( 0, 0, 0, 0 );
QVBoxLayout *layout = new QVBoxLayout( &dlg );
layout->addWidget( labelingGui );

QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply, Qt::Horizontal, &dlg );
layout->addWidget( buttonBox );

dlg.setLayout( layout );

QSettings settings;
dlg.restoreGeometry( settings.value( "/Windows/Labeling/geometry" ).toByteArray() );

connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL( clicked() ), &dlg, SLOT( accept() ) );
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL( clicked() ), &dlg, SLOT( reject() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), labelingGui, SLOT( apply() ) );

if ( dlg.exec() )
void QgisApp::setMapStyleDockLayer( QgsMapLayer* layer )
{
if ( !layer )
{
labelingGui->writeSettingsToLayer();
mMapStylingDock->setEnabled( false );
return;
}

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

// trigger refresh
if ( mMapCanvas )
{
mMapCanvas->refresh();
}
}
mMapStylingDock->setWindowTitle( tr( "Map Styling - %1" ).arg( layer->name() ) );
}

activateDeactivateLayerRelatedActions( vlayer );
void QgisApp::mapStyleDock()
{
mMapStylingDock->show();
setMapStyleDockLayer( activeLayer() );
}

void QgisApp::diagramProperties()
@@ -9848,7 +9858,7 @@ void QgisApp::layerEditStateChanged()
}
}

void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
void QgisApp::updateLabelToolButtons()
{
bool enableMove = false, enableRotate = false, enablePin = false, enableShowHide = false, enableChange = false;

@@ -9895,6 +9905,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionMoveLabel->setEnabled( enableMove );
mActionRotateLabel->setEnabled( enableRotate );
mActionChangeLabelProperties->setEnabled( enableChange );
}

void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{
updateLabelToolButtons();

mMenuPasteAs->setEnabled( clipboard() && !clipboard()->isEmpty() );
mActionPasteAsNewVector->setEnabled( clipboard() && !clipboard()->isEmpty() );
@@ -12,8 +12,7 @@
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
* * ***************************************************************************/

This comment has been minimized.

Copy link
@sbrunner

sbrunner Nov 17, 2016

Contributor

Oups :-)


#ifndef QGISAPP_H
#define QGISAPP_H
@@ -94,6 +93,8 @@ class QgsScaleComboBox;
class QgsDataItem;
class QgsTileScaleWidget;

class QgsLabelingWidget;
class QgsMapStylingWidget;
class QgsDiagramProperties;

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


#include "ui_qgisapp.h"

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

/** Update the label toolbar buttons */
void updateLabelToolButtons();

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

//! shows the map styling dock
void mapStyleDock();

//! diagrams properties
void diagramProperties();

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

/** Set the layer for the map style dock. Doesn't show the style dock */
void setMapStyleDockLayer( QgsMapLayer *layer );

signals:
/** Emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -1682,6 +1693,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsSnappingDialog *mSnappingDialog;

QgsPluginManager *mPluginManager;
QDockWidget *mMapStylingDock;
QgsMapStylingWidget* mMapStyleWidget;

QgsComposerManager *mComposerManager;

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

QAction* mActionFilterLegend;
QAction* mActionStyleDock;

QgsLegendFilterButton* mLegendExpressionFilterButton;

8 comments on commit 831e7cd

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Apr 19, 2016

@NathanW2 nice work!

@nyalldawson , we need to find a shorter stringer for "Discourage other labels from covering features on this layer", that's the only reason why the dock is so wide.

"Features act as label obstacles" ?

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Apr 19, 2016

@wonder-sk keen to get your thoughts on what we can do to speed up live rendering.

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Nov 17, 2016

On Fedora, headers for labeling tabs are not visible.

image

@NathanW2 any idea?

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Nov 17, 2016

@3nids change the theme for QGIS. Adawaita is very buggy in qt apps, eg the horrible spin boxes

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Nov 17, 2016

@3nids my suggestion - use "fusion" instead. I wonder if we can blacklist Adawaita from qgis....

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Nov 22, 2016

No "fusion"...
Apart from Adawaita, I get Breeze, Windows, Plastique, Motif, CDE, GTK+, Cleanlooks.
Any idea why I miss Fusion (I'm on Fedora)

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson replied Nov 22, 2016

@3nids I'm on Fedora 24 and I get Fusion...

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Nov 24, 2016

went for cleanlooks, seems quite good!

Please sign in to comment.
You can’t perform that action at this time.