Exemplo n.º 1
0
void QgsSaveStyleToDbDialog::mFilePickButton_clicked()
{
  QgsSettings myQSettings;  // where we keep last used filter in persistent state
  QString myLastUsedDir = myQSettings.value( QStringLiteral( "style/lastStyleDir" ), QDir::homePath() ).toString();

  QString myFileName = QFileDialog::getOpenFileName( this, tr( "Attach Qt Designer UI File" ), myLastUsedDir, tr( "Qt Designer UI file .ui" ) + " (*.ui)" );
  if ( myFileName.isNull() )
  {
    return;
  }
  QFileInfo myFI( myFileName );
  QFile uiFile( myFI.filePath() );

  QString myPath = myFI.path();
  myQSettings.setValue( QStringLiteral( "style/lastStyleDir" ), myPath );

  if ( uiFile.open( QIODevice::ReadOnly ) )
  {
    QString content( uiFile.readAll() );
    QDomDocument doc;

    if ( !doc.setContent( content ) || doc.documentElement().tagName().compare( QLatin1String( "ui" ) ) )
    {
      QMessageBox::warning( this, tr( "Attach UI File" ),
                            tr( "The selected file does not appear to be a valid Qt Designer UI file." ) );
      return;
    }
    mUIFileContent = content;
    mFileNameLabel->setText( myFI.fileName() );
  }
}
Exemplo n.º 2
0
void QgsSpatiaLiteSourceSelect::on_btnNew_clicked()
{
// Retrieve last used project dir from persistent settings
  sqlite3 *handle;
  QSettings settings;
  QString lastUsedDir = settings.value( "/UI/lastSpatiaLiteDir", "." ).toString();

  QString myFile = QFileDialog::getOpenFileName( this,
                   tr( "Choose a SpatiaLite/SQLite DB to open" ),
                   lastUsedDir, QObject::tr( "SQLite DB (*.sqlite *.db);;All files (*)" ) );

  if ( myFile.isEmpty() )
    return;

  QFileInfo myFI( myFile );
  QString myPath = myFI.path();
  QString myName = myFI.fileName();

  handle = openSpatiaLiteDb( myFI.canonicalFilePath() );
  if ( !handle )
    return;

  // OK, this one is a valid SpatiaLite DB
  closeSpatiaLiteDb( handle );

  // Persist last used SpatiaLite dir
  settings.setValue( "/UI/lastSpatiaLiteDir", myPath );
  // inserting this SQLite DB path
  QString baseKey = "/SpatiaLite/connections/";
  settings.setValue( baseKey + "selected", myName );
  baseKey += myName;
  settings.setValue( baseKey + "/sqlitepath", myFI.canonicalFilePath() );

  populateConnectionList();
}
Exemplo n.º 3
0
bool FileSystem::fileExists(const QString& filename, const QFileInfo& fileInfo)
{
#ifdef Q_OS_WIN
    if (isLnkFile(filename)) {
        // Use a native check.
        return fileExistsWin(filename);
    }
#endif
    bool re = fileInfo.exists();
    // if the filename is different from the filename in fileInfo, the fileInfo is
    // not valid. There needs to be one initialised here. Otherwise the incoming
    // fileInfo is re-used.
    if( fileInfo.filePath() != filename ) {
        QFileInfo myFI(filename);
        re = myFI.exists();
    }
    return re;
}
void QgsMapLayerStyleManagerWidget::loadStyle()
{
  QgsSettings myQSettings;  // where we keep last used filter in persistent state
  QString myLastUsedDir = myQSettings.value( QStringLiteral( "style/lastStyleDir" ), QDir::homePath() ).toString();

  QString myFileName = QFileDialog::getOpenFileName( this, tr( "Load layer properties from style file" ), myLastUsedDir,
                       tr( "QGIS Layer Style File" ) + " (*.qml);;" + tr( "SLD File" ) + " (*.sld)" );
  if ( myFileName.isNull() )
  {
    return;
  }

  QString myMessage;
  bool defaultLoadedFlag = false;

  if ( myFileName.endsWith( QLatin1String( ".sld" ), Qt::CaseInsensitive ) )
  {
    // load from SLD
    myMessage = mLayer->loadSldStyle( myFileName, defaultLoadedFlag );
  }
  else
  {
    myMessage = mLayer->loadNamedStyle( myFileName, defaultLoadedFlag );
  }
  //reset if the default style was loaded OK only
  if ( defaultLoadedFlag )
  {
    emit widgetChanged();
  }
  else
  {
    //let the user know what went wrong
    QMessageBox::warning( this, tr( "Load Style" ), myMessage );
  }

  QFileInfo myFI( myFileName );
  QString myPath = myFI.path();
  myQSettings.setValue( QStringLiteral( "style/lastStyleDir" ), myPath );

}
Exemplo n.º 5
0
void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
{
  QSettings myQSettings;  // where we keep last used filter in persistent state
  QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();

  QString myFileName = QFileDialog::getOpenFileName( this, tr( "Load layer properties from style file" ), myLastUsedDir,
                       tr( "QGIS Layer Style File" ) + " (*.qml);;" + tr( "SLD File" ) + " (*.sld)" );
  if ( myFileName.isNull() )
  {
    return;
  }

  QString myMessage;
  bool defaultLoadedFlag = false;

  if ( myFileName.endsWith( ".sld", Qt::CaseInsensitive ) )
  {
    // load from SLD
    myMessage = layer->loadSldStyle( myFileName, defaultLoadedFlag );
  }
  else
  {
    myMessage = layer->loadNamedStyle( myFileName, defaultLoadedFlag );
  }
  //reset if the default style was loaded ok only
  if ( defaultLoadedFlag )
  {
    reset();
  }
  else
  {
    //let the user know what went wrong
    QMessageBox::information( this, tr( "Load Style" ), myMessage );
  }

  QFileInfo myFI( myFileName );
  QString myPath = myFI.path();
  myQSettings.setValue( "style/lastStyleDir", myPath );
}
Exemplo n.º 6
0
void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
{
  QSettings myQSettings;  // where we keep last used filter in persistent state
  QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();

  QString format, extension;
  if ( styleType == SLD )
  {
    format = tr( "SLD File" ) + " (*.sld)";
    extension = ".sld";
  }
  else
  {
    format =  tr( "QGIS Layer Style File" ) + " (*.qml)";
    extension = ".qml";
  }

  QString myOutputFileName = QFileDialog::getSaveFileName( this, tr( "Save layer properties as style file" ),
                             myLastUsedDir, format );
  if ( myOutputFileName.isNull() ) //dialog canceled
  {
    return;
  }

  apply(); // make sure the style to save is uptodate

  QString myMessage;
  bool defaultLoadedFlag = false;

  //ensure the user never omitted the extension from the file name
  if ( !myOutputFileName.endsWith( extension, Qt::CaseInsensitive ) )
  {
    myOutputFileName += extension;
  }

  if ( styleType == SLD )
  {
    // convert to SLD
    myMessage = layer->saveSldStyle( myOutputFileName, defaultLoadedFlag );
  }
  else
  {
    myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
  }

  //reset if the default style was loaded ok only
  if ( defaultLoadedFlag )
  {
    reset();
  }
  else
  {
    //let the user know what went wrong
    QMessageBox::information( this, tr( "Saved Style" ), myMessage );
  }

  QFileInfo myFI( myOutputFileName );
  QString myPath = myFI.path();
  // Persist last used dir
  myQSettings.setValue( "style/lastStyleDir", myPath );
}
Exemplo n.º 7
0
bool QgsSpatiaLiteSourceSelect::getTableInfo( sqlite3 * handle )
{
  int ret;
  int i;
  char **results;
  int rows;
  int columns;
  char *errMsg = NULL;
  bool ok = false;
  char sql[1024];
  QApplication::setOverrideCursor( Qt::WaitCursor );

  // setting the SQLite DB name
  QFileInfo myFI( mSqlitePath );
  QString myName = myFI.fileName();
  mTableModel.setSqliteDb( myName );

  // the following query return the tables containing a Geometry column
  strcpy( sql, "SELECT f_table_name, f_geometry_column, type " );
  strcat( sql, "FROM geometry_columns" );
  ret = sqlite3_get_table( handle, sql, &results, &rows, &columns, &errMsg );
  if ( ret != SQLITE_OK )
    goto error;
  if ( rows < 1 )
    ;
  else
  {
    for ( i = 1; i <= rows; i++ )
    {
      if ( isRasterlite1Datasource( handle, results[( i * columns ) + 0] ) )
        continue;
      QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
      QString column = QString::fromUtf8( results[( i * columns ) + 1] );
      QString type = results[( i * columns ) + 2];
      if ( isDeclaredHidden( handle, tableName, column ) )
        continue;

      mTableModel.addTableEntry( type, tableName, column, "" );
    }
    ok = true;
  }
  sqlite3_free_table( results );

  if ( checkViewsGeometryColumns( handle ) )
  {
    // the following query return the views supporting a Geometry column
    strcpy( sql, "SELECT view_name, view_geometry, type " );
    strcat( sql, "FROM views_geometry_columns " );
    strcat( sql, "JOIN geometry_columns USING (f_table_name, f_geometry_column)" );
    ret = sqlite3_get_table( handle, sql, &results, &rows, &columns, &errMsg );
    if ( ret != SQLITE_OK )
      goto error;
    if ( rows < 1 )
      ;
    else
    {
      for ( i = 1; i <= rows; i++ )
      {
        QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
        QString column = QString::fromUtf8( results[( i * columns ) + 1] );
        QString type = results[( i * columns ) + 2];
        if ( isDeclaredHidden( handle, tableName, column ) )
          continue;

        mTableModel.addTableEntry( type, tableName, column, "" );
      }
      ok = true;
    }
    sqlite3_free_table( results );
  }

  if ( checkVirtsGeometryColumns( handle ) )
  {
    // the following query return the VirtualShapefiles
    strcpy( sql, "SELECT virt_name, virt_geometry, type " );
    strcat( sql, "FROM virts_geometry_columns" );
    ret = sqlite3_get_table( handle, sql, &results, &rows, &columns, &errMsg );
    if ( ret != SQLITE_OK )
      goto error;
    if ( rows < 1 )
      ;
    else
    {
      for ( i = 1; i <= rows; i++ )
      {
        QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
        QString column = QString::fromUtf8( results[( i * columns ) + 1] );
        QString type = results[( i * columns ) + 2];
        if ( isDeclaredHidden( handle, tableName, column ) )
          continue;

        mTableModel.addTableEntry( type, tableName, column, "" );
      }
      ok = true;
    }
    sqlite3_free_table( results );
  }

  QApplication::restoreOverrideCursor();
  return ok;

error:
  // unexpected IO error
  QString errCause = tr( "unknown error cause" );
  if ( errMsg != NULL )
  {
    errCause = errMsg;
    sqlite3_free( errMsg );
  }
  QMessageBox::critical( this, tr( "SpatiaLite getTableInfo Error" ),
                         tr( "Failure exploring tables from: %1\n\n%2" ).arg( mSqlitePath ).arg( errCause ) );
  return false;
}