Skip to content

Commit

Permalink
[offline-editing] 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
  • Loading branch information
elpaso committed Nov 21, 2017
1 parent 4bc4494 commit 68ddf3b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
69 changes: 52 additions & 17 deletions src/plugins/offline_editing/offline_editing_plugin_gui.cpp
Expand Up @@ -30,33 +30,67 @@
#include <QFileDialog>
#include <QMessageBox>


QgsSelectLayerTreeModel::QgsSelectLayerTreeModel( QgsLayerTree *rootNode, QObject *parent )
: QgsLayerTreeModel( rootNode, parent )
{
setFlag( QgsLayerTreeModel::ShowLegend, false );
setFlag( QgsLayerTreeModel::AllowNodeChangeVisibility, true );
}

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


QVariant QgsSelectLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( role == Qt::CheckStateRole )
QgsLayerTreeNode *node = index2node( index );
if ( index.column() == 0 )
{
QgsLayerTreeNode *node = index2node( index );
if ( QgsLayerTree::isLayer( node ) )
if ( role == Qt::CheckStateRole )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
return nodeLayer->isVisible();
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::isGroup( node ) )
{
QgsLayerTreeGroup *nodeGroup = QgsLayerTree::toGroup( node );
return nodeGroup->isVisible();
}
else
}
else
{
if ( QgsLayerTree::isLayer( node ) && index.column() > 0 )
{
return QVariant();
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer()->dataProvider()->name() == QStringLiteral( "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 unreliable/missing primary<br>"
"keys, please check with your system<br>"
"administrator if this WFS layer can<br>"
"be used for offline editing." );
break;
case Qt::DecorationRole:
return QgsApplication::getThemeIcon( "/mIconWarning.svg" );
break;
}
}
}
return QVariant();
}
return QgsLayerTreeModel::data( index, role );
}
Expand All @@ -79,6 +113,7 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget *parent, Qt::Win
QgsLayerTree *rootNode = QgsProject::instance()->layerTreeRoot()->clone();
QgsLayerTreeModel *treeModel = new QgsSelectLayerTreeModel( rootNode, this );
mLayerTree->setModel( treeModel );
mLayerTree->header()->setResizeMode( QHeaderView::ResizeToContents );

connect( mSelectAllButton, &QAbstractButton::clicked, this, &QgsOfflineEditingPluginGui::selectAll );
connect( mDeselectAllButton, &QAbstractButton::clicked, this, &QgsOfflineEditingPluginGui::deSelectAll );
Expand All @@ -87,8 +122,8 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget *parent, Qt::Win
QgsOfflineEditingPluginGui::~QgsOfflineEditingPluginGui()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Plugin-OfflineEditing/geometry" ), saveGeometry() );
settings.setValue( QStringLiteral( "Plugin-OfflineEditing/offline_data_path" ), mOfflineDataPath );
settings.setValue( QStringLiteral( "OfflineEditing/geometry" ), saveGeometry(), QgsSettings::Section::Plugins );
settings.setValue( QStringLiteral( "OfflineEditing/offline_data_path" ), mOfflineDataPath, QgsSettings::Section::Plugins );
}

QString QgsOfflineEditingPluginGui::offlineDataPath()
Expand Down Expand Up @@ -172,8 +207,8 @@ void QgsOfflineEditingPluginGui::showHelp()
void QgsOfflineEditingPluginGui::restoreState()
{
QgsSettings settings;
mOfflineDataPath = settings.value( QStringLiteral( "Plugin-OfflineEditing/offline_data_path" ), QDir::homePath() ).toString();
restoreGeometry( settings.value( QStringLiteral( "Plugin-OfflineEditing/geometry" ) ).toByteArray() );
mOfflineDataPath = settings.value( QStringLiteral( "OfflineEditing/offline_data_path" ), QDir::homePath(), QgsSettings::Section::Plugins ).toString();
restoreGeometry( settings.value( QStringLiteral( "OfflineEditing/geometry" ), QgsSettings::Section::Plugins ).toByteArray() );
}

void QgsOfflineEditingPluginGui::selectAll()
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/offline_editing/offline_editing_plugin_gui.h
Expand Up @@ -30,9 +30,8 @@ class QgsSelectLayerTreeModel : public QgsLayerTreeModel
Q_OBJECT
public:
QgsSelectLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr );

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

class QgsOfflineEditingPluginGui : public QDialog, private Ui::QgsOfflineEditingPluginGuiBase
Expand Down

0 comments on commit 68ddf3b

Please sign in to comment.