Skip to content
Permalink
Browse files

Merge pull request #5687 from elpaso/bugfix-16753-offline-editing-wfs…

…-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 059c9977660ad0560b3ae094b4cb92e9058d6bdb
@@ -30,33 +30,66 @@
#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
{
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 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 );
}
@@ -79,6 +112,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 );
@@ -87,8 +121,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()
@@ -172,8 +206,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()
@@ -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

0 comments on commit 059c997

Please sign in to comment.
You can’t perform that action at this time.