Skip to content

Commit 7f5128b

Browse files
committedNov 27, 2017
[bugfix] Add a warning icon and tooltip to WFS sources
Fixes #16753 off-line editing synchronization cripples the original datasource if this is a WFS-T Layer Backported from master commit 68ddf3b
1 parent 485cd80 commit 7f5128b

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
 

‎src/plugins/offline_editing/offline_editing_plugin_gui.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QFileDialog>
3131
#include <QMessageBox>
3232
#include <QSettings>
33+
#include <QDebug>
3334

3435

3536
QgsSelectLayerTreeModel::QgsSelectLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject* parent )
@@ -43,6 +44,12 @@ QgsSelectLayerTreeModel::~QgsSelectLayerTreeModel()
4344
{
4445
}
4546

47+
int QgsSelectLayerTreeModel::columnCount( const QModelIndex &parent ) const
48+
{
49+
return QgsLayerTreeModel::columnCount( parent ) + 1;
50+
}
51+
52+
/*
4653
QVariant QgsSelectLayerTreeModel::data( const QModelIndex& index, int role ) const
4754
{
4855
if ( role == Qt::CheckStateRole )
@@ -65,7 +72,59 @@ QVariant QgsSelectLayerTreeModel::data( const QModelIndex& index, int role ) con
6572
}
6673
return QgsLayerTreeModel::data( index, role );
6774
}
75+
*/
6876

77+
QVariant QgsSelectLayerTreeModel::data( const QModelIndex &index, int role ) const
78+
{
79+
QgsLayerTreeNode *node = index2node( index );
80+
if ( index.column() == 0 )
81+
{
82+
if ( role == Qt::CheckStateRole )
83+
{
84+
if ( QgsLayerTree::isLayer( node ) )
85+
{
86+
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
87+
return nodeLayer->isVisible();
88+
}
89+
else if ( QgsLayerTree::isGroup( node ) )
90+
{
91+
QgsLayerTreeGroup *nodeGroup = QgsLayerTree::toGroup( node );
92+
return nodeGroup->isVisible();
93+
}
94+
else
95+
{
96+
return QVariant();
97+
}
98+
}
99+
}
100+
else
101+
{
102+
if ( QgsLayerTree::isLayer( node ) && index.column() > 0 )
103+
{
104+
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
105+
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
106+
if ( vlayer && vlayer->dataProvider()->name() == QLatin1String( "WFS" ) )
107+
{
108+
switch ( role )
109+
{
110+
case Qt::ToolTipRole:
111+
return tr( "The source of this layer is a <b>WFS</b> server.<br>"
112+
"Some WFS layers are not suitable for offline<br>"
113+
"editing due to unstable primary keys<br>"
114+
"please check with your system administrator<br>"
115+
"if this WFS layer can be used for offline<br>"
116+
"editing." );
117+
break;
118+
case Qt::DecorationRole:
119+
return QgsApplication::getThemeIcon( "/mIconWarning.svg" );
120+
break;
121+
}
122+
}
123+
}
124+
return QVariant();
125+
}
126+
return QgsLayerTreeModel::data( index, role );
127+
}
69128

70129
QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget* parent, Qt::WindowFlags fl )
71130
: QDialog( parent, fl )
@@ -80,6 +139,7 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget* parent, Qt::Win
80139
QgsLayerTreeGroup* rootNode = QgsLayerTree::toGroup( QgsProject::instance()->layerTreeRoot()->clone() );
81140
QgsLayerTreeModel* treeModel = new QgsSelectLayerTreeModel( rootNode, this );
82141
mLayerTree->setModel( treeModel );
142+
mLayerTree->header()->setResizeMode( QHeaderView::ResizeToContents );
83143

84144
connect( mSelectAllButton, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
85145
connect( mUnselectAllButton, SIGNAL( clicked() ), this, SLOT( unSelectAll() ) );

‎src/plugins/offline_editing/offline_editing_plugin_gui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class QgsSelectLayerTreeModel : public QgsLayerTreeModel
3232
QgsSelectLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *parent = nullptr );
3333
~QgsSelectLayerTreeModel();
3434

35+
int columnCount( const QModelIndex &parent ) const;
36+
3537
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
3638
// bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
3739
};

0 commit comments

Comments
 (0)
Please sign in to comment.