Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
#include <QObject>
#include <QString>

class QgsLegendInterface;
class QgsMapLayer;
class QgsOfflineEditingProgressDialog;
class QgsVectorLayer;
struct sqlite3;

Expand All @@ -36,12 +34,55 @@ class QgsOfflineEditing : public QObject
Q_OBJECT

public:
QgsOfflineEditing( QgsOfflineEditingProgressDialog* progressDialog );
enum ProgressMode {
CopyFeatures = 0,
ProcessFeatures,
AddFields,
AddFeatures,
RemoveFeatures,
UpdateFeatures,
UpdateGeometries
};

QgsOfflineEditing();
~QgsOfflineEditing();

/** convert current project for offline editing
* @param offlineDataPath path to offline db file
* @param offlineDbFile offline db file name
* @param layerIds list of layer names to convert
*/
bool convertToOfflineProject( const QString& offlineDataPath, const QString& offlineDbFile, const QStringList& layerIds );

/** return true if current project is offline */
bool isOfflineProject();
void synchronize( QgsLegendInterface* legendInterface );

/** synchronize to remote layers */
void synchronize();

signals:
/** emit a signal that processing has started */
void progressStarted();

/** emit a signal that the next layer of numLayers has started processing
* @param layer current layer index
* @param numLayers total number of layers
*/
void layerProgressUpdated( int layer, int numLayers );

/** emit a signal that sets the mode for the progress of the current operation
* @param mode progress mode
* @param maximum total number of entities to process in the current operation
*/
void progressModeSet( QgsOfflineEditing::ProgressMode mode, int maximum );

/** emit a signal with the progress of the current mode
* @param progress current index of processed entities
*/
void progressUpdated( int progress );

/** emit a signal that processing of all layers has finished */
void progressStopped();

private:
void initializeSpatialMetadata( sqlite3 *sqlite_handle );
Expand Down Expand Up @@ -93,8 +134,6 @@ class QgsOfflineEditing : public QObject
typedef QList<GeometryChange> GeometryChanges;
GeometryChanges sqlQueryGeometryChanges( sqlite3* db, const QString& sql );

QgsOfflineEditingProgressDialog* mProgressDialog;

private slots:
void layerAdded( QgsMapLayer* layer );
void committedAttributesAdded( const QString& qgisLayerId, const QList<QgsField>& addedAttributes );
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/offline_editing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
SET (offline_editing_plugin_SRCS
offline_editing_plugin.cpp
offline_editing_plugin_gui.cpp
offline_editing.cpp
offline_editing_progress_dialog.cpp
)

Expand All @@ -17,7 +16,6 @@ SET (offline_editing_plugin_UIS
SET (offline_editing_plugin_MOC_HDRS
offline_editing_plugin.h
offline_editing_plugin_gui.h
offline_editing.h
offline_editing_progress_dialog.h
)

Expand Down
70 changes: 67 additions & 3 deletions src/plugins/offline_editing/offline_editing_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "offline_editing_plugin.h"
#include "offline_editing_plugin_gui.h"
#include "offline_editing_progress_dialog.h"
#include "offline_editing.h"

#include <qgisinterface.h>
#include <qgisgui.h>
Expand Down Expand Up @@ -47,6 +46,7 @@ QgsOfflineEditingPlugin::QgsOfflineEditingPlugin( QgisInterface* theQgisInterfac
QgsOfflineEditingPlugin::~QgsOfflineEditingPlugin()
{
delete mOfflineEditing;
delete mProgressDialog;
}

void QgsOfflineEditingPlugin::initGui()
Expand All @@ -69,7 +69,14 @@ void QgsOfflineEditingPlugin::initGui()
mQGisIface->addPluginToDatabaseMenu( tr( "&Offline Editing" ), mActionSynchronize );
mActionSynchronize->setEnabled( false );

mOfflineEditing = new QgsOfflineEditing( new QgsOfflineEditingProgressDialog( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags ) );
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( mQGisIface->mainWindow(), SIGNAL( projectRead() ), this, SLOT( updateActions() ) );
connect( mQGisIface->mainWindow(), SIGNAL( newProject() ), this, SLOT( updateActions() ) );
Expand All @@ -94,6 +101,7 @@ void QgsOfflineEditingPlugin::convertProject()
return;
}

mProgressDialog->setTitle( tr( "Converting to offline project" ) );
if ( mOfflineEditing->convertToOfflineProject( myPluginGui->offlineDataPath(), myPluginGui->offlineDbFile(), selectedLayerIds ) )
{
updateActions();
Expand All @@ -105,7 +113,8 @@ void QgsOfflineEditingPlugin::convertProject()

void QgsOfflineEditingPlugin::synchronize()
{
mOfflineEditing->synchronize( mQGisIface->legendInterface() );
mProgressDialog->setTitle( tr( "Synchronizing to remote layers" ) );
mOfflineEditing->synchronize();
updateActions();
}

Expand Down Expand Up @@ -137,6 +146,61 @@ void QgsOfflineEditingPlugin::updateActions()
mActionSynchronize->setEnabled( hasLayers && isOfflineProject );
}

void QgsOfflineEditingPlugin::showProgress()
{
mProgressDialog->show();
}

void QgsOfflineEditingPlugin::setLayerProgress( int layer, int numLayers )
{
mProgressDialog->setCurrentLayer( layer, numLayers );
}

void QgsOfflineEditingPlugin::setProgressMode( QgsOfflineEditing::ProgressMode mode, int maximum )
{
QString format = "";
switch ( mode )
{
case QgsOfflineEditing::CopyFeatures:
format = tr( "%v / %m features copied" );
break;
case QgsOfflineEditing::ProcessFeatures:
format = tr( "%v / %m features processed" );
break;
case QgsOfflineEditing::AddFields:
format = tr( "%v / %m fields added" );
break;
case QgsOfflineEditing::AddFeatures:
format = tr( "%v / %m features added" );
break;
case QgsOfflineEditing::RemoveFeatures:
format = tr( "%v / %m features removed" );
break;
case QgsOfflineEditing::UpdateFeatures:
format = tr( "%v / %m feature updates" );
break;
case QgsOfflineEditing::UpdateGeometries:
format = tr( "%v / %m feature geometry updates" );
break;

default:
break;
}

mProgressDialog->setupProgressBar( format, maximum );
}

void QgsOfflineEditingPlugin::updateProgress( int progress )
{
mProgressDialog->setProgressValue( progress );
}

void QgsOfflineEditingPlugin::hideProgress()
{
mProgressDialog->hide();
}


/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/offline_editing/offline_editing_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
#define QGS_OFFLINE_EDITING_PLUGIN_H

#include "../qgisplugin.h"
#include <qgsofflineediting.h>
#include <QObject>

class QAction;
class QgisInterface;
class QgsOfflineEditing;
class QgsOfflineEditingProgressDialog;

class QgsOfflineEditingPlugin : public QObject, public QgisPlugin
{
Expand Down Expand Up @@ -54,9 +55,17 @@ class QgsOfflineEditingPlugin : public QObject, public QgisPlugin
QAction* mActionSynchronize;

QgsOfflineEditing* mOfflineEditing;
QgsOfflineEditingProgressDialog* mProgressDialog;

private slots:
void updateActions();

//! update progress dialog
void showProgress();
void setLayerProgress( int layer, int numLayers );
void setProgressMode( QgsOfflineEditing::ProgressMode mode, int maximum );
void updateProgress( int progress );
void hideProgress();
};

#endif // QGS_OFFLINE_EDITING_PLUGIN_H