Skip to content
Permalink
Browse files

Fix crash and add CheckBox support for autocreate editorwidgets

Followup de547ad
  • Loading branch information
m-kuhn committed Jul 27, 2015
1 parent 10d262f commit f899f539db0481383fa158552675016691d089b5
@@ -100,7 +100,7 @@ QgsEditorWidgetWrapper* QgsEditorWidgetRegistry::create( const QString& widgetId
if ( !ww->valid() )
{
delete ww;
QString wid = findSuitableWrapper( editor );
QString wid = findSuitableWrapper( editor, "TextEdit" );
ww = mWidgetFactories[wid]->create( vl, fieldIdx, editor, parent );
ww->setConfig( config );
ww->setContext( context );
@@ -186,7 +186,7 @@ bool QgsEditorWidgetRegistry::registerWidget( const QString& widgetId, QgsEditor
{
if ( it.value() > mFactoriesByType[it.key()].first )
{
mFactoriesByType[it.key()] = qMakePair( it.value(), widgetFactory );
mFactoriesByType[it.key()] = qMakePair( it.value(), widgetId );
}
}

@@ -343,9 +343,9 @@ void QgsEditorWidgetRegistry::writeSymbology( QDomElement& element, QDomDocument
writeMapLayer( vl, element, doc );
}

QString QgsEditorWidgetRegistry::findSuitableWrapper( QWidget* editor )
QString QgsEditorWidgetRegistry::findSuitableWrapper( QWidget* editor, const QString& defaultWidget )
{
QMap<const char*, QPair<int, QgsEditorWidgetFactory*> >::ConstIterator it;
QMap<const char*, QPair<int, QString> >::ConstIterator it;

QString widgetid;
int weight = 0;
@@ -356,18 +356,20 @@ QString QgsEditorWidgetRegistry::findSuitableWrapper( QWidget* editor )
if ( editor->staticMetaObject.className() == it.key() )
{
// if it's a perfect match: return it directly
return it.value().second->name();
return it.value().second;
}
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();
widgetid = it.value().second;
}
}
}

if ( widgetid.isNull() )
widgetid = defaultWidget;
return widgetid;
}
@@ -193,10 +193,10 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
void writeSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage );

private:
QString findSuitableWrapper( QWidget* editor );
QString findSuitableWrapper( QWidget* editor , const QString& defaultWidget );

QMap<QString, QgsEditorWidgetFactory*> mWidgetFactories;
QMap<const char*, QPair<int, QgsEditorWidgetFactory*> > mFactoriesByType;
QMap<const char*, QPair<int, QString> > mFactoriesByType;
};

#endif // QGSEDITORWIDGETREGISTRY_H
@@ -55,3 +55,11 @@ void QgsCheckboxWidgetFactory::writeConfig( const QgsEditorWidgetConfig& config,
configElement.setAttribute( "CheckedState", config.value( "CheckedState", "1" ).toString() );
configElement.setAttribute( "UncheckedState", config.value( "UncheckedState", "0" ).toString() );
}

QMap<const char*, int> QgsCheckboxWidgetFactory::supportedWidgetTypes()
{
QMap<const char*, int> map = QMap<const char*, int>();
map.insert( QCheckBox::staticMetaObject.className(), 10 );
map.insert( QGroupBox::staticMetaObject.className(), 10 );
return map;
}
@@ -29,6 +29,7 @@ class GUI_EXPORT QgsCheckboxWidgetFactory : public QgsEditorWidgetFactory
QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const override;
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;
QMap<const char*, int> supportedWidgetTypes();
};

#endif // QGSCHECKBOXWIDGETFACTORY_H

0 comments on commit f899f53

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