Skip to content
Permalink
Browse files

Merge pull request #38610 from qgis-bot/backport-38383-to-release-3_14

[Backport release-3_14] Allow adding new features via attribute form
  • Loading branch information
m-kuhn committed Sep 5, 2020
2 parents 3782ca9 + 8f3276e commit c13d82f0f7f469eecbf5144ef545faec255d5273
Showing with 71 additions and 2 deletions.
  1. +48 −2 src/app/qgsattributetabledialog.cpp
  2. +2 −0 src/app/qgsattributetabledialog.h
  3. +21 −0 src/ui/qgsattributetabledialog.ui
@@ -17,6 +17,7 @@
#include <QMessageBox>
#include <QGridLayout>
#include <QDialogButtonBox>
#include <QMenu>

#include "qgsattributetabledialog.h"
#include "qgsattributetablemodel.h"
@@ -111,6 +112,8 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mActionDeleteSelected, &QAction::triggered, this, &QgsAttributeTableDialog::mActionDeleteSelected_triggered );
connect( mMainView, &QgsDualView::currentChanged, this, &QgsAttributeTableDialog::mMainView_currentChanged );
connect( mActionAddFeature, &QAction::triggered, this, &QgsAttributeTableDialog::mActionAddFeature_triggered );
connect( mActionAddFeatureViaAttributeTable, &QAction::triggered, this, &QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered );
connect( mActionAddFeatureViaAttributeForm, &QAction::triggered, this, &QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered );
connect( mActionExpressionSelect, &QAction::triggered, this, &QgsAttributeTableDialog::mActionExpressionSelect_triggered );
connect( mMainView, &QgsDualView::showContextMenuExternally, this, &QgsAttributeTableDialog::showContextMenu );

@@ -123,6 +126,16 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
mActionPasteFeatures->setShortcuts( QKeySequence::Paste );
mActionPasteFeatures->setShortcutContext( Qt::WidgetWithChildrenShortcut );

QgsSettings settings;

mActionAddFeature->setMenu( new QMenu( mActionAddFeature->parentWidget() ) );
mActionAddFeature->menu()->addAction( mActionAddFeatureViaAttributeTable );
mActionAddFeature->menu()->addAction( mActionAddFeatureViaAttributeForm );
mActionAddFeature->setIcon(
settings.value( QStringLiteral( "/qgis/attributeTableLastAddFeatureMethod" ) ) == QStringLiteral( "attributeForm" )
? mActionAddFeatureViaAttributeForm->icon()
: mActionAddFeatureViaAttributeTable->icon() );

const QgsFields fields = mLayer->fields();
for ( const QgsField &field : fields )
{
@@ -138,8 +151,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
layout()->setContentsMargins( 0, 0, 0, 0 );
static_cast< QGridLayout * >( layout() )->setVerticalSpacing( 0 );

QgsSettings settings;

int size = settings.value( QStringLiteral( "/qgis/iconSize" ), 16 ).toInt();
if ( size > 32 )
{
@@ -586,10 +597,24 @@ void QgsAttributeTableDialog::mActionReload_triggered()
}

void QgsAttributeTableDialog::mActionAddFeature_triggered()
{
QgsSettings s;

if ( s.value( QStringLiteral( "/qgis/attributeTableLastAddFeatureMethod" ) ) == QStringLiteral( "attributeForm" ) )
mActionAddFeatureViaAttributeForm_triggered();
else
mActionAddFeatureViaAttributeTable_triggered();
}

void QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered()
{
if ( !mLayer->isEditable() )
return;

QgsSettings s;
s.setValue( QStringLiteral( "/qgis/attributeTableLastAddFeatureMethod" ), QStringLiteral( "attributeTable" ) );
mActionAddFeature->setIcon( mActionAddFeatureViaAttributeTable->icon() );

QgsAttributeTableModel *masterModel = mMainView->masterModel();

QgsFeature f;
@@ -601,6 +626,27 @@ void QgsAttributeTableDialog::mActionAddFeature_triggered()
}
}

void QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered()
{
if ( !mLayer->isEditable() )
return;

QgsSettings s;
s.setValue( QStringLiteral( "/qgis/attributeTableLastAddFeatureMethod" ), QStringLiteral( "attributeForm" ) );
mActionAddFeature->setIcon( mActionAddFeatureViaAttributeForm->icon() );

QgsFeature f;

QgsFeatureAction action( tr( "Feature Added" ), f, mLayer, QString(), -1, this );
QgsAttributeTableModel *masterModel = mMainView->masterModel();

if ( action.addFeature() )
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
}
}


void QgsAttributeTableDialog::mActionExpressionSelect_triggered()
{
QgsExpressionSelectionDialog *dlg = new QgsExpressionSelectionDialog( mLayer );
@@ -171,6 +171,8 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
* add feature
*/
void mActionAddFeature_triggered();
void mActionAddFeatureViaAttributeTable_triggered();
void mActionAddFeatureViaAttributeForm_triggered();

void mActionExpressionSelect_triggered();

@@ -532,6 +532,27 @@
<string>Organize Columns</string>
</property>
</action>
<action name="mActionAddFeatureViaAttributeTable">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionNewTableRow.svg</normaloff>:/images/themes/default/mActionNewTableRow.svg</iconset>
</property>
<property name="text">
<string>Add feature via attribute table</string>
</property>
</action>
<action name="mActionAddFeatureViaAttributeForm">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mIconFormSelect.svg</normaloff>:/images/themes/default/mIconFormSelect.svg</iconset>
</property>
<property name="text">
<string>Add feature via attribute form</string>
</property>
<property name="toolTip">
<string>Add feature via attribute form</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

0 comments on commit c13d82f

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