From 3b3d1a75daf652da282b7c024e31058938f88b16 Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Fri, 14 Dec 2012 19:39:00 -0700 Subject: [PATCH] Update labeling tools and make more undo/redo friendly - Change QgsVectorLayer::redoEditCommand to only strip invalid QVariants, not null ones - Update undo/redo command text to start with action and end with sample of label text - Update pin/unpin labels tool to be fully undo/redo-able - Store generated label text in QgsLabelPosition (sans direction symbols) - Update change label properties dialog to show whether label text is expression --- python/core/qgsmaprenderer.sip | 3 +- src/app/qgslabelpropertydialog.cpp | 50 +++++++++------- src/app/qgslabelpropertydialog.h | 4 +- src/app/qgsmaptoolchangelabelproperties.cpp | 14 ++++- src/app/qgsmaptoollabel.cpp | 45 +++++++++++--- src/app/qgsmaptoollabel.h | 4 +- src/app/qgsmaptoolmovelabel.cpp | 8 +-- src/app/qgsmaptoolpinlabels.cpp | 66 ++++++++++----------- src/app/qgsmaptoolrotatelabel.cpp | 4 +- src/app/qgsmaptoolshowhidelabels.cpp | 27 +++++++-- src/core/qgslabelsearchtree.cpp | 4 +- src/core/qgslabelsearchtree.h | 2 +- src/core/qgsmaprenderer.h | 7 ++- src/core/qgspallabeling.cpp | 5 +- src/core/qgsvectorlayer.cpp | 2 +- 15 files changed, 154 insertions(+), 91 deletions(-) diff --git a/python/core/qgsmaprenderer.sip b/python/core/qgsmaprenderer.sip index 2cd7e31c470..e7c75fdee8c 100644 --- a/python/core/qgsmaprenderer.sip +++ b/python/core/qgsmaprenderer.sip @@ -6,7 +6,7 @@ class QgsLabelPosition #include %End public: - QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, bool upside_down, bool diagram = false, bool pinned = false ); + QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, const QString& labeltext, bool upside_down, bool diagram = false, bool pinned = false ); QgsLabelPosition(); int featureId; double rotation; @@ -15,6 +15,7 @@ class QgsLabelPosition double width; double height; QString layerID; + QString labelText; bool upsideDown; bool isDiagram; bool isPinned; diff --git a/src/app/qgslabelpropertydialog.cpp b/src/app/qgslabelpropertydialog.cpp index e19c6e08be7..649e9e0875d 100644 --- a/src/app/qgslabelpropertydialog.cpp +++ b/src/app/qgslabelpropertydialog.cpp @@ -22,20 +22,20 @@ #include #include -QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString& layerId, int featureId, QgsMapRenderer* renderer, QWidget * parent, Qt::WindowFlags f ): +QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString& layerId, int featureId, const QString& labelText, QgsMapRenderer* renderer, QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mMapRenderer( renderer ), mCurrentLabelField( -1 ) { setupUi( this ); fillHaliComboBox(); fillValiComboBox(); - init( layerId, featureId ); + init( layerId, featureId, labelText ); } QgsLabelPropertyDialog::~QgsLabelPropertyDialog() { } -void QgsLabelPropertyDialog::init( const QString& layerId, int featureId ) +void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const QString& labelText ) { if ( !mMapRenderer ) { @@ -65,30 +65,40 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId ) blockElementSignals( true ); + QgsPalLayerSettings& layerSettings = lbl->layer( layerId ); + //get label field and fill line edit - QString labelFieldName = vlayer->customProperty( "labeling/fieldName" ).toString(); - if ( !labelFieldName.isEmpty() ) + if ( layerSettings.isExpression && !labelText.isNull() ) { - mCurrentLabelField = vlayer->fieldNameIndex( labelFieldName ); - mLabelTextLineEdit->setText( attributeValues[mCurrentLabelField].toString() ); - const QgsFieldMap& layerFields = vlayer->pendingFields(); - switch ( layerFields[mCurrentLabelField].type() ) + mLabelTextLineEdit->setText( labelText ); + mLabelTextLineEdit->setEnabled( false ); + mLabelTextLabel->setText( tr( "Expression result" ) ); + } + else + { + QString labelFieldName = vlayer->customProperty( "labeling/fieldName" ).toString(); + if ( !labelFieldName.isEmpty() ) { - case QVariant::Double: - mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) ); - break; - case QVariant::Int: - case QVariant::UInt: - case QVariant::LongLong: - mLabelTextLineEdit->setValidator( new QIntValidator( this ) ); - break; - default: - break; + mCurrentLabelField = vlayer->fieldNameIndex( labelFieldName ); + mLabelTextLineEdit->setText( attributeValues[mCurrentLabelField].toString() ); + const QgsFieldMap& layerFields = vlayer->pendingFields(); + switch ( layerFields[mCurrentLabelField].type() ) + { + case QVariant::Double: + mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) ); + break; + case QVariant::Int: + case QVariant::UInt: + case QVariant::LongLong: + mLabelTextLineEdit->setValidator( new QIntValidator( this ) ); + break; + default: + break; + } } } //get attributes of the feature and fill data defined values - QgsPalLayerSettings& layerSettings = lbl->layer( layerId ); mLabelFont = layerSettings.textFont; //set all the gui elements to the default values diff --git a/src/app/qgslabelpropertydialog.h b/src/app/qgslabelpropertydialog.h index 47d2fbed748..30e1837f6b7 100644 --- a/src/app/qgslabelpropertydialog.h +++ b/src/app/qgslabelpropertydialog.h @@ -30,7 +30,7 @@ class QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPropertyDialog { Q_OBJECT public: - QgsLabelPropertyDialog( const QString& layerId, int featureId, QgsMapRenderer* renderer, QWidget * parent = 0, Qt::WindowFlags f = 0 ); + QgsLabelPropertyDialog( const QString& layerId, int featureId, const QString& labelText, QgsMapRenderer* renderer, QWidget * parent = 0, Qt::WindowFlags f = 0 ); ~QgsLabelPropertyDialog(); /**Returns properties changed by the user*/ @@ -56,7 +56,7 @@ class QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPropertyDialog private: /**Sets activation / values to the gui elements depending on the label settings and feature values*/ - void init( const QString& layerId, int featureId ); + void init( const QString& layerId, int featureId, const QString& labelText ); void disableGuiElements(); /**Block / unblock all input element signals*/ void blockElementSignals( bool block ); diff --git a/src/app/qgsmaptoolchangelabelproperties.cpp b/src/app/qgsmaptoolchangelabelproperties.cpp index 2113d3ee508..f79cb26dd01 100644 --- a/src/app/qgsmaptoolchangelabelproperties.cpp +++ b/src/app/qgsmaptoolchangelabelproperties.cpp @@ -53,18 +53,26 @@ void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e ) QgsVectorLayer* vlayer = currentLayer(); if ( mLabelRubberBand && mCanvas && vlayer ) { - QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCanvas->mapRenderer() ); + QString labeltext = QString(); // NULL QString signifies no expression + bool settingsOk; + QgsPalLayerSettings& labelSettings = currentLabelSettings( &settingsOk ); + if ( settingsOk && labelSettings.isExpression ) + { + labeltext = mCurrentLabelPos.labelText; + } + + QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, labeltext, mCanvas->mapRenderer() ); if ( d.exec() == QDialog::Accepted ) { const QgsAttributeMap& changes = d.changedProperties(); if ( changes.size() > 0 ) { - vlayer->beginEditCommand( tr( "Label properties changed" ) ); + vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) ); QgsAttributeMap::const_iterator changeIt = changes.constBegin(); for ( ; changeIt != changes.constEnd(); ++changeIt ) { - vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), false ); + vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), true ); } vlayer->endEditCommand(); diff --git a/src/app/qgsmaptoollabel.cpp b/src/app/qgsmaptoollabel.cpp index 9cca946acb7..7f26a574124 100644 --- a/src/app/qgsmaptoollabel.cpp +++ b/src/app/qgsmaptoollabel.cpp @@ -145,22 +145,49 @@ QgsPalLayerSettings& QgsMapToolLabel::currentLabelSettings( bool* ok ) return mInvalidLabelSettings; } -QString QgsMapToolLabel::currentLabelText() +QString QgsMapToolLabel::currentLabelText( int trunc ) { - QgsVectorLayer* vlayer = currentLayer(); - if ( !vlayer ) + bool settingsOk; + QgsPalLayerSettings& labelSettings = currentLabelSettings( &settingsOk ); + if ( !settingsOk ) { return ""; } - QString labelField = vlayer->customProperty( "labeling/fieldName" ).toString(); - if ( !labelField.isEmpty() ) + if ( labelSettings.isExpression ) { - int labelFieldId = vlayer->fieldNameIndex( labelField ); - QgsFeature f; - if ( vlayer->featureAtId( mCurrentLabelPos.featureId, f, false, true ) ) + QString labelText = mCurrentLabelPos.labelText; + + if ( trunc > 0 && labelText.length() > trunc ) { - return f.attributeMap()[labelFieldId].toString(); + labelText.truncate( trunc ); + labelText += "..."; + } + return labelText; + } + else + { + QgsVectorLayer* vlayer = currentLayer(); + if ( !vlayer ) + { + return ""; + } + + QString labelField = vlayer->customProperty( "labeling/fieldName" ).toString(); + if ( !labelField.isEmpty() ) + { + int labelFieldId = vlayer->fieldNameIndex( labelField ); + QgsFeature f; + if ( vlayer->featureAtId( mCurrentLabelPos.featureId, f, false, true ) ) + { + QString labelText = f.attributeMap()[labelFieldId].toString(); + if ( trunc > 0 && labelText.length() > trunc ) + { + labelText.truncate( trunc ); + labelText += "..."; + } + return labelText; + } } } return ""; diff --git a/src/app/qgsmaptoollabel.h b/src/app/qgsmaptoollabel.h index ca48b566fdd..9bd320732d5 100644 --- a/src/app/qgsmaptoollabel.h +++ b/src/app/qgsmaptoollabel.h @@ -85,7 +85,9 @@ class QgsMapToolLabel: public QgsMapTool /**Returns layer settings of current label position*/ QgsPalLayerSettings& currentLabelSettings( bool* ok ); - QString currentLabelText(); + /**Returns current label's text + @param trunc number of chars to truncate to, with ... added (added in 1.9)*/ + QString currentLabelText( int trunc = 0 ); void currentAlignment( QString& hali, QString& vali ); diff --git a/src/app/qgsmaptoolmovelabel.cpp b/src/app/qgsmaptoolmovelabel.cpp index b1f580ea83f..8d0b3d0ed75 100644 --- a/src/app/qgsmaptoolmovelabel.cpp +++ b/src/app/qgsmaptoolmovelabel.cpp @@ -149,9 +149,9 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e ) } } - vlayer->beginEditCommand( tr( "Label moved" ) ); - vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew, false ); - vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew, false ); + vlayer->beginEditCommand( tr( "Moved label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) ); + vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew, true ); + vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew, true ); // set rotation to that of label, if data-defined and no rotation set yet // honor whether to preserve preexisting data on pin @@ -167,7 +167,7 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e ) if ( dataDefinedRotation( vlayer, mCurrentLabelPos.featureId, defRot, rSuccess ) ) { double labelRot = mCurrentLabelPos.rotation * 180 / M_PI; - vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot, false ); + vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rCol, labelRot, true ); } } vlayer->endEditCommand(); diff --git a/src/app/qgsmaptoolpinlabels.cpp b/src/app/qgsmaptoolpinlabels.cpp index 0e048184dad..d0c99ac6021 100644 --- a/src/app/qgsmaptoolpinlabels.cpp +++ b/src/app/qgsmaptoolpinlabels.cpp @@ -134,7 +134,7 @@ void QgsMapToolPinLabels::updatePinnedLabels() if ( mShowPinned ) { QgsDebugMsg( QString( "Updating highlighting due to layer editing mode change" ) ); - mCanvas->refresh(); + highlightPinnedLabels(); } } @@ -287,11 +287,11 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent * mCurrentLabelPos = *it; #ifdef QGISDEBUG - QString labeltxt = currentLabelText(); QString labellyr = currentLayer()->name(); + QString labeltxt = currentLabelText(); #endif - QgsDebugMsg( QString( "Label: %0" ).arg( labeltxt ) ); QgsDebugMsg( QString( "Layer: %0" ).arg( labellyr ) ); + QgsDebugMsg( QString( "Label: %0" ).arg( labeltxt ) ); QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( mCurrentLabelPos.layerID ); if ( !layer ) @@ -390,7 +390,8 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer, // edit attribute table int fid = labelpos.featureId; - QString failedWrite = QString( "Failed write to attribute table" ); + bool writeFailed = false; + QString labelText = currentLabelText( 24 ); if ( pin ) { @@ -416,49 +417,42 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer, labelY = transformedPoint.y(); } - vlayer->beginEditCommand( tr( "Label pinned" ) ); - if ( !vlayer->changeAttributeValue( fid, xCol, labelX, false ) ) - { - QgsDebugMsg( failedWrite ); - return false; - } - if ( !vlayer->changeAttributeValue( fid, yCol, labelY, false ) ) - { - QgsDebugMsg( failedWrite ); - return false; - } + vlayer->beginEditCommand( tr( "Pinned label" ) + QString( " '%1'" ).arg( labelText ) ); + writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX, true ); + writeFailed = !vlayer->changeAttributeValue( fid, yCol, labelY, true ); if ( hasRCol && !preserveRot ) { - if ( !vlayer->changeAttributeValue( fid, rCol, labelR, false ) ) - { - QgsDebugMsg( failedWrite ); - return false; - } + writeFailed = !vlayer->changeAttributeValue( fid, rCol, labelR, true ); } vlayer->endEditCommand(); } else { - vlayer->beginEditCommand( tr( "Label unpinned" ) ); - if ( !vlayer->changeAttributeValue( fid, xCol, QVariant(), false ) ) - { - QgsDebugMsg( failedWrite ); - return false; - } - if ( !vlayer->changeAttributeValue( fid, yCol, QVariant(), false ) ) - { - QgsDebugMsg( failedWrite ); - return false; - } + vlayer->beginEditCommand( tr( "Unpinned label" ) + QString( " '%1'" ).arg( labelText ) ); + writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString::null ), true ); + writeFailed = !vlayer->changeAttributeValue( fid, yCol, QVariant( QString::null ), true ); if ( hasRCol && !preserveRot ) { - if ( !vlayer->changeAttributeValue( fid, rCol, QVariant(), false ) ) - { - QgsDebugMsg( failedWrite ); - return false; - } + writeFailed = !vlayer->changeAttributeValue( fid, rCol, QVariant( QString::null ), true ); } vlayer->endEditCommand(); } + + if ( writeFailed ) + { + QgsDebugMsg( QString( "Write to attribute table failed" ) ); + +// QgsDebugMsg( QString( "Undoing and removing failed command from layer's undo stack" ) ); +// int lastCmdIndx = vlayer->undoStack()->count(); +// const QgsUndoCommand* lastCmd = qobject_cast( vlayer->undoStack()->command( lastCmdIndx ) ); +// if ( lastCmd ) +// { +// vlayer->undoEditCommand( lastCmd ); +// delete vlayer->undoStack()->command( lastCmdIndx ); +// } + + return false; + } + return true; } diff --git a/src/app/qgsmaptoolrotatelabel.cpp b/src/app/qgsmaptoolrotatelabel.cpp index 95a096109c8..a64227909ac 100644 --- a/src/app/qgsmaptoolrotatelabel.cpp +++ b/src/app/qgsmaptoolrotatelabel.cpp @@ -171,8 +171,8 @@ void QgsMapToolRotateLabel::canvasReleaseEvent( QMouseEvent *e ) return; } - vlayer->beginEditCommand( tr( "Label rotated" ) ); - vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rotationCol, rotation, false ); + vlayer->beginEditCommand( tr( "Rotated label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) ); + vlayer->changeAttributeValue( mCurrentLabelPos.featureId, rotationCol, rotation, true ); vlayer->endEditCommand(); mCanvas->refresh(); } diff --git a/src/app/qgsmaptoolshowhidelabels.cpp b/src/app/qgsmaptoolshowhidelabels.cpp index 592b31a427c..a674eab398c 100644 --- a/src/app/qgsmaptoolshowhidelabels.cpp +++ b/src/app/qgsmaptoolshowhidelabels.cpp @@ -280,12 +280,31 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer, return false; } - // edit attribute table - QString editTxt = hide ? tr( "Label hidden" ) : tr( "Label shown" ); - vlayer->beginEditCommand( editTxt ); - if ( !vlayer->changeAttributeValue( fid, showCol, ( hide ? 0 : 1 ), false ) ) + // check if attribute value is already the same + QgsFeature f; + if ( !vlayer->featureAtId( fid, f, false, true ) ) + { + return false; + } + + int colVal = hide ? 0 : 1; + QVariant fQVal = f.attributeMap()[showCol]; + bool convToInt; + int fVal = fQVal.toInt( &convToInt ); + + if ( !convToInt || fVal == colVal ) + { + return false; + } + + // different attribute value, edit table + QString labelText = currentLabelText( 24 ); + QString editTxt = hide ? tr( "Hid label" ) : tr( "Showed label" ); + vlayer->beginEditCommand( editTxt + QString( " '%1'" ).arg( labelText ) ); + if ( !vlayer->changeAttributeValue( fid, showCol, colVal, true ) ) { QgsDebugMsg( "Failed write to attribute table" ); + vlayer->endEditCommand(); return false; } vlayer->endEditCommand(); diff --git a/src/core/qgslabelsearchtree.cpp b/src/core/qgslabelsearchtree.cpp index 2eea4da662e..79c1fd8c773 100644 --- a/src/core/qgslabelsearchtree.cpp +++ b/src/core/qgslabelsearchtree.cpp @@ -67,7 +67,7 @@ void QgsLabelSearchTree::labelsInRect( const QgsRectangle& r, QListgetX( i ), labelPos->getY( i ) ) ); } QgsLabelPosition* newEntry = new QgsLabelPosition( featureId, labelPos->getAlpha(), cornerPoints, QgsRectangle( c_min[0], c_min[1], c_max[0], c_max[1] ), - labelPos->getWidth(), labelPos->getHeight(), layerName, labelPos->getUpsideDown(), diagram, pinned ); + labelPos->getWidth(), labelPos->getHeight(), layerName, labeltext, labelPos->getUpsideDown(), diagram, pinned ); mSpatialIndex.Insert( c_min, c_max, newEntry ); return true; } diff --git a/src/core/qgslabelsearchtree.h b/src/core/qgslabelsearchtree.h index 45d531b4735..e9371aa3e12 100644 --- a/src/core/qgslabelsearchtree.h +++ b/src/core/qgslabelsearchtree.h @@ -55,7 +55,7 @@ class CORE_EXPORT QgsLabelSearchTree * @return true in case of success * @note not available in python bindings */ - bool insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram = false, bool pinned = false ); + bool insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, const QString& labeltext, bool diagram = false, bool pinned = false ); private: RTree mSpatialIndex; diff --git a/src/core/qgsmaprenderer.h b/src/core/qgsmaprenderer.h index 792b0c2b7fd..345bf4f33f5 100644 --- a/src/core/qgsmaprenderer.h +++ b/src/core/qgsmaprenderer.h @@ -45,9 +45,9 @@ class QgsDiagramLayerSettings; class CORE_EXPORT QgsLabelPosition { public: - QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, bool upside_down, bool diagram = false, bool pinned = false ): - featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), upsideDown( upside_down ), isDiagram( diagram ), isPinned( pinned ) {} - QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), upsideDown( false ), isDiagram( false ), isPinned( false ) {} + QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, const QString& labeltext, bool upside_down, bool diagram = false, bool pinned = false ): + featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), labelText( labeltext ), upsideDown( upside_down ), isDiagram( diagram ), isPinned( pinned ) {} + QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), labelText( "" ), upsideDown( false ), isDiagram( false ), isPinned( false ) {} int featureId; double rotation; QVector< QgsPoint > cornerPoints; @@ -55,6 +55,7 @@ class CORE_EXPORT QgsLabelPosition double width; double height; QString layerID; + QString labelText; bool upsideDown; bool isDiagram; bool isPinned; diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index bd90718be7b..3a8a21926fd 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -1577,7 +1577,7 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context ) //for diagrams, remove the additional 'd' at the end of the layer id QString layerId = layerNameUtf8; layerId.chop( 1 ); - mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), layerId, true, false ); + mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), QString( "" ) , layerId, true, false ); } continue; } @@ -1690,7 +1690,8 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context ) if ( mLabelSearchTree ) { - mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), ( *it )->getLayerName(), false, palGeometry->isPinned() ); + QString labeltext = (( QgsPalGeometry* )( *it )->getFeaturePart()->getUserGeometry() )->text(); + mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), ( *it )->getLayerName(), labeltext, false, palGeometry->isPinned() ); } } diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 61248baec11..13b20808055 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -5190,7 +5190,7 @@ void QgsVectorLayer::redoEditCommand( QgsUndoCommand* cmd ) if ( !FID_IS_NEW( fid ) ) { // existing feature - if ( attrChIt.value().target.isNull() ) + if ( !attrChIt.value().target.isValid() ) { mChangedAttributeValues[fid].remove( attrChIt.key() ); if ( mChangedAttributeValues[fid].isEmpty() )