Find a suitable editor widget if widget and config mismatch

If a .ui file is specified and the widget specified in the .ui file is not
supported by the widgetwrapper which is configured in the layer properties
the system will automatically try to find a better suitable widgetwrapper.

To do this, widgetwrappers (respectively their factories) can return a map of
supported widget types with priority values.
The widgetwrapper which offers the heighest priority for a certain widget type
will be used in case of a mismatch.

Sponsored by OPENGIS.ch special projects team (aka gis.se troubleshooting
section)
This commit is contained in:
Matthias Kuhn 2015-07-23 11:49:26 +02:00
parent 1d888acac3
commit de547adc19
47 changed files with 322 additions and 88 deletions

View File

@ -88,6 +88,7 @@ class QgsEditorWidgetWrapper : QObject
*/
void setEnabled( bool enabled );
virtual bool valid() = 0;
protected:
virtual QWidget* createWidget( QWidget* parent ) = 0;

View File

@ -111,6 +111,17 @@ class QgsWidgetWrapper : QObject
*/
static QgsWidgetWrapper* fromWidget( QWidget* widget );
/**
* Return true if the widget has been properly initialized.
* This acts as hint for the calling party if this wrapper can be used
* after initializing it.
* If it cannot be used this is a hint tothe caller that he may try to find
* another suitable widget type instead.
*
* @return Validity status of this widget.
*/
virtual bool valid() = 0;
protected:
/**
* This method should create a new widget with the provided parent. This will only be called

View File

@ -30,8 +30,9 @@ QgsEditorWidgetFactory::~QgsEditorWidgetFactory()
{
}
/** Override in own factory to get something different than the default (a simple QgsFilterLineEdit)
*
/**
* By default a simple QgsFilterLineEdit is returned as search widget.
* Override in own factory to get something different than the default.
*/
QgsSearchWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const
{

View File

@ -115,6 +115,15 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
inline bool supportsField( QgsVectorLayer* vl, int fieldIdx ) { return isFieldSupported( vl, fieldIdx ); }
/**
* Returns a list of widget types which this editor widget supports.
* Each widget type can have a priority value attached, the factory with the highest one
* will be used.
*
* @return A map of widget type names and weight values
*/
virtual QMap<const char*, int> supportedWidgetTypes() { return QMap<const char*, int>(); }
/**
* Create a pretty String representation of the value.
*

View File

@ -95,9 +95,21 @@ QgsEditorWidgetWrapper* QgsEditorWidgetRegistry::create( const QString& widgetId
// Make sure that there is a widget created at this point
// so setValue() et al won't crash
ww->widget();
// If we tried to set a widget which is not supported by this wrapper
if ( !ww->valid() )
{
delete ww;
QString wid = findSuitableWrapper( editor );
ww = mWidgetFactories[wid]->create( vl, fieldIdx, editor, parent );
ww->setConfig( config );
ww->setContext( context );
}
return ww;
}
}
return 0;
}
@ -164,6 +176,20 @@ bool QgsEditorWidgetRegistry::registerWidget( const QString& widgetId, QgsEditor
else
{
mWidgetFactories.insert( widgetId, widgetFactory );
// Use this factory as default where it provides the heighest priority
QMap<const char*, int> types = widgetFactory->supportedWidgetTypes();
QMap<const char*, int>::ConstIterator it;
it = types.constBegin();
for ( ; it != types.constEnd(); ++it )
{
if ( it.value() > mFactoriesByType[it.key()].first )
{
mFactoriesByType[it.key()] = qMakePair( it.value(), widgetFactory );
}
}
return true;
}
}
@ -316,3 +342,32 @@ void QgsEditorWidgetRegistry::writeSymbology( QDomElement& element, QDomDocument
writeMapLayer( vl, element, doc );
}
QString QgsEditorWidgetRegistry::findSuitableWrapper( QWidget* editor )
{
QMap<const char*, QPair<int, QgsEditorWidgetFactory*> >::ConstIterator it;
QString widgetid;
int weight = 0;
it = mFactoriesByType.constBegin();
for ( ; it != mFactoriesByType.constEnd(); ++it )
{
if ( editor->staticMetaObject.className() == it.key() )
{
// if it's a perfect match: return it directly
return it.value().second->name();
}
else if ( editor->inherits( it.key() ) )
{
// if it's a subclass, continue evaluating, maybe we find a more-specific or one with more weight
if ( it.value().first > weight )
{
weight = it.value().first;
widgetid = it.value().second->name();
}
}
}
return widgetid;
}

View File

@ -193,7 +193,10 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
void writeSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage );
private:
QString findSuitableWrapper( QWidget* editor );
QMap<QString, QgsEditorWidgetFactory*> mWidgetFactories;
QMap<const char*, QPair<int, QgsEditorWidgetFactory*> > mFactoriesByType;
};
#endif // QGSEDITORWIDGETREGISTRY_H

View File

@ -119,6 +119,17 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
*/
static QgsWidgetWrapper* fromWidget( QWidget* widget );
/**
* Return true if the widget has been properly initialized.
* This acts as hint for the calling party if this wrapper can be used
* after initializing it.
* If it cannot be used this is a hint tothe caller that he may try to find
* another suitable widget type instead.
*
* @return Validity status of this widget.
*/
virtual bool valid() = 0;
protected:
/**
* This method should create a new widget with the provided parent. This will only be called

View File

@ -53,6 +53,11 @@ void QgsCheckboxWidgetWrapper::initWidget( QWidget* editor )
connect( mGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( valueChanged( bool ) ) );
}
bool QgsCheckboxWidgetWrapper::valid()
{
return mCheckBox || mGroupBox;
}
void QgsCheckboxWidgetWrapper::setValue( const QVariant& value )
{
if ( mGroupBox )

View File

@ -45,6 +45,7 @@ class GUI_EXPORT QgsCheckboxWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -59,6 +59,11 @@ void QgsClassificationWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsClassificationWidgetWrapper::valid()
{
return mComboBox;
}
void QgsClassificationWidgetWrapper::setValue( const QVariant& value )
{
mComboBox->setCurrentIndex( mComboBox->findData( value ) );

View File

@ -33,6 +33,7 @@ class GUI_EXPORT QgsClassificationWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget*createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -46,6 +46,11 @@ void QgsColorWidgetWrapper::initWidget( QWidget* editor )
connect( mColorButton, SIGNAL( colorChanged( QColor ) ), this, SLOT( valueChanged() ) );
}
bool QgsColorWidgetWrapper::valid()
{
return mColorButton;
}
void QgsColorWidgetWrapper::setValue( const QVariant& value )
{
if ( mColorButton )

View File

@ -39,6 +39,7 @@ class GUI_EXPORT QgsColorWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -90,6 +90,11 @@ void QgsDateTimeEditWrapper::initWidget( QWidget *editor )
}
}
bool QgsDateTimeEditWrapper::valid()
{
return mQgsDateTimeEdit || mQDateTimeEdit;
}
void QgsDateTimeEditWrapper::dateTimeChanged( const QDateTime& dateTime )
{
const QString fieldFormat = config( "field_format", QGSDATETIMEEDIT_DATEFORMAT ).toString();

View File

@ -54,6 +54,7 @@ class GUI_EXPORT QgsDateTimeEditWrapper : public QgsEditorWidgetWrapper
QVariant value() override;
QWidget *createWidget( QWidget *parent ) override;
void initWidget( QWidget *editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant &value ) override;

View File

@ -26,7 +26,7 @@ QgsDefaultSearchWidgetWrapper::QgsDefaultSearchWidgetWrapper( QgsVectorLayer* vl
, mLineEdit( NULL )
, mCheckbox( NULL )
, mContainer( NULL )
, mCaseString(QString("LIKE"))
, mCaseString( QString( "LIKE" ) )
{
}
@ -36,45 +36,45 @@ QString QgsDefaultSearchWidgetWrapper::expression()
return mExpression;
}
void QgsDefaultSearchWidgetWrapper::setCaseString(int caseSensitiveCheckState)
void QgsDefaultSearchWidgetWrapper::setCaseString( int caseSensitiveCheckState )
{
if ( caseSensitiveCheckState == Qt::Checked)
{
mCaseString = "LIKE";
}
else
{
mCaseString = "ILIKE";
}
// need to update also the line edit
setExpression(mLineEdit->text());
if ( caseSensitiveCheckState == Qt::Checked )
{
mCaseString = "LIKE";
}
else
{
mCaseString = "ILIKE";
}
// need to update also the line edit
setExpression( mLineEdit->text() );
}
void QgsDefaultSearchWidgetWrapper::setExpression(QString exp)
void QgsDefaultSearchWidgetWrapper::setExpression( QString exp )
{
QVariant::Type fldType = layer()->pendingFields()[mFieldIdx].type();
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong );
QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
QString fieldName = layer()->pendingFields()[mFieldIdx].name();
QString str;
if ( exp == nullValue )
{
str = QString( "%1 IS NULL" ).arg( QgsExpression::quotedColumnRef( fieldName ) );
}
else
{
str = QString( "%1 %2 '%3'" )
.arg( QgsExpression::quotedColumnRef( fieldName ) )
.arg( numeric ? "=" : mCaseString )
.arg( numeric
? exp.replace( "'", "''" )
:
"%" + exp.replace( "'", "''" ) + "%" ); // escape quotes
}
mExpression = str;
emit expressionChanged(mExpression);
QVariant::Type fldType = layer()->pendingFields()[mFieldIdx].type();
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double || fldType == QVariant::LongLong );
QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
QString fieldName = layer()->pendingFields()[mFieldIdx].name();
QString str;
if ( exp == nullValue )
{
str = QString( "%1 IS NULL" ).arg( QgsExpression::quotedColumnRef( fieldName ) );
}
else
{
str = QString( "%1 %2 '%3'" )
.arg( QgsExpression::quotedColumnRef( fieldName ) )
.arg( numeric ? "=" : mCaseString )
.arg( numeric
? exp.replace( "'", "''" )
:
"%" + exp.replace( "'", "''" ) + "%" ); // escape quotes
}
mExpression = str;
emit expressionChanged( mExpression );
}
QWidget* QgsDefaultSearchWidgetWrapper::createWidget( QWidget* parent )
@ -82,21 +82,26 @@ QWidget* QgsDefaultSearchWidgetWrapper::createWidget( QWidget* parent )
return new QWidget( parent );
}
bool QgsDefaultSearchWidgetWrapper::applyDirectly()
bool QgsDefaultSearchWidgetWrapper::applyDirectly()
{
return false;
return false;
}
void QgsDefaultSearchWidgetWrapper::initWidget( QWidget* widget )
{
mContainer = widget;
mContainer->setLayout(new QHBoxLayout() );
mContainer->setLayout( new QHBoxLayout() );
mLineEdit = new QgsFilterLineEdit();
mCheckbox = new QCheckBox("Case sensitive");
mContainer->layout()->addWidget(mLineEdit);
mContainer->layout()->addWidget(mCheckbox);
mCheckbox = new QCheckBox( "Case sensitive" );
mContainer->layout()->addWidget( mLineEdit );
mContainer->layout()->addWidget( mCheckbox );
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( setExpression( QString ) ) );
connect( mCheckbox, SIGNAL( stateChanged( int ) ), this, SLOT( setCaseString(int) ) );
mCheckbox->setChecked(Qt::Unchecked);
connect( mCheckbox, SIGNAL( stateChanged( int ) ), this, SLOT( setCaseString( int ) ) );
mCheckbox->setChecked( Qt::Unchecked );
mCaseString = "ILIKE";
}
bool QgsDefaultSearchWidgetWrapper::valid()
{
return true;
}

View File

@ -37,14 +37,15 @@ class GUI_EXPORT QgsDefaultSearchWidgetWrapper : public QgsSearchWidgetWrapper
QString expression() override;
bool applyDirectly() override;
protected slots:
void setExpression(QString exp) override;
void setExpression( QString exp ) override;
private slots:
void setCaseString(int);
void setCaseString( int );
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
private:
QgsFilterLineEdit* mLineEdit;

View File

@ -57,6 +57,11 @@ void QgsEnumerationWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsEnumerationWidgetWrapper::valid()
{
return mComboBox;
}
void QgsEnumerationWidgetWrapper::setValue( const QVariant& value )
{
if ( mComboBox )

View File

@ -33,6 +33,7 @@ class GUI_EXPORT QgsEnumerationWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -47,6 +47,11 @@ QVariant QgsFileNameWidgetWrapper::value()
return value;
}
bool QgsFileNameWidgetWrapper::valid()
{
return mLineEdit || mLabel;
}
QWidget* QgsFileNameWidgetWrapper::createWidget( QWidget* parent )
{
QWidget* container = new QWidget( parent );

View File

@ -40,6 +40,7 @@ class GUI_EXPORT QgsFileNameWidgetWrapper : public QgsEditorWidgetWrapper
// QgsEditorWidgetWrapper interface
public:
QVariant value() override;
bool valid() override;
protected:
QWidget* createWidget( QWidget* parent ) override;

View File

@ -40,6 +40,11 @@ void QgsHiddenWidgetWrapper::initWidget( QWidget* editor )
editor->setVisible( false );
}
bool QgsHiddenWidgetWrapper::valid()
{
return true;
}
void QgsHiddenWidgetWrapper::setValue( const QVariant& value )
{
mValue = value;

View File

@ -36,6 +36,7 @@ class GUI_EXPORT QgsHiddenWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -156,6 +156,11 @@ void QgsPhotoWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsPhotoWidgetWrapper::valid()
{
return mPhotoLabel || mLineEdit || mButton || mWebView;
}
void QgsPhotoWidgetWrapper::setValue( const QVariant& value )
{
if ( mLineEdit )

View File

@ -48,6 +48,7 @@ class GUI_EXPORT QgsPhotoWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -84,3 +84,13 @@ bool QgsRangeWidgetFactory::isFieldSupported( QgsVectorLayer* vl, int fieldIdx )
return false;
}
}
QMap<const char*, int> QgsRangeWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
map.insert( QSlider::staticMetaObject.className(), 10 );
map.insert( QDial::staticMetaObject.className(), 10 );
map.insert( QSpinBox::staticMetaObject.className(), 10 );
map.insert( QDoubleSpinBox::staticMetaObject.className(), 10 );
return map;
}

View File

@ -29,6 +29,7 @@ class GUI_EXPORT QgsRangeWidgetFactory : public QgsEditorWidgetFactory
virtual QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
virtual QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
virtual void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
private:
virtual bool isFieldSupported( QgsVectorLayer *vl, int fieldIdx ) override;

View File

@ -75,6 +75,10 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
bool allowNull = config( "AllowNull" ).toBool();
QVariant min( config( "Min" ) );
QVariant max( config( "Max" ) );
QVariant step( config( "Step" ) );
if ( mDoubleSpinBox )
{
// set the precision if field is integer
@ -84,8 +88,8 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
mDoubleSpinBox->setDecimals( layer()->pendingFields()[fieldIdx()].precision() );
}
double min = config( "Min" ).toDouble();
double step = config( "Step" ).toDouble();
double minval = min.toDouble();
double stepval = step.toDouble();
QgsDoubleSpinBox* qgsWidget = dynamic_cast<QgsDoubleSpinBox*>( mDoubleSpinBox );
if ( qgsWidget )
qgsWidget->setShowClearButton( allowNull );
@ -93,90 +97,107 @@ void QgsRangeWidgetWrapper::initWidget( QWidget* editor )
{
if ( precision > 0 )
{
min -= 10 ^ -precision;
minval -= 10 ^ -precision;
}
else
{
min -= step;
minval -= stepval;
}
mDoubleSpinBox->setValue( min );
mDoubleSpinBox->setValue( minval );
mDoubleSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}
mDoubleSpinBox->setMinimum( min );
mDoubleSpinBox->setMaximum( config( "Max" ).toDouble() );
mDoubleSpinBox->setSingleStep( step );
if ( min.isValid() )
mDoubleSpinBox->setMinimum( min.toDouble() );
if ( max.isValid() )
mDoubleSpinBox->setMaximum( max.toDouble() );
if ( step.isValid() )
mDoubleSpinBox->setSingleStep( step.toDouble() );
if ( config( "Suffix" ).isValid() )
{
mDoubleSpinBox->setSuffix( config( "Suffix" ).toString() );
}
connect( mDoubleSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( valueChanged( double ) ) );
}
if ( mIntSpinBox )
{
int min = config( "Min" ).toInt();
int step = config( "Step" ).toInt();
int minval = min.toInt();
int stepval = step.toInt();
QgsSpinBox* qgsWidget = dynamic_cast<QgsSpinBox*>( mIntSpinBox );
if ( qgsWidget )
qgsWidget->setShowClearButton( allowNull );
if ( allowNull )
{
min -= step;
mIntSpinBox->setValue( min );
minval -= stepval;
mIntSpinBox->setValue( minval );
mIntSpinBox->setSpecialValueText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}
mIntSpinBox->setMinimum( min );
mIntSpinBox->setMaximum( config( "Max" ).toInt() );
mIntSpinBox->setSingleStep( step );
if ( min.isValid() )
mIntSpinBox->setMinimum( min.toInt() );
if ( max.isValid() )
mIntSpinBox->setMaximum( max.toInt() );
if ( step.isValid() )
mIntSpinBox->setSingleStep( step.toInt() );
if ( config( "Suffix" ).isValid() )
{
mIntSpinBox->setSuffix( config( "Suffix" ).toString() );
}
connect( mIntSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
}
if ( mQgsDial || mQgsSlider )
{
QVariant min( config( "Min" ) );
QVariant max( config( "Max" ) );
QVariant step( config( "Step" ) );
field().convertCompatible( min );
field().convertCompatible( max );
field().convertCompatible( step );
if ( mQgsSlider )
{
mQgsSlider->setMinimum( min );
mQgsSlider->setMaximum( max );
mQgsSlider->setSingleStep( step );
if ( min.isValid() )
mQgsSlider->setMinimum( min );
if ( max.isValid() )
mQgsSlider->setMaximum( max );
if ( step.isValid() )
mQgsSlider->setSingleStep( step );
}
if ( mQgsDial )
{
mQgsDial->setMinimum( min );
mQgsDial->setMaximum( max );
mQgsDial->setSingleStep( step );
if ( min.isValid() )
mQgsDial->setMinimum( min );
if ( max.isValid() )
mQgsDial->setMaximum( max );
if ( step.isValid() )
mQgsDial->setSingleStep( step );
}
connect( editor, SIGNAL( valueChanged( QVariant ) ), this, SLOT( valueChanged( QVariant ) ) );
}
else if ( mDial )
{
mDial->setMinimum( config( "Min" ).toInt() );
mDial->setMaximum( config( "Max" ).toInt() );
mDial->setSingleStep( config( "Step" ).toInt() );
if ( min.isValid() )
mDial->setMinimum( min.toInt() );
if ( max.isValid() )
mDial->setMaximum( max.toInt() );
if ( step.isValid() )
mDial->setSingleStep( step.toInt() );
connect( mDial, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
}
else if ( mSlider )
{
mSlider->setMinimum( config( "Min" ).toInt() );
mSlider->setMaximum( config( "Max" ).toInt() );
mSlider->setSingleStep( config( "Step" ).toInt() );
if ( min.isValid() )
mSlider->setMinimum( min.toInt() );
if ( max.isValid() )
mSlider->setMaximum( max.toInt() );
if ( step.isValid() )
mSlider->setSingleStep( step.toInt() );
connect( mSlider, SIGNAL( valueChanged( int ) ), this, SLOT( valueChanged( int ) ) );
}
}
bool QgsRangeWidgetWrapper::valid()
{
return mSlider || mDial || mQgsDial || mQgsSlider || mIntSpinBox || mDoubleSpinBox;
}
void QgsRangeWidgetWrapper::valueChanged( QVariant v )
{
if ( v.type() == QVariant::Int )

View File

@ -50,6 +50,7 @@ class GUI_EXPORT QgsRangeWidgetWrapper : public QgsEditorWidgetWrapper
protected:
virtual QWidget* createWidget( QWidget* parent ) override;
virtual void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
virtual void setValue( const QVariant& value ) override;

View File

@ -99,6 +99,11 @@ QVariant QgsRelationReferenceWidgetWrapper::value()
}
}
bool QgsRelationReferenceWidgetWrapper::valid()
{
return mWidget;
}
void QgsRelationReferenceWidgetWrapper::setValue( const QVariant& val )
{
if ( !mWidget || val == value() )

View File

@ -49,6 +49,7 @@ class GUI_EXPORT QgsRelationReferenceWidgetWrapper : public QgsEditorWidgetWrapp
virtual QWidget* createWidget( QWidget* parent ) override;
virtual void initWidget( QWidget* editor ) override;
virtual QVariant value() override;
bool valid() override;
public slots:
virtual void setValue( const QVariant& value ) override;

View File

@ -73,3 +73,8 @@ void QgsRelationWidgetWrapper::initWidget( QWidget* editor )
mWidget = w;
}
bool QgsRelationWidgetWrapper::valid()
{
return mWidget;
}

View File

@ -30,6 +30,7 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setFeature( const QgsFeature& feature ) override;

View File

@ -130,6 +130,11 @@ void QgsTextEditWrapper::initWidget( QWidget* editor )
}
}
bool QgsTextEditWrapper::valid()
{
return mLineEdit || mTextEdit || mPlainTextEdit;
}
void QgsTextEditWrapper::setValue( const QVariant& val )
{
QString v;

View File

@ -46,6 +46,7 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
protected:
QWidget*createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -100,6 +100,11 @@ void QgsUniqueValuesWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsUniqueValuesWidgetWrapper::valid()
{
return mComboBox || mLineEdit;
}
void QgsUniqueValuesWidgetWrapper::setValue( const QVariant& value )
{
if ( mComboBox )

View File

@ -44,6 +44,7 @@ class GUI_EXPORT QgsUniqueValuesWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -49,6 +49,11 @@ void QgsUuidWidgetWrapper::initWidget( QWidget* editor )
mLineEdit->setEnabled( false );
}
bool QgsUuidWidgetWrapper::valid()
{
return mLineEdit || mLabel;
}
void QgsUuidWidgetWrapper::setValue( const QVariant& value )
{
if ( value.isNull() )

View File

@ -41,6 +41,7 @@ class GUI_EXPORT QgsUuidWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -88,3 +88,10 @@ QString QgsValueMapWidgetFactory::representValue( QgsVectorLayer* vl, int fieldI
return config.key( value, QVariant( QString( "(%1)" ).arg( value.toString() ) ).toString() );
}
QMap<const char*, int> QgsValueMapWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
map.insert( QComboBox::staticMetaObject.className(), 10 );
return map;
}

View File

@ -31,6 +31,7 @@ class GUI_EXPORT QgsValueMapWidgetFactory : public QgsEditorWidgetFactory
QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ) override;
void writeConfig( const QgsEditorWidgetConfig& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx ) override;
QString representValue( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config, const QVariant& cache, const QVariant& value ) const override;
virtual QMap<const char*, int> supportedWidgetTypes() override;
};
#endif // QGSVALUEMAPWIDGETFACTORY_H

View File

@ -55,6 +55,11 @@ void QgsValueMapWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsValueMapWidgetWrapper::valid()
{
return mComboBox;
}
void QgsValueMapWidgetWrapper::setValue( const QVariant& value )
{
if ( mComboBox )

View File

@ -46,6 +46,7 @@ class GUI_EXPORT QgsValueMapWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -25,7 +25,7 @@
#include <QCompleter>
bool QgsValueRelationWidgetWrapper::orderByKeyLessThan( const QgsValueRelationWidgetWrapper::ValueRelationItem& p1
, const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 )
, const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 )
{
switch ( p1.first.type() )
{
@ -44,7 +44,7 @@ bool QgsValueRelationWidgetWrapper::orderByKeyLessThan( const QgsValueRelationWi
}
bool QgsValueRelationWidgetWrapper::orderByValueLessThan( const QgsValueRelationWidgetWrapper::ValueRelationItem& p1
, const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 )
, const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 )
{
return p1.second < p2.second;
}
@ -164,6 +164,11 @@ void QgsValueRelationWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsValueRelationWidgetWrapper::valid()
{
return mListWidget || mLineEdit || mComboBox;
}
void QgsValueRelationWidgetWrapper::setValue( const QVariant& value )
{
if ( mListWidget )

View File

@ -55,9 +55,9 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
public:
explicit QgsValueRelationWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor = 0, QWidget* parent = 0 );
static bool orderByKeyLessThan( const QgsValueRelationWidgetWrapper::ValueRelationItem& p1 ,
const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 );
const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 );
static bool orderByValueLessThan( const QgsValueRelationWidgetWrapper::ValueRelationItem& p1 ,
const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 );
const QgsValueRelationWidgetWrapper::ValueRelationItem& p2 );
@ -70,6 +70,7 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;

View File

@ -121,6 +121,11 @@ void QgsWebViewWidgetWrapper::initWidget( QWidget* editor )
}
}
bool QgsWebViewWidgetWrapper::valid()
{
return mWebView || mButton || mLineEdit;
}
void QgsWebViewWidgetWrapper::setValue( const QVariant& value )
{
if ( mLineEdit )

View File

@ -41,6 +41,7 @@ class GUI_EXPORT QgsWebViewWidgetWrapper : public QgsEditorWidgetWrapper
protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
bool valid() override;
public slots:
void setValue( const QVariant& value ) override;