17
17
#include < QMessageBox>
18
18
#include < QGridLayout>
19
19
#include < QDialogButtonBox>
20
+ #include < QMenu>
20
21
21
22
#include " qgsattributetabledialog.h"
22
23
#include " qgsattributetablemodel.h"
@@ -111,6 +112,8 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
111
112
connect ( mActionDeleteSelected , &QAction::triggered, this , &QgsAttributeTableDialog::mActionDeleteSelected_triggered );
112
113
connect ( mMainView , &QgsDualView::currentChanged, this , &QgsAttributeTableDialog::mMainView_currentChanged );
113
114
connect ( mActionAddFeature , &QAction::triggered, this , &QgsAttributeTableDialog::mActionAddFeature_triggered );
115
+ connect ( mActionAddFeatureViaAttributeTable , &QAction::triggered, this , &QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered );
116
+ connect ( mActionAddFeatureViaAttributeForm , &QAction::triggered, this , &QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered );
114
117
connect ( mActionExpressionSelect , &QAction::triggered, this , &QgsAttributeTableDialog::mActionExpressionSelect_triggered );
115
118
connect ( mMainView , &QgsDualView::showContextMenuExternally, this , &QgsAttributeTableDialog::showContextMenu );
116
119
@@ -123,6 +126,16 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
123
126
mActionPasteFeatures ->setShortcuts ( QKeySequence::Paste );
124
127
mActionPasteFeatures ->setShortcutContext ( Qt::WidgetWithChildrenShortcut );
125
128
129
+ QgsSettings settings;
130
+
131
+ mActionAddFeature ->setMenu ( new QMenu ( mActionAddFeature ->parentWidget () ) );
132
+ mActionAddFeature ->menu ()->addAction ( mActionAddFeatureViaAttributeTable );
133
+ mActionAddFeature ->menu ()->addAction ( mActionAddFeatureViaAttributeForm );
134
+ mActionAddFeature ->setIcon (
135
+ settings.value ( QStringLiteral ( " /qgis/attributeTableLastAddFeatureMethod" ) ) == QStringLiteral ( " attributeForm" )
136
+ ? mActionAddFeatureViaAttributeForm ->icon ()
137
+ : mActionAddFeatureViaAttributeTable ->icon () );
138
+
126
139
const QgsFields fields = mLayer ->fields ();
127
140
for ( const QgsField &field : fields )
128
141
{
@@ -138,8 +151,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
138
151
layout ()->setContentsMargins ( 0 , 0 , 0 , 0 );
139
152
static_cast < QGridLayout * >( layout () )->setVerticalSpacing ( 0 );
140
153
141
- QgsSettings settings;
142
-
143
154
int size = settings.value ( QStringLiteral ( " /qgis/iconSize" ), 16 ).toInt ();
144
155
if ( size > 32 )
145
156
{
@@ -586,10 +597,24 @@ void QgsAttributeTableDialog::mActionReload_triggered()
586
597
}
587
598
588
599
void QgsAttributeTableDialog::mActionAddFeature_triggered ()
600
+ {
601
+ QgsSettings s;
602
+
603
+ if ( s.value ( QStringLiteral ( " /qgis/attributeTableLastAddFeatureMethod" ) ) == QStringLiteral ( " attributeForm" ) )
604
+ mActionAddFeatureViaAttributeForm_triggered ();
605
+ else
606
+ mActionAddFeatureViaAttributeTable_triggered ();
607
+ }
608
+
609
+ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered ()
589
610
{
590
611
if ( !mLayer ->isEditable () )
591
612
return ;
592
613
614
+ QgsSettings s;
615
+ s.setValue ( QStringLiteral ( " /qgis/attributeTableLastAddFeatureMethod" ), QStringLiteral ( " attributeTable" ) );
616
+ mActionAddFeature ->setIcon ( mActionAddFeatureViaAttributeTable ->icon () );
617
+
593
618
QgsAttributeTableModel *masterModel = mMainView ->masterModel ();
594
619
595
620
QgsFeature f;
@@ -601,6 +626,27 @@ void QgsAttributeTableDialog::mActionAddFeature_triggered()
601
626
}
602
627
}
603
628
629
+ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered ()
630
+ {
631
+ if ( !mLayer ->isEditable () )
632
+ return ;
633
+
634
+ QgsSettings s;
635
+ s.setValue ( QStringLiteral ( " /qgis/attributeTableLastAddFeatureMethod" ), QStringLiteral ( " attributeForm" ) );
636
+ mActionAddFeature ->setIcon ( mActionAddFeatureViaAttributeForm ->icon () );
637
+
638
+ QgsFeature f;
639
+
640
+ QgsFeatureAction action ( tr ( " Feature Added" ), f, mLayer , QString (), -1 , this );
641
+ QgsAttributeTableModel *masterModel = mMainView ->masterModel ();
642
+
643
+ if ( action.addFeature () )
644
+ {
645
+ masterModel->reload ( masterModel->index ( 0 , 0 ), masterModel->index ( masterModel->rowCount () - 1 , masterModel->columnCount () - 1 ) );
646
+ }
647
+ }
648
+
649
+
604
650
void QgsAttributeTableDialog::mActionExpressionSelect_triggered ()
605
651
{
606
652
QgsExpressionSelectionDialog *dlg = new QgsExpressionSelectionDialog ( mLayer );
0 commit comments