Showing with 154 additions and 125 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +131 −105 src/app/qgslabelinggui.cpp
  3. +7 −2 src/app/qgslabelinggui.h
  4. +8 −7 src/app/qgsvectorlayerproperties.cpp
  5. +1 −1 src/app/qgsvectorlayerproperties.h
  6. +3 −3 src/core/qgsmaplayer.cpp
  7. +3 −6 src/core/qgsvectorlayer.cpp
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8758,7 +8758,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
QgsVectorLayerProperties *vlp = NULL; // See note above about reusing this
if ( vlp )
{
vlp->reset();
vlp->syncToLayer();
}
else
{
Expand Down
236 changes: 131 additions & 105 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,41 +119,135 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
mDirectSymbolsFrame->setVisible( layer->geometryType() == QGis::Line );
mMinSizeFrame->setVisible( layer->geometryType() != QGis::Point );

populateFieldNames(); // this is just for label text combo box
populateFontCapitalsComboBox();

// set up quadrant offset button group
mQuadrantBtnGrp = new QButtonGroup( this );
mQuadrantBtnGrp->addButton( mPointOffsetAboveLeft, ( int )QgsPalLayerSettings::QuadrantAboveLeft );
mQuadrantBtnGrp->addButton( mPointOffsetAbove, ( int )QgsPalLayerSettings::QuadrantAbove );
mQuadrantBtnGrp->addButton( mPointOffsetAboveRight, ( int )QgsPalLayerSettings::QuadrantAboveRight );
mQuadrantBtnGrp->addButton( mPointOffsetLeft, ( int )QgsPalLayerSettings::QuadrantLeft );
mQuadrantBtnGrp->addButton( mPointOffsetOver, ( int )QgsPalLayerSettings::QuadrantOver );
mQuadrantBtnGrp->addButton( mPointOffsetRight, ( int )QgsPalLayerSettings::QuadrantRight );
mQuadrantBtnGrp->addButton( mPointOffsetBelowLeft, ( int )QgsPalLayerSettings::QuadrantBelowLeft );
mQuadrantBtnGrp->addButton( mPointOffsetBelow, ( int )QgsPalLayerSettings::QuadrantBelow );
mQuadrantBtnGrp->addButton( mPointOffsetBelowRight, ( int )QgsPalLayerSettings::QuadrantBelowRight );
mQuadrantBtnGrp->setExclusive( true );

// setup direction symbol(s) button group
mDirectSymbBtnGrp = new QButtonGroup( this );
mDirectSymbBtnGrp->addButton( mDirectSymbRadioBtnLR, ( int )QgsPalLayerSettings::SymbolLeftRight );
mDirectSymbBtnGrp->addButton( mDirectSymbRadioBtnAbove, ( int )QgsPalLayerSettings::SymbolAbove );
mDirectSymbBtnGrp->addButton( mDirectSymbRadioBtnBelow, ( int )QgsPalLayerSettings::SymbolBelow );
mDirectSymbBtnGrp->setExclusive( true );

// upside-down labels button group
mUpsidedownBtnGrp = new QButtonGroup( this );
mUpsidedownBtnGrp->addButton( mUpsidedownRadioOff, ( int )QgsPalLayerSettings::Upright );
mUpsidedownBtnGrp->addButton( mUpsidedownRadioDefined, ( int )QgsPalLayerSettings::ShowDefined );
mUpsidedownBtnGrp->addButton( mUpsidedownRadioAll, ( int )QgsPalLayerSettings::ShowAll );
mUpsidedownBtnGrp->setExclusive( true );

//mShapeCollisionsChkBx->setVisible( false ); // until implemented

// post updatePlacementWidgets() connections
connect( chkLineAbove, SIGNAL( toggled( bool ) ), this, SLOT( updatePlacementWidgets() ) );
connect( chkLineBelow, SIGNAL( toggled( bool ) ), this, SLOT( updatePlacementWidgets() ) );

// setup point placement button group (assigned enum id currently unused)
mPlacePointBtnGrp = new QButtonGroup( this );
mPlacePointBtnGrp->addButton( radAroundPoint, ( int )QgsPalLayerSettings::AroundPoint );
mPlacePointBtnGrp->addButton( radOverPoint, ( int )QgsPalLayerSettings::OverPoint );
mPlacePointBtnGrp->setExclusive( true );
connect( mPlacePointBtnGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( updatePlacementWidgets() ) );

// setup line placement button group (assigned enum id currently unused)
mPlaceLineBtnGrp = new QButtonGroup( this );
mPlaceLineBtnGrp->addButton( radLineParallel, ( int )QgsPalLayerSettings::Line );
mPlaceLineBtnGrp->addButton( radLineCurved, ( int )QgsPalLayerSettings::Curved );
mPlaceLineBtnGrp->addButton( radLineHorizontal, ( int )QgsPalLayerSettings::Horizontal );
mPlaceLineBtnGrp->setExclusive( true );
connect( mPlaceLineBtnGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( updatePlacementWidgets() ) );

// setup polygon placement button group (assigned enum id currently unused)
mPlacePolygonBtnGrp = new QButtonGroup( this );
mPlacePolygonBtnGrp->addButton( radOverCentroid, ( int )QgsPalLayerSettings::OverPoint );
mPlacePolygonBtnGrp->addButton( radAroundCentroid, ( int )QgsPalLayerSettings::AroundPoint );
mPlacePolygonBtnGrp->addButton( radPolygonHorizontal, ( int )QgsPalLayerSettings::Horizontal );
mPlacePolygonBtnGrp->addButton( radPolygonFree, ( int )QgsPalLayerSettings::Free );
mPlacePolygonBtnGrp->addButton( radPolygonPerimeter, ( int )QgsPalLayerSettings::Line );
mPlacePolygonBtnGrp->setExclusive( true );
connect( mPlacePolygonBtnGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( updatePlacementWidgets() ) );

// TODO: is this necessary? maybe just use the data defined-only rotation?
mPointAngleDDBtn->setVisible( false );

// load layer's current QgsPalLayerSettings
init();

// Global settings group for groupboxes' saved/retored collapsed state
// maintains state across different dialogs
foreach ( QgsCollapsibleGroupBox *grpbox, findChildren<QgsCollapsibleGroupBox*>() )
{
grpbox->setSettingGroup( QString( "mAdvLabelingDlg" ) );
}

connect( groupBox_mPreview,
SIGNAL( collapsedStateChanged( bool ) ),
this,
SLOT( collapseSample( bool ) ) );

// get rid of annoying outer focus rect on Mac
mLabelingOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect, false );

QSettings settings;

// reset horiz strech of left side of options splitter (set to 1 for previewing in Qt Designer)
QSizePolicy policy( mLabelingOptionsListFrame->sizePolicy() );
policy.setHorizontalStretch( 0 );
mLabelingOptionsListFrame->setSizePolicy( policy );
if ( !settings.contains( QString( "/Windows/Labeling/OptionsSplitState" ) ) )
{
// set left list widget width on intial showing
QList<int> splitsizes;
splitsizes << 115;
mLabelingOptionsSplitter->setSizes( splitsizes );
}

// set up reverse connection from stack to list
connect( mLabelStackedWidget, SIGNAL( currentChanged( int ) ), this, SLOT( optionsStackedWidget_CurrentChanged( int ) ) );

// restore dialog, splitters and current tab
mFontPreviewSplitter->restoreState( settings.value( QString( "/Windows/Labeling/FontPreviewSplitState" ) ).toByteArray() );
mLabelingOptionsSplitter->restoreState( settings.value( QString( "/Windows/Labeling/OptionsSplitState" ) ).toByteArray() );

mLabelingOptionsListWidget->setCurrentRow( settings.value( QString( "/Windows/Labeling/Tab" ), 0 ).toInt() );
}

void QgsLabelingGui::init()
{
// load labeling settings from layer
QgsPalLayerSettings lyr;
lyr.readFromLayer( layer );
lyr.readFromLayer( mLayer );

blockInitSignals( true );

// enable/disable main options based upon whether layer is being labeled
chkEnableLabeling->setChecked( lyr.enabled );
cboFieldName->setEnabled( chkEnableLabeling->isChecked() );
btnExpression->setEnabled( chkEnableLabeling->isChecked() );
mLabelingFrame->setEnabled( chkEnableLabeling->isChecked() );

populateFieldNames(); // this is just for label text combo box
// add the current expression to the bottom of the list
if ( lyr.isExpression && !lyr.fieldName.isEmpty() )
cboFieldName->addItem( lyr.fieldName );

cboFieldName->setCurrentIndex( cboFieldName->findText( lyr.fieldName ) );

populateFontCapitalsComboBox();

// populate placement options
int distUnitIndex = lyr.distInMapUnits ? 1 : 0;

// set up quadrant offset button group
mQuadrantBtnGrp = new QButtonGroup( this );
mQuadrantBtnGrp->addButton( mPointOffsetAboveLeft, ( int )QgsPalLayerSettings::QuadrantAboveLeft );
mQuadrantBtnGrp->addButton( mPointOffsetAbove, ( int )QgsPalLayerSettings::QuadrantAbove );
mQuadrantBtnGrp->addButton( mPointOffsetAboveRight, ( int )QgsPalLayerSettings::QuadrantAboveRight );
mQuadrantBtnGrp->addButton( mPointOffsetLeft, ( int )QgsPalLayerSettings::QuadrantLeft );
mQuadrantBtnGrp->addButton( mPointOffsetOver, ( int )QgsPalLayerSettings::QuadrantOver );
mQuadrantBtnGrp->addButton( mPointOffsetRight, ( int )QgsPalLayerSettings::QuadrantRight );
mQuadrantBtnGrp->addButton( mPointOffsetBelowLeft, ( int )QgsPalLayerSettings::QuadrantBelowLeft );
mQuadrantBtnGrp->addButton( mPointOffsetBelow, ( int )QgsPalLayerSettings::QuadrantBelow );
mQuadrantBtnGrp->addButton( mPointOffsetBelowRight, ( int )QgsPalLayerSettings::QuadrantBelowRight );
mQuadrantBtnGrp->setExclusive( true );

mCentroidRadioWhole->setChecked( lyr.centroidWhole );
switch ( lyr.placement )
{
Expand Down Expand Up @@ -218,20 +312,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
mDirectSymbLeftLineEdit->setText( lyr.leftDirectionSymbol );
mDirectSymbRightLineEdit->setText( lyr.rightDirectionSymbol );
mDirectSymbRevChkBx->setChecked( lyr.reverseDirectionSymbol );
// setup direction symbol(s) button group
mDirectSymbBtnGrp = new QButtonGroup( this );
mDirectSymbBtnGrp->addButton( mDirectSymbRadioBtnLR, ( int )QgsPalLayerSettings::SymbolLeftRight );
mDirectSymbBtnGrp->addButton( mDirectSymbRadioBtnAbove, ( int )QgsPalLayerSettings::SymbolAbove );
mDirectSymbBtnGrp->addButton( mDirectSymbRadioBtnBelow, ( int )QgsPalLayerSettings::SymbolBelow );
mDirectSymbBtnGrp->setExclusive( true );
mDirectSymbBtnGrp->button(( int )lyr.placeDirectionSymbol )->setChecked( true );

// upside-down labels button group
mUpsidedownBtnGrp = new QButtonGroup( this );
mUpsidedownBtnGrp->addButton( mUpsidedownRadioOff, ( int )QgsPalLayerSettings::Upright );
mUpsidedownBtnGrp->addButton( mUpsidedownRadioDefined, ( int )QgsPalLayerSettings::ShowDefined );
mUpsidedownBtnGrp->addButton( mUpsidedownRadioAll, ( int )QgsPalLayerSettings::ShowAll );
mUpsidedownBtnGrp->setExclusive( true );
mDirectSymbBtnGrp->button(( int )lyr.placeDirectionSymbol )->setChecked( true );
mUpsidedownBtnGrp->button(( int )lyr.upsidedownLabels )->setChecked( true );

// curved label max character angles
Expand Down Expand Up @@ -319,8 +401,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
mLoadSvgParams = false;
on_mShapeTypeCmbBx_currentIndexChanged( lyr.shapeType ); // force update of shape background gui

//mShapeCollisionsChkBx->setVisible( false ); // until implemented

// drop shadow
mShadowDrawChkBx->setChecked( lyr.shadowDraw );
mShadowUnderCmbBx->setCurrentIndex( lyr.shadowUnder );
Expand All @@ -340,77 +420,19 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM

updatePlacementWidgets();

// post updatePlacementWidgets() connections
connect( chkLineAbove, SIGNAL( toggled( bool ) ), this, SLOT( updatePlacementWidgets() ) );
connect( chkLineBelow, SIGNAL( toggled( bool ) ), this, SLOT( updatePlacementWidgets() ) );

// setup connection to changes in the placement
QRadioButton* placementRadios[] =
{
radAroundPoint, radOverPoint, // point
radLineParallel, radLineCurved, radLineHorizontal, // line
radAroundCentroid, radPolygonHorizontal, radPolygonFree, radPolygonPerimeter // polygon
};
for ( unsigned int i = 0; i < sizeof( placementRadios ) / sizeof( QRadioButton* ); i++ )
{
connect( placementRadios[i], SIGNAL( toggled( bool ) ), this, SLOT( updatePlacementWidgets() ) );
}

// TODO: is this necessary? maybe just use the data defined-only rotation?
mPointAngleDDBtn->setVisible( false );
// needs to come before data defined setup, so connections work
blockInitSignals( false );

// set up data defined toolbuttons
// disable H,V data defined alignment until X,Y are active
disableDataDefinedAlignment();
// do this after other widgets are configured, so they can be enabled/disabled
populateDataDefinedButtons( lyr );

if ( mCoordXDDBtn->isActive() && mCoordYDDBtn->isActive() )
{
enableDataDefinedAlignment();
}
enableDataDefinedAlignment( mCoordXDDBtn->isActive() && mCoordYDDBtn->isActive() );

updateUi(); // should come after data defined button setup

// Global settings group for groupboxes' saved/retored collapsed state
// maintains state across different dialogs
foreach ( QgsCollapsibleGroupBox *grpbox, findChildren<QgsCollapsibleGroupBox*>() )
{
grpbox->setSettingGroup( QString( "mAdvLabelingDlg" ) );
}

connect( groupBox_mPreview,
SIGNAL( collapsedStateChanged( bool ) ),
this,
SLOT( collapseSample( bool ) ) );

// get rid of annoying outer focus rect on Mac
mLabelingOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect, false );

QSettings settings;

// reset horiz strech of left side of options splitter (set to 1 for previewing in Qt Designer)
QSizePolicy policy( mLabelingOptionsListFrame->sizePolicy() );
policy.setHorizontalStretch( 0 );
mLabelingOptionsListFrame->setSizePolicy( policy );
if ( !settings.contains( QString( "/Windows/Labeling/OptionsSplitState" ) ) )
{
// set left list widget width on intial showing
QList<int> splitsizes;
splitsizes << 115;
mLabelingOptionsSplitter->setSizes( splitsizes );
}

// set up reverse connection from stack to list
connect( mLabelStackedWidget, SIGNAL( currentChanged( int ) ), this, SLOT( optionsStackedWidget_CurrentChanged( int ) ) );

// restore dialog, splitters and current tab
mFontPreviewSplitter->restoreState( settings.value( QString( "/Windows/Labeling/FontPreviewSplitState" ) ).toByteArray() );
mLabelingOptionsSplitter->restoreState( settings.value( QString( "/Windows/Labeling/OptionsSplitState" ) ).toByteArray() );

mLabelingOptionsListWidget->setCurrentRow( settings.value( QString( "/Windows/Labeling/Tab" ), 0 ).toInt() );
}


QgsLabelingGui::~QgsLabelingGui()
{
QSettings settings;
Expand All @@ -419,6 +441,15 @@ QgsLabelingGui::~QgsLabelingGui()
settings.setValue( QString( "/Windows/Labeling/Tab" ), mLabelingOptionsListWidget->currentRow() );
}

void QgsLabelingGui::blockInitSignals( bool block )
{
chkLineAbove->blockSignals( block );
chkLineBelow->blockSignals( block );
mPlacePointBtnGrp->blockSignals( block );
mPlaceLineBtnGrp->blockSignals( block );
mPlacePolygonBtnGrp->blockSignals( block );
}

void QgsLabelingGui::optionsStackedWidget_CurrentChanged( int indx )
{
mLabelingOptionsListWidget->blockSignals( true );
Expand Down Expand Up @@ -1441,23 +1472,23 @@ void QgsLabelingGui::on_mCoordXDDBtn_dataDefinedActivated( bool active )
{
if ( !active ) //no data defined alignment without data defined position
{
disableDataDefinedAlignment();
enableDataDefinedAlignment( false );
}
else if ( mCoordYDDBtn->isActive() )
{
enableDataDefinedAlignment();
enableDataDefinedAlignment( true );
}
}

void QgsLabelingGui::on_mCoordYDDBtn_dataDefinedActivated( bool active )
{
if ( !active ) //no data defined alignment without data defined position
{
disableDataDefinedAlignment();
enableDataDefinedAlignment( false );
}
else if ( mCoordXDDBtn->isActive() )
{
enableDataDefinedAlignment();
enableDataDefinedAlignment( true );
}
}

Expand Down Expand Up @@ -1658,12 +1689,7 @@ void QgsLabelingGui::showBackgroundPenStyle( bool show )
mShapePenStyleDDBtn->setVisible( show );
}

void QgsLabelingGui::disableDataDefinedAlignment()
{
mCoordAlignmentFrame->setEnabled( false );
}

void QgsLabelingGui::enableDataDefinedAlignment()
void QgsLabelingGui::enableDataDefinedAlignment( bool enable )
{
mCoordAlignmentFrame->setEnabled( true );
mCoordAlignmentFrame->setEnabled( enable );
}
9 changes: 7 additions & 2 deletions src/app/qgslabelinggui.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void writeSettingsToLayer();

public slots:
void init();
void collapseSample( bool collapse );
void apply();
void changeTextColor( const QColor &color );
Expand Down Expand Up @@ -81,6 +82,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void on_mDirectSymbRightToolBtn_clicked();

protected:
void blockInitSignals( bool block );
void blockFontChangeSignals( bool blk );
void setPreviewBackground( QColor color );
void updateFontViaStyle( const QString & fontstyle );
Expand All @@ -105,6 +107,10 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
QButtonGroup* mDirectSymbBtnGrp;
QButtonGroup* mUpsidedownBtnGrp;

QButtonGroup* mPlacePointBtnGrp;
QButtonGroup* mPlaceLineBtnGrp;
QButtonGroup* mPlacePolygonBtnGrp;

// background reference font
QFont mRefFont;
int mPreviewSize;
Expand All @@ -113,8 +119,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase

bool mLoadSvgParams;

void disableDataDefinedAlignment();
void enableDataDefinedAlignment();
void enableDataDefinedAlignment( bool enable );

private slots:
void optionsStackedWidget_CurrentChanged( int indx );
Expand Down
Loading