Skip to content

Commit 1e9774f

Browse files
committedFeb 13, 2015
qgis server fixes:
* support edit types based on edit widgets (adds qgis_gui dependency; fixes #12091) * show null values (fixes #12114) * only quote non-numeric non-null values in feature info * fix crash on exit * remove obsolete parser method and debug output
1 parent 3294505 commit 1e9774f

File tree

9 files changed

+64
-74
lines changed

9 files changed

+64
-74
lines changed
 

‎src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ QgsEditorWidgetRegistry* QgsEditorWidgetRegistry::instance()
4747
return &sInstance;
4848
}
4949

50-
void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas* mapCanvas, QgsMessageBar* messageBar )
50+
void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas *mapCanvas, QgsMessageBar *messageBar )
5151
{
52-
QgsEditorWidgetRegistry* reg = instance();
52+
QgsEditorWidgetRegistry *reg = instance();
5353
reg->registerWidget( "Classification", new QgsClassificationWidgetWrapperFactory( tr( "Classification" ) ) );
5454
reg->registerWidget( "Range", new QgsRangeWidgetFactory( tr( "Range" ) ) );
5555
reg->registerWidget( "UniqueValues", new QgsUniqueValueWidgetFactory( tr( "Unique Values" ) ) );

‎src/server/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ENDIF (WIN32)
8888

8989
QT4_WRAP_CPP(qgis_mapserv_MOC_SRCS ${qgis_mapserv_MOC_HDRS})
9090

91-
ADD_LIBRARY(qgis_server SHARED ${qgis_mapserv_SRCS} ${qgis_mapserv_MOC_SRCS} ${qgis_mapserv_HDRS} ${qgis_mapserv_MOC_HDRS} )
91+
ADD_LIBRARY(qgis_server SHARED ${qgis_mapserv_SRCS} ${qgis_mapserv_MOC_SRCS} ${qgis_mapserv_HDRS} ${qgis_mapserv_MOC_HDRS})
9292

9393
#generate unversioned libs for android
9494
IF (NOT ANDROID)
@@ -100,6 +100,7 @@ ENDIF (NOT ANDROID)
100100

101101
TARGET_LINK_LIBRARIES(qgis_server
102102
qgis_core
103+
qgis_gui
103104
qgis_analysis
104105
qgispython
105106
${PROJ_LIBRARY}
@@ -155,13 +156,17 @@ INCLUDE_DIRECTORIES(
155156
../core/symbology-ng
156157
../core/composer
157158
../core/layertree
159+
../gui
160+
../gui/editorwidgets
161+
../gui/editorwidgets/core
158162
../analysis/interpolation
159163
../plugins/diagram_overlay
160164
.
161165
)
162166

163167
TARGET_LINK_LIBRARIES(qgis_mapserv.fcgi
164168
qgis_core
169+
qgis_gui
165170
qgis_analysis
166171
${PROJ_LIBRARY}
167172
${FCGI_LIBRARY}

‎src/server/qgis_map_serv.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "qgsnetworkaccessmanager.h"
3838
#include "qgsmaplayerregistry.h"
3939
#include "qgsserverlogger.h"
40+
#include "qgseditorwidgetregistry.h"
4041

4142
#ifdef HAVE_SERVER_PYTHON_PLUGINS
4243
#include "qgsserverplugins.h"
@@ -287,8 +288,6 @@ int main( int argc, char * argv[] )
287288
QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() );
288289
QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) );
289290

290-
// FIXME: what is this debug line for?
291-
QgsDebugMsg( qgsapp.applicationDirPath() + "/qgis_wms_server.log" );
292291
QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs)
293292

294293
QString defaultConfigFilePath;
@@ -337,6 +336,8 @@ int main( int argc, char * argv[] )
337336
QMultiMap<int, QgsServerFilter*> pluginFilters = serverIface.filters();
338337
#endif
339338

339+
QgsEditorWidgetRegistry::initEditors();
340+
340341
while ( fcgi_accept() >= 0 )
341342
{
342343
QgsMapLayerRegistry::instance()->removeAllMapLayers();

‎src/server/qgsconfigcache.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727

2828
QgsConfigCache* QgsConfigCache::instance()
2929
{
30-
static QgsConfigCache mInstance;
31-
return &mInstance;
30+
static QgsConfigCache *instance = 0;
31+
32+
if ( !instance )
33+
instance = new QgsConfigCache();
34+
35+
return instance;
3236
}
3337

3438
QgsConfigCache::QgsConfigCache()

‎src/server/qgsconfigcache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class QgsConfigCache: public QObject
4444

4545
private:
4646
QgsConfigCache();
47-
static QgsConfigCache* mInstance;
4847

4948
/**Check for configuration file updates (remove entry from cache if file changes)*/
5049
QFileSystemWatcher mFileSystemWatcher;

‎src/server/qgshttprequesthandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ void QgsHttpRequestHandler::setGetFeatureInfoResponse( const QDomDocument& infoD
368368
QDomElement attributeElement = attributeNodeList.at( k ).toElement();
369369
if ( infoFormat == "text/plain" )
370370
{
371-
featureInfoString.append( attributeElement.attribute( "name" ) + " = '" +
372-
attributeElement.attribute( "value" ) + "'\n" );
371+
featureInfoString.append( attributeElement.attribute( "name" ) + " = " +
372+
attributeElement.attribute( "value" ) + "\n" );
373373
}
374374
else if ( infoFormat == "text/html" )
375375
{

‎src/server/qgsserverprojectparser.cpp

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsmaplayerregistry.h"
2525
#include "qgsmslayercache.h"
2626
#include "qgsrasterlayer.h"
27+
#include "qgseditorwidgetregistry.h"
2728

2829
#include <QDomDocument>
2930
#include <QFileInfo>
@@ -241,6 +242,12 @@ QgsMapLayer* QgsServerProjectParser::createLayerFromElement( const QDomElement&
241242

242243
if ( layer )
243244
{
245+
if ( layer->type() == QgsMapLayer::VectorLayer )
246+
{
247+
// see QgsEditorWidgetRegistry::mapLayerAdded()
248+
QObject::connect( layer, SIGNAL( readCustomSymbology( const QDomElement&, QString& ) ), QgsEditorWidgetRegistry::instance(), SLOT( readSymbology( const QDomElement&, QString& ) ) );
249+
}
250+
244251
layer->readLayerXML( const_cast<QDomElement&>( elem ) ); //should be changed to const in QgsMapLayer
245252
layer->setLayerName( layerName( elem ) );
246253
if ( useCache )
@@ -919,50 +926,6 @@ QStringList QgsServerProjectParser::supportedOutputCrsList() const
919926
return crsList;
920927
}
921928

922-
//not very nice, needs to be kept in sync with QgsVectorLayer class...
923-
QString QgsServerProjectParser::editTypeString( QgsVectorLayer::EditType type )
924-
{
925-
switch ( type )
926-
{
927-
case QgsVectorLayer::LineEdit:
928-
return "LineEdit";
929-
case QgsVectorLayer::UniqueValues:
930-
return "UniqueValues";
931-
case QgsVectorLayer::UniqueValuesEditable:
932-
return "UniqueValuesEditable";
933-
case QgsVectorLayer::ValueMap:
934-
return "ValueMap";
935-
case QgsVectorLayer::Classification:
936-
return "Classification";
937-
case QgsVectorLayer::EditRange:
938-
return "EditRange";
939-
case QgsVectorLayer::SliderRange:
940-
return "SliderRange";
941-
case QgsVectorLayer::CheckBox:
942-
return "CheckBox";
943-
case QgsVectorLayer::FileName:
944-
return "FileName";
945-
case QgsVectorLayer::Enumeration:
946-
return "Enumeration";
947-
case QgsVectorLayer::Immutable:
948-
return "Immutable";
949-
case QgsVectorLayer::Hidden:
950-
return "Hidden";
951-
case QgsVectorLayer::TextEdit:
952-
return "TextEdit";
953-
case QgsVectorLayer::Calendar:
954-
return "Calendar";
955-
case QgsVectorLayer::DialRange:
956-
return "DialRange";
957-
case QgsVectorLayer::ValueRelation:
958-
return "ValueRelation";
959-
case QgsVectorLayer::UuidGenerator:
960-
return "UuidGenerator";
961-
default:
962-
return "Unknown";
963-
}
964-
}
965-
966929
QString QgsServerProjectParser::projectTitle() const
967930
{
968931
if ( !mXMLDoc )

‎src/server/qgsserverprojectparser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ class QgsServerProjectParser
7070

7171
QStringList supportedOutputCrsList() const;
7272

73-
static QString editTypeString( QgsVectorLayer::EditType type );
74-
7573
const QList<QDomElement>& projectLayerElements() const { return mProjectLayerElements; }
7674

7775
const QList<QDomElement>& legendGroupElements() const { return mLegendGroupElements; }

‎src/server/qgswmsserver.cpp

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,7 +2094,26 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
20942094

20952095
QDomElement attributeElement = infoDocument.createElement( "Attribute" );
20962096
attributeElement.setAttribute( "name", attributeName );
2097-
attributeElement.setAttribute( "value", replaceValueMapAndRelation( layer, i, QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) ) );
2097+
2098+
QString value;
2099+
if ( featureAttributes[i].isNull() )
2100+
value = QSettings().value( "qgis/nullValue", "NULL" ).toString();
2101+
else
2102+
{
2103+
value = replaceValueMapAndRelation( layer, i, QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) );
2104+
2105+
switch ( featureAttributes[i].type() )
2106+
{
2107+
case QVariant::Int:
2108+
case QVariant::LongLong:
2109+
case QVariant::Double:
2110+
break;
2111+
default:
2112+
value = "'" + value + "'";
2113+
}
2114+
}
2115+
2116+
attributeElement.setAttribute( "value", value );
20982117
featureElement.appendChild( attributeElement );
20992118
}
21002119

@@ -3054,42 +3073,43 @@ QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, c
30543073
QMap<QString, QVariant>::const_iterator vmapIt = cfg.constBegin();
30553074
for ( ; vmapIt != cfg.constEnd(); ++vmapIt )
30563075
{
3057-
if ( vmapIt.value().toString() == attributeVal )
3076+
if ( vmapIt.key() == attributeVal )
30583077
{
3059-
return vmapIt.key();
3078+
return vmapIt.value().toString();
30603079
}
30613080
}
3081+
return QString( "(%1)" ).arg( attributeVal );
30623082
}
30633083
else if ( type == "ValueRelation" )
30643084
{
30653085
QgsEditorWidgetConfig cfg( vl->editorWidgetV2Config( idx ) );
30663086
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( cfg.value( "Layer" ).toString() ) );
30673087
if ( !layer )
30683088
{
3069-
return attributeVal;
3089+
return QString( "(%1)" ).arg( attributeVal );
30703090
}
30713091

30723092
QString outputString;
3073-
if ( cfg.value( "AllowMulti" ).toBool() )
3093+
QString valueString = attributeVal;
3094+
QStringList valueList = cfg.value( "AllowMulti" ).toBool()
3095+
? valueString.remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," )
3096+
: QStringList( valueString );
3097+
for ( int i = 0; i < valueList.size(); ++i )
30743098
{
3075-
QString valueString = attributeVal;
3076-
QStringList valueList = valueString.remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," );
3077-
for ( int i = 0; i < valueList.size(); ++i )
3099+
if ( i > 0 )
30783100
{
3079-
if ( i > 0 )
3080-
{
3081-
outputString += ";";
3082-
}
3083-
outputString += relationValue(
3084-
valueList.at( i ),
3085-
layer,
3086-
cfg.value( "Key" ).toString(),
3087-
cfg.value( "Value" ).toString()
3088-
);
3101+
outputString += ";";
30893102
}
3103+
outputString += relationValue(
3104+
valueList.at( i ),
3105+
layer,
3106+
cfg.value( "Key" ).toString(),
3107+
cfg.value( "Value" ).toString()
3108+
);
30903109
}
30913110
return outputString;
30923111
}
3112+
30933113
return attributeVal;
30943114
}
30953115

0 commit comments

Comments
 (0)
Please sign in to comment.