Skip to content

Commit

Permalink
Merge pull request #5687 from elpaso/bugfix-16753-offline-editing-wfs…
Browse files Browse the repository at this point in the history
…-warning

[offline-editing] Add a warning icon and tooltip to WFS sources
  • Loading branch information
elpaso committed Nov 22, 2017
2 parents 58bfbd5 + 5f6c1ba commit 059c997
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
68 changes: 51 additions & 17 deletions src/plugins/offline_editing/offline_editing_plugin_gui.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,33 +30,66 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>



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


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


QVariant QgsSelectLayerTreeModel::data( const QModelIndex &index, int role ) const 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 ( role == Qt::CheckStateRole )
if ( QgsLayerTree::isLayer( node ) )
{ {
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node ); if ( QgsLayerTree::isLayer( node ) )
return nodeLayer->isVisible(); {
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 ) ) }
{ else
QgsLayerTreeGroup *nodeGroup = QgsLayerTree::toGroup( node ); {
return nodeGroup->isVisible(); if ( QgsLayerTree::isLayer( node ) && index.column() > 0 )
}
else
{ {
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 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 ); return QgsLayerTreeModel::data( index, role );
} }
Expand All @@ -79,6 +112,7 @@ QgsOfflineEditingPluginGui::QgsOfflineEditingPluginGui( QWidget *parent, Qt::Win
QgsLayerTree *rootNode = QgsProject::instance()->layerTreeRoot()->clone(); QgsLayerTree *rootNode = QgsProject::instance()->layerTreeRoot()->clone();
QgsLayerTreeModel *treeModel = new QgsSelectLayerTreeModel( rootNode, this ); QgsLayerTreeModel *treeModel = new QgsSelectLayerTreeModel( rootNode, this );
mLayerTree->setModel( treeModel ); mLayerTree->setModel( treeModel );
mLayerTree->header()->setResizeMode( QHeaderView::ResizeToContents );


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


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


void QgsOfflineEditingPluginGui::selectAll() void QgsOfflineEditingPluginGui::selectAll()
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/offline_editing/offline_editing_plugin_gui.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class QgsSelectLayerTreeModel : public QgsLayerTreeModel
Q_OBJECT Q_OBJECT
public: public:
QgsSelectLayerTreeModel( QgsLayerTree *rootNode, QObject *parent = nullptr ); 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; 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 class QgsOfflineEditingPluginGui : public QDialog, private Ui::QgsOfflineEditingPluginGuiBase
Expand Down

0 comments on commit 059c997

Please sign in to comment.