コード例 #1
0
ファイル: qgsgrassnewmapset.cpp プロジェクト: nbozon/QGIS
void QgsGrassNewMapset::databaseChanged()
{
    QgsDebugMsg( "entered." );
    // TODO: reset next tabs
    //
    QSettings settings;
    settings.setValue( "/GRASS/lastGisdbase", mDatabaseLineEdit->text() );

    button( QWizard::NextButton )->setEnabled( false );
    setError( mDatabaseErrorLabel, "" );

    QString database = mDatabaseLineEdit->text().trimmed();

    if ( database.length() == 0 )
    {
        setError( mDatabaseErrorLabel, tr( "Enter path to GRASS database" ) );
        return;
    }

    QFileInfo databaseInfo( mDatabaseLineEdit->text() );

    if ( !databaseInfo.exists() )
    {
        setError( mDatabaseErrorLabel, tr( "The directory doesn't exist!" ) );
        return;
    }

    // Check if at least one writable location exists or
    // database is writable
    bool locationExists = false;
    QDir d( mDatabaseLineEdit->text() );
    for ( unsigned int i = 0; i < d.count(); i++ )
    {
        if ( d[i] == "." || d[i] == ".." )
            continue;

        QString windName = mDatabaseLineEdit->text() + "/" + d[i] + "/PERMANENT/DEFAULT_WIND";
        QString locationName = mDatabaseLineEdit->text() + "/" + d[i];
        QFileInfo locationInfo( locationName );

        if ( QFile::exists( windName ) && locationInfo.isWritable() )
        {
            locationExists = true;
            break;
        }
    }

    if ( locationExists || databaseInfo.isWritable() )
    {
        button( QWizard::NextButton )->setEnabled( true );
    }
    else
    {
        setError( mDatabaseErrorLabel, tr( "No writable locations, the database is not writable!" ) );
    }
}
コード例 #2
0
void QgsGrassNewMapset::databaseChanged()
{
  QgsDebugMsg( "entered" );

  QSettings settings;
  settings.setValue( "/GRASS/lastGisdbase", mDatabaseLineEdit->text() );

  button( QWizard::NextButton )->setEnabled( false );
  setError( mDatabaseErrorLabel );

  if ( gisdbase().isEmpty() )
  {
    //setError( mDatabaseErrorLabel, tr( "Enter path to GRASS database" ) );
    button( QWizard::NextButton )->setEnabled( false );
    return;
  }
  button( QWizard::NextButton )->setEnabled( true );

  if ( !gisdbaseExists() )
  {
    // Do not warn, it may be default $HOME/grassdata, if does not exist, it will be created on finish
    //setError( mDatabaseErrorLabel, tr( "The directory doesn't exist!" ) );
    //return;
  }
  else
  {
    // Check if at least one writable location exists or database is writable
    bool locationExists = false;
    QDir dir( gisdbase() );
    for ( unsigned int i = 0; i < dir.count(); i++ )
    {
      if ( dir[i] == "." || dir[i] == ".." )
        continue;

      QString windName = gisdbase() + "/" + dir[i] + "/PERMANENT/DEFAULT_WIND";
      QString locationName = gisdbase() + "/" + dir[i];
      QFileInfo locationInfo( locationName );

      if ( QFile::exists( windName ) && locationInfo.isWritable() )
      {
        locationExists = true;
        break;
      }
    }

    QFileInfo gisdbaseInfo( gisdbase() );
    if ( locationExists || gisdbaseInfo.isWritable() )
    {
      button( QWizard::NextButton )->setEnabled( true );
    }
    else
    {
      setError( mDatabaseErrorLabel, tr( "No writable locations, the database is not writable!" ) );
    }
  }
}
コード例 #3
0
void QgsGrassNewMapset::setLocations()
{
  QgsDebugMsg( "entered" );

  mLocationComboBox->clear();

  QSettings settings;
  QString lastLocation = settings.value( "/GRASS/lastLocation" ).toString();

  if ( gisdbaseExists() )
  {
    // Get available locations with write permissions
    QDir gisdbaseDir( gisdbase() );

    // Add all subdirs containing PERMANENT/DEFAULT_WIND
    int idx = 0;
    int sel = -1;
    for ( unsigned int i = 0; i < gisdbaseDir.count(); i++ )
    {
      if ( gisdbaseDir[i] == "." || gisdbaseDir[i] == ".." )
        continue;

      QString windName = mDatabaseLineEdit->text() + "/" + gisdbaseDir[i] + "/PERMANENT/DEFAULT_WIND";
      QString locationName = mDatabaseLineEdit->text() + "/" + gisdbaseDir[i];
      QFileInfo locationInfo( locationName );

      if ( QFile::exists( windName ) && locationInfo.isWritable() )
      {
        mLocationComboBox->insertItem( -1, QString( gisdbaseDir[i] ) );
        if ( QString( gisdbaseDir[i] ) == lastLocation )
        {
          sel = idx;
        }
        idx++;
      }
    }
    if ( sel >= 0 )
    {
      mLocationComboBox->setCurrentIndex( sel );
    }
  }

  if ( mLocationComboBox->count() == 0 )
  {
    mCreateLocationRadioButton->setChecked( true );
    mSelectLocationRadioButton->setEnabled( false );
  }
  else
  {
    mSelectLocationRadioButton->setEnabled( true );
  }

  locationRadioSwitched(); // calls also checkLocation()
}