Ejemplo n.º 1
0
void BracketedWindow::queryFailed(QString error)
{
    progressStopped(0, 0);

    QMessageBox::critical(this, tr("Error processing query"),
        tr("Could not process query: ") + error,
        QMessageBox::Ok);
}
Ejemplo n.º 2
0
void QgsOfflineEditingPlugin::initGui()
{
  delete mActionConvertProject;

  // Create the action for tool
  mActionConvertProject = new QAction( QIcon( ":/offline_editing/offline_editing_copy.png" ), tr( "Convert to offline project" ), this );
  mActionConvertProject->setObjectName( "mActionConvertProject" );
  // Set the what's this text
  mActionConvertProject->setWhatsThis( tr( "Create offline copies of selected layers and save as offline project" ) );
  // Connect the action to the run
  connect( mActionConvertProject, SIGNAL( triggered() ), this, SLOT( convertProject() ) );
  // Add the icon to the toolbar
  mQGisIface->addDatabaseToolBarIcon( mActionConvertProject );
  mQGisIface->addPluginToDatabaseMenu( tr( "&Offline Editing" ), mActionConvertProject );
  mActionConvertProject->setEnabled( false );

  mActionSynchronize = new QAction( QIcon( ":/offline_editing/offline_editing_sync.png" ), tr( "Synchronize" ), this );
  mActionSynchronize->setObjectName( "mActionSynchronize" );
  mActionSynchronize->setWhatsThis( tr( "Synchronize offline project with remote layers" ) );
  connect( mActionSynchronize, SIGNAL( triggered() ), this, SLOT( synchronize() ) );
  mQGisIface->addDatabaseToolBarIcon( mActionSynchronize );
  mQGisIface->addPluginToDatabaseMenu( tr( "&Offline Editing" ), mActionSynchronize );
  mActionSynchronize->setEnabled( false );

  mOfflineEditing = new QgsOfflineEditing();
  mProgressDialog = new QgsOfflineEditingProgressDialog( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );

  connect( mOfflineEditing, SIGNAL( progressStarted() ), this, SLOT( showProgress() ) );
  connect( mOfflineEditing, SIGNAL( layerProgressUpdated( int, int ) ), this, SLOT( setLayerProgress( int, int ) ) );
  connect( mOfflineEditing, SIGNAL( progressModeSet( QgsOfflineEditing::ProgressMode, int ) ), this, SLOT( setProgressMode( QgsOfflineEditing::ProgressMode, int ) ) );
  connect( mOfflineEditing, SIGNAL( progressUpdated( int ) ), this, SLOT( updateProgress( int ) ) );
  connect( mOfflineEditing, SIGNAL( progressStopped() ), this, SLOT( hideProgress() ) );
  connect( mOfflineEditing, SIGNAL( warning( QString, QString ) ), mQGisIface->messageBar(), SLOT( pushWarning( QString, QString ) ) );

  connect( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( updateActions() ) );
  connect( mQGisIface->mainWindow(), SIGNAL( newProject() ), this, SLOT( updateActions() ) );
  connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), this, SLOT( updateActions() ) );
  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateActions() ) );
  connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateActions() ) );
  updateActions();
}
Ejemplo n.º 3
0
/**
 * convert current project to offline project
 * returns offline project file path
 */
bool QgsOfflineEditing::convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds )
{
  if ( layerIds.isEmpty() )
  {
    return false;
  }
  QString dbPath = QDir( offlineDataPath ).absoluteFilePath( offlineDbFile );
  if ( createSpatialiteDB( dbPath ) )
  {
    spatialite_init( 0 );
    sqlite3* db;
    int rc = sqlite3_open( dbPath.toStdString().c_str(), &db );
    if ( rc != SQLITE_OK )
    {
      showWarning( tr( "Could not open the spatialite database" ) );
    }
    else
    {
      // create logging tables
      createLoggingTables( db );

      emit progressStarted();

      // copy selected vector layers to SpatiaLite
      for ( int i = 0; i < layerIds.count(); i++ )
      {
        emit layerProgressUpdated( i + 1, layerIds.count() );

        QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerIds.at( i ) );
        copyVectorLayer( qobject_cast<QgsVectorLayer*>( layer ), db, dbPath );
      }

      emit progressStopped();

      sqlite3_close( db );

      // save offline project
      QString projectTitle = QgsProject::instance()->title();
      if ( projectTitle.isEmpty() )
      {
        projectTitle = QFileInfo( QgsProject::instance()->fileName() ).fileName();
      }
      projectTitle += " (offline)";
      QgsProject::instance()->title( projectTitle );

      QgsProject::instance()->writeEntry( PROJECT_ENTRY_SCOPE_OFFLINE, PROJECT_ENTRY_KEY_OFFLINE_DB_PATH, dbPath );

      return true;
    }
  }

  return false;

  // Workflow:
  // copy layers to spatialite
  // create spatialite db at offlineDataPath
  // create table for each layer
  // add new spatialite layer
  // copy features
  // save as offline project
  // mark offline layers
  // remove remote layers
  // mark as offline project
}
Ejemplo n.º 4
0
void QgsOfflineEditing::synchronize()
{
  // open logging db
  sqlite3* db = openLoggingDb();
  if ( db == NULL )
  {
    return;
  }

  emit progressStarted();

  // restore and sync remote layers
  QList<QgsMapLayer*> offlineLayers;
  QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
  for ( QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin() ; layer_it != mapLayers.end(); ++layer_it )
  {
    QgsMapLayer* layer = layer_it.value();
    if ( layer->customProperty( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, false ).toBool() )
    {
      offlineLayers << layer;
    }
  }

  for ( int l = 0; l < offlineLayers.count(); l++ )
  {
    QgsMapLayer* layer = offlineLayers[l];

    emit layerProgressUpdated( l + 1, offlineLayers.count() );

    QString remoteSource = layer->customProperty( CUSTOM_PROPERTY_REMOTE_SOURCE, "" ).toString();
    QString remoteProvider = layer->customProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, "" ).toString();
    QString remoteName = layer->name();
    remoteName.remove( QRegExp( " \\(offline\\)$" ) );

    QgsVectorLayer* remoteLayer = new QgsVectorLayer( remoteSource, remoteName, remoteProvider );
    if ( remoteLayer->isValid() )
    {
      // TODO: only add remote layer if there are log entries?

      QgsVectorLayer* offlineLayer = qobject_cast<QgsVectorLayer*>( layer );

      // copy style
      copySymbology( offlineLayer, remoteLayer );

      // register this layer with the central layers registry
      QgsMapLayerRegistry::instance()->addMapLayers(
        QList<QgsMapLayer *>() << remoteLayer, true );

      // apply layer edit log
      QString qgisLayerId = layer->id();
      QString sql = QString( "SELECT \"id\" FROM 'log_layer_ids' WHERE \"qgis_id\" = '%1'" ).arg( qgisLayerId );
      int layerId = sqlQueryInt( db, sql, -1 );
      if ( layerId != -1 )
      {
        remoteLayer->startEditing();

        // TODO: only get commitNos of this layer?
        int commitNo = getCommitNo( db );
        for ( int i = 0; i < commitNo; i++ )
        {
          // apply commits chronologically
          applyAttributesAdded( remoteLayer, db, layerId, i );
          applyAttributeValueChanges( offlineLayer, remoteLayer, db, layerId, i );
          applyGeometryChanges( remoteLayer, db, layerId, i );
        }

        applyFeaturesAdded( offlineLayer, remoteLayer, db, layerId );
        applyFeaturesRemoved( remoteLayer, db, layerId );

        if ( remoteLayer->commitChanges() )
        {
          // update fid lookup
          updateFidLookup( remoteLayer, db, layerId );

          // clear edit log for this layer
          sql = QString( "DELETE FROM 'log_added_attrs' WHERE \"layer_id\" = %1" ).arg( layerId );
          sqlExec( db, sql );
          sql = QString( "DELETE FROM 'log_added_features' WHERE \"layer_id\" = %1" ).arg( layerId );
          sqlExec( db, sql );
          sql = QString( "DELETE FROM 'log_removed_features' WHERE \"layer_id\" = %1" ).arg( layerId );
          sqlExec( db, sql );
          sql = QString( "DELETE FROM 'log_feature_updates' WHERE \"layer_id\" = %1" ).arg( layerId );
          sqlExec( db, sql );
          sql = QString( "DELETE FROM 'log_geometry_updates' WHERE \"layer_id\" = %1" ).arg( layerId );
          sqlExec( db, sql );

          // reset commitNo
          QString sql = QString( "UPDATE 'log_indices' SET 'last_index' = 0 WHERE \"name\" = 'commit_no'" );
          sqlExec( db, sql );
        }
        else
        {
          showWarning( remoteLayer->commitErrors().join( "\n" ) );
        }
      }

      // remove offline layer
      QgsMapLayerRegistry::instance()->removeMapLayers(
        ( QStringList() << qgisLayerId ) );

      // disable offline project
      QString projectTitle = QgsProject::instance()->title();
      projectTitle.remove( QRegExp( " \\(offline\\)$" ) );
      QgsProject::instance()->title( projectTitle );
      QgsProject::instance()->removeEntry( PROJECT_ENTRY_SCOPE_OFFLINE, PROJECT_ENTRY_KEY_OFFLINE_DB_PATH );
      remoteLayer->reload(); //update with other changes
    }
  }

  emit progressStopped();

  sqlite3_close( db );
}
Ejemplo n.º 5
0
/* 
 *  Constructs a KBabelDictView which is a child of 'parent', with the 
 *  name 'name' and widget flags set to 'f' 
 */
KBabelDictView::KBabelDictView( QWidget* parent,  const char* name, WFlags fl )
    : QWidget( parent, name, fl )
{
    QVBoxLayout    *mainLayout = new QVBoxLayout(this);
    mainLayout->setSpacing(KDialog::spacingHint());
    mainLayout->setMargin(KDialog::marginHint());

    splitter = new QSplitter(this);
    mainLayout->addWidget(splitter);

    QWidget *w = new QWidget(splitter);
    QVBoxLayout *wLayout= new QVBoxLayout(w);
    wLayout->setSpacing(KDialog::spacingHint());
    wLayout->setMargin(KDialog::marginHint());
    
    QHBoxLayout *hbox = new QHBoxLayout(wLayout);
    QLabel *label = new QLabel(i18n("Search in module:"), w);
    hbox->addWidget(label);
    moduleCombo = new KComboBox(w);
    hbox->addWidget(moduleCombo);

    QWidget *temp = new QWidget(w);
    hbox->addWidget(temp);
    hbox->setStretchFactor(temp,2);
    editButton = new QPushButton(i18n("&Edit"),w);
    editButton->setEnabled(false);
    hbox->addWidget(editButton);

    // added a button "clear search" here
    hbox = new QHBoxLayout(wLayout);
    QPushButton* clearButton = new QPushButton(w);
    clearButton->setFlat(true);
    clearButton->setPixmap(SmallIcon("locationbar_erase"));
    hbox->addWidget(clearButton);
    textEdit = new KLineEdit(w,"textedit");
    textEdit->setFocus();
    hbox->addWidget(textEdit);

    hbox = new QHBoxLayout(wLayout);
    startButton = new QPushButton(i18n("&Start Search"),w);
    hbox->addWidget(startButton);
    inTransButton = new QCheckBox(i18n("Sea&rch in translations"),w);
    hbox->addWidget(inTransButton);
    hbox->addStretch(1);
    stopButton = new QPushButton(i18n("S&top"),w);
    stopButton->setEnabled(false);
    hbox->addWidget(stopButton);

    KSeparator *sep = new KSeparator(w);
    wLayout->addWidget(sep);
    dictBox = new KBabelDictBox(w,"kbabeldictbox");
    wLayout->addWidget(dictBox);

    prefWidget = new QWidget(splitter);
    QVBoxLayout *tempLayout= new QVBoxLayout(prefWidget);
    tempLayout->setSpacing(KDialog::spacingHint());
    tempLayout->setMargin(KDialog::marginHint());

    label = new QLabel(i18n("Settings:"),prefWidget);
    tempLayout->addWidget(label);
    
    prefStack = new QWidgetStack(prefWidget);
    tempLayout->addWidget(prefStack);
    tempLayout->addStretch(1);

    KConfig *config = KGlobal::config();
    dictBox->readSettings(config);
    dictBox->setAutoUpdateOptions(true);
           
    QStringList modules = dictBox->moduleNames();
    moduleCombo->insertStringList(modules);

    QPtrList<PrefWidget> prefs = dictBox->modPrefWidgets(prefStack);
    prefs.setAutoDelete(false);

    PrefWidget *p;
    int i=0;
    for(p = prefs.first(); p != 0; p=prefs.next())
    {
        prefStack->addWidget(p,i);
        i++;
    }

    int active=dictBox->activeModule();
    prefStack->raiseWidget(active);
    moduleCombo->setCurrentItem(active);


    QHBox *h = new QHBox(this);
    h->setSpacing(KDialog::spacingHint());
    mainLayout->addWidget(h);
    progressLabel = new QLabel(h);
    progressBar = new KProgress(h);

    connect(textEdit,SIGNAL(returnPressed()),startButton,SLOT(animateClick()));
    connect(startButton,SIGNAL(clicked()),this, SLOT(startSearch()));
    connect(stopButton, SIGNAL(clicked()), dictBox,SLOT(slotStopSearch()));
    connect(editButton, SIGNAL(clicked()), dictBox, SLOT(edit()));
    connect(dictBox, SIGNAL(searchStarted()), this, SLOT(searchStarted()));
    connect(dictBox, SIGNAL(searchStopped()), this, SLOT(searchStopped()));
    connect(dictBox, SIGNAL(progressed(int)), progressBar, SLOT(setProgress(int)));
    connect(dictBox, SIGNAL(activeModuleChanged(bool))
            , editButton, SLOT(setEnabled(bool)));
    
    connect(dictBox, SIGNAL(progressStarts(const QString&))
            , this, SLOT(progressStarted(const QString&)));
    connect(dictBox, SIGNAL(progressEnds()), this, SLOT(progressStopped()));
    
    connect(moduleCombo, SIGNAL(activated(int)), 
                    dictBox, SLOT(setActiveModule(int)));
    connect(dictBox, SIGNAL(activeModuleChanged(int))
                    , this, SLOT(switchModule(int)));
    connect(clearButton, SIGNAL(clicked()), this, SLOT(slotClearSearch()));
}