21
21
#include < qgscontexthelp.h>
22
22
#include < qgsmaplayer.h>
23
23
#include < qgsmaplayerregistry.h>
24
+ #include < qgsvectordataprovider.h>
25
+ #include < qgsvectorlayer.h>
24
26
25
27
#include < QFileDialog>
26
28
#include < QMessageBox>
@@ -39,15 +41,7 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget* parent /*= 0*/,
39
41
mOfflineDbFile = " offline.sqlite" ;
40
42
ui_offlineDataPath->setText ( QDir ( mOfflineDataPath ).absoluteFilePath ( mOfflineDbFile ) );
41
43
42
- QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance ()->mapLayers ();
43
- for ( QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin () ; layer_it != mapLayers.end (); ++layer_it )
44
- {
45
- if ( layer_it.value ()->type () == QgsMapLayer::VectorLayer )
46
- {
47
- QListWidgetItem* item = new QListWidgetItem ( layer_it.value ()->name (), ui_layerList );
48
- item->setData ( Qt::UserRole, QVariant ( layer_it.key () ) );
49
- }
50
- }
44
+ updateLayerList ( checkboxShowEditableLayers->checkState () == Qt::Checked );
51
45
}
52
46
53
47
QgsOfflineEditingPluginGui::~QgsOfflineEditingPluginGui ()
@@ -69,6 +63,36 @@ QStringList& QgsOfflineEditingPluginGui::selectedLayerIds()
69
63
return mSelectedLayerIds ;
70
64
}
71
65
66
+ void QgsOfflineEditingPluginGui::updateLayerList ( bool filterEditableLayers )
67
+ {
68
+ ui_layerList->clear ();
69
+
70
+ QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance ()->mapLayers ();
71
+ for ( QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin () ; layer_it != mapLayers.end (); ++layer_it )
72
+ {
73
+ if ( layer_it.value ()->type () == QgsMapLayer::VectorLayer )
74
+ {
75
+ QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( layer_it.value () );
76
+
77
+ bool showLayer = true ;
78
+ if ( filterEditableLayers )
79
+ {
80
+ int cap = layer->dataProvider ()->capabilities ();
81
+ showLayer = ( cap & QgsVectorDataProvider::AddFeatures ) &&
82
+ ( cap & QgsVectorDataProvider::DeleteFeatures ) &&
83
+ ( cap & QgsVectorDataProvider::ChangeAttributeValues ) &&
84
+ ( cap & QgsVectorDataProvider::AddAttributes ) &&
85
+ ( cap & QgsVectorDataProvider::ChangeGeometries );
86
+ }
87
+ if ( showLayer )
88
+ {
89
+ QListWidgetItem* item = new QListWidgetItem ( layer->name (), ui_layerList );
90
+ item->setData ( Qt::UserRole, QVariant ( layer_it.key () ) );
91
+ }
92
+ }
93
+ }
94
+ }
95
+
72
96
void QgsOfflineEditingPluginGui::on_butBrowse_clicked ()
73
97
{
74
98
QString fileName = QFileDialog::getSaveFileName ( this ,
@@ -85,6 +109,11 @@ void QgsOfflineEditingPluginGui::on_butBrowse_clicked()
85
109
}
86
110
}
87
111
112
+ void QgsOfflineEditingPluginGui::on_checkboxShowEditableLayers_stateChanged ( int state )
113
+ {
114
+ updateLayerList ( checkboxShowEditableLayers->checkState () == Qt::Checked );
115
+ }
116
+
88
117
void QgsOfflineEditingPluginGui::on_buttonBox_accepted ()
89
118
{
90
119
if ( QFile ( QDir ( mOfflineDataPath ).absoluteFilePath ( mOfflineDbFile ) ).exists () )
0 commit comments