Skip to content

Commit

Permalink
Add QgsAttributeFormWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 20, 2017
1 parent 6d0f2af commit f5559b5
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 119 deletions.
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -55,6 +55,7 @@
%Include qgsattributedialog.sip
%Include qgsattributeform.sip
%Include qgsattributeformeditorwidget.sip
%Include qgsattributeformwidget.sip
%Include qgsattributetypeloaddialog.sip
%Include qgsblendmodecombobox.sip
%Include qgsbrowsertreeview.sip
Expand Down
47 changes: 8 additions & 39 deletions python/gui/qgsattributeformeditorwidget.sip
Expand Up @@ -9,7 +9,7 @@



class QgsAttributeFormEditorWidget : QWidget
class QgsAttributeFormEditorWidget : QgsAttributeFormWidget
{
%Docstring
A widget consisting of both an editor widget and additional widgets for controlling the behavior
Expand All @@ -24,15 +24,8 @@ class QgsAttributeFormEditorWidget : QWidget
%End
public:

enum Mode
{
DefaultMode,
MultiEditMode,
SearchMode,
};

explicit QgsAttributeFormEditorWidget( QgsEditorWidgetWrapper *editorWidget,
QgsAttributeForm *form /TransferThis/ );
explicit QgsAttributeFormEditorWidget( QgsEditorWidgetWrapper *editorWidget, const QString &widgetType,
QgsAttributeForm *form /TransferThis/ );
%Docstring
Constructor for QgsAttributeFormEditorWidget.
\param editorWidget associated editor widget wrapper (for default/edit modes)
Expand All @@ -41,32 +34,7 @@ class QgsAttributeFormEditorWidget : QWidget

~QgsAttributeFormEditorWidget();

void createSearchWidgetWrappers( const QString &widgetId, int fieldIdx,
const QVariantMap &config );

%Docstring
Creates the search widget wrappers for the widget used when the form is in
search mode.
\param widgetId id of the widget type to create a search wrapper for
\param fieldIdx index of field associated with widget
\param config configuration which should be used for the widget creation
\param context editor context (not available in Python bindings)
%End

void setMode( Mode mode );
%Docstring
Sets the current mode for the widget. The widget will adapt its state and visible widgets to
reflect the updated mode. For example, showing multi edit tool buttons if the mode is set to MultiEditMode.
\param mode widget mode
.. seealso:: mode()
%End

Mode mode() const;
%Docstring
Returns the current mode for the widget.
.. seealso:: setMode()
:rtype: Mode
%End
virtual void createSearchWidgetWrappers();

void initialize( const QVariant &initialValue, bool mixedValues = false );
%Docstring
Expand All @@ -88,7 +56,8 @@ class QgsAttributeFormEditorWidget : QWidget
:rtype: QVariant
%End

QString currentFilterExpression() const;
virtual QString currentFilterExpression() const;

%Docstring
Creates an expression matching the current search filter value and
search properties represented in the widget.
Expand Down Expand Up @@ -156,7 +125,7 @@ class QgsAttributeFormEditorWidget : QWidget
.. note::

this method is in place for unit testing only, and is not considered
stable AP
stable API
%End

QWidget *searchWidgetFrame();
Expand All @@ -177,7 +146,7 @@ class QgsAttributeFormEditorWidget : QWidget
.. note::

this method is in place for unit testing only, and is not considered
stable AP
stable API
:rtype: list of QgsSearchWidgetWrapper
%End

Expand Down
79 changes: 79 additions & 0 deletions python/gui/qgsattributeformwidget.sip
@@ -0,0 +1,79 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsattributeformwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAttributeFormWidget : QWidget /Abstract/
{

%TypeHeaderCode
#include "qgsattributeformwidget.h"
%End
public:

enum Mode
{
DefaultMode,
MultiEditMode,
SearchMode,
};

explicit QgsAttributeFormWidget( QgsWidgetWrapper *widget, QgsAttributeForm *form );

virtual void createSearchWidgetWrappers() = 0;
%Docstring
Creates the search widget wrappers for the widget used when the form is in
search mode.

\param context editor context (not available in Python bindings)
%End

virtual QString currentFilterExpression() const = 0;
%Docstring
Creates an expression matching the current search filter value and
search properties represented in the widget.
.. versionadded:: 2.16
:rtype: str
%End


void setMode( Mode mode );
%Docstring
Sets the current mode for the widget. The widget will adapt its state and visible widgets to
reflect the updated mode. For example, showing multi edit tool buttons if the mode is set to MultiEditMode.
\param mode widget mode
.. seealso:: mode()
%End

Mode mode() const;
%Docstring
Returns the current mode for the widget.
.. seealso:: setMode()
:rtype: Mode
%End

QgsVectorLayer *layer();
%Docstring
:rtype: QgsVectorLayer
%End

QgsAttributeForm *form() const;
%Docstring
:rtype: QgsAttributeForm
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsattributeformwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -197,6 +197,7 @@ SET(QGIS_GUI_SRCS
qgsattributeforminterface.cpp
qgsattributeformlegacyinterface.cpp
qgsattributetypeloaddialog.cpp
qgsattributeformwidget.cpp
qgsblendmodecombobox.cpp
qgsbrowsertreeview.cpp
qgsbrowserdockwidget.cpp
Expand Down Expand Up @@ -370,6 +371,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsattributedialog.h
qgsattributeform.h
qgsattributeformeditorwidget.h
qgsattributeformwidget.h
qgsattributetypeloaddialog.h
qgsblendmodecombobox.h
qgsbrowsertreeview.h
Expand Down
18 changes: 9 additions & 9 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -151,24 +151,24 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
}

//update all form editor widget modes to match
Q_FOREACH ( QgsAttributeFormEditorWidget *w, findChildren< QgsAttributeFormEditorWidget * >() )
for ( QgsAttributeFormWidget *w : findChildren< QgsAttributeFormWidget * >() )
{
switch ( mode )
{
case QgsAttributeForm::SingleEditMode:
w->setMode( QgsAttributeFormEditorWidget::DefaultMode );
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;

case QgsAttributeForm::AddFeatureMode:
w->setMode( QgsAttributeFormEditorWidget::DefaultMode );
w->setMode( QgsAttributeFormWidget::DefaultMode );
break;

case QgsAttributeForm::MultiEditMode:
w->setMode( QgsAttributeFormEditorWidget::MultiEditMode );
w->setMode( QgsAttributeFormWidget::MultiEditMode );
break;

case QgsAttributeForm::SearchMode:
w->setMode( QgsAttributeFormEditorWidget::SearchMode );
w->setMode( QgsAttributeFormWidget::SearchMode );
break;
}
}
Expand Down Expand Up @@ -1221,10 +1221,10 @@ void QgsAttributeForm::init()
QWidget *w = nullptr;
if ( eww )
{
QgsAttributeFormEditorWidget *formWidget = new QgsAttributeFormEditorWidget( eww, this );
QgsAttributeFormEditorWidget *formWidget = new QgsAttributeFormEditorWidget( eww, widgetSetup.type(), this );
w = formWidget;
mFormEditorWidgets.insert( idx, formWidget );
formWidget->createSearchWidgetWrappers( widgetSetup.type(), idx, widgetSetup.config(), mContext );
formWidget->createSearchWidgetWrappers( mContext );

l->setBuddy( eww->widget() );
}
Expand Down Expand Up @@ -1523,10 +1523,10 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
const QgsEditorWidgetSetup widgetSetup = QgsGui::editorWidgetRegistry()->findBest( mLayer, fieldDef->name() );

QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( widgetSetup.type(), mLayer, fldIdx, widgetSetup.config(), nullptr, this, mContext );
QgsAttributeFormEditorWidget *w = new QgsAttributeFormEditorWidget( eww, this );
QgsAttributeFormEditorWidget *w = new QgsAttributeFormEditorWidget( eww, widgetSetup.type(), this );
mFormEditorWidgets.insert( fldIdx, w );

w->createSearchWidgetWrappers( widgetSetup.type(), fldIdx, widgetSetup.config(), mContext );
w->createSearchWidgetWrappers( mContext );

newWidgetInfo.widget = w;
addWidgetWrapper( eww );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -34,6 +34,7 @@ class QgsMessageBar;
class QgsMessageBarItem;
class QgsWidgetWrapper;
class QgsTabWidget;
class QgsAttributeFormWidget;

/**
* \ingroup gui
Expand Down
38 changes: 15 additions & 23 deletions src/gui/qgsattributeformeditorwidget.cpp
Expand Up @@ -26,12 +26,11 @@
#include <QLabel>
#include <QStackedWidget>

QgsAttributeFormEditorWidget::QgsAttributeFormEditorWidget( QgsEditorWidgetWrapper *editorWidget,
QgsAttributeForm *form )
: QWidget( form )
QgsAttributeFormEditorWidget::QgsAttributeFormEditorWidget( QgsEditorWidgetWrapper *editorWidget, const QString &widgetType, QgsAttributeForm *form )
: QgsAttributeFormWidget( editorWidget, form )
, mWidgetType( widgetType )
, mWidget( editorWidget )
, mForm( form )
, mMode( DefaultMode )
, mMultiEditButton( new QgsMultiEditToolButton() )
, mBlockValueUpdate( false )
, mIsMixed( false )
Expand Down Expand Up @@ -99,16 +98,20 @@ QgsAttributeFormEditorWidget::~QgsAttributeFormEditorWidget()
delete mMultiEditButton;
}

void QgsAttributeFormEditorWidget::createSearchWidgetWrappers( const QString &widgetId, int fieldIdx, const QVariantMap &config, const QgsAttributeEditorContext &context )
void QgsAttributeFormEditorWidget::createSearchWidgetWrappers( const QgsAttributeEditorContext &context )
{
QgsSearchWidgetWrapper *sww = QgsGui::editorWidgetRegistry()->createSearchWidget( widgetId, layer(), fieldIdx, config,
Q_ASSERT( !mWidgetType.isEmpty() );
const QVariantMap config = mWidget->config();
const int fieldIdx = mWidget->fieldIdx();

QgsSearchWidgetWrapper *sww = QgsGui::editorWidgetRegistry()->createSearchWidget( mWidgetType, layer(), fieldIdx, config,
mSearchFrame, context );
setSearchWidgetWrapper( sww );
if ( sww->supportedFlags() & QgsSearchWidgetWrapper::Between ||
sww->supportedFlags() & QgsSearchWidgetWrapper::IsNotBetween )
{
// create secondary widget for between type searches
QgsSearchWidgetWrapper *sww2 = QgsGui::editorWidgetRegistry()->createSearchWidget( widgetId, layer(), fieldIdx, config,
QgsSearchWidgetWrapper *sww2 = QgsGui::editorWidgetRegistry()->createSearchWidget( mWidgetType, layer(), fieldIdx, config,
mSearchFrame, context );
mSearchWidgets << sww2;
mSearchFrame->layout()->addWidget( sww2->widget() );
Expand Down Expand Up @@ -164,12 +167,6 @@ void QgsAttributeFormEditorWidget::setConstraintResultVisible( bool editable )
mConstraintResultLabel->setHidden( !editable );
}

void QgsAttributeFormEditorWidget::setMode( QgsAttributeFormEditorWidget::Mode mode )
{
mMode = mode;
updateWidgets();
}

void QgsAttributeFormEditorWidget::setIsMixed( bool mixed )
{
if ( mWidget && mixed )
Expand Down Expand Up @@ -249,7 +246,7 @@ void QgsAttributeFormEditorWidget::editorWidgetChanged( const QVariant &value )

mIsChanged = true;

switch ( mMode )
switch ( mode() )
{
case DefaultMode:
case SearchMode:
Expand All @@ -269,7 +266,7 @@ void QgsAttributeFormEditorWidget::resetValue()
mWidget->setValue( mPreviousValue );
mBlockValueUpdate = false;

switch ( mMode )
switch ( mode() )
{
case DefaultMode:
case SearchMode:
Expand Down Expand Up @@ -313,11 +310,6 @@ QgsSearchWidgetToolButton *QgsAttributeFormEditorWidget::searchWidgetToolButton(
return mSearchWidgetToolButton;
}

QgsVectorLayer *QgsAttributeFormEditorWidget::layer()
{
return mForm ? mForm->layer() : nullptr;
}

void QgsAttributeFormEditorWidget::updateWidgets()
{
//first update the tool buttons
Expand All @@ -326,21 +318,21 @@ void QgsAttributeFormEditorWidget::updateWidgets()

if ( hasMultiEditButton )
{
if ( mMode != MultiEditMode || fieldReadOnly )
if ( mode() != MultiEditMode || fieldReadOnly )
{
mEditPage->layout()->removeWidget( mMultiEditButton );
mMultiEditButton->setParent( nullptr );
}
}
else
{
if ( mMode == MultiEditMode && !fieldReadOnly )
if ( mode() == MultiEditMode && !fieldReadOnly )
{
mEditPage->layout()->addWidget( mMultiEditButton );
}
}

switch ( mMode )
switch ( mode() )
{
case DefaultMode:
case MultiEditMode:
Expand Down

0 comments on commit f5559b5

Please sign in to comment.