Skip to content

Commit

Permalink
[bugfix] Add a warning icon and tooltip to WFS sources
Browse files Browse the repository at this point in the history
Fixes #16753 off-line editing synchronization cripples
the original datasource if this is a WFS-T Layer

Backported from master commit 68ddf3b
  • Loading branch information
elpaso committed Nov 27, 2017
1 parent 485cd80 commit 7f5128b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/plugins/offline_editing/offline_editing_plugin_gui.cpp
Expand Up @@ -30,6 +30,7 @@
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QDebug>


QgsSelectLayerTreeModel::QgsSelectLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject* parent )
Expand All @@ -43,6 +44,12 @@ QgsSelectLayerTreeModel::~QgsSelectLayerTreeModel()
{
}

int QgsSelectLayerTreeModel::columnCount( const QModelIndex &parent ) const
{
return QgsLayerTreeModel::columnCount( parent ) + 1;
}

/*
QVariant QgsSelectLayerTreeModel::data( const QModelIndex& index, int role ) const
{
if ( role == Qt::CheckStateRole )
Expand All @@ -65,7 +72,59 @@ QVariant QgsSelectLayerTreeModel::data( const QModelIndex& index, int role ) con
}
return QgsLayerTreeModel::data( index, role );
}
*/

QVariant QgsSelectLayerTreeModel::data( const QModelIndex &index, int role ) const
{
QgsLayerTreeNode *node = index2node( index );
if ( index.column() == 0 )
{
if ( role == Qt::CheckStateRole )
{
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
return nodeLayer->isVisible();
}
else if ( QgsLayerTree::isGroup( node ) )
{
QgsLayerTreeGroup *nodeGroup = QgsLayerTree::toGroup( node );
return nodeGroup->isVisible();
}
else
{
return QVariant();
}
}
}
else
{
if ( QgsLayerTree::isLayer( node ) && index.column() > 0 )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
if ( vlayer && vlayer->dataProvider()->name() == QLatin1String( "WFS" ) )
{
switch ( role )
{
case Qt::ToolTipRole:
return tr( "The source of this layer is a <b>WFS</b> server.<br>"
"Some WFS layers are not suitable for offline<br>"
"editing due to unstable primary keys<br>"
"please check with your system administrator<br>"
"if this WFS layer can be used for offline<br>"
"editing." );
break;
case Qt::DecorationRole:
return QgsApplication::getThemeIcon( "/mIconWarning.svg" );
break;
}
}
}
return QVariant();
}
return QgsLayerTreeModel::data( index, role );
}

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

connect( mSelectAllButton, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
connect( mUnselectAllButton, SIGNAL( clicked() ), this, SLOT( unSelectAll() ) );
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/offline_editing/offline_editing_plugin_gui.h
Expand Up @@ -32,6 +32,8 @@ class QgsSelectLayerTreeModel : public QgsLayerTreeModel
QgsSelectLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *parent = nullptr );
~QgsSelectLayerTreeModel();

int columnCount( const QModelIndex &parent ) const;

QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
// bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
};
Expand Down

0 comments on commit 7f5128b

Please sign in to comment.