Skip to content
Permalink
Browse files

Cleanups for attribute form in search mode

  • Loading branch information
nyalldawson committed Jun 9, 2016
1 parent 7cfe7f8 commit b44f62a1c2a1963c2b84e2f40ed831e2a2bbd849
@@ -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;
};
@@ -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() ) );
@@ -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 );
}

@@ -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()
@@ -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() ) );
@@ -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*>();
@@ -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
@@ -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:
@@ -193,6 +193,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )

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

@@ -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()
@@ -394,7 +396,8 @@ void QgsAttributeForm::filterAndTriggered()
if ( filter.isEmpty() )
return;

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

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

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

@@ -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()
@@ -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 );
@@ -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 );
}
@@ -1302,6 +1317,12 @@ void QgsAttributeForm::init()
{
iface->initForm();
}

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

QApplication::restoreOverrideCursor();
}

@@ -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();

/**

0 comments on commit b44f62a

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