コード例 #1
0
ファイル: qgsdelimitedtextfile.cpp プロジェクト: paulfab/QGIS
QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
    mFileName( QString() ),
    mEncoding( "UTF-8" ),
    mFile( 0 ),
    mStream( 0 ),
    mUseWatcher( true ),
    mWatcher( 0 ),
    mDefinitionValid( false ),
    mUseHeader( true ),
    mDiscardEmptyFields( false ),
    mTrimFields( false ),
    mSkipLines( 0 ),
    mMaxFields( 0 ),
    mMaxNameLength( 200 ), // Don't want field names to be too unweildy!
    mAnchoredRegexp( false ),
    mLineNumber( -1 ),
    mRecordLineNumber( -1 ),
    mRecordNumber( -1 ),
    mHoldCurrentRecord( false ),
    mMaxRecordNumber( -1 ),
    mMaxFieldCount( 0 ),
    mDefaultFieldName( "field_%1" ),
    // field_ is optional in following regexp to simplify QgsDelimitedTextFile::fieldNumber()
    mDefaultFieldRegexp( "^(?:field_)?(\\d+)$", Qt::CaseInsensitive )
{
  // The default type is CSV
  setTypeCSV();
  if ( ! url.isNull() ) setFromUrl( url );
}
コード例 #2
0
QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
    mFileName( QString() ),
    mEncoding( "UTF-8" ),
    mFile( 0 ),
    mStream( 0 ),
    mUseWatcher( true ),
    mWatcher( 0 ),
    mDefinitionValid( false ),
    mUseHeader( true ),
    mDiscardEmptyFields( false ),
    mTrimFields( false ),
    mSkipLines( 0 ),
    mMaxFields( 0 ),
    mMaxNameLength( 200 ),  // Don't want field names to be too unweildy!
    mLineNumber( -1 ),
    mRecordLineNumber( -1 ),
    mRecordNumber( -1 ),
    mHoldCurrentRecord( false ),
    mMaxRecordNumber( -1 ),
    mMaxFieldCount( 0 )
{
  // The default type is CSV
  setTypeCSV();
  if ( ! url.isNull() ) setFromUrl( url );
}
コード例 #3
0
QgsDelimitedTextFile::QgsDelimitedTextFile( const QString &url )
  : mFileName( QString() )
  , mEncoding( QStringLiteral( "UTF-8" ) )
  , mDefaultFieldName( QStringLiteral( "field_%1" ) )
  , mDefaultFieldRegexp( "^(?:field_)(\\d+)$", Qt::CaseInsensitive )
{
  // The default type is CSV
  setTypeCSV();
  if ( ! url.isNull() ) setFromUrl( url );
}
コード例 #4
0
ファイル: qgsdelimitedtextfile.cpp プロジェクト: CS-SI/QGIS
QgsDelimitedTextFile::QgsDelimitedTextFile( const QString &url )
  : mFileName( QString() )
  , mEncoding( QStringLiteral( "UTF-8" ) )
  , mDefaultFieldName( QStringLiteral( "field_%1" ) )
    // field_ is optional in following regexp to simplify QgsDelimitedTextFile::fieldNumber()
  , mDefaultFieldRegexp( "^(?:field_)?(\\d+)$", Qt::CaseInsensitive )
{
  // The default type is CSV
  setTypeCSV();
  if ( ! url.isNull() ) setFromUrl( url );
}
コード例 #5
0
QgsDelimitedTextFile::QgsDelimitedTextFile( QString url ) :
    mFileName( QString() ),
    mEncoding( "UTF-8" ),
    mFile( 0 ),
    mStream( 0 ),
    mDefinitionValid( false ),
    mUseHeader( true ),
    mDiscardEmptyFields( false ),
    mTrimFields( false ),
    mSkipLines( 0 ),
    mMaxFields( 0 ),
    mLineNumber( 0 ),
    mRecordLineNumber( 0 )
{
  // The default type is CSV
  setTypeCSV();
  if ( ! url.isNull() ) setFromUrl( url );
}
コード例 #6
0
ファイル: qgsdelimitedtextfile.cpp プロジェクト: paulfab/QGIS
// Extract the provider definition from the url
bool QgsDelimitedTextFile::setFromUrl( const QUrl &url )
{
  // Close any existing definition
  resetDefinition();

  // Extract the file name
  setFileName( url.toLocalFile() );

  // Extract the encoding
  if ( url.hasQueryItem( "encoding" ) )
  {
    mEncoding = url.queryItemValue( "encoding" );
  }

  //
  if ( url.hasQueryItem( "useWatcher" ) )
  {
    mUseWatcher = ! url.queryItemValue( "useWatcher" ).toUpper().startsWith( 'N' );
  }

  // The default type is csv, to be consistent with the
  // previous implementation (except that quoting should be handled properly)

  QString type( "csv" );
  QString delimiter( "," );
  QString quote = "\"";
  QString escape = "\"";
  mUseHeader = true;
  mSkipLines = 0;

  // Prefer simple "type" for delimiter type, but include delimiterType
  // as optional name  for backwards compatibility
  if ( url.hasQueryItem( "type" ) || url.hasQueryItem( "delimiterType" ) )
  {
    if ( url.hasQueryItem( "type" ) )
      type = url.queryItemValue( "type" );
    else if ( url.hasQueryItem( "delimiterType" ) )
      type = url.queryItemValue( "delimiterType" );

    // Support for previous version of Qgs - plain chars had
    // quote characters ' or "
    if ( type == "plain" )
    {
      quote = "'\"";
      escape = "";
    }
    else if ( type == "regexp " )
    {
      delimiter = "";
      quote = "";
      escape = "";
    }
  }
  if ( url.hasQueryItem( "delimiter" ) )
  {
    delimiter = url.queryItemValue( "delimiter" );
  }
  if ( url.hasQueryItem( "quote" ) )
  {
    quote = url.queryItemValue( "quote" );
  }
  if ( url.hasQueryItem( "escape" ) )
  {
    escape = url.queryItemValue( "escape" );
  }
  if ( url.hasQueryItem( "skipLines" ) )
  {
    mSkipLines = url.queryItemValue( "skipLines" ).toInt();
  }
  if ( url.hasQueryItem( "useHeader" ) )
  {
    mUseHeader = ! url.queryItemValue( "useHeader" ).toUpper().startsWith( 'N' );
  }
  if ( url.hasQueryItem( "skipEmptyFields" ) )
  {
    mDiscardEmptyFields = ! url.queryItemValue( "skipEmptyFields" ).toUpper().startsWith( 'N' );
  }
  if ( url.hasQueryItem( "trimFields" ) )
  {
    mTrimFields = ! url.queryItemValue( "trimFields" ).toUpper().startsWith( 'N' );
  }
  if ( url.hasQueryItem( "maxFields" ) )
  {
    mMaxFields = url.queryItemValue( "maxFields" ).toInt();
  }

  QgsDebugMsg( "Delimited text file is: " + mFileName );
  QgsDebugMsg( "Encoding is: " + mEncoding );
  QgsDebugMsg( "Delimited file type is: " + type );
  QgsDebugMsg( "Delimiter is: [" + delimiter + "]" );
  QgsDebugMsg( "Quote character is: [" + quote + "]" );
  QgsDebugMsg( "Escape character is: [" + escape + "]" );
  QgsDebugMsg( "Skip lines: " + QString::number( mSkipLines ) );
  QgsDebugMsg( "Maximum number of fields in record: " + QString::number( mMaxFields ) );
  QgsDebugMsg( "Use headers: " + QString( mUseHeader ? "Yes" : "No" ) );
  QgsDebugMsg( "Discard empty fields: " + QString( mDiscardEmptyFields ? "Yes" : "No" ) );
  QgsDebugMsg( "Trim fields: " + QString( mTrimFields ? "Yes" : "No" ) );

  // Support for previous version of plain characters
  if ( type == "csv" || type == "plain" )
  {
    setTypeCSV( delimiter, quote, escape );
  }
  else if ( type == "whitespace" )
  {
    setTypeWhitespace();
  }
  else if ( type == "regexp" )
  {
    setTypeRegexp( delimiter );
  }
  else
  {
    return false;
  }
  return mDefinitionValid;
}