Skip to content
Permalink
Browse files

Offline editing plugin: add option to filter editable remote layers u…

…sing capabilities

git-svn-id: http://svn.osgeo.org/qgis/trunk@14560 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mwalker
mwalker committed Nov 12, 2010
1 parent 9fa0f04 commit fab2b0fd76d092c14d72446435b5d4d001ed8e96
@@ -21,6 +21,8 @@
#include <qgscontexthelp.h>
#include <qgsmaplayer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectordataprovider.h>
#include <qgsvectorlayer.h>

#include <QFileDialog>
#include <QMessageBox>
@@ -39,15 +41,7 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget* parent /*= 0*/,
mOfflineDbFile = "offline.sqlite";
ui_offlineDataPath->setText( QDir( mOfflineDataPath ).absoluteFilePath( mOfflineDbFile ) );

QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin() ; layer_it != mapLayers.end(); ++layer_it )
{
if ( layer_it.value()->type() == QgsMapLayer::VectorLayer )
{
QListWidgetItem* item = new QListWidgetItem( layer_it.value()->name(), ui_layerList );
item->setData( Qt::UserRole, QVariant( layer_it.key() ) );
}
}
updateLayerList( checkboxShowEditableLayers->checkState() == Qt::Checked );
}

QgsOfflineEditingPluginGui::~QgsOfflineEditingPluginGui()
@@ -69,6 +63,36 @@ QStringList& QgsOfflineEditingPluginGui::selectedLayerIds()
return mSelectedLayerIds;
}

void QgsOfflineEditingPluginGui::updateLayerList( bool filterEditableLayers )
{
ui_layerList->clear();

QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin() ; layer_it != mapLayers.end(); ++layer_it )
{
if ( layer_it.value()->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( layer_it.value() );

bool showLayer = true;
if ( filterEditableLayers )
{
int cap = layer->dataProvider()->capabilities();
showLayer = ( cap & QgsVectorDataProvider::AddFeatures ) &&
( cap & QgsVectorDataProvider::DeleteFeatures ) &&
( cap & QgsVectorDataProvider::ChangeAttributeValues ) &&
( cap & QgsVectorDataProvider::AddAttributes ) &&
( cap & QgsVectorDataProvider::ChangeGeometries );
}
if ( showLayer )
{
QListWidgetItem* item = new QListWidgetItem( layer->name(), ui_layerList );
item->setData( Qt::UserRole, QVariant( layer_it.key() ) );
}
}
}
}

void QgsOfflineEditingPluginGui::on_butBrowse_clicked()
{
QString fileName = QFileDialog::getSaveFileName( this,
@@ -85,6 +109,11 @@ void QgsOfflineEditingPluginGui::on_butBrowse_clicked()
}
}

void QgsOfflineEditingPluginGui::on_checkboxShowEditableLayers_stateChanged( int state )
{
updateLayerList( checkboxShowEditableLayers->checkState() == Qt::Checked );
}

void QgsOfflineEditingPluginGui::on_buttonBox_accepted()
{
if ( QFile( QDir( mOfflineDataPath ).absoluteFilePath( mOfflineDbFile ) ).exists() )
@@ -35,13 +35,16 @@ class QgsOfflineEditingPluginGui : public QDialog, private Ui::QgsOfflineEditing
QStringList& selectedLayerIds();

private:
void updateLayerList( bool filterEditableLayers );

static const int context_id = 0;
QString mOfflineDataPath;
QString mOfflineDbFile;
QStringList mSelectedLayerIds;

private slots:
void on_butBrowse_clicked();
void on_checkboxShowEditableLayers_stateChanged( int state );
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_buttonBox_helpRequested();
@@ -63,14 +63,28 @@
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkboxShowEditableLayers">
<property name="text">
<string>Show only editable layers</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

0 comments on commit fab2b0f

Please sign in to comment.
You can’t perform that action at this time.