示例#1
0
QgsEditorWidgetConfig QgsValueMapConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  //store data to map
  for ( int i = 0; i < tableWidget->rowCount() - 1; i++ )
  {
    QTableWidgetItem *ki = tableWidget->item( i, 0 );
    QTableWidgetItem *vi = tableWidget->item( i, 1 );

    if ( !ki )
      continue;

    if ( !vi || vi->text().isNull() )
    {
      cfg.insert( ki->text(), ki->text() );
    }
    else
    {
      cfg.insert( vi->text(), ki->text() );
    }
  }

  return cfg;
}
QgsEditorWidgetConfig QgsTextEditConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  cfg.insert( "IsMultiline", mIsMultiline->isChecked() );
  cfg.insert( "UseHtml", mUseHtml->isChecked() );

  return cfg;
}
示例#3
0
QgsEditorWidgetConfig QgsPhotoConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  cfg.insert( "Height", sbWidgetHeight->value() );
  cfg.insert( "Width", sbWidgetWidth->value() );

  return cfg;
}
QgsEditorWidgetConfig QgsTextEditWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  cfg.insert( "IsMultiline", configElement.attribute( "IsMultiline", "0" ) == "1" );
  cfg.insert( "UseHtml", configElement.attribute( "UseHtml", "0" ) == "1" );

  return cfg;
}
QgsEditorWidgetConfig QgsCheckboxWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  cfg.insert( QStringLiteral( "CheckedState" ), configElement.attribute( QStringLiteral( "CheckedState" ) ) );
  cfg.insert( QStringLiteral( "UncheckedState" ), configElement.attribute( QStringLiteral( "UncheckedState" ) ) );

  return cfg;
}
QgsEditorWidgetConfig QgsTextEditWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  cfg.insert( QStringLiteral( "IsMultiline" ), configElement.attribute( QStringLiteral( "IsMultiline" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );
  cfg.insert( QStringLiteral( "UseHtml" ), configElement.attribute( QStringLiteral( "UseHtml" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );

  return cfg;
}
示例#7
0
QgsEditorWidgetConfig QgsPhotoWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  cfg.insert( "Height", configElement.attribute( "Height", 0 ).toInt() );
  cfg.insert( "Width", configElement.attribute( "Width", 0 ).toInt() );

  return cfg;
}
示例#8
0
QgsEditorWidgetConfig QgsDateTimeEditFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer );
  Q_UNUSED( fieldIdx );
  QgsEditorWidgetConfig cfg;

  cfg.insert( "field_format", configElement.attribute( "field_format" ) );
  cfg.insert( "display_format", configElement.attribute( "display_format" ) );
  cfg.insert( "calendar_popup", configElement.attribute( "calendar_popup" ) == "1" );

  return cfg;
}
QgsEditorWidgetConfig QgsDateTimeEditFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer );
  Q_UNUSED( fieldIdx );
  QgsEditorWidgetConfig cfg;

  cfg.insert( QStringLiteral( "field_format" ), configElement.attribute( QStringLiteral( "field_format" ) ) );
  cfg.insert( QStringLiteral( "display_format" ), configElement.attribute( QStringLiteral( "display_format" ) ) );
  cfg.insert( QStringLiteral( "calendar_popup" ), configElement.attribute( QStringLiteral( "calendar_popup" ) ) == QLatin1String( "1" ) );
  cfg.insert( QStringLiteral( "allow_null" ), configElement.attribute( QStringLiteral( "allow_null" ) ) == QLatin1String( "1" ) );

  return cfg;
}
示例#10
0
QgsEditorWidgetConfig QgsRelReferenceConfigDlg::config()
{
  QgsEditorWidgetConfig myConfig;
  myConfig.insert( "AllowNULL", mCbxAllowNull->isChecked() );
  myConfig.insert( "ShowForm", mCbxShowForm->isChecked() );
  myConfig.insert( "Relation", mComboRelation->itemData( mComboRelation->currentIndex() ) );

  QString relName = mComboRelation->itemData( mComboRelation->currentIndex() ).toString();
  QgsRelation relation = QgsProject::instance()->relationManager()->relation( relName );

  if ( relation.isValid() )
  {
    relation.referencedLayer()->setDisplayExpression( mTxtDisplayExpression->text() );
  }

  return myConfig;
}
QgsEditorWidgetConfig QgsUniqueValuesConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  cfg.insert( "Editable", editableUniqueValues->isChecked() );

  return cfg;
}
示例#12
0
QgsEditorWidgetConfig QgsRangeConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  switch ( layer()->fields().at( field() ).type() )
  {
    case QVariant::Int:
    case QVariant::LongLong:
      cfg.insert( "Min", minimumSpinBox->value() );
      cfg.insert( "Max", maximumSpinBox->value() );
      cfg.insert( "Step", stepSpinBox->value() );
      break;

    case QVariant::Double:
      cfg.insert( "Min", minimumDoubleSpinBox->value() );
      cfg.insert( "Max", maximumDoubleSpinBox->value() );
      cfg.insert( "Step", stepDoubleSpinBox->value() );
      break;

    default:
      break;
  }

  cfg.insert( "Style", rangeWidget->itemData( rangeWidget->currentIndex() ).toString() );
  cfg.insert( "AllowNull", allowNullCheckBox->isChecked() );

  if ( suffixLineEdit->text() != "" )
  {
    cfg.insert( "Suffix", suffixLineEdit->text() );
  }

  return cfg;
}
示例#13
0
QgsEditorWidgetConfig QgsRangeWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer );
  Q_UNUSED( fieldIdx );
  QgsEditorWidgetConfig cfg;

  cfg.insert( "Style", configElement.attribute( "Style" ) );
  cfg.insert( "Min", configElement.attribute( "Min" ) );
  cfg.insert( "Max", configElement.attribute( "Max" ) );
  cfg.insert( "Step", configElement.attribute( "Step" ) );
  cfg.insert( "AllowNull", configElement.attribute( "AllowNull" ) == "1" );

  if ( configElement.hasAttribute( "Suffix" ) )
  {
    cfg.insert( "Suffix", configElement.attribute( "Suffix" ) );
  }

  return cfg;
}
QgsEditorWidgetConfig QgsUniqueValueWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  cfg.insert( "Editable", configElement.attribute( "Editable", "0" ) == "1" );

  return cfg;
}
示例#15
0
void TestQgsField::editorWidgetSetup()
{
  QgsField field;
  QgsEditorWidgetConfig config;
  config.insert( QStringLiteral( "a" ), "value_a" );
  const QgsEditorWidgetSetup setup( QStringLiteral( "test" ), config );
  field.setEditorWidgetSetup( setup );

  QCOMPARE( field.editorWidgetSetup().type(), setup.type() );
  QCOMPARE( field.editorWidgetSetup().config(), setup.config() );
}
QgsEditorWidgetConfig QgsValueRelationConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  cfg.insert( QStringLiteral( "Layer" ), mLayerName->currentLayer() ? mLayerName->currentLayer()->id() : QString() );
  cfg.insert( QStringLiteral( "Key" ), mKeyColumn->currentField() );
  cfg.insert( QStringLiteral( "Value" ), mValueColumn->currentField() );
  cfg.insert( QStringLiteral( "AllowMulti" ), mAllowMulti->isChecked() );
  cfg.insert( QStringLiteral( "AllowNull" ), mAllowNull->isChecked() );
  cfg.insert( QStringLiteral( "OrderByValue" ), mOrderByValue->isChecked() );
  cfg.insert( QStringLiteral( "FilterExpression" ), mFilterExpression->toPlainText() );
  cfg.insert( QStringLiteral( "UseCompleter" ), mUseCompleter->isChecked() );

  return cfg;
}
QgsEditorWidgetConfig QgsExternalResourceWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  if ( configElement.hasAttribute( "FileWidgetButton" ) )
    cfg.insert( "FileWidgetButton", configElement.attribute( "FileWidgetButton" ) == "1" );

  if ( configElement.hasAttribute( "FileWidget" ) )
    cfg.insert( "FileWidget", configElement.attribute( "FileWidget" ) == "1" );

  if ( configElement.hasAttribute( "UseLink" ) )
    cfg.insert( "UseLink", configElement.attribute( "UseLink" ) == "1" );

  if ( configElement.hasAttribute( "FullUrl" ) )
    cfg.insert( "FullUrl", configElement.attribute( "FullUrl" ) == "1" );

  if ( configElement.hasAttribute( "DefaultRoot" ) )
    cfg.insert( "DefaultRoot", configElement.attribute( "DefaultRoot" ) );

  if ( configElement.hasAttribute( "RelativeStorage" ) )
  {
    if (( configElement.attribute( "RelativeStorage" ) == "Default" && configElement.hasAttribute( "DefaultRoot" ) ) ||
        configElement.attribute( "RelativeStorage" ) == "Project" )
      cfg.insert( "RelativeStorage" , configElement.attribute( "RelativeStorage" ) );
  }

  if ( configElement.hasAttribute( "DocumentViewer" ) )
    cfg.insert( "DocumentViewer", configElement.attribute( "DocumentViewer" ) );

  if ( configElement.hasAttribute( "FileWidgetFilter" ) )
    cfg.insert( "FileWidgetFilter", configElement.attribute( "FileWidgetFilter" ) );


  cfg.insert( "StorageMode", configElement.attribute( "StorageMode", "Files" ) );

  return cfg;
}
QgsEditorWidgetConfig QgsValueRelationWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  cfg.insert( "Layer", configElement.attribute( "Layer" ) );
  cfg.insert( "Key", configElement.attribute( "Key" ) );
  cfg.insert( "Value", configElement.attribute( "Value" ) );
  cfg.insert( "FilterExpression", configElement.attribute( "FilterExpression" ) );
  cfg.insert( "OrderByValue", configElement.attribute( "OrderByValue" ) );
  cfg.insert( "AllowMulti", configElement.attribute( "AllowMulti" ) );
  cfg.insert( "AllowNull", configElement.attribute( "AllowNull" ) );
  cfg.insert( "UseCompleter", configElement.attribute( "UseCompleter" ) );

  return cfg;
}
示例#19
0
QgsEditorWidgetConfig QgsValueMapWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  QDomNodeList nodes = configElement.elementsByTagName( "value" );

  for ( unsigned int i = 0; i < nodes.length(); ++i )
  {
    QDomElement elem = nodes.at( i ).toElement();
    cfg.insert( elem.attribute( "key" ), elem.attribute( "value" ) );
  }

  return cfg;
}
示例#20
0
const QString QgsLegacyHelpers::convertEditType( QgsVectorLayer::EditType editType, QgsEditorWidgetConfig& cfg, QgsVectorLayer* vl, const QString& name, const QDomElement editTypeElement )
{
  QString widgetType = "TextEdit"; // Fallback

  switch ( editType )
  {
    case QgsVectorLayer::ValueMap:
    {
      widgetType = "ValueMap";
      QDomNodeList valueMapNodes = editTypeElement.childNodes();

      for ( int j = 0; j < valueMapNodes.size(); j++ )
      {
        QDomElement value = valueMapNodes.at( j ).toElement();
        cfg.insert( value.attribute( "key" ), value.attribute( "value" ) );
      }
      break;
    }

    case QgsVectorLayer::EditRange:
    {
      widgetType = "Range";
      cfg.insert( "Style", "Edit" );
      cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
      cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
      cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
      break;
    }

    case QgsVectorLayer::SliderRange:
    {
      widgetType = "SliderRange";
      cfg.insert( "Style", "Slider" );
      cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
      cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
      cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
      break;
    }

    case QgsVectorLayer::DialRange:
    {
      widgetType = "DialRange";
      cfg.insert( "Style", "Dial" );
      cfg.insert( "Min", editTypeElement.attribute( "min" ).toFloat() );
      cfg.insert( "Max", editTypeElement.attribute( "max" ).toFloat() );
      cfg.insert( "Step", editTypeElement.attribute( "step" ).toFloat() );
      break;
    }

    case QgsVectorLayer::CheckBox:
    {
      widgetType = "CheckBox";
      cfg.insert( "CheckedState", editTypeElement.attribute( "checked" ) );
      cfg.insert( "UncheckedState", editTypeElement.attribute( "unchecked" ) );
      break;
    }

    case QgsVectorLayer::ValueRelation:
    {
      widgetType = "ValueRelation";
      cfg.insert( "AllowNull", editTypeElement.attribute( "allowNull" ) == "true" );
      cfg.insert( "OrderByValue", editTypeElement.attribute( "orderByValue" ) == "true" );
      cfg.insert( "AllowMulti", editTypeElement.attribute( "allowMulti", "false" ) == "true" );
      QString filterExpression;
      if ( editTypeElement.hasAttribute( "filterAttributeColumn" ) &&
           editTypeElement.hasAttribute( "filterAttributeValue" ) )
      {
        filterExpression = QString( "\"%1\"='%2'" )
                           .arg( editTypeElement.attribute( "filterAttributeColumn" ) )
                           .arg( editTypeElement.attribute( "filterAttributeValue" ) );
      }
      else
      {
        filterExpression  = editTypeElement.attribute( "filterExpression", QString::null );
      }
      cfg.insert( "FilterExpression", filterExpression );
      cfg.insert( "Layer", editTypeElement.attribute( "layer" ) );
      cfg.insert( "Key", editTypeElement.attribute( "key" ) );
      cfg.insert( "Value", editTypeElement.attribute( "value" ) );

      break;
    }

    case QgsVectorLayer::Calendar:
    {
      widgetType = "DateTime";
      cfg.insert( "display_format", editTypeElement.attribute( "dateFormat" ) );
      cfg.insert( "field_format", "yyyy-mm-dd" );
      break;
    }

    case QgsVectorLayer::Photo:
    {
      widgetType = "Photo";
      cfg.insert( "Width", editTypeElement.attribute( "widgetWidth" ).toInt() );
      cfg.insert( "Height", editTypeElement.attribute( "widgetHeight" ).toInt() );
      break;
    }

    case QgsVectorLayer::WebView:
    {
      widgetType = "WebView";
      cfg.insert( "Width", editTypeElement.attribute( "widgetWidth" ).toInt() );
      cfg.insert( "Height", editTypeElement.attribute( "widgetHeight" ).toInt() );
      break;
    }

    case QgsVectorLayer::Classification:
    {
      widgetType = "Classification";
      break;
    }

    case QgsVectorLayer::FileName:
    {
      widgetType = "FileName";
      break;
    }

    case QgsVectorLayer::Immutable:
    {
      widgetType = "TextEdit";
      cfg.insert( "IsMultiline", false );
      vl->setFieldEditable( vl->pendingFields().fieldNameIndex( name ), false );
      break;
    }

    case QgsVectorLayer::Hidden:
    {
      widgetType = "Hidden";
      break;
    }

    case QgsVectorLayer::LineEdit:
    {
      widgetType = "LineEdit";
      cfg.insert( "IsMultiline", false );
      break;
    }

    case QgsVectorLayer::TextEdit:
    {
      widgetType = "TextEdit";
      cfg.insert( "IsMultiline", true );
      cfg.insert( "UseHtml", false );
      break;
    }

    case QgsVectorLayer::Enumeration:
    {
      widgetType = "Enumeration";
      break;
    }

    case QgsVectorLayer::UniqueValues:
    {
      widgetType = "UniqueValues";
      cfg.insert( "Editable", false );
      break;
    }

    case QgsVectorLayer::UniqueValuesEditable:
    {
      widgetType = "UniqueValues";
      cfg.insert( "Editable", true );
      break;
    }

    case QgsVectorLayer::UuidGenerator:
    {
      widgetType = "UuidGenerator";
      break;
    }

    case QgsVectorLayer::Color:
    {
      widgetType = "Color";
      break;
    }

    case QgsVectorLayer::EditorWidgetV2: // Should not land here
      break;
  }

  return widgetType;
}
示例#21
0
void QgsEditFormConfig::readXml( const QDomNode& node )
{
  QDomNode editFormNode = node.namedItem( "editform" );
  if ( !editFormNode.isNull() )
  {
    QDomElement e = editFormNode.toElement();
    mUiFormPath = QgsProject::instance()->readPath( e.text() );
  }

  QDomNode editFormInitNode = node.namedItem( "editforminit" );
  if ( !editFormInitNode.isNull() )
  {
    mInitFunction = editFormInitNode.toElement().text();
  }

  QDomNode editFormInitCodeSourceNode = node.namedItem( "editforminitcodesource" );
  if ( !editFormInitCodeSourceNode.isNull() || ( !editFormInitCodeSourceNode.isNull() && !editFormInitCodeSourceNode.toElement().text().isEmpty() ) )
  {
    setInitCodeSource( static_cast< QgsEditFormConfig::PythonInitCodeSource >( editFormInitCodeSourceNode.toElement().text().toInt() ) );
  }

  QDomNode editFormInitCodeNode = node.namedItem( "editforminitcode" );
  if ( !editFormInitCodeNode.isNull() )
  {
    setInitCode( editFormInitCodeNode.toElement().text() );
  }

  // Temporary < 2.12 b/w compatibility "dot" support patch
  // @see: https://github.com/qgis/QGIS/pull/2498
  // For b/w compatibility, check if there's a dot in the function name
  // and if yes, transform it in an import statement for the module
  // and set the PythonInitCodeSource to CodeSourceDialog
  int dotPos = mInitFunction.lastIndexOf( '.' );
  if ( dotPos >= 0 ) // It's a module
  {
    setInitCodeSource( QgsEditFormConfig::CodeSourceDialog );
    setInitCode( QString( "from %1 import %2\n" ).arg( mInitFunction.left( dotPos ), mInitFunction.mid( dotPos + 1 ) ) );
    setInitFunction( mInitFunction.mid( dotPos + 1 ) );
  }

  QDomNode editFormInitFilePathNode = node.namedItem( "editforminitfilepath" );
  if ( !editFormInitFilePathNode.isNull() || ( !editFormInitFilePathNode.isNull() && !editFormInitFilePathNode.toElement().text().isEmpty() ) )
  {
    setInitFilePath( QgsProject::instance()->readPath( editFormInitFilePathNode.toElement().text() ) );
  }

  QDomNode fFSuppNode = node.namedItem( "featformsuppress" );
  if ( fFSuppNode.isNull() )
  {
    mSuppressForm = QgsEditFormConfig::SuppressDefault;
  }
  else
  {
    QDomElement e = fFSuppNode.toElement();
    mSuppressForm = static_cast< QgsEditFormConfig::FeatureFormSuppress >( e.text().toInt() );
  }

  // tab display
  QDomNode editorLayoutNode = node.namedItem( "editorlayout" );
  if ( editorLayoutNode.isNull() )
  {
    mEditorLayout = QgsEditFormConfig::GeneratedLayout;
  }
  else
  {
    if ( editorLayoutNode.toElement().text() == "uifilelayout" )
    {
      mEditorLayout = QgsEditFormConfig::UiFileLayout;
    }
    else if ( editorLayoutNode.toElement().text() == "tablayout" )
    {
      mEditorLayout = QgsEditFormConfig::TabLayout;
    }
    else
    {
      mEditorLayout = QgsEditFormConfig::GeneratedLayout;
    }
  }

  // tabs and groups display info
  clearTabs();
  QDomNode attributeEditorFormNode = node.namedItem( "attributeEditorForm" );
  QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();

  for ( int i = 0; i < attributeEditorFormNodeList.size(); i++ )
  {
    QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();

    QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, this );
    addTab( attributeEditorWidget );
  }


  //// TODO: MAKE THIS MORE GENERIC, SO INDIVIDUALL WIDGETS CAN NOT ONLY SAVE STRINGS
  /// SEE QgsEditorWidgetFactory::writeConfig

  QDomElement widgetsElem = node.namedItem( "widgets" ).toElement();

  QDomNodeList widgetConfigsElems = widgetsElem.childNodes();

  for ( int i = 0; i < widgetConfigsElems.size(); ++i )
  {
    QgsEditorWidgetConfig cfg;

    QDomElement wdgElem = widgetConfigsElems.at( i ).toElement();

    QDomElement cfgElem = wdgElem.namedItem( "config" ).toElement();

    for ( int j = 0; j < cfgElem.attributes().size(); ++j )
    {
      QDomAttr attr = cfgElem.attributes().item( j ).toAttr();
      cfg.insert( attr.name(), attr.value() );
    }

    QDomNodeList optionElements = cfgElem.elementsByTagName( "option" );
    for ( int j = 0; j < optionElements.size(); ++j )
    {
      QString key = optionElements.at( j ).toElement().attribute( "key" );
      QString value = optionElements.at( j ).toElement().attribute( "value" );
      cfg.insert( key, value );
    }

    setWidgetConfig( wdgElem.attribute( "name" ), cfg );
  }
  //// END TODO
}
QgsEditorWidgetConfig QgsExternalResourceConfigDlg::config()
{
  QgsEditorWidgetConfig cfg;

  cfg.insert( "FileWidget", mFileWidgetGroupBox->isChecked() );
  cfg.insert( "FileWidgetButton", mFileWidgetButtonGroupBox->isChecked() );
  cfg.insert( "FileWidgetFilter", mFileWidgetFilterLineEdit->text() );

  if ( mUseLink->isChecked() )
  {
    cfg.insert( "UseLink", mUseLink->isChecked() );
    if ( mFullUrl->isChecked() )
      cfg.insert( "FullUrl", mFullUrl->isChecked() );
  }

  if ( !mRootPath->text().isEmpty() )
  {
    cfg.insert( "DefaultRoot", mRootPath->text() );
  }

  // Save Storage Mode
  cfg.insert( "StorageMode", mStorageButtonGroup->checkedId() );

  // Save Relative Paths option
  if ( mRelativeGroupBox->isChecked() )
  {
    cfg.insert( "RelativeStorage", mRelativeButtonGroup->checkedId() );
  }
  else
  {
    cfg.insert( "RelativeStorage", ( int )QgsFileWidget::Absolute );
  }

  if ( mDocumentViewerGroupBox->isChecked() )
  {
    cfg.insert( "DocumentViewer", mDocumentViewerContentComboBox->itemData( mDocumentViewerContentComboBox->currentIndex() ).toInt() );
    cfg.insert( "DocumentViewerHeight", mDocumentViewerHeight->value() );
    cfg.insert( "DocumentViewerWidth", mDocumentViewerWidth->value() );
  }
  else
  {
    cfg.insert( "DocumentViewer", ( int )QgsExternalResourceWidget::NoContent );
  }

  return cfg;
}
QgsEditorWidgetConfig QgsExternalResourceWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
  Q_UNUSED( layer )
  Q_UNUSED( fieldIdx )

  QgsEditorWidgetConfig cfg;

  if ( configElement.hasAttribute( QStringLiteral( "FileWidgetButton" ) ) )
    cfg.insert( QStringLiteral( "FileWidgetButton" ), configElement.attribute( QStringLiteral( "FileWidgetButton" ) ) == QLatin1String( "1" ) );

  if ( configElement.hasAttribute( QStringLiteral( "FileWidget" ) ) )
    cfg.insert( QStringLiteral( "FileWidget" ), configElement.attribute( QStringLiteral( "FileWidget" ) ) == QLatin1String( "1" ) );

  if ( configElement.hasAttribute( QStringLiteral( "UseLink" ) ) )
    cfg.insert( QStringLiteral( "UseLink" ), configElement.attribute( QStringLiteral( "UseLink" ) ) == QLatin1String( "1" ) );

  if ( configElement.hasAttribute( QStringLiteral( "FullUrl" ) ) )
    cfg.insert( QStringLiteral( "FullUrl" ), configElement.attribute( QStringLiteral( "FullUrl" ) ) == QLatin1String( "1" ) );

  if ( configElement.hasAttribute( QStringLiteral( "DefaultRoot" ) ) )
    cfg.insert( QStringLiteral( "DefaultRoot" ), configElement.attribute( QStringLiteral( "DefaultRoot" ) ) );

  if ( configElement.hasAttribute( QStringLiteral( "RelativeStorage" ) ) )
  {
    if (( configElement.attribute( QStringLiteral( "RelativeStorage" ) ).toInt() == QgsFileWidget::RelativeDefaultPath && configElement.hasAttribute( QStringLiteral( "DefaultRoot" ) ) ) ||
        configElement.attribute( QStringLiteral( "RelativeStorage" ) ).toInt() == QgsFileWidget::RelativeProject )
      cfg.insert( QStringLiteral( "RelativeStorage" ) , configElement.attribute( QStringLiteral( "RelativeStorage" ) ).toInt() );
  }

  if ( configElement.hasAttribute( QStringLiteral( "DocumentViewer" ) ) )
    cfg.insert( QStringLiteral( "DocumentViewer" ), configElement.attribute( QStringLiteral( "DocumentViewer" ) ) );

  if ( configElement.hasAttribute( QStringLiteral( "DocumentViewerWidth" ) ) )
    cfg.insert( QStringLiteral( "DocumentViewerWidth" ), configElement.attribute( QStringLiteral( "DocumentViewerWidth" ) ) );

  if ( configElement.hasAttribute( QStringLiteral( "DocumentViewerHeight" ) ) )
    cfg.insert( QStringLiteral( "DocumentViewerHeight" ), configElement.attribute( QStringLiteral( "DocumentViewerHeight" ) ) );

  if ( configElement.hasAttribute( QStringLiteral( "FileWidgetFilter" ) ) )
    cfg.insert( QStringLiteral( "FileWidgetFilter" ), configElement.attribute( QStringLiteral( "FileWidgetFilter" ) ) );


  cfg.insert( QStringLiteral( "StorageMode" ), configElement.attribute( QStringLiteral( "StorageMode" ), QStringLiteral( "Files" ) ) );

  return cfg;
}