Skip to content
Permalink
Browse files

[Feature][QGIS Server] Add configuration checker to project properties

To help user configuring project for QGIS Server, this code adds some tests to check the configuration.

The tests are:
* duplicate names or short names used as ows names
* check ows names with regexp
* check vector layer encodings are set
  • Loading branch information
rldhont committed Jan 14, 2016
1 parent 0b96621 commit 4adae2853c1316cb597a0c78bffc236c82db7284
Showing with 169 additions and 0 deletions.
  1. +96 −0 src/app/qgsprojectproperties.cpp
  2. +9 −0 src/app/qgsprojectproperties.h
  3. +64 −0 src/ui/qgsprojectpropertiesbase.ui
@@ -50,6 +50,10 @@
#include "qgscolordialog.h"
#include "qgsexpressioncontext.h"
#include "qgsmapoverviewcanvas.h"
#include "qgslayertreenode.h"
#include "qgslayertreegroup.h"
#include "qgslayertreelayer.h"
#include "qgslayertreemodel.h"

#include "qgsmessagelog.h"

@@ -1462,6 +1466,63 @@ void QgsProjectProperties::on_pbnWCSLayersUnselectAll_clicked()
}
}

void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
{
QString myStyle = QgsApplication::reportStyleSheet();
teOWSChecker->clear();
teOWSChecker->document()->setDefaultStyleSheet( myStyle );
teOWSChecker->setHtml( "<h1>" + tr( "Start checking QGIS Server" ) + "</h1>" );

QStringList owsNames, encodingMessages;
checkOWS( QgisApp::instance()->layerTreeView()->layerTreeModel()->rootGroup(), owsNames, encodingMessages );

QStringList duplicateNames, regExpMessages;
QRegExp snRegExp = QgsApplication::shortNameRegExp();
Q_FOREACH ( QString name, owsNames )
{
if ( !snRegExp.exactMatch( name ) )
regExpMessages << tr( "Use short name for \"%1\"" ).arg( name );
if ( duplicateNames.contains( name ) )
continue;
if ( owsNames.count( name ) > 1 )
duplicateNames << name;
}

if ( duplicateNames.size() != 0 )
{
QString nameMessage = "<h1>" + tr( "Some layers and groups have the same name or short name" ) + "</h1>";
nameMessage += "<h2>" + tr( "Duplicate names:" ) + "</h2>";
nameMessage += duplicateNames.join( "</li><li>" ) + "</li></ul>";
teOWSChecker->setHtml( teOWSChecker->toHtml() + nameMessage );
}
else
{
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All names and short names of layer and group are unique" ) + "</h1>" );
}

if ( regExpMessages.size() != 0 )
{
QString encodingMessage = "<h1>" + tr( "Some layer short names have to be updated:" ) + "</h1><ul><li>" + regExpMessages.join( "</li><li>" ) + "</li></ul>";
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
}
else
{
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All layer short names are well formed" ) + "</h1>" );
}

if ( encodingMessages.size() != 0 )
{
QString encodingMessage = "<h1>" + tr( "Some layer encodings are not set:" ) + "</h1><ul><li>" + encodingMessages.join( "</li><li>" ) + "</li></ul>";
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
}
else
{
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All layer encodings are set" ) + "</h1>" );
}

teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "Start checking QGIS Server" ) + "</h1>" );
}

void QgsProjectProperties::on_pbnAddScale_clicked()
{
int myScale = QInputDialog::getInt(
@@ -1696,6 +1757,41 @@ void QgsProjectProperties::resetPythonMacros()
"def closeProject():\n pass\n" );
}

void QgsProjectProperties::checkOWS( QgsLayerTreeGroup* treeGroup, QStringList& owsNames, QStringList& encodingMessages )
{
QList< QgsLayerTreeNode * > treeGroupChildren = treeGroup->children();
for ( int i = 0; i < treeGroupChildren.size(); ++i )
{
QgsLayerTreeNode* treeNode = treeGroupChildren.at( i );
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
{
QgsLayerTreeGroup* treeGroupChild = static_cast<QgsLayerTreeGroup *>( treeNode );
QString shortName = treeGroupChild->customProperty( "wmsShortName" ).toString();
if ( shortName.isEmpty() )
owsNames << treeGroupChild->name();
else
owsNames << shortName;
checkOWS( treeGroupChild, owsNames, encodingMessages );
}
else
{
QgsLayerTreeLayer* treeLayer = static_cast<QgsLayerTreeLayer *>( treeNode );
QgsMapLayer* l = treeLayer->layer();
QString shortName = l->shortName();
if ( shortName.isEmpty() )
owsNames << l->name();
else
owsNames << shortName;
if ( l->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer *>( l );
if ( vl->dataProvider()->encoding() == "System" )
encodingMessages << tr( "Update layer \"%1\" encoding" ).arg( l->name() );
}
}
}
}

void QgsProjectProperties::populateEllipsoidList()
{
//
@@ -27,6 +27,7 @@ class QgsMapCanvas;
class QgsRelationManagerDialog;
class QgsStyleV2;
class QgsExpressionContext;
class QgsLayerTreeGroup;

/** Dialog to set project level properties
@@ -119,6 +120,11 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
void on_pbnWCSLayersSelectAll_clicked();
void on_pbnWCSLayersUnselectAll_clicked();

/*!
* Slots to launch OWS test
*/
void on_pbnLaunchOWSChecker_clicked();

/*!
* Slots for Styles
*/
@@ -210,6 +216,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
QList<EllipsoidDefs> mEllipsoidList;
int mEllipsoidIndex;

//! Check OWS configuration
void checkOWS( QgsLayerTreeGroup* treeGroup, QStringList& owsNames, QStringList& encodingMessages );

//! Populates list with ellipsoids from Sqlite3 db
void populateEllipsoidList();

@@ -2373,6 +2373,70 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mOWSCheckerGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Test configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_24">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QPushButton" name="pbnLaunchOWSChecker">
<property name="text">
<string>Launch</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="teOWSChecker">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="acceptRichText">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">

0 comments on commit 4adae28

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