Skip to content
Permalink
Browse files

Add QgsAttributeFormWidget

  • Loading branch information
m-kuhn committed Nov 1, 2017
1 parent 6d0f2af commit f5559b5143ab76fee3d8bc786a6c3b919eedfc87
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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.
@@ -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();
@@ -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

@@ -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 *
************************************************************************/
@@ -197,6 +197,7 @@ SET(QGIS_GUI_SRCS
qgsattributeforminterface.cpp
qgsattributeformlegacyinterface.cpp
qgsattributetypeloaddialog.cpp
qgsattributeformwidget.cpp
qgsblendmodecombobox.cpp
qgsbrowsertreeview.cpp
qgsbrowserdockwidget.cpp
@@ -370,6 +371,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsattributedialog.h
qgsattributeform.h
qgsattributeformeditorwidget.h
qgsattributeformwidget.h
qgsattributetypeloaddialog.h
qgsblendmodecombobox.h
qgsbrowsertreeview.h
@@ -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;
}
}
@@ -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() );
}
@@ -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 );
@@ -34,6 +34,7 @@ class QgsMessageBar;
class QgsMessageBarItem;
class QgsWidgetWrapper;
class QgsTabWidget;
class QgsAttributeFormWidget;

/**
* \ingroup gui
@@ -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 )
@@ -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() );
@@ -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 )
@@ -249,7 +246,7 @@ void QgsAttributeFormEditorWidget::editorWidgetChanged( const QVariant &value )

mIsChanged = true;

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

switch ( mMode )
switch ( mode() )
{
case DefaultMode:
case SearchMode:
@@ -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
@@ -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:

0 comments on commit f5559b5

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