Пример #1
0
void QgsStyleManagerDialog::addItem()
{
  bool changed = false;
  if ( currentItemType() < 3 )
  {
    changed = addSymbol();
  }
  else if ( currentItemType() == 3 )
  {
    changed = addColorRamp();
  }
  else
  {
    Q_ASSERT( 0 && "not implemented" );
  }

  if ( changed )
  {
    populateList();
    populateTypes();
  }
}
Пример #2
0
bool QgsStyleManagerDialog::addColorRamp()
{
  return addColorRamp( nullptr );
}
Пример #3
0
bool QgsStyleV2::load( QString filename )
{
  mErrorString = QString();

  // import xml file
  QDomDocument doc( "style" );
  QFile f( filename );
  if ( !f.open( QFile::ReadOnly ) )
  {
    mErrorString = "Couldn't open the style file: " + filename;
    return false;
  }

  // parse the document
  if ( !doc.setContent( &f ) )
  {
    mErrorString = "Couldn't parse the style file: " + filename;
    f.close();
    return false;
  }
  f.close();

  QDomElement docElem = doc.documentElement();
  if ( docElem.tagName() != "qgis_style" )
  {
    mErrorString = "Incorrect root tag in style: " + docElem.tagName();
    return false;
  }

  // check for style version
  QString version = docElem.attribute( "version" );
  if ( version != STYLE_CURRENT_VERSION )
  {
    mErrorString = "Unknown style file version: " + version;
    return false;
  }

  // load symbols
  QDomElement symbolsElement = docElem.firstChildElement( "symbols" );
  if ( !symbolsElement.isNull() )
  {
    mSymbols = QgsSymbolLayerV2Utils::loadSymbols( symbolsElement );
  }

  // load color ramps
  QDomElement rampsElement = docElem.firstChildElement( "colorramps" );
  QDomElement e = rampsElement.firstChildElement();
  while ( !e.isNull() )
  {
    if ( e.tagName() == "colorramp" )
    {
      QgsVectorColorRampV2* ramp = QgsSymbolLayerV2Utils::loadColorRamp( e );
      if ( ramp != NULL )
        addColorRamp( e.attribute( "name" ), ramp );
    }
    else
    {
      QgsDebugMsg( "unknown tag: " + e.tagName() );
    }
    e = e.nextSiblingElement();
  }

  mFileName = filename;
  return true;
}