Skip to content

Commit

Permalink
Cleanups for attribute form in search mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 9, 2016
1 parent 7cfe7f8 commit b44f62a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 35 deletions.
10 changes: 10 additions & 0 deletions python/gui/qgsattributeeditorcontext.sip
Expand Up @@ -42,7 +42,17 @@ class QgsAttributeEditorContext
const QgsRelation& relation() const;
RelationMode relationMode() const;

/** Returns the form mode.
* @see setFormMode()
*/
FormMode formMode() const;

/** Sets the form mode.
* @param mode form mode
* @see formMode()
* @note added in QGIS 2.16
*/
void setFormMode( FormMode mode );

const QgsAttributeEditorContext* parentContext() const;
};
2 changes: 0 additions & 2 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -96,8 +96,6 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
mAttributeEditor->layout()->addWidget( mAttributeForm );
}

mAttributeForm->hideButtonBox();

connect( mAttributeForm, SIGNAL( attributeChanged( QString, QVariant ) ), this, SLOT( featureFormAttributeChanged() ) );
connect( mAttributeForm, SIGNAL( modeChanged( QgsAttributeForm::Mode ) ), this, SIGNAL( formModeChanged( QgsAttributeForm::Mode ) ) );
connect( mMasterModel, SIGNAL( modelChanged() ), mAttributeForm, SLOT( refreshFeature() ) );
Expand Down
1 change: 0 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -197,7 +197,6 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation& relation, bool
{
mAttributeEditorFrame->setTitle( mReferencedLayer->name() );
mReferencedAttributeForm = new QgsAttributeForm( relation.referencedLayer(), QgsFeature(), context, this );
mReferencedAttributeForm->hideButtonBox();
mAttributeEditorLayout->addWidget( mReferencedAttributeForm );
}

Expand Down
14 changes: 4 additions & 10 deletions src/gui/qgsattributedialog.cpp
Expand Up @@ -33,21 +33,15 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeat
QgsAttributeEditorContext context;
context.setDistanceArea( myDa );

init( vl, thepFeature, context );

if ( !showDialogButtons )
mAttributeForm->hideButtonBox();
init( vl, thepFeature, context, showDialogButtons );
}

QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QWidget* parent, bool showDialogButtons, const QgsAttributeEditorContext &context )
: QDialog( parent )
, mHighlight( nullptr )
, mOwnedFeature( featureOwner ? thepFeature : nullptr )
{
init( vl, thepFeature, context );

if ( !showDialogButtons )
mAttributeForm->hideButtonBox();
init( vl, thepFeature, context, showDialogButtons );
}

QgsAttributeDialog::~QgsAttributeDialog()
Expand Down Expand Up @@ -106,7 +100,7 @@ void QgsAttributeDialog::reject()
QDialog::reject();
}

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

mAttributeForm = new QgsAttributeForm( layer, *feature, trackedContext, this );
mAttributeForm = new QgsAttributeForm( layer, *feature, trackedContext, this, !showDialogButtons );
mAttributeForm->disconnectButtonBox();
layout()->addWidget( mAttributeForm );
QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsattributedialog.h
Expand Up @@ -141,7 +141,7 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
void show( bool autoDelete = true );

private:
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context );
void init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons );

QString mSettingsPath;
// Used to sync multiple widgets for the same field
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgsattributeeditorcontext.h
Expand Up @@ -99,8 +99,18 @@ class GUI_EXPORT QgsAttributeEditorContext
inline const QgsRelation& relation() const { return mRelation; }
inline RelationMode relationMode() const { return mRelationMode; }

/** Returns the form mode.
* @see setFormMode()
*/
inline FormMode formMode() const { return mFormMode; }

/** Sets the form mode.
* @param mode form mode
* @see formMode()
* @note added in QGIS 2.16
*/
inline void setFormMode( FormMode mode ) { mFormMode = mode; }

inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }

private:
Expand Down
61 changes: 41 additions & 20 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -193,6 +193,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )

case QgsAttributeForm::SearchMode:
mSearchButtonBox->setVisible( true );
hideButtonBox();
break;
}

Expand Down Expand Up @@ -385,7 +386,8 @@ void QgsAttributeForm::filterTriggered()
{
QString filter = createFilterExpression();
emit filterExpressionSet( filter, ReplaceFilter );
setMode( SingleEditMode );
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
}

void QgsAttributeForm::filterAndTriggered()
Expand All @@ -394,7 +396,8 @@ void QgsAttributeForm::filterAndTriggered()
if ( filter.isEmpty() )
return;

setMode( SingleEditMode );
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
emit filterExpressionSet( filter, FilterAnd );
}

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

setMode( SingleEditMode );
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
emit filterExpressionSet( filter, FilterOr );
}

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

mLayer->selectByExpression( filter, behaviour );
pushSelectedFeaturesMessage();
setMode( SingleEditMode );
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
setMode( SingleEditMode );
}

void QgsAttributeForm::searchSetSelection()
Expand Down Expand Up @@ -1245,14 +1250,14 @@ void QgsAttributeForm::init()
mSearchButtonBox->setLayout( boxLayout );
mSearchButtonBox->setObjectName( "searchButtonBox" );

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

QToolButton* selectButton = new QToolButton();
selectButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
selectButton->setText( tr( "Select features" ) );
selectButton->setText( tr( "&Select features" ) );
selectButton->setPopupMode( QToolButton::MenuButtonPopup );
connect( selectButton, SIGNAL( clicked( bool ) ), this, SLOT( searchSetSelection() ) );
QMenu* selectMenu = new QMenu( selectButton );
Expand All @@ -1271,20 +1276,30 @@ void QgsAttributeForm::init()
selectButton->setMenu( selectMenu );
boxLayout->addWidget( selectButton );

QToolButton* filterButton = new QToolButton();
filterButton->setText( tr( "Filter features" ) );
filterButton->setPopupMode( QToolButton::MenuButtonPopup );
filterButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
connect( filterButton, SIGNAL( clicked( bool ) ), this, SLOT( filterTriggered() ) );
QMenu* filterMenu = new QMenu( filterButton );
QAction* filterAndAction = new QAction( tr( "Filter within (\"AND\")" ), filterMenu );
connect( filterAndAction, SIGNAL( triggered( bool ) ), this, SLOT( filterAndTriggered() ) );
filterMenu->addAction( filterAndAction );
QAction* filterOrAction = new QAction( tr( "Extend filter (\"OR\")" ), filterMenu );
connect( filterOrAction, SIGNAL( triggered( bool ) ), this, SLOT( filterOrTriggered() ) );
filterMenu->addAction( filterOrAction );
filterButton->setMenu( filterMenu );
boxLayout->addWidget( filterButton );
if ( mContext.formMode() == QgsAttributeEditorContext::Embed )
{
QToolButton* filterButton = new QToolButton();
filterButton->setText( tr( "Filter features" ) );
filterButton->setPopupMode( QToolButton::MenuButtonPopup );
filterButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
connect( filterButton, SIGNAL( clicked( bool ) ), this, SLOT( filterTriggered() ) );
QMenu* filterMenu = new QMenu( filterButton );
QAction* filterAndAction = new QAction( tr( "Filter within (\"AND\")" ), filterMenu );
connect( filterAndAction, SIGNAL( triggered( bool ) ), this, SLOT( filterAndTriggered() ) );
filterMenu->addAction( filterAndAction );
QAction* filterOrAction = new QAction( tr( "Extend filter (\"OR\")" ), filterMenu );
connect( filterOrAction, SIGNAL( triggered( bool ) ), this, SLOT( filterOrTriggered() ) );
filterMenu->addAction( filterOrAction );
filterButton->setMenu( filterMenu );
boxLayout->addWidget( filterButton );
}
else
{
QPushButton* closeButton = new QPushButton( tr( "Close" ), mSearchButtonBox );
connect( closeButton, SIGNAL( clicked( bool ) ), this, SLOT( close() ) );
closeButton->setShortcut( Qt::Key_Escape );
boxLayout->addWidget( closeButton );
}

layout->addWidget( mSearchButtonBox );
}
Expand All @@ -1302,6 +1317,12 @@ void QgsAttributeForm::init()
{
iface->initForm();
}

if ( mContext.formMode() == QgsAttributeEditorContext::Embed || mMode == SearchMode )
{
hideButtonBox();
}

QApplication::restoreOverrideCursor();
}

Expand Down
8 changes: 7 additions & 1 deletion src/gui/qgsattributeform.h
Expand Up @@ -54,25 +54,31 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
FilterOr, /*!< Filter should be combined using "OR" */
};

explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature = QgsFeature(), const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent = nullptr );
explicit QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &feature = QgsFeature(),
const QgsAttributeEditorContext& context = QgsAttributeEditorContext(), QWidget *parent = nullptr );
~QgsAttributeForm();

const QgsFeature& feature() { return mFeature; }

/**
* Hides the button box (Ok/Cancel) and enables auto-commit
* @note set Embed in QgsAttributeEditorContext in constructor instead
*/
// TODO QGIS 3.0 - make private
void hideButtonBox();

/**
* Shows the button box (Ok/Cancel) and disables auto-commit
* @note set Embed in QgsAttributeEditorContext in constructor instead
*/
// TODO QGIS 3.0 - make private
void showButtonBox();

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

/**
Expand Down

0 comments on commit b44f62a

Please sign in to comment.