Skip to content

Commit

Permalink
[FEATURE][styles] Add new style dock for interactive styling
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Apr 19, 2016
1 parent b7a43f2 commit 831e7cd
Show file tree
Hide file tree
Showing 18 changed files with 1,362 additions and 932 deletions.
3 changes: 3 additions & 0 deletions python/gui/qgsfieldexpressionwidget.sip
Expand Up @@ -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 );

Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -94,6 +94,7 @@ SET(QGIS_APP_SRCS
nodetool/qgsvertexentry.cpp
nodetool/qgsnodeeditor.cpp

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

qgsmapstylingwidget.h
qgsmeasuredialog.h
qgsmeasuretool.h
qgsmergeattributesdialog.h
Expand Down
83 changes: 49 additions & 34 deletions src/app/qgisapp.cpp
Expand Up @@ -75,6 +75,7 @@
#include <qgsnetworkaccessmanager.h>
#include <qgsapplication.h>
#include <qgscomposition.h>
#include <qgsmapstylingwidget.h>

#include <QNetworkReply>
#include <QNetworkProxy>
Expand Down Expand Up @@ -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" );

Expand Down Expand Up @@ -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 ) ),
Expand Down Expand Up @@ -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" ) );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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() );
Expand Down
18 changes: 16 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -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
Expand Down Expand Up @@ -94,6 +93,8 @@ class QgsScaleComboBox;
class QgsDataItem;
class QgsTileScaleWidget;

class QgsLabelingWidget;
class QgsMapStylingWidget;
class QgsDiagramProperties;

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


#include "ui_qgisapp.h"

#ifdef HAVE_TOUCH
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -1682,6 +1693,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsSnappingDialog *mSnappingDialog;

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

QgsComposerManager *mComposerManager;

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

QAction* mActionFilterLegend;
QAction* mActionStyleDock;

QgsLegendFilterButton* mLegendExpressionFilterButton;

Expand Down

8 comments on commit 831e7cd

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 831e7cd Apr 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@3nids
Copy link
Member

@3nids 3nids commented on 831e7cd Nov 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Fedora, headers for labeling tabs are not visible.

image

@NathanW2 any idea?

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@3nids
Copy link
Member

@3nids 3nids commented on 831e7cd Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@3nids
Copy link
Member

@3nids 3nids commented on 831e7cd Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went for cleanlooks, seems quite good!

Please sign in to comment.