Skip to content

Commit 4adae28

Browse files
committed
[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
1 parent 0b96621 commit 4adae28

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed

src/app/qgsprojectproperties.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
#include "qgscolordialog.h"
5151
#include "qgsexpressioncontext.h"
5252
#include "qgsmapoverviewcanvas.h"
53+
#include "qgslayertreenode.h"
54+
#include "qgslayertreegroup.h"
55+
#include "qgslayertreelayer.h"
56+
#include "qgslayertreemodel.h"
5357

5458
#include "qgsmessagelog.h"
5559

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

1469+
void QgsProjectProperties::on_pbnLaunchOWSChecker_clicked()
1470+
{
1471+
QString myStyle = QgsApplication::reportStyleSheet();
1472+
teOWSChecker->clear();
1473+
teOWSChecker->document()->setDefaultStyleSheet( myStyle );
1474+
teOWSChecker->setHtml( "<h1>" + tr( "Start checking QGIS Server" ) + "</h1>" );
1475+
1476+
QStringList owsNames, encodingMessages;
1477+
checkOWS( QgisApp::instance()->layerTreeView()->layerTreeModel()->rootGroup(), owsNames, encodingMessages );
1478+
1479+
QStringList duplicateNames, regExpMessages;
1480+
QRegExp snRegExp = QgsApplication::shortNameRegExp();
1481+
Q_FOREACH ( QString name, owsNames )
1482+
{
1483+
if ( !snRegExp.exactMatch( name ) )
1484+
regExpMessages << tr( "Use short name for \"%1\"" ).arg( name );
1485+
if ( duplicateNames.contains( name ) )
1486+
continue;
1487+
if ( owsNames.count( name ) > 1 )
1488+
duplicateNames << name;
1489+
}
1490+
1491+
if ( duplicateNames.size() != 0 )
1492+
{
1493+
QString nameMessage = "<h1>" + tr( "Some layers and groups have the same name or short name" ) + "</h1>";
1494+
nameMessage += "<h2>" + tr( "Duplicate names:" ) + "</h2>";
1495+
nameMessage += duplicateNames.join( "</li><li>" ) + "</li></ul>";
1496+
teOWSChecker->setHtml( teOWSChecker->toHtml() + nameMessage );
1497+
}
1498+
else
1499+
{
1500+
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All names and short names of layer and group are unique" ) + "</h1>" );
1501+
}
1502+
1503+
if ( regExpMessages.size() != 0 )
1504+
{
1505+
QString encodingMessage = "<h1>" + tr( "Some layer short names have to be updated:" ) + "</h1><ul><li>" + regExpMessages.join( "</li><li>" ) + "</li></ul>";
1506+
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
1507+
}
1508+
else
1509+
{
1510+
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All layer short names are well formed" ) + "</h1>" );
1511+
}
1512+
1513+
if ( encodingMessages.size() != 0 )
1514+
{
1515+
QString encodingMessage = "<h1>" + tr( "Some layer encodings are not set:" ) + "</h1><ul><li>" + encodingMessages.join( "</li><li>" ) + "</li></ul>";
1516+
teOWSChecker->setHtml( teOWSChecker->toHtml() + encodingMessage );
1517+
}
1518+
else
1519+
{
1520+
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "All layer encodings are set" ) + "</h1>" );
1521+
}
1522+
1523+
teOWSChecker->setHtml( teOWSChecker->toHtml() + "<h1>" + tr( "Start checking QGIS Server" ) + "</h1>" );
1524+
}
1525+
14651526
void QgsProjectProperties::on_pbnAddScale_clicked()
14661527
{
14671528
int myScale = QInputDialog::getInt(
@@ -1696,6 +1757,41 @@ void QgsProjectProperties::resetPythonMacros()
16961757
"def closeProject():\n pass\n" );
16971758
}
16981759

1760+
void QgsProjectProperties::checkOWS( QgsLayerTreeGroup* treeGroup, QStringList& owsNames, QStringList& encodingMessages )
1761+
{
1762+
QList< QgsLayerTreeNode * > treeGroupChildren = treeGroup->children();
1763+
for ( int i = 0; i < treeGroupChildren.size(); ++i )
1764+
{
1765+
QgsLayerTreeNode* treeNode = treeGroupChildren.at( i );
1766+
if ( treeNode->nodeType() == QgsLayerTreeNode::NodeGroup )
1767+
{
1768+
QgsLayerTreeGroup* treeGroupChild = static_cast<QgsLayerTreeGroup *>( treeNode );
1769+
QString shortName = treeGroupChild->customProperty( "wmsShortName" ).toString();
1770+
if ( shortName.isEmpty() )
1771+
owsNames << treeGroupChild->name();
1772+
else
1773+
owsNames << shortName;
1774+
checkOWS( treeGroupChild, owsNames, encodingMessages );
1775+
}
1776+
else
1777+
{
1778+
QgsLayerTreeLayer* treeLayer = static_cast<QgsLayerTreeLayer *>( treeNode );
1779+
QgsMapLayer* l = treeLayer->layer();
1780+
QString shortName = l->shortName();
1781+
if ( shortName.isEmpty() )
1782+
owsNames << l->name();
1783+
else
1784+
owsNames << shortName;
1785+
if ( l->type() == QgsMapLayer::VectorLayer )
1786+
{
1787+
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer *>( l );
1788+
if ( vl->dataProvider()->encoding() == "System" )
1789+
encodingMessages << tr( "Update layer \"%1\" encoding" ).arg( l->name() );
1790+
}
1791+
}
1792+
}
1793+
}
1794+
16991795
void QgsProjectProperties::populateEllipsoidList()
17001796
{
17011797
//

src/app/qgsprojectproperties.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class QgsMapCanvas;
2727
class QgsRelationManagerDialog;
2828
class QgsStyleV2;
2929
class QgsExpressionContext;
30+
class QgsLayerTreeGroup;
3031

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

123+
/*!
124+
* Slots to launch OWS test
125+
*/
126+
void on_pbnLaunchOWSChecker_clicked();
127+
122128
/*!
123129
* Slots for Styles
124130
*/
@@ -210,6 +216,9 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
210216
QList<EllipsoidDefs> mEllipsoidList;
211217
int mEllipsoidIndex;
212218

219+
//! Check OWS configuration
220+
void checkOWS( QgsLayerTreeGroup* treeGroup, QStringList& owsNames, QStringList& encodingMessages );
221+
213222
//! Populates list with ellipsoids from Sqlite3 db
214223
void populateEllipsoidList();
215224

src/ui/qgsprojectpropertiesbase.ui

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,70 @@
23732373
</layout>
23742374
</widget>
23752375
</item>
2376+
<item>
2377+
<widget class="QgsCollapsibleGroupBox" name="mOWSCheckerGroupBox">
2378+
<property name="sizePolicy">
2379+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
2380+
<horstretch>0</horstretch>
2381+
<verstretch>3</verstretch>
2382+
</sizepolicy>
2383+
</property>
2384+
<property name="title">
2385+
<string>Test configuration</string>
2386+
</property>
2387+
<layout class="QVBoxLayout" name="verticalLayout_24">
2388+
<item>
2389+
<layout class="QHBoxLayout" name="horizontalLayout_11">
2390+
<item>
2391+
<widget class="QPushButton" name="pbnLaunchOWSChecker">
2392+
<property name="text">
2393+
<string>Launch</string>
2394+
</property>
2395+
</widget>
2396+
</item>
2397+
<item>
2398+
<spacer name="horizontalSpacer_7">
2399+
<property name="orientation">
2400+
<enum>Qt::Horizontal</enum>
2401+
</property>
2402+
<property name="sizeHint" stdset="0">
2403+
<size>
2404+
<width>40</width>
2405+
<height>20</height>
2406+
</size>
2407+
</property>
2408+
</spacer>
2409+
</item>
2410+
</layout>
2411+
</item>
2412+
<item>
2413+
<widget class="QTextEdit" name="teOWSChecker">
2414+
<property name="enabled">
2415+
<bool>true</bool>
2416+
</property>
2417+
<property name="minimumSize">
2418+
<size>
2419+
<width>0</width>
2420+
<height>200</height>
2421+
</size>
2422+
</property>
2423+
<property name="acceptDrops">
2424+
<bool>true</bool>
2425+
</property>
2426+
<property name="lineWidth">
2427+
<number>2</number>
2428+
</property>
2429+
<property name="readOnly">
2430+
<bool>true</bool>
2431+
</property>
2432+
<property name="acceptRichText">
2433+
<bool>true</bool>
2434+
</property>
2435+
</widget>
2436+
</item>
2437+
</layout>
2438+
</widget>
2439+
</item>
23762440
<item>
23772441
<spacer name="verticalSpacer_6">
23782442
<property name="orientation">

0 commit comments

Comments
 (0)