@@ -134,7 +134,7 @@ void QgsMapToolPinLabels::updatePinnedLabels()
134
134
if ( mShowPinned )
135
135
{
136
136
QgsDebugMsg ( QString ( " Updating highlighting due to layer editing mode change" ) );
137
- mCanvas -> refresh ();
137
+ highlightPinnedLabels ();
138
138
}
139
139
}
140
140
@@ -287,11 +287,11 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent *
287
287
mCurrentLabelPos = *it;
288
288
289
289
#ifdef QGISDEBUG
290
- QString labeltxt = currentLabelText ();
291
290
QString labellyr = currentLayer ()->name ();
291
+ QString labeltxt = currentLabelText ();
292
292
#endif
293
- QgsDebugMsg ( QString ( " Label: %0" ).arg ( labeltxt ) );
294
293
QgsDebugMsg ( QString ( " Layer: %0" ).arg ( labellyr ) );
294
+ QgsDebugMsg ( QString ( " Label: %0" ).arg ( labeltxt ) );
295
295
296
296
QgsMapLayer* layer = QgsMapLayerRegistry::instance ()->mapLayer ( mCurrentLabelPos .layerID );
297
297
if ( !layer )
@@ -390,7 +390,8 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
390
390
// edit attribute table
391
391
int fid = labelpos.featureId ;
392
392
393
- QString failedWrite = QString ( " Failed write to attribute table" );
393
+ bool writeFailed = false ;
394
+ QString labelText = currentLabelText ( 24 );
394
395
395
396
if ( pin )
396
397
{
@@ -416,49 +417,42 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
416
417
labelY = transformedPoint.y ();
417
418
}
418
419
419
- vlayer->beginEditCommand ( tr ( " Label pinned" ) );
420
- if ( !vlayer->changeAttributeValue ( fid, xCol, labelX, false ) )
421
- {
422
- QgsDebugMsg ( failedWrite );
423
- return false ;
424
- }
425
- if ( !vlayer->changeAttributeValue ( fid, yCol, labelY, false ) )
426
- {
427
- QgsDebugMsg ( failedWrite );
428
- return false ;
429
- }
420
+ vlayer->beginEditCommand ( tr ( " Pinned label" ) + QString ( " '%1'" ).arg ( labelText ) );
421
+ writeFailed = !vlayer->changeAttributeValue ( fid, xCol, labelX, true );
422
+ writeFailed = !vlayer->changeAttributeValue ( fid, yCol, labelY, true );
430
423
if ( hasRCol && !preserveRot )
431
424
{
432
- if ( !vlayer->changeAttributeValue ( fid, rCol, labelR, false ) )
433
- {
434
- QgsDebugMsg ( failedWrite );
435
- return false ;
436
- }
425
+ writeFailed = !vlayer->changeAttributeValue ( fid, rCol, labelR, true );
437
426
}
438
427
vlayer->endEditCommand ();
439
428
}
440
429
else
441
430
{
442
- vlayer->beginEditCommand ( tr ( " Label unpinned" ) );
443
- if ( !vlayer->changeAttributeValue ( fid, xCol, QVariant (), false ) )
444
- {
445
- QgsDebugMsg ( failedWrite );
446
- return false ;
447
- }
448
- if ( !vlayer->changeAttributeValue ( fid, yCol, QVariant (), false ) )
449
- {
450
- QgsDebugMsg ( failedWrite );
451
- return false ;
452
- }
431
+ vlayer->beginEditCommand ( tr ( " Unpinned label" ) + QString ( " '%1'" ).arg ( labelText ) );
432
+ writeFailed = !vlayer->changeAttributeValue ( fid, xCol, QVariant ( QString::null ), true );
433
+ writeFailed = !vlayer->changeAttributeValue ( fid, yCol, QVariant ( QString::null ), true );
453
434
if ( hasRCol && !preserveRot )
454
435
{
455
- if ( !vlayer->changeAttributeValue ( fid, rCol, QVariant (), false ) )
456
- {
457
- QgsDebugMsg ( failedWrite );
458
- return false ;
459
- }
436
+ writeFailed = !vlayer->changeAttributeValue ( fid, rCol, QVariant ( QString::null ), true );
460
437
}
461
438
vlayer->endEditCommand ();
462
439
}
440
+
441
+ if ( writeFailed )
442
+ {
443
+ QgsDebugMsg ( QString ( " Write to attribute table failed" ) );
444
+
445
+ // QgsDebugMsg( QString( "Undoing and removing failed command from layer's undo stack" ) );
446
+ // int lastCmdIndx = vlayer->undoStack()->count();
447
+ // const QgsUndoCommand* lastCmd = qobject_cast<const QgsUndoCommand *>( vlayer->undoStack()->command( lastCmdIndx ) );
448
+ // if ( lastCmd )
449
+ // {
450
+ // vlayer->undoEditCommand( lastCmd );
451
+ // delete vlayer->undoStack()->command( lastCmdIndx );
452
+ // }
453
+
454
+ return false ;
455
+ }
456
+
463
457
return true ;
464
458
}
0 commit comments