@@ -1058,6 +1058,106 @@ void QgsMapCanvas::panToSelected( QgsVectorLayer *layer )
1058
1058
refresh ();
1059
1059
}
1060
1060
1061
+ void QgsMapCanvas::flashFeatureIds ( QgsVectorLayer *layer, const QgsFeatureIds &ids,
1062
+ const QColor &color1, const QColor &color2,
1063
+ int flashes, int duration )
1064
+ {
1065
+ if ( !layer )
1066
+ {
1067
+ return ;
1068
+ }
1069
+
1070
+ QList< QgsGeometry > geoms;
1071
+
1072
+ QgsFeatureIterator it = layer->getFeatures ( QgsFeatureRequest ().setFilterFids ( ids ).setSubsetOfAttributes ( QgsAttributeList () ) );
1073
+ QgsFeature fet;
1074
+ while ( it.nextFeature ( fet ) )
1075
+ {
1076
+ if ( !fet.hasGeometry () )
1077
+ continue ;
1078
+ geoms << fet.geometry ();
1079
+ }
1080
+
1081
+ flashGeometries ( geoms, layer->crs (), color1, color2, flashes, duration );
1082
+ }
1083
+
1084
+ void QgsMapCanvas::flashGeometries ( const QList<QgsGeometry> &geometries, const QgsCoordinateReferenceSystem &crs, const QColor &color1, const QColor &color2, int flashes, int duration )
1085
+ {
1086
+ if ( geometries.isEmpty () )
1087
+ return ;
1088
+
1089
+ QgsWkbTypes::GeometryType geomType = QgsWkbTypes::geometryType ( geometries.at ( 0 ).wkbType () );
1090
+ QgsRubberBand *rb = new QgsRubberBand ( this , geomType );
1091
+ for ( const QgsGeometry &geom : geometries )
1092
+ rb->addGeometry ( geom, crs );
1093
+
1094
+ if ( geomType == QgsWkbTypes::LineGeometry || geomType == QgsWkbTypes::PointGeometry )
1095
+ {
1096
+ rb->setWidth ( 2 );
1097
+ rb->setSecondaryStrokeColor ( QColor ( 255 , 255 , 255 ) );
1098
+ }
1099
+ if ( geomType == QgsWkbTypes::PointGeometry )
1100
+ rb->setIcon ( QgsRubberBand::ICON_CIRCLE );
1101
+
1102
+ QColor startColor = color1;
1103
+ if ( !startColor.isValid () )
1104
+ {
1105
+ if ( geomType == QgsWkbTypes::PolygonGeometry )
1106
+ {
1107
+ startColor = rb->fillColor ();
1108
+ }
1109
+ else
1110
+ {
1111
+ startColor = rb->strokeColor ();
1112
+ }
1113
+ startColor.setAlpha ( 255 );
1114
+ }
1115
+ QColor endColor = color2;
1116
+ if ( !endColor.isValid () )
1117
+ {
1118
+ endColor = startColor;
1119
+ endColor.setAlpha ( 0 );
1120
+ }
1121
+
1122
+
1123
+ QVariantAnimation *animation = new QVariantAnimation ( this );
1124
+ connect ( animation, &QVariantAnimation::finished, this , [animation, rb]
1125
+ {
1126
+ animation->deleteLater ();
1127
+ delete rb;
1128
+ } );
1129
+ connect ( animation, &QPropertyAnimation::valueChanged, this , [rb, geomType]( const QVariant & value )
1130
+ {
1131
+ QColor c = value.value <QColor>();
1132
+ if ( geomType == QgsWkbTypes::PolygonGeometry )
1133
+ {
1134
+ rb->setFillColor ( c );
1135
+ }
1136
+ else
1137
+ {
1138
+ rb->setStrokeColor ( c );
1139
+ QColor c = rb->secondaryStrokeColor ();
1140
+ c.setAlpha ( c.alpha () );
1141
+ rb->setSecondaryStrokeColor ( c );
1142
+ }
1143
+ rb->update ();
1144
+ } );
1145
+
1146
+ animation->setDuration ( duration * flashes );
1147
+ animation->setStartValue ( endColor );
1148
+ double midStep = 0.2 / flashes;
1149
+ for ( int i = 0 ; i < flashes; ++i )
1150
+ {
1151
+ double start = static_cast < double >( i ) / flashes;
1152
+ animation->setKeyValueAt ( start + midStep, startColor );
1153
+ double end = static_cast < double >( i + 1 ) / flashes;
1154
+ if ( !qgsDoubleNear ( end, 1.0 ) )
1155
+ animation->setKeyValueAt ( end, endColor );
1156
+ }
1157
+ animation->setEndValue ( endColor );
1158
+ animation->start ();
1159
+ }
1160
+
1061
1161
void QgsMapCanvas::keyPressEvent ( QKeyEvent *e )
1062
1162
{
1063
1163
if ( mCanvasProperties ->mouseButtonDown || mCanvasProperties ->panSelectorDown )
0 commit comments