mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-17 00:09:36 -04:00
typo, lambda and other minor fixes
This commit is contained in:
parent
c79123bcb8
commit
ac19bd3212
@ -223,7 +223,7 @@ Any new actions added to the menu should be correctly parented to ``menu``.
|
|||||||
|
|
||||||
A pointer to the map mouse ``event`` can be provided to allow particular behavior depending on the map tool.
|
A pointer to the map mouse ``event`` can be provided to allow particular behavior depending on the map tool.
|
||||||
|
|
||||||
This method can return true to inform the caller that the menu was effectivly populated.
|
This method can return true to inform the caller that the menu was effectively populated.
|
||||||
|
|
||||||
The default implementation does nothing and returns false.
|
The default implementation does nothing and returns false.
|
||||||
|
|
||||||
|
@ -144,9 +144,13 @@ QgsMapTool::Flags QgsMapToolSelect::flags() const
|
|||||||
bool QgsMapToolSelect::populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEvent *event )
|
bool QgsMapToolSelect::populateContextMenuWithEvent( QMenu *menu, QgsMapMouseEvent *event )
|
||||||
{
|
{
|
||||||
Q_ASSERT( menu );
|
Q_ASSERT( menu );
|
||||||
menu->addSeparator();
|
|
||||||
QgsVectorLayer *vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas );
|
QgsVectorLayer *vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas );
|
||||||
|
|
||||||
|
if ( !vlayer )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
Qt::KeyboardModifiers modifiers = Qt::NoModifier;
|
Qt::KeyboardModifiers modifiers = Qt::NoModifier;
|
||||||
QgsPointXY mapPoint;
|
QgsPointXY mapPoint;
|
||||||
if ( event )
|
if ( event )
|
||||||
|
@ -483,7 +483,7 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::onSearchFinished()
|
|||||||
mAllFeatureIds = mFutureWatcher->result();
|
mAllFeatureIds = mFutureWatcher->result();
|
||||||
mActionChooseAll->setText( textForChooseAll( mAllFeatureIds.size() ) );
|
mActionChooseAll->setText( textForChooseAll( mAllFeatureIds.size() ) );
|
||||||
if ( !mAllFeatureIds.isEmpty() )
|
if ( !mAllFeatureIds.isEmpty() )
|
||||||
connect( mActionChooseAll, &QAction::hovered, this, &QgsMapToolSelectMenuActions::highlightFeatures );
|
connect( mActionChooseAll, &QAction::hovered, this, &QgsMapToolSelectMenuActions::highlightAllFeatures );
|
||||||
else
|
else
|
||||||
mActionChooseAll->setEnabled( false );
|
mActionChooseAll->setEnabled( false );
|
||||||
if ( mAllFeatureIds.count() > 1 )
|
if ( mAllFeatureIds.count() > 1 )
|
||||||
@ -514,7 +514,7 @@ QString QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::textForChooseAll( qi
|
|||||||
|
|
||||||
QString featureCountText;
|
QString featureCountText;
|
||||||
if ( featureCount < 0 )
|
if ( featureCount < 0 )
|
||||||
featureCountText = QStringLiteral( "Searching..." );
|
featureCountText = tr( "Searching…" );
|
||||||
else
|
else
|
||||||
featureCountText = QString::number( featureCount );
|
featureCountText = QString::number( featureCount );
|
||||||
|
|
||||||
@ -561,41 +561,45 @@ QString QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::textForChooseOneMenu
|
|||||||
|
|
||||||
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::populateChooseOneMenu( const QgsFeatureIds &ids )
|
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::populateChooseOneMenu( const QgsFeatureIds &ids )
|
||||||
{
|
{
|
||||||
|
if ( !mVectorLayer )
|
||||||
|
return;
|
||||||
|
|
||||||
QgsFeatureIds displayedFeatureIds;
|
QgsFeatureIds displayedFeatureIds;
|
||||||
|
|
||||||
QgsFeatureIds::ConstIterator it = ids.constBegin();
|
QgsFeatureIds::ConstIterator it = ids.constBegin();
|
||||||
while ( displayedFeatureIds.count() <= 20 && it != ids.constEnd() ) //for now hardcoded, but maybe define a settings for this
|
while ( displayedFeatureIds.count() <= 20 && it != ids.constEnd() ) //for now hardcoded, but maybe define a settings for this
|
||||||
displayedFeatureIds.insert( *( it++ ) );
|
displayedFeatureIds.insert( *( it++ ) );
|
||||||
|
|
||||||
|
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mVectorLayer ) );
|
||||||
|
QgsExpression exp = mVectorLayer->displayExpression();
|
||||||
|
exp.prepare( &context );
|
||||||
|
|
||||||
for ( QgsFeatureId id : qgis::as_const( displayedFeatureIds ) )
|
for ( QgsFeatureId id : qgis::as_const( displayedFeatureIds ) )
|
||||||
{
|
{
|
||||||
QAction *featureAction = new QAction( tr( "Feature %1" ).arg( id ), this ) ;
|
QgsFeature feat = mVectorLayer->getFeature( id );
|
||||||
featureAction->setData( id );
|
context.setFeature( feat );
|
||||||
connect( featureAction, &QAction::triggered, this, &QgsMapToolSelectMenuActions::chooseOneCandidateFeature );
|
|
||||||
connect( featureAction, &QAction::hovered, this, &QgsMapToolSelectMenuActions::highlightFeatures );
|
QString featureTitle = exp.evaluate( &context ).toString();
|
||||||
|
if ( featureTitle.isEmpty() )
|
||||||
|
featureTitle = FID_TO_STRING( feat.id() );
|
||||||
|
|
||||||
|
QAction *featureAction = new QAction( tr( "Feature %1" ).arg( featureTitle ), this ) ;
|
||||||
|
connect( featureAction, &QAction::triggered, this, [this, id]() {chooseOneCandidateFeature( id );} );
|
||||||
|
connect( featureAction, &QAction::hovered, this, [this, id]() {this->highlightOneFeature( id );} );
|
||||||
mMenuChooseOne->addAction( featureAction );
|
mMenuChooseOne->addAction( featureAction );
|
||||||
}
|
}
|
||||||
|
|
||||||
mMenuChooseOne->setEnabled( ids.count() != 0 );
|
mMenuChooseOne->setEnabled( ids.count() != 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::chooseOneCandidateFeature()
|
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::chooseOneCandidateFeature( QgsFeatureId id )
|
||||||
{
|
{
|
||||||
if ( !mVectorLayer )
|
if ( !mVectorLayer )
|
||||||
return;
|
return;
|
||||||
QAction *senderAction = qobject_cast<QAction *>( sender() );
|
|
||||||
|
|
||||||
if ( !senderAction )
|
|
||||||
return;
|
|
||||||
|
|
||||||
QVariant featureVariant = senderAction->data();
|
|
||||||
|
|
||||||
QgsFeatureIds ids;
|
QgsFeatureIds ids;
|
||||||
if ( featureVariant.type() == QVariant::LongLong )
|
ids << id;
|
||||||
ids.insert( featureVariant.toLongLong() );
|
mVectorLayer->selectByIds( ids, mBehavior );
|
||||||
|
|
||||||
if ( !ids.empty() )
|
|
||||||
mVectorLayer->selectByIds( ids, mBehavior );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::chooseAllCandidateFeature()
|
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::chooseAllCandidateFeature()
|
||||||
@ -615,38 +619,17 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::chooseAllCandidateFeatu
|
|||||||
mVectorLayer->selectByIds( mAllFeatureIds, mBehavior );
|
mVectorLayer->selectByIds( mAllFeatureIds, mBehavior );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::highlightFeatures()
|
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::highlightAllFeatures()
|
||||||
{
|
{
|
||||||
removeHighlight();
|
removeHighlight();
|
||||||
|
|
||||||
if ( !mVectorLayer )
|
if ( !mVectorLayer )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QAction *senderAction = qobject_cast<QAction *>( sender() );
|
if ( !mAllFeatureIds.empty() )
|
||||||
if ( !senderAction )
|
|
||||||
return;
|
|
||||||
|
|
||||||
QgsFeatureIds ids;
|
|
||||||
if ( senderAction == mActionChooseAll )
|
|
||||||
ids = mAllFeatureIds;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QVariant featureVariant = senderAction->data();
|
|
||||||
if ( featureVariant.type() == QVariant::List )
|
|
||||||
{
|
|
||||||
QVariantList list = featureVariant.toList();
|
|
||||||
for ( const QVariant &var : list )
|
|
||||||
ids.insert( var.toLongLong() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( featureVariant.type() == QVariant::LongLong )
|
|
||||||
ids.insert( featureVariant.toLongLong() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !ids.empty() )
|
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for ( const QgsFeatureId &id : ids )
|
for ( const QgsFeatureId &id : mAllFeatureIds )
|
||||||
{
|
{
|
||||||
QgsFeature feat = mVectorLayer->getFeature( id );
|
QgsFeature feat = mVectorLayer->getFeature( id );
|
||||||
QgsGeometry geom = feat.geometry();
|
QgsGeometry geom = feat.geometry();
|
||||||
@ -663,6 +646,23 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::highlightFeatures()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::highlightOneFeature( QgsFeatureId id )
|
||||||
|
{
|
||||||
|
removeHighlight();
|
||||||
|
|
||||||
|
if ( !mVectorLayer )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QgsFeature feat = mVectorLayer->getFeature( id );
|
||||||
|
QgsGeometry geom = feat.geometry();
|
||||||
|
if ( !geom.isEmpty() )
|
||||||
|
{
|
||||||
|
QgsHighlight *hl = new QgsHighlight( mCanvas, geom, mVectorLayer );
|
||||||
|
styleHighlight( hl );
|
||||||
|
mHighlight.append( hl );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::styleHighlight( QgsHighlight *highlight )
|
void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::styleHighlight( QgsHighlight *highlight )
|
||||||
{
|
{
|
||||||
QgsSettings settings;
|
QgsSettings settings;
|
||||||
|
@ -152,9 +152,8 @@ namespace QgsMapToolSelectUtils
|
|||||||
void populateMenu( QMenu *menu );
|
void populateMenu( QMenu *menu );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void chooseOneCandidateFeature();
|
|
||||||
void chooseAllCandidateFeature();
|
void chooseAllCandidateFeature();
|
||||||
void highlightFeatures();
|
void highlightAllFeatures();
|
||||||
void onLayerDestroyed();
|
void onLayerDestroyed();
|
||||||
void removeHighlight();
|
void removeHighlight();
|
||||||
void onSearchFinished();
|
void onSearchFinished();
|
||||||
@ -197,6 +196,9 @@ namespace QgsMapToolSelectUtils
|
|||||||
std::shared_ptr<DataForSearchingJob> mJobData;
|
std::shared_ptr<DataForSearchingJob> mJobData;
|
||||||
|
|
||||||
static QgsFeatureIds search( std::shared_ptr<DataForSearchingJob> data );
|
static QgsFeatureIds search( std::shared_ptr<DataForSearchingJob> data );
|
||||||
|
|
||||||
|
void chooseOneCandidateFeature( QgsFeatureId id );
|
||||||
|
void highlightOneFeature( QgsFeatureId id );
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ class GUI_EXPORT QgsMapTool : public QObject
|
|||||||
*
|
*
|
||||||
* A pointer to the map mouse \a event can be provided to allow particular behavior depending on the map tool.
|
* A pointer to the map mouse \a event can be provided to allow particular behavior depending on the map tool.
|
||||||
*
|
*
|
||||||
* This method can return true to inform the caller that the menu was effectivly populated.
|
* This method can return true to inform the caller that the menu was effectively populated.
|
||||||
*
|
*
|
||||||
* The default implementation does nothing and returns false.
|
* The default implementation does nothing and returns false.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user