Skip to content

Commit b44f62a

Browse files
committed
Cleanups for attribute form in search mode
1 parent 7cfe7f8 commit b44f62a

File tree

8 files changed

+73
-35
lines changed

8 files changed

+73
-35
lines changed

python/gui/qgsattributeeditorcontext.sip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ class QgsAttributeEditorContext
4242
const QgsRelation& relation() const;
4343
RelationMode relationMode() const;
4444

45+
/** Returns the form mode.
46+
* @see setFormMode()
47+
*/
4548
FormMode formMode() const;
4649

50+
/** Sets the form mode.
51+
* @param mode form mode
52+
* @see formMode()
53+
* @note added in QGIS 2.16
54+
*/
55+
void setFormMode( FormMode mode );
56+
4757
const QgsAttributeEditorContext* parentContext() const;
4858
};

src/gui/attributetable/qgsdualview.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
9696
mAttributeEditor->layout()->addWidget( mAttributeForm );
9797
}
9898

99-
mAttributeForm->hideButtonBox();
100-
10199
connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) );
102100
connect( mAttributeForm, SIGNAL( modeChanged( QgsAttributeForm::Mode ) ), this, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ) );
103101
connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation& relation, bool
197197
{
198198
mAttributeEditorFrame->setTitle( mReferencedLayer->name() );
199199
mReferencedAttributeForm = new QgsAttributeForm( relation.referencedLayer(), QgsFeature(), context, this );
200-
mReferencedAttributeForm->hideButtonBox();
201200
mAttributeEditorLayout->addWidget( mReferencedAttributeForm );
202201
}
203202

src/gui/qgsattributedialog.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,15 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeat
3333
QgsAttributeEditorContext context;
3434
context.setDistanceArea( myDa );
3535

36-
init( vl, thepFeature, context );
37-
38-
if ( !showDialogButtons )
39-
mAttributeForm->hideButtonBox();
36+
init( vl, thepFeature, context, showDialogButtons );
4037
}
4138

4239
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QWidget* parent, bool showDialogButtons, const QgsAttributeEditorContext &context )
4340
: QDialog( parent )
4441
, mHighlight( nullptr )
4542
, mOwnedFeature( featureOwner ? thepFeature : nullptr )
4643
{
47-
init( vl, thepFeature, context );
48-
49-
if ( !showDialogButtons )
50-
mAttributeForm->hideButtonBox();
44+
init( vl, thepFeature, context, showDialogButtons );
5145
}
5246

5347
QgsAttributeDialog::~QgsAttributeDialog()
@@ -106,7 +100,7 @@ void QgsAttributeDialog::reject()
106100
QDialog::reject();
107101
}
108102

109-
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context )
103+
void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons )
110104
{
111105
QgsAttributeEditorContext trackedContext = context;
112106
setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
@@ -115,7 +109,7 @@ void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const
115109
mTrackedVectorLayerTools.setVectorLayerTools( trackedContext.vectorLayerTools() );
116110
trackedContext.setVectorLayerTools( &mTrackedVectorLayerTools );
117111

118-
mAttributeForm = new QgsAttributeForm( layer, *feature, trackedContext, this );
112+
mAttributeForm = new QgsAttributeForm( layer, *feature, trackedContext, this, !showDialogButtons );
119113
mAttributeForm->disconnectButtonBox();
120114
layout()->addWidget( mAttributeForm );
121115
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();

src/gui/qgsattributedialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
141141
void show( bool autoDelete = true );
142142

143143
private:
144-
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context );
144+
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons );
145145

146146
QString mSettingsPath;
147147
// Used to sync multiple widgets for the same field

src/gui/qgsattributeeditorcontext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@ class GUI_EXPORT QgsAttributeEditorContext
9999
inline const QgsRelation& relation() const { return mRelation; }
100100
inline RelationMode relationMode() const { return mRelationMode; }
101101

102+
/** Returns the form mode.
103+
* @see setFormMode()
104+
*/
102105
inline FormMode formMode() const { return mFormMode; }
103106

107+
/** Sets the form mode.
108+
* @param mode form mode
109+
* @see formMode()
110+
* @note added in QGIS 2.16
111+
*/
112+
inline void setFormMode( FormMode mode ) { mFormMode = mode; }
113+
104114
inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }
105115

106116
private:

src/gui/qgsattributeform.cpp

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
193193

194194
case QgsAttributeForm::SearchMode:
195195
mSearchButtonBox->setVisible( true );
196+
hideButtonBox();
196197
break;
197198
}
198199

@@ -385,7 +386,8 @@ void QgsAttributeForm::filterTriggered()
385386
{
386387
QString filter = createFilterExpression();
387388
emit filterExpressionSet( filter, ReplaceFilter );
388-
setMode( SingleEditMode );
389+
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
390+
setMode( SingleEditMode );
389391
}
390392

391393
void QgsAttributeForm::filterAndTriggered()
@@ -394,7 +396,8 @@ void QgsAttributeForm::filterAndTriggered()
394396
if ( filter.isEmpty() )
395397
return;
396398

397-
setMode( SingleEditMode );
399+
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
400+
setMode( SingleEditMode );
398401
emit filterExpressionSet( filter, FilterAnd );
399402
}
400403

@@ -404,7 +407,8 @@ void QgsAttributeForm::filterOrTriggered()
404407
if ( filter.isEmpty() )
405408
return;
406409

407-
setMode( SingleEditMode );
410+
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
411+
setMode( SingleEditMode );
408412
emit filterExpressionSet( filter, FilterOr );
409413
}
410414

@@ -436,7 +440,8 @@ void QgsAttributeForm::runSearchSelect( QgsVectorLayer::SelectBehaviour behaviou
436440

437441
mLayer->selectByExpression( filter, behaviour );
438442
pushSelectedFeaturesMessage();
439-
setMode( SingleEditMode );
443+
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
444+
setMode( SingleEditMode );
440445
}
441446

442447
void QgsAttributeForm::searchSetSelection()
@@ -1245,14 +1250,14 @@ void QgsAttributeForm::init()
12451250
mSearchButtonBox->setLayout( boxLayout );
12461251
mSearchButtonBox->setObjectName( "searchButtonBox" );
12471252

1248-
QPushButton* clearButton = new QPushButton( tr( "Reset form" ), mSearchButtonBox );
1253+
QPushButton* clearButton = new QPushButton( tr( "&Reset form" ), mSearchButtonBox );
12491254
connect( clearButton, SIGNAL( clicked( bool ) ), this, SLOT( resetSearch() ) );
12501255
boxLayout->addWidget( clearButton );
12511256
boxLayout->addStretch( 1 );
12521257

12531258
QToolButton* selectButton = new QToolButton();
12541259
selectButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1255-
selectButton->setText( tr( "Select features" ) );
1260+
selectButton->setText( tr( "&Select features" ) );
12561261
selectButton->setPopupMode( QToolButton::MenuButtonPopup );
12571262
connect( selectButton, SIGNAL( clicked( bool ) ), this, SLOT( searchSetSelection() ) );
12581263
QMenu* selectMenu = new QMenu( selectButton );
@@ -1271,20 +1276,30 @@ void QgsAttributeForm::init()
12711276
selectButton->setMenu( selectMenu );
12721277
boxLayout->addWidget( selectButton );
12731278

1274-
QToolButton* filterButton = new QToolButton();
1275-
filterButton->setText( tr( "Filter features" ) );
1276-
filterButton->setPopupMode( QToolButton::MenuButtonPopup );
1277-
filterButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1278-
connect( filterButton, SIGNAL( clicked( bool ) ), this, SLOT( filterTriggered() ) );
1279-
QMenu* filterMenu = new QMenu( filterButton );
1280-
QAction* filterAndAction = new QAction( tr( "Filter within (\"AND\")" ), filterMenu );
1281-
connect( filterAndAction, SIGNAL( triggered( bool ) ), this, SLOT( filterAndTriggered() ) );
1282-
filterMenu->addAction( filterAndAction );
1283-
QAction* filterOrAction = new QAction( tr( "Extend filter (\"OR\")" ), filterMenu );
1284-
connect( filterOrAction, SIGNAL( triggered( bool ) ), this, SLOT( filterOrTriggered() ) );
1285-
filterMenu->addAction( filterOrAction );
1286-
filterButton->setMenu( filterMenu );
1287-
boxLayout->addWidget( filterButton );
1279+
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
1280+
{
1281+
QToolButton* filterButton = new QToolButton();
1282+
filterButton->setText( tr( "Filter features" ) );
1283+
filterButton->setPopupMode( QToolButton::MenuButtonPopup );
1284+
filterButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1285+
connect( filterButton, SIGNAL( clicked( bool ) ), this, SLOT( filterTriggered() ) );
1286+
QMenu* filterMenu = new QMenu( filterButton );
1287+
QAction* filterAndAction = new QAction( tr( "Filter within (\"AND\")" ), filterMenu );
1288+
connect( filterAndAction, SIGNAL( triggered( bool ) ), this, SLOT( filterAndTriggered() ) );
1289+
filterMenu->addAction( filterAndAction );
1290+
QAction* filterOrAction = new QAction( tr( "Extend filter (\"OR\")" ), filterMenu );
1291+
connect( filterOrAction, SIGNAL( triggered( bool ) ), this, SLOT( filterOrTriggered() ) );
1292+
filterMenu->addAction( filterOrAction );
1293+
filterButton->setMenu( filterMenu );
1294+
boxLayout->addWidget( filterButton );
1295+
}
1296+
else
1297+
{
1298+
QPushButton* closeButton = new QPushButton( tr( "Close" ), mSearchButtonBox );
1299+
connect( closeButton, SIGNAL( clicked( bool ) ), this, SLOT( close() ) );
1300+
closeButton->setShortcut( Qt::Key_Escape );
1301+
boxLayout->addWidget( closeButton );
1302+
}
12881303

12891304
layout->addWidget( mSearchButtonBox );
12901305
}
@@ -1302,6 +1317,12 @@ void QgsAttributeForm::init()
13021317
{
13031318
iface->initForm();
13041319
}
1320+
1321+
if ( mContext.formMode() == QgsAttributeEditorContext::Embed || mMode == SearchMode )
1322+
{
1323+
hideButtonBox();
1324+
}
1325+
13051326
QApplication::restoreOverrideCursor();
13061327
}
13071328

src/gui/qgsattributeform.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,31 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
5454
FilterOr, /*!< Filter should be combined using "OR" */
5555
};
5656

57-
explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature = QgsFeature(), const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent = nullptr );
57+
explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature = QgsFeature(),
58+
const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent = nullptr );
5859
~QgsAttributeForm();
5960

6061
const QgsFeature& feature() { return mFeature; }
6162

6263
/**
6364
* Hides the button box (Ok/Cancel) and enables auto-commit
65+
* @note set Embed in QgsAttributeEditorContext in constructor instead
6466
*/
67+
// TODO QGIS 3.0 - make private
6568
void hideButtonBox();
6669

6770
/**
6871
* Shows the button box (Ok/Cancel) and disables auto-commit
72+
* @note set Embed in QgsAttributeEditorContext in constructor instead
6973
*/
74+
// TODO QGIS 3.0 - make private
7075
void showButtonBox();
7176

7277
/**
7378
* Disconnects the button box (Ok/Cancel) from the accept/resetValues slots
7479
* If this method is called, you have to create these connections from outside
7580
*/
81+
// TODO QGIS 3.0 - make private
7682
void disconnectButtonBox();
7783

7884
/**

0 commit comments

Comments
 (0)