Skip to content
Permalink
Browse files

hide instead of disable

and use mode for identify - not to show the actions with isEnabledOnlyWhenEditable is active
  • Loading branch information
signedav committed Feb 23, 2018
1 parent 7a3dc42 commit a11582f79c8f60fab6d35f589b249ddec0ce8dc7
@@ -6464,12 +6464,11 @@ void QgisApp::refreshFeatureActions()
QList<QgsAction> actions = vlayer->actions()->actions( QStringLiteral( "Canvas" ) );
Q_FOREACH ( const QgsAction &action, actions )
{
if( vlayer->readOnly() && action.isEnabledOnlyWhenEditable() )
if ( !vlayer->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

QString actionTitle = !action.shortTitle().isEmpty() ? action.shortTitle() : action.icon().isNull() ? action.name() : QStringLiteral( "" );
QAction *qAction = new QAction( action.icon(), actionTitle, mFeatureActionMenu );
qAction->setEnabled( !action.isEnabledOnlyWhenEditable() || vlayer->isEditable() );
qAction->setData( QVariant::fromValue<QgsAction>( action ) );
mFeatureActionMenu->addAction( qAction );

@@ -6489,10 +6488,9 @@ void QgisApp::refreshFeatureActions()

for ( int i = 0; i < registeredActions.size(); i++ )
{
if( vlayer->readOnly() && registeredActions.at( i )->isEnabledOnlyWhenEditable() )
if ( !vlayer->isEditable() && registeredActions.at( i )->isEnabledOnlyWhenEditable() )
continue;

registeredActions.at( i )->setEnabled( !registeredActions.at( i )->isEnabledOnlyWhenEditable() || vlayer->isEditable() );
mFeatureActionMenu->addAction( registeredActions.at( i ) );
if ( registeredActions.at( i ) == QgsGui::mapLayerActionRegistry()->defaultActionForLayer( vlayer ) )
{
@@ -71,7 +71,7 @@ class APP_EXPORT QgsAttributeActionDialog: public QWidget, private Ui::QgsAttrib

private:
void insertRow( int row, const QgsAction &action );
void insertRow( int row, QgsAction::ActionType type, const QString &name, const QString &actionText, const QString &iconPath, bool capture, const QString &shortTitle, const QSet<QString> &actionScopes, const QString &notificationMessage, const bool isEnabledOnlyWhenEditable=false );
void insertRow( int row, QgsAction::ActionType type, const QString &name, const QString &actionText, const QString &iconPath, bool capture, const QString &shortTitle, const QSet<QString> &actionScopes, const QString &notificationMessage, const bool isEnabledOnlyWhenEditable = false );
void swapRows( int row1, int row2 );
QgsAction rowToAction( int row ) const;

@@ -850,11 +850,10 @@ void QgsAttributeTableDialog::editingToggled()
QMenu *actionMenu = new QMenu();
Q_FOREACH ( const QgsAction &action, actions )
{
if( mLayer->readOnly() && action.isEnabledOnlyWhenEditable() )
if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

QAction *qAction = actionMenu->addAction( action.icon(), action.shortTitle() );
qAction->setEnabled( !action.isEnabledOnlyWhenEditable() || mLayer->isEditable() );
qAction->setToolTip( action.name() );
qAction->setData( QVariant::fromValue<QgsAction>( action ) );
connect( qAction, &QAction::triggered, this, &QgsAttributeTableDialog::layerActionTriggered );
@@ -82,12 +82,11 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
if ( !action.runable() )
continue;

if( mLayer->readOnly() && action.isEnabledOnlyWhenEditable() )
if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

QgsFeature &feat = const_cast<QgsFeature &>( *dialog->feature() );
QgsFeatureAction *a = new QgsFeatureAction( action.name(), feat, mLayer, action.id(), -1, dialog );
a->setEnabled( !action.isEnabledOnlyWhenEditable() || mLayer->isEditable() );
dialog->addAction( a );
connect( a, &QAction::triggered, a, &QgsFeatureAction::execute );

@@ -511,7 +511,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
if ( !action.runable() )
continue;

if( action.isEnabledOnlyWhenEditable() )
if ( action.isEnabledOnlyWhenEditable() )
continue;

QTreeWidgetItem *twi = new QTreeWidgetItem( QStringList() << QLatin1String( "" ) << action.name() );
@@ -524,7 +524,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
//add actions from QgsMapLayerActionRegistry
for ( int i = 0; i < registeredActions.size(); i++ )
{
if( registeredActions.at( i )->isEnabledOnlyWhenEditable() )
if ( registeredActions.at( i )->isEnabledOnlyWhenEditable() )
continue;

QgsMapLayerAction *action = registeredActions.at( i );
@@ -1098,7 +1098,7 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent *event )
if ( !action.runable() )
continue;

if( action.isEnabledOnlyWhenEditable() )
if ( action.isEnabledOnlyWhenEditable() )
continue;

QgsFeatureAction *a = new QgsFeatureAction( action.name(), mFeatures[ featIdx ], vlayer, action.id(), idx, this );
@@ -1122,7 +1122,7 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent *event )
QList<QgsMapLayerAction *>::const_iterator actionIt;
for ( actionIt = registeredActions.begin(); actionIt != registeredActions.end(); ++actionIt )
{
if( ( *actionIt )->isEnabledOnlyWhenEditable() )
if ( ( *actionIt )->isEnabledOnlyWhenEditable() )
continue;

QgsIdentifyResultsDialogMapLayerAction *a = new QgsIdentifyResultsDialogMapLayerAction( ( *actionIt )->text(), this, ( *actionIt ), vlayer, &( mFeatures[ featIdx ] ) );
@@ -180,12 +180,11 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
QList<QgsAction> actions = mFilterModel->layer()->actions()->actions( QStringLiteral( "Feature" ) );
Q_FOREACH ( const QgsAction &action, actions )
{
if( mFilterModel->layer()->readOnly() && action.isEnabledOnlyWhenEditable() )
if ( !mFilterModel->layer()->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

QString actionTitle = !action.shortTitle().isEmpty() ? action.shortTitle() : action.icon().isNull() ? action.name() : QLatin1String( "" );
QAction *act = new QAction( action.icon(), actionTitle, container );
act->setEnabled( !action.isEnabledOnlyWhenEditable() || mFilterModel->layer()->isEditable() );
act->setToolTip( action.name() );
act->setData( "user_action" );
act->setProperty( "fid", fid );
@@ -202,11 +201,10 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
QgsGui::mapLayerActionRegistry()->mapLayerActions( mFilterModel->layer(),
QgsMapLayerAction::SingleFeature ) )
{
if( mFilterModel->layer()->readOnly() && mapLayerAction->isEnabledOnlyWhenEditable() )
if ( !mFilterModel->layer()->isEditable() && mapLayerAction->isEnabledOnlyWhenEditable() )
continue;

QAction *action = new QAction( mapLayerAction->icon(), mapLayerAction->text(), container );
action->setEnabled( !mapLayerAction->isEnabledOnlyWhenEditable() || mFilterModel->layer()->isEditable() );
action->setData( "map_layer_action" );
action->setToolTip( mapLayerAction->text() );
action->setProperty( "fid", fid );
@@ -571,16 +571,15 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
if ( !action.runable() )
continue;

if( vl->readOnly() && action.isEnabledOnlyWhenEditable() )
if ( !vl->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

QgsAttributeTableAction *a = new QgsAttributeTableAction( action.name(), this, action.id(), sourceIndex );
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
QAction *ma = menu->addAction( action.name(), a, SLOT( execute() ) );
menu->addAction( action.name(), a, SLOT( execute() ) );
#else
QAction *ma = menu->addAction( action.name(), a, &QgsAttributeTableAction::execute );
menu->addAction( action.name(), a, &QgsAttributeTableAction::execute );
#endif
ma->setEnabled( !action.isEnabledOnlyWhenEditable() || vl->isEditable() );
}
}

@@ -593,16 +592,15 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd

Q_FOREACH ( QgsMapLayerAction *action, registeredActions )
{
if( vl->readOnly() && action->isEnabledOnlyWhenEditable() )
if ( !vl->isEditable() && action->isEnabledOnlyWhenEditable() )
continue;

QgsAttributeTableMapLayerAction *a = new QgsAttributeTableMapLayerAction( action->text(), this, action, sourceIndex );
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
QAction *ma = menu->addAction( action->text(), a, SLOT( execut() ) );
menu->addAction( action->text(), a, SLOT( execut() ) );
#else
QAction *ma = menu->addAction( action->text(), a, &QgsAttributeTableMapLayerAction::execute );
menu->addAction( action->text(), a, &QgsAttributeTableMapLayerAction::execute );
#endif
ma->setEnabled( !action->isEnabledOnlyWhenEditable() || vl->isEditable() );
}
}

@@ -68,7 +68,7 @@ void QgsActionMenu::setFeature( const QgsFeature &feature )

void QgsActionMenu::setMode( const QgsAttributeForm::Mode mode )
{
mMode=mode;
mMode = mode;
reloadActions();
}

@@ -116,17 +116,16 @@ void QgsActionMenu::reloadActions()

Q_FOREACH ( const QgsAction &action, mActions )
{
if( mLayer->readOnly() && action.isEnabledOnlyWhenEditable() )
if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

if( action.isEnabledOnlyWhenEditable() && mMode==QgsAttributeForm::AddFeatureMode )
if ( action.isEnabledOnlyWhenEditable() && ( mMode==QgsAttributeForm::AddFeatureMode || mMode==QgsAttributeForm::IdentifyMode ) )
continue;

QgsAction act( action );
act.setExpressionContextScope( mExpressionContextScope );

QAction *qAction = new QAction( action.icon(), action.name(), this );
qAction->setEnabled( !action.isEnabledOnlyWhenEditable() || mLayer->isEditable() );
qAction->setData( QVariant::fromValue<ActionData>( ActionData( act, mFeatureId, mLayer ) ) );
qAction->setIcon( action.icon() );

@@ -155,14 +154,13 @@ void QgsActionMenu::reloadActions()
{
QgsMapLayerAction *qaction = mapLayerActions.at( i );

if( mLayer->readOnly() && qaction->isEnabledOnlyWhenEditable() )
if ( !mLayer->isEditable() && qaction->isEnabledOnlyWhenEditable() )
continue;

if( qaction->isEnabledOnlyWhenEditable() && mMode==QgsAttributeForm::AddFeatureMode )
if ( qaction->isEnabledOnlyWhenEditable() && ( mMode==QgsAttributeForm::AddFeatureMode || mMode==QgsAttributeForm::IdentifyMode ) )
continue;

QAction *qAction = new QAction( qaction->icon(), qaction->text(), this );
qAction->setEnabled( !qaction->isEnabledOnlyWhenEditable() || mLayer->isEditable() );
qAction->setData( QVariant::fromValue<ActionData>( ActionData( qaction, mFeatureId, mLayer ) ) );
addAction( qAction );
connect( qAction, &QAction::triggered, this, &QgsActionMenu::triggerAction );
@@ -55,6 +55,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
MultiEditMode, //!< Multi edit mode, for editing fields of multiple features at once
SearchMode, //!< Form values are used for searching/filtering the layer
AggregateSearchMode, //!< Form is in aggregate search mode, show each widget in this mode \since QGIS 3.0
IdentifyMode //!< Identify the feature \since QGIS 3.0
};

//! Filter types
@@ -260,6 +260,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
if ( !createMenu && mShowFeatureActions )
{
QgsActionMenu *featureActionMenu = new QgsActionMenu( layer, results[0].mFeature, QStringLiteral( "Feature" ), this );
featureActionMenu->setMode( QgsAttributeForm::IdentifyMode );
createMenu = !featureActionMenu->actions().isEmpty();
delete featureActionMenu;
}

0 comments on commit a11582f

Please sign in to comment.
You can’t perform that action at this time.